From 08289158d7ce0328ee23f8b2fb09020da8ac4e9e Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Mon, 16 Aug 2010 17:14:37 +0200 Subject: [PATCH] Added support for WAV files with libsndfile --- CMakeLists.txt | 16 ++++--- apps/openmw/mwsound/soundmanager.cpp | 15 ++++--- apps/soundtest/CMakeLists.txt | 14 ------ apps/soundtest/main.cpp | 65 ---------------------------- cmake/FindSNDFILE.cmake | 41 ++++++++++++++++++ libs/mangle | 2 +- 6 files changed, 59 insertions(+), 94 deletions(-) delete mode 100644 apps/soundtest/CMakeLists.txt delete mode 100644 apps/soundtest/main.cpp create mode 100644 cmake/FindSNDFILE.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b021916..32f4e483a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ project(OpenMW) # Sound source selection -option(USE_AUDIERE "use Audiere for sound" ON) +option(USE_AUDIERE "use Audiere for sound" OFF) option(USE_FFMPEG "use ffmpeg for sound" OFF) -option(USE_MPG123 "use mpg123 for sound" OFF) +option(USE_MPG123 "use mpg123 + libsndfile for sound" ON) # We probably support older versions than this. cmake_minimum_required(VERSION 2.6) @@ -103,6 +103,7 @@ set(OENGINE_GUI if (USE_AUDIERE) set(MANGLE_SOUND_OUTPUT ${LIBDIR}/mangle/sound/sources/audiere_source.cpp + ${LIBDIR}/mangle/sound/sources/sample_reader.cpp ${LIBDIR}/mangle/stream/clients/audiere_file.cpp) find_package(Audiere REQUIRED) set(SOUND_INPUT_INCLUDES ${AUDIERE_INCLUDE_DIR}) @@ -121,10 +122,13 @@ endif (USE_FFMPEG) if (USE_MPG123) set(MANGLE_SOUND_OUTPUT - ${LIBDIR}/mangle/sound/sources/mpg123_source.cpp) + ${LIBDIR}/mangle/sound/sources/mpg123_source.cpp + ${LIBDIR}/mangle/sound/sources/libsndfile.cpp + ${LIBDIR}/mangle/sound/sources/sample_reader.cpp) find_package(MPG123 REQUIRED) - set(SOUND_INPUT_INCLUDES ${MPG123_INCLUDE_DIR}) - set(SOUND_INPUT_LIBRARY ${MPG123_LIBRARY}) + find_package(SNDFILE REQUIRED) + set(SOUND_INPUT_INCLUDES ${MPG123_INCLUDE_DIR} ${SNDFILE_INCLUDE_DIR}) + set(SOUND_INPUT_LIBRARY ${MPG123_LIBRARY} ${SNDFILE_LIBRARY}) set(SOUND_DEFINE -DOPENMW_USE_MPG123) endif (USE_MPG123) @@ -236,5 +240,3 @@ option(BUILD_ESMTOOL "build ESM inspector" ON) if (BUILD_ESMTOOL) add_subdirectory( apps/esmtool ) endif() - -add_subdirectory( apps/soundtest ) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 95b013568..03a118eda 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -13,8 +13,9 @@ using namespace std; #include -/* Set up the sound manager to use Audiere, FFMPEG or MPG123 for - input. The OPENMW_USE_x macros are set in CMakeLists.txt. +/* Set up the sound manager to use Audiere, FFMPEG or + MPG123/libsndfile for input. The OPENMW_USE_x macros are set in + CMakeLists.txt. */ #ifdef OPENMW_USE_AUDIERE #include @@ -27,8 +28,8 @@ using namespace std; #endif #ifdef OPENMW_USE_MPG123 -#include -#define SOUND_FACTORY OpenAL_Mpg123_Factory +#include +#define SOUND_FACTORY OpenAL_SndFile_Mpg123_Factory #endif using namespace Mangle::Sound; @@ -104,8 +105,8 @@ namespace MWSound volume *= snd->data.volume / 255.0; // These factors are not very fine tuned. - min = snd->data.minRange * 4; - max = snd->data.maxRange * 1000; + min = snd->data.minRange * 7; + max = snd->data.maxRange * 2000; std::string file = dir + snd->sound; std::replace(file.begin(), file.end(), '\\', '/'); return file; @@ -188,7 +189,7 @@ namespace MWSound // control volume etc. SoundPtr music = mData->mgr->play(filename); music->setStreaming(true); - music->setVolume(0.6); + music->setVolume(0.4); } void SoundManager::playSound (const std::string& soundId, float volume, float pitch) diff --git a/apps/soundtest/CMakeLists.txt b/apps/soundtest/CMakeLists.txt deleted file mode 100644 index b7ff04039..000000000 --- a/apps/soundtest/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -project(SoundTest) - -# local files - -# Main executable -add_executable(sound_test main.cpp ${OENGINE_SOUND}) - -include_directories(${SOUND_INPUT_INCLUDES}) -add_definitions(${SOUND_DEFINE}) - -target_link_libraries(sound_test - ${OPENAL_LIBRARY} - ${SOUND_INPUT_LIBRARY} -) diff --git a/apps/soundtest/main.cpp b/apps/soundtest/main.cpp deleted file mode 100644 index dde76d9bd..000000000 --- a/apps/soundtest/main.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include - -#include -#include -#include - -using namespace std; -using namespace Mangle::Stream; -using namespace Mangle::Sound; - -#ifdef OPENMW_USE_AUDIERE -#include -AudiereLoader loader; -#endif - -#ifdef OPENMW_USE_FFMPEG -#include -FFMpegLoader loader; -#endif - -#ifdef OPENMW_USE_MPG123 -#include -Mpg123Loader loader; -#endif - -OpenAL_Factory openal; - -void play(const char* name) -{ - try - { - cout << "Opening " << name << "\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