]> git.mxchange.org Git - simgear.git/blob - simgear/sound/openal_test4.cxx
One more Linux compile fix.
[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->init("OSS Default");
25     sgr = smgr->find("default", true);
26     smgr->set_volume(0.9);
27     smgr->activate();
28
29
30     void *data;
31     size_t len;
32     int freq, fmt;
33     string file = SRC_DIR"/jet.wav";
34     smgr->load(file, &data, &fmt, &len, &freq);
35
36     squeue = new SGSampleQueue( freq, fmt );
37     sgr->add(squeue, "queue");
38
39     squeue->add(  data, len );
40     squeue->add(  data, len );
41     squeue->play();
42     printf("playing queue\n");
43
44     smgr->update(1.0);
45     sleep(10);
46     smgr->update(10.0);
47
48     printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
49     pos = SGGeod::fromDeg(9.99,-9.99);
50     squeue->set_position( SGVec3d::fromGeod(SGGeod::fromDeg(10,-10)) );
51     smgr->set_position( SGVec3d::fromGeod(pos), pos );
52
53     squeue->add(  data, len );
54     squeue->add(  data, len );
55     squeue->play( true ); // play looped
56     printf("playing queue\n");
57
58     smgr->update(1.0);
59     sleep(10);
60     smgr->update(10.0);
61
62     squeue->stop();
63     smgr->update(1.0);
64     sleep(1);
65
66     sgr->remove("queue");
67     smgr->unbind();
68     sleep(2);
69
70     delete smgr;
71 }