1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 04:23:53 +00:00

Added tests for 3d sound and pausing.

This commit is contained in:
Nicolay Korslund 2010-08-12 14:49:58 +02:00
parent e2e5a2138d
commit 2aa41dfffe
5 changed files with 83 additions and 3 deletions

View file

@ -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

View file

@ -0,0 +1,3 @@
Playing at 0,0,0
Playing at 1,1,0
Playing at -1,0,0

View file

@ -0,0 +1,5 @@
Playing ../../mangle/sound/tests/cow.wav
Replaying
pause
restart
Done playing.

View file

@ -0,0 +1,46 @@
#include <iostream>
#include <exception>
#include <assert.h>
#include <mangle/stream/servers/file_stream.hpp>
#include <mangle/sound/filters/openal_audiere.hpp>
#include <sound/sndmanager.hpp>
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;
}

View file

@ -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);