From 2aa41dfffec4c84ff3a47208aaaa0bf425f417b2 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Thu, 12 Aug 2010 14:49:58 +0200 Subject: [PATCH] Added tests for 3d sound and pausing. --- sound/tests/Makefile | 5 ++- sound/tests/output/sound_3d_test.out | 3 ++ sound/tests/output/sound_manager_test.out | 5 +++ sound/tests/sound_3d_test.cpp | 46 +++++++++++++++++++++++ sound/tests/sound_manager_test.cpp | 27 ++++++++++++- 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 sound/tests/output/sound_3d_test.out create mode 100644 sound/tests/output/sound_manager_test.out create mode 100644 sound/tests/sound_3d_test.cpp diff --git a/sound/tests/Makefile b/sound/tests/Makefile index 9e84cb5803..04952167f7 100644 --- a/sound/tests/Makefile +++ b/sound/tests/Makefile @@ -1,6 +1,6 @@ GCC=g++ -I../ -all: sound_manager_test +all: sound_manager_test sound_3d_test L_FFMPEG=$(shell pkg-config --libs libavcodec libavformat) L_OPENAL=$(shell pkg-config --libs openal) @@ -9,5 +9,8 @@ L_AUDIERE=-laudiere sound_manager_test: sound_manager_test.cpp ../../mangle/sound/sources/audiere_source.cpp ../../mangle/sound/outputs/openal_out.cpp ../../mangle/stream/clients/audiere_file.cpp ../sndmanager.cpp $(GCC) $^ -o $@ $(L_AUDIERE) $(L_OPENAL) -I../.. +sound_3d_test: sound_3d_test.cpp ../../mangle/sound/sources/audiere_source.cpp ../../mangle/sound/outputs/openal_out.cpp ../../mangle/stream/clients/audiere_file.cpp ../sndmanager.cpp + $(GCC) $^ -o $@ $(L_AUDIERE) $(L_OPENAL) -I../.. + clean: rm *_test diff --git a/sound/tests/output/sound_3d_test.out b/sound/tests/output/sound_3d_test.out new file mode 100644 index 0000000000..a443c84f02 --- /dev/null +++ b/sound/tests/output/sound_3d_test.out @@ -0,0 +1,3 @@ +Playing at 0,0,0 +Playing at 1,1,0 +Playing at -1,0,0 diff --git a/sound/tests/output/sound_manager_test.out b/sound/tests/output/sound_manager_test.out new file mode 100644 index 0000000000..2b458493d2 --- /dev/null +++ b/sound/tests/output/sound_manager_test.out @@ -0,0 +1,5 @@ +Playing ../../mangle/sound/tests/cow.wav +Replaying +pause +restart +Done playing. diff --git a/sound/tests/sound_3d_test.cpp b/sound/tests/sound_3d_test.cpp new file mode 100644 index 0000000000..f5b197fd0b --- /dev/null +++ b/sound/tests/sound_3d_test.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +#include +#include + +#include + +using namespace std; +using namespace Mangle::Stream; +using namespace Mangle::Sound; +using namespace OEngine::Sound; + +const std::string sound = "../../mangle/sound/tests/cow.wav"; + +SoundManagerPtr m; + +// Play and wait for finish +void play(float x, float y, float z) +{ + cout << "Playing at " << x << "," << y << "," << z << endl; + + SoundPtr snd = m->play3D(sound,x,y,z); + + while(snd->isPlaying()) + { + usleep(10000); + m->update(); + } +} + +int main() +{ + SoundFactoryPtr oaf(new OpenAL_Audiere_Factory); + SoundManagerPtr mg(new SoundManager(oaf)); + m = mg; + + mg->setListenerPos(0,0,0,0,1,0,0,0,1); + + play(0,0,0); + play(1,1,0); + play(-1,0,0); + + return 0; +} diff --git a/sound/tests/sound_manager_test.cpp b/sound/tests/sound_manager_test.cpp index 7c09cd583d..3794c4a3cf 100644 --- a/sound/tests/sound_manager_test.cpp +++ b/sound/tests/sound_manager_test.cpp @@ -33,15 +33,38 @@ int main() assert(mg->numSounds() == 1); // Loop while there are still sounds to manage - int i=0; while(mg->numSounds() != 0) { - i++; assert(mg->numSounds() == 1); usleep(10000); if(mg->needsUpdate) mg->update(); } + + SoundPtr snd = mg->play(sound); + cout << "Replaying\n"; + int i = 0; + while(mg->numSounds() != 0) + { + assert(mg->numSounds() == 1); + usleep(10000); + if(mg->needsUpdate) + mg->update(); + + if(i++ == 70) + { + cout << "pause\n"; + snd->pause(); + } + if(i == 130) + { + cout << "restart\n"; + snd->play(); + // Let the sound go out of scope + snd.reset(); + } + } + cout << "Done playing.\n"; assert(mg->numSounds() == 0);