00001 #include <stdio.h> 00002 #ifdef _WIN32 00003 #include <windows.h> 00004 #define sleep(x) Sleep(x*1000) 00005 #else 00006 #include <unistd.h> 00007 #endif 00008 00009 #include <simgear/debug/logstream.hxx> 00010 #include <simgear/misc/sg_path.hxx> 00011 00012 #include "soundmgr_openal.hxx" 00013 00014 SGGeod pos = SGGeod::fromDeg(0,0); 00015 00016 int main( int argc, char *argv[] ) { 00017 SGSampleGroup *sgr; 00018 SGSoundMgr *smgr; 00019 00020 smgr = new SGSoundMgr; 00021 00022 smgr->bind(); 00023 smgr->init(); 00024 sgr = smgr->find("default", true); 00025 smgr->set_volume(0.9); 00026 smgr->set_position( SGVec3d::fromGeod(pos), pos ); 00027 smgr->activate(); 00028 00029 SGSoundSample *sample1 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00030 sample1->set_volume(1.0); 00031 sample1->set_pitch(1.0); 00032 sample1->play_looped(); 00033 sgr->add(sample1, "sound1"); 00034 smgr->update(1.0); 00035 printf("playing sample1\n"); 00036 sleep(1); 00037 00038 SGSoundSample *sample2 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00039 sample2->set_volume(0.5); 00040 sample2->set_pitch(0.4); 00041 sample2->play_looped(); 00042 sgr->add(sample2, "sound2"); 00043 smgr->update(1.0); 00044 printf("playing sample2\n"); 00045 sleep(1); 00046 00047 SGSoundSample *sample3 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00048 sample3->set_volume(0.5); 00049 sample3->set_pitch(0.8); 00050 sample3->play_looped(); 00051 sgr->add(sample3, "sound3"); 00052 smgr->update(1.0); 00053 printf("playing sample3\n"); 00054 sleep(1); 00055 00056 SGSoundSample *sample4 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00057 sample4->set_volume(0.5); 00058 sample4->set_pitch(1.2); 00059 sample4->play_looped(); 00060 sgr->add(sample4, "sound4"); 00061 smgr->update(1.0); 00062 printf("playing sample4\n"); 00063 sleep(1); 00064 00065 SGSoundSample *sample5 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00066 sample5->set_volume(0.5); 00067 sample5->set_pitch(1.6); 00068 sample5->play_looped(); 00069 sgr->add(sample5, "sound5"); 00070 smgr->update(1.0); 00071 printf("playing sample5\n"); 00072 sleep(1); 00073 00074 SGSoundSample *sample6 = new SGSoundSample( SRC_DIR, "jet.wav" ); 00075 sample6->set_volume(0.5); 00076 sample6->set_pitch(2.0); 00077 sample6->play_looped(); 00078 sgr->add(sample6, "sound6"); 00079 smgr->update(1.0); 00080 printf("playing sample6\n"); 00081 sleep(1); 00082 00083 for (int i=0; i<10; i++) { 00084 sleep(1); 00085 smgr->update(1); 00086 } 00087 00088 sgr->stop("sound1"); 00089 sgr->stop("sound2"); 00090 sgr->stop("sound3"); 00091 sleep(0.5); 00092 smgr->update(0.5); 00093 sgr->stop("sound4"); 00094 sgr->stop("sound5"); 00095 sgr->stop("sound6"); 00096 smgr->update(1); 00097 sleep(1); 00098 00099 smgr->unbind(); 00100 sleep(2); 00101 delete smgr; 00102 }