From cf4185faef2db62e9baea94eb36c6e0ab2880e39 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 13 Aug 2010 14:43:57 +0200 Subject: [PATCH] Added sound test (remember to git submodule update) --- CMakeLists.txt | 2 ++ apps/soundtest/CMakeLists.txt | 11 ++++++++ apps/soundtest/main.cpp | 52 +++++++++++++++++++++++++++++++++++ libs/mangle | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 apps/soundtest/CMakeLists.txt create mode 100644 apps/soundtest/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 34925152a3..97f8ba6b36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,3 +200,5 @@ option(BUILD_ESMTOOL "build ESM inspector" ON) if (BUILD_ESMTOOL) add_subdirectory( apps/esmtool ) endif() + +add_subdirectory( apps/soundtest ) diff --git a/apps/soundtest/CMakeLists.txt b/apps/soundtest/CMakeLists.txt new file mode 100644 index 0000000000..81ea7a395e --- /dev/null +++ b/apps/soundtest/CMakeLists.txt @@ -0,0 +1,11 @@ +project(SoundTest) + +# local files + +# Main executable +add_executable(sound_test main.cpp ${OENGINE_SOUND}) + +target_link_libraries(sound_test + ${OPENAL_LIBRARY} + ${AUDIERE_LIBRARY} +) diff --git a/apps/soundtest/main.cpp b/apps/soundtest/main.cpp new file mode 100644 index 0000000000..a645d37537 --- /dev/null +++ b/apps/soundtest/main.cpp @@ -0,0 +1,52 @@ +#include + +#include +#include +#include +#include + +using namespace std; +using namespace Mangle::Stream; +using namespace Mangle::Sound; + +AudiereLoader loader; +OpenAL_Factory openal; + +void play(const char* name) +{ + try + { + cout << "Opening " << name << " via Audiere\n"; + SampleSourcePtr samples = loader.load(name); + cout << "Loading entire file into memory\n"; + StreamPtr buf(new BufferStream(samples)); + + // Recreate the stream as a sample source (we're only doing it + // this complicated to test each step individually) + int a,b,c; + samples->getInfo(&a,&b,&c); + samples.reset(new Stream2Samples(buf, a,b,c)); + + cout << "Creating OpenAL sound from data\n"; + SoundPtr snd = openal.loadRaw(samples); + cout << "Playing (abort with Ctrl-C)\n"; + snd->play(); + + while(snd->isPlaying()) + usleep(10000); + cout << "Done playing\n"; + } + catch(exception &e) + { + cout << " ERROR: " << e.what() << "\n"; + } +} + +int main(int argc, char** argv) +{ + if(argc==1) + cout << "Specify sound file (wav, mp3, ogg) on command line.\n"; + for(int i=1; i