]> git.mxchange.org Git - simgear.git/blob - simgear/sound/openal_test4.cxx
Sound Manager: support subsystem reinit,
[simgear.git] / simgear / sound / openal_test4.cxx
1 #include <stdio.h>
2 #ifdef _WIN32
3 #include <windows.h>
4 #define sleep(x) Sleep(x*1000)
5 #else
6 #include <unistd.h>
7 #endif
8
9 #include <simgear/debug/logstream.hxx>
10 #include <simgear/misc/sg_path.hxx>
11
12 #include "soundmgr_openal.hxx"
13
14
15 int main( int argc, char *argv[] ) {
16     SGSampleQueue *squeue;
17     SGSampleGroup *sgr;
18     SGSoundMgr *smgr;
19     SGGeod pos;
20
21     smgr = new SGSoundMgr;
22
23     smgr->bind();
24     smgr->select_device("OSS Default");
25     smgr->init();
26     sgr = smgr->find("default", true);
27     smgr->set_volume(0.9);
28     smgr->activate();
29
30
31     void *data;
32     size_t len;
33     int freq, fmt;
34     string file = SRC_DIR"/jet.wav";
35     smgr->load(file, &data, &fmt, &len, &freq);
36
37     squeue = new SGSampleQueue( freq, fmt );
38     sgr->add(squeue, "queue");
39
40     squeue->add(  data, len );
41     squeue->add(  data, len );
42     squeue->play();
43     printf("playing queue\n");
44
45     smgr->update(1.0);
46     sleep(10);
47     smgr->update(10.0);
48
49     printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
50     pos = SGGeod::fromDeg(9.99,-9.99);
51     squeue->set_position( SGVec3d::fromGeod(SGGeod::fromDeg(10,-10)) );
52     smgr->set_position( SGVec3d::fromGeod(pos), pos );
53
54     squeue->add(  data, len );
55     squeue->add(  data, len );
56     squeue->play( true ); // play looped
57     printf("playing queue\n");
58
59     smgr->update(1.0);
60     sleep(10);
61     smgr->update(10.0);
62
63     squeue->stop();
64     smgr->update(1.0);
65     sleep(1);
66
67     sgr->remove("queue");
68     smgr->unbind();
69     sleep(2);
70
71     delete smgr;
72 }