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 "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<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

@ -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<std::string> 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<std::string> GetSoundBackends();
// Backend Types
#define BACKEND_DIRECTSOUND "DSound"
#define BACKEND_AOSOUND "AOSound"
#define BACKEND_OPENAL "OpenAL"
#define BACKEND_NULL "NullSound"
}
#endif // _AUDIO_COMMON_H_