]> git.mxchange.org Git - simgear.git/blob - simgear/sound/openal_test4.cxx
Reset: allow re-init of Nasal Ghosts.
[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 #include "sample_group.hxx"
14 #include "sample_openal.hxx"
15
16 int main( int argc, char *argv[] ) {
17     SGSampleQueue *squeue;
18     SGSampleGroup *sgr;
19     SGSoundMgr *smgr;
20     SGGeod pos;
21
22     smgr = new SGSoundMgr;
23
24     smgr->bind();
25     smgr->select_device("OSS Default");
26     smgr->init();
27     sgr = smgr->find("default", true);
28     smgr->set_volume(0.9);
29     smgr->activate();
30     smgr->set_position( SGVec3d::fromGeod(SGGeod()), SGGeod() );
31
32     void *data;
33     size_t len;
34     int freq, fmt;
35     std::string file = SRC_DIR"/jet.wav";
36     smgr->load(file, &data, &fmt, &len, &freq);
37
38     squeue = new SGSampleQueue( freq, fmt );
39     squeue->set_volume(1.0);
40   
41     sgr->add(squeue, "queue");
42
43     squeue->add(  data, len );
44     squeue->add(  data, len );
45     squeue->play();
46     printf("playing queue\n");
47
48     smgr->update(1.0);
49     sleep(10);
50     smgr->update(10.0);
51
52     printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
53     pos = SGGeod::fromDeg(9.99,-9.99);
54     sgr->set_position_geod( SGGeod::fromDeg(10,-10) );
55     smgr->set_position( SGVec3d::fromGeod(pos), pos );
56
57     squeue->add(  data, len );
58     squeue->add(  data, len );
59     squeue->play( true ); // play looped
60     printf("playing queue\n");
61
62     smgr->update(1.0);
63     sleep(10);
64     smgr->update(10.0);
65
66     squeue->stop();
67     smgr->update(1.0);
68     sleep(1);
69
70     sgr->remove("queue");
71     smgr->unbind();
72     sleep(2);
73
74     delete smgr;
75 }