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,62 +17,44 @@
#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) {
if (!mixer) {
SoundStream *InitSoundStream(std::string backend, CMixer *mixer)
{
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());
}
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") {
PanicAlert("Sound backend %s is not valid, falling back to NULL", backend.c_str());
delete soundStream;
soundStream = new NullSound(mixer);
}
else {
PanicAlert("Cannot recognize backend %s", backend.c_str());
soundStream->Start();
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 soundStream;
}
void ShutdownSoundStream() {
void ShutdownSoundStream()
{
NOTICE_LOG(DSPHLE, "Shutting down sound stream");
if (soundStream) {
if (soundStream)
{
soundStream->Stop();
soundStream->StopLogAudio();
delete soundStream;
@ -80,25 +62,24 @@ void ShutdownSoundStream() {
}
// Check that soundstream already is stopped.
while (soundStream) {
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() {
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");
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;
}
}
} // Namespace

View File

@ -27,11 +27,17 @@ class CMixer;
extern DSPInitialize g_dspInitialize;
extern SoundStream *soundStream;
namespace AudioCommon {
namespace AudioCommon
{
SoundStream *InitSoundStream(std::string backend, CMixer *mixer = NULL);
void ShutdownSoundStream();
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_