From efb7637b00b4c549c1125493de474329d6f88f40 Mon Sep 17 00:00:00 2001 From: skyjake Date: Tue, 6 Nov 2012 21:05:52 +0200 Subject: [PATCH] FluidSynth|Unix: Use the pulseaudio driver by default When using the system libfluidsynth, by default use pulseaudio as the output driver. --- doomsday/plugins/fluidsynth/fluidsynth.pro | 26 +++++++++---------- .../fluidsynth/include/driver_fluidsynth.h | 1 + .../fluidsynth/src/driver_fluidsynth.cpp | 22 ++++++++++++++++ .../fluidsynth/src/fluidsynth_music.cpp | 7 +++++ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/doomsday/plugins/fluidsynth/fluidsynth.pro b/doomsday/plugins/fluidsynth/fluidsynth.pro index c1383b7d72..b1df0744a6 100644 --- a/doomsday/plugins/fluidsynth/fluidsynth.pro +++ b/doomsday/plugins/fluidsynth/fluidsynth.pro @@ -35,10 +35,22 @@ unix:!macx { target.path = $$DENG_PLUGIN_LIB_DIR } +INCLUDEPATH += include + +HEADERS += \ + include/driver_fluidsynth.h \ + include/fluidsynth_music.h \ + include/version.h + +SOURCES += \ + src/driver_fluidsynth.cpp \ + src/fluidsynth_music.cpp + # libfluidsynth config ------------------------------------------------------ !deng_embedfluidsynth { include(../../dep_fluidsynth.pri) + DEFINES += FLUIDSYNTH_DEFAULT_DRIVER_NAME=\"\\\"pulseaudio\\\"\" } deng_embedfluidsynth { @@ -66,20 +78,6 @@ unix { HAVE_NETINET_TCP_H HAVE_FCNTL_H HAVE_ERRNO_H } -# Sources ------------------------------------------------------------------- - -INCLUDEPATH += include - -HEADERS += \ - include/driver_fluidsynth.h \ - include/fluidsynth_music.h \ - include/version.h - -SOURCES += \ - src/driver_fluidsynth.cpp \ - src/fluidsynth_music.cpp - -# libfluidsynth FS_DIR = ../../external/fluidsynth INCLUDEPATH += \ diff --git a/doomsday/plugins/fluidsynth/include/driver_fluidsynth.h b/doomsday/plugins/fluidsynth/include/driver_fluidsynth.h index b94f753e5d..b836fbdf92 100644 --- a/doomsday/plugins/fluidsynth/include/driver_fluidsynth.h +++ b/doomsday/plugins/fluidsynth/include/driver_fluidsynth.h @@ -43,6 +43,7 @@ int DS_Set(int prop, const void* ptr); } fluid_synth_t* DMFluid_Synth(); +fluid_audio_driver_t* DMFluid_Driver(); audiointerface_sfx_generic_t* DMFluid_Sfx(); #ifdef DENG_DSFLUIDSYNTH_DEBUG diff --git a/doomsday/plugins/fluidsynth/src/driver_fluidsynth.cpp b/doomsday/plugins/fluidsynth/src/driver_fluidsynth.cpp index 7df512737b..b874a198a3 100644 --- a/doomsday/plugins/fluidsynth/src/driver_fluidsynth.cpp +++ b/doomsday/plugins/fluidsynth/src/driver_fluidsynth.cpp @@ -29,6 +29,7 @@ static fluid_settings_t* fsConfig; static fluid_synth_t* fsSynth; static audiointerface_sfx_t* fsSfx; +static fluid_audio_driver_t* fsDriver; fluid_synth_t* DMFluid_Synth() { @@ -36,6 +37,11 @@ fluid_synth_t* DMFluid_Synth() return fsSynth; } +fluid_audio_driver_t* DMFluid_Driver() +{ + return fsDriver; +} + audiointerface_sfx_generic_t* DMFluid_Sfx() { DENG_ASSERT(fsSfx != 0); @@ -64,6 +70,18 @@ int DS_Init(void) return false; } +#ifndef FLUIDSYNTH_NOT_A_DLL + // Create the output driver that will play the music. + const char* driverName = FLUIDSYNTH_DEFAULT_DRIVER_NAME; + fluid_settings_setstr(fsConfig, "audio.driver", driverName); + fsDriver = new_fluid_audio_driver(fsConfig, fsSynth); + if(!fsDriver) + { + Con_Message("Failed to create FluidSynth audio driver '%s'.\n", driverName); + return false; + } +#endif + DSFLUIDSYNTH_TRACE("DS_Init: FluidSynth initialized."); return true; } @@ -79,6 +97,10 @@ void DS_Shutdown(void) DSFLUIDSYNTH_TRACE("DS_Shutdown."); + if(fsDriver) + { + delete_fluid_audio_driver(fsDriver); + } delete_fluid_synth(fsSynth); delete_fluid_settings(fsConfig); diff --git a/doomsday/plugins/fluidsynth/src/fluidsynth_music.cpp b/doomsday/plugins/fluidsynth/src/fluidsynth_music.cpp index 27dcfa6646..022c2f0df2 100644 --- a/doomsday/plugins/fluidsynth/src/fluidsynth_music.cpp +++ b/doomsday/plugins/fluidsynth/src/fluidsynth_music.cpp @@ -238,6 +238,7 @@ static int streamOutSamples(sfxbuffer_t* buf, void* data, unsigned int size) static void startWorker() { + DENG_ASSERT(DMFluid_Driver() == NULL); DENG_ASSERT(worker == NULL); workerShouldStop = false; @@ -249,6 +250,8 @@ static void startWorker() */ static void startPlayer() { + if(DMFluid_Driver()) return; + DENG_ASSERT(!worker); DENG_ASSERT(sfxBuf == NULL); @@ -278,6 +281,8 @@ static void startPlayer() static void stopWorker() { + DENG_ASSERT(DMFluid_Driver() == NULL); + if(worker) { DSFLUIDSYNTH_TRACE("stopWorker: Stopping thread " << worker); @@ -292,6 +297,8 @@ static void stopWorker() static void stopPlayer() { + if(DMFluid_Driver()) return; + DSFLUIDSYNTH_TRACE("stopPlayer: fsPlayer " << fsPlayer); if(!fsPlayer) return;