summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/Src/AudioCommon.cpp
blob: e8f60bc175ef98d8fc25895ad6a7abc9294cdcec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "AudioCommon.h"
#include "Mixer.h"
#include "AOSoundStream.h"
#include "DSoundStream.h"
#include "NullSoundStream.h"


namespace AudioCommon {
	
SoundStream *InitSoundStream(std::string backend, CMixer *mixer) {

	if (!mixer) {
		mixer = new CMixer();
	}

	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 == "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 soundStream;
}

} // Namespace