diff --git a/Source/Core/AudioCommon/Src/AudioCommon.cpp b/Source/Core/AudioCommon/Src/AudioCommon.cpp index fae1a405e0..227035a817 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommon.cpp @@ -17,88 +17,69 @@ #include "AudioCommon.h" #include "Mixer.h" -#include "AOSoundStream.h" #include "DSoundStream.h" +#include "AOSoundStream.h" #include "NullSoundStream.h" #include "OpenALStream.h" namespace AudioCommon { -SoundStream *InitSoundStream(std::string backend, CMixer *mixer) { + SoundStream *InitSoundStream(std::string backend, CMixer *mixer) + { + if (!mixer) + mixer = new CMixer(); - if (!mixer) { - mixer = new CMixer(); - } + if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd); + if (backend == BACKEND_AOSOUND && AOSound::isValid()) soundStream = new AOSound(mixer); + if (backend == BACKEND_OPENAL && OpenALStream::isValid()) soundStream = new OpenALStream(mixer); + if (backend == BACKEND_NULL && NullSound::isValid()) soundStream = new NullSound(mixer); + + if (soundStream != NULL) { + if (soundStream->Start()) + return soundStream; + PanicAlert("Could not initialize backend %s, falling back to NULL", backend.c_str()); + } + + PanicAlert("Sound backend %s is not valid, falling back to NULL", backend.c_str()); - if (backend == "DSound") { - if (DSound::isValid()) - soundStream = new DSound(mixer, g_dspInitialize.hWnd); - } - else if (backend == "AOSound") { - if (AOSound::isValid()) - soundStream = new AOSound(mixer); - } - else if (backend == "OpenAL") { - if (OpenALStream::isValid()) - soundStream = new OpenALStream(mixer); - } - else if (backend == "NullSound") { - soundStream = new NullSound(mixer); - } - else { - PanicAlert("Cannot recognize backend %s", backend.c_str()); - return NULL; - } - - if (soundStream) { - if (!soundStream->Start()) { - PanicAlert("Could not initialize backend %s, falling back to NULL", - backend.c_str()); - delete soundStream; - soundStream = new NullSound(mixer); - soundStream->Start(); - } - } - else { - PanicAlert("Sound backend %s is not valid, falling back to NULL", - backend.c_str()); delete soundStream; soundStream = new NullSound(mixer); soundStream->Start(); + + return NULL; } - return soundStream; -} -void ShutdownSoundStream() { - NOTICE_LOG(DSPHLE, "Shutting down sound stream"); + void ShutdownSoundStream() + { + NOTICE_LOG(DSPHLE, "Shutting down sound stream"); - if (soundStream) { - soundStream->Stop(); - soundStream->StopLogAudio(); - delete soundStream; - soundStream = NULL; + if (soundStream) + { + soundStream->Stop(); + soundStream->StopLogAudio(); + delete soundStream; + soundStream = NULL; + } + + // Check that soundstream already is stopped. + while (soundStream) + { + ERROR_LOG(DSPHLE, "Waiting for sound stream"); + Common::SleepCurrentThread(2000); + } + + INFO_LOG(DSPHLE, "Done shutting down sound stream"); } - - // Check that soundstream already is stopped. - while (soundStream) { - ERROR_LOG(DSPHLE, "Waiting for sound stream"); - Common::SleepCurrentThread(2000); + + std::vector GetSoundBackends() + { + std::vector backends; + + if (DSound::isValid()) backends.push_back(BACKEND_DIRECTSOUND); + if (DSound::isValid()) backends.push_back(BACKEND_AOSOUND); + if (DSound::isValid()) backends.push_back(BACKEND_OPENAL); + if (DSound::isValid()) backends.push_back(BACKEND_NULL); + + return backends; } - INFO_LOG(DSPHLE, "Done shutting down sound stream"); } - -std::vector GetSoundBackends() { - std::vector backends; - // Add avaliable output options - if (DSound::isValid()) - backends.push_back("DSound"); - if (AOSound::isValid()) - backends.push_back("AOSound"); - if (OpenALStream::isValid()) - backends.push_back("OpenAL"); - backends.push_back("NullSound"); - - return backends; -} - -} // Namespace diff --git a/Source/Core/AudioCommon/Src/AudioCommon.h b/Source/Core/AudioCommon/Src/AudioCommon.h index ad043eb6c4..10451a8743 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.h +++ b/Source/Core/AudioCommon/Src/AudioCommon.h @@ -13,25 +13,31 @@ // If not, see http://www.gnu.org/licenses/ // Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#ifndef _AUDIO_COMMON_H_ -#define _AUDIO_COMMON_H_ - -#include "Common.h" -#include "../../../PluginSpecs/pluginspecs_dsp.h" -#include "SoundStream.h" - -class CMixer; - -extern DSPInitialize g_dspInitialize; -extern SoundStream *soundStream; - -namespace AudioCommon { - - SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL); - void ShutdownSoundStream(); - std::vector GetSoundBackends(); -} // Namespace - -#endif // _AUDIO_COMMON_H_ +// http://code.google.com/p/dolphin-emu/ + +#ifndef _AUDIO_COMMON_H_ +#define _AUDIO_COMMON_H_ + +#include "Common.h" +#include "../../../PluginSpecs/pluginspecs_dsp.h" +#include "SoundStream.h" + +class CMixer; + +extern DSPInitialize g_dspInitialize; +extern SoundStream *soundStream; + +namespace AudioCommon +{ + SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL); + void ShutdownSoundStream(); + std::vector GetSoundBackends(); + + // Backend Types + #define BACKEND_DIRECTSOUND "DSound" + #define BACKEND_AOSOUND "AOSound" + #define BACKEND_OPENAL "OpenAL" + #define BACKEND_NULL "NullSound" +} + +#endif // _AUDIO_COMMON_H_