AudioCommon.cpp cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2784 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox 2009-03-29 00:48:46 +00:00
parent 5d9871e85e
commit 2a5866d5f1
2 changed files with 77 additions and 90 deletions

View File

@ -17,88 +17,69 @@
#include "AudioCommon.h" #include "AudioCommon.h"
#include "Mixer.h" #include "Mixer.h"
#include "AOSoundStream.h"
#include "DSoundStream.h" #include "DSoundStream.h"
#include "AOSoundStream.h"
#include "NullSoundStream.h" #include "NullSoundStream.h"
#include "OpenALStream.h" #include "OpenALStream.h"
namespace AudioCommon namespace AudioCommon
{ {
SoundStream *InitSoundStream(std::string backend, CMixer *mixer) { SoundStream *InitSoundStream(std::string backend, CMixer *mixer)
{
if (!mixer)
mixer = new CMixer();
if (!mixer) { if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd);
mixer = new CMixer(); 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 (backend == "DSound") { if (soundStream != NULL) {
if (DSound::isValid()) if (soundStream->Start())
soundStream = new DSound(mixer, g_dspInitialize.hWnd); return soundStream;
} PanicAlert("Could not initialize backend %s, falling back to NULL", backend.c_str());
else if (backend == "AOSound") { }
if (AOSound::isValid())
soundStream = new AOSound(mixer); PanicAlert("Sound backend %s is not valid, falling back to NULL", backend.c_str());
}
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; delete soundStream;
soundStream = new NullSound(mixer); soundStream = new NullSound(mixer);
soundStream->Start(); soundStream->Start();
}
return soundStream;
}
void ShutdownSoundStream() { return NULL;
NOTICE_LOG(DSPHLE, "Shutting down sound stream");
if (soundStream) {
soundStream->Stop();
soundStream->StopLogAudio();
delete soundStream;
soundStream = NULL;
} }
// Check that soundstream already is stopped. void ShutdownSoundStream()
while (soundStream) { {
ERROR_LOG(DSPHLE, "Waiting for sound stream"); NOTICE_LOG(DSPHLE, "Shutting down sound stream");
Common::SleepCurrentThread(2000);
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");
}
std::vector<std::string> GetSoundBackends()
{
std::vector<std::string> 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<std::string> GetSoundBackends() {
std::vector<std::string> 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

View File

@ -27,11 +27,17 @@ class CMixer;
extern DSPInitialize g_dspInitialize; extern DSPInitialize g_dspInitialize;
extern SoundStream *soundStream; extern SoundStream *soundStream;
namespace AudioCommon { namespace AudioCommon
{
SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL); SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL);
void ShutdownSoundStream(); void ShutdownSoundStream();
std::vector<std::string> GetSoundBackends(); std::vector<std::string> GetSoundBackends();
} // Namespace
// Backend Types
#define BACKEND_DIRECTSOUND "DSound"
#define BACKEND_AOSOUND "AOSound"
#define BACKEND_OPENAL "OpenAL"
#define BACKEND_NULL "NullSound"
}
#endif // _AUDIO_COMMON_H_ #endif // _AUDIO_COMMON_H_