forked from snes9xgit/snes9x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFMODEx.cpp
146 lines (116 loc) · 2.96 KB
/
CFMODEx.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifdef FMODEX_SUPPORT
#ifndef FMOD_SUPPORT
#include "CFMODEx.h"
#include "wsnes9x.h"
#include "../snes9x.h"
#include "../apu/apu.h"
CFMODEx::CFMODEx(void)
{
initDone = false;
fmodStream = NULL;
fmodSystem = NULL;
}
CFMODEx::~CFMODEx(void)
{
DeInitFMODEx();
if(fmodSystem)
fmodSystem->release();
}
bool CFMODEx::InitStream()
{
FMOD_CREATESOUNDEXINFO createSoundExInfo={0};
createSoundExInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
createSoundExInfo.defaultfrequency = Settings.SoundPlaybackRate;
createSoundExInfo.numchannels = (Settings.Stereo?2:1);
createSoundExInfo.format = (Settings.SixteenBitSound?FMOD_SOUND_FORMAT_PCM16:FMOD_SOUND_FORMAT_PCM8);
createSoundExInfo.pcmreadcallback = FMODExStreamCallback;
createSoundExInfo.suggestedsoundtype = FMOD_SOUND_TYPE_USER;
//fmodSystem->getDSPBufferSize(&temp,NULL);
// 768 was the bufferSize in FMOD
sampleCount = (Settings.SoundPlaybackRate * GUI.SoundBufferSize/2 ) / 1000;
if (Settings.Stereo)
sampleCount *= 2;
bufferSize = sampleCount * (Settings.SixteenBitSound?2:1);
createSoundExInfo.length = bufferSize;
createSoundExInfo.decodebuffersize = bufferSize/4;
FMOD_RESULT fr = fmodSystem->createStream(NULL,FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_OPENRAW,&createSoundExInfo,&fmodStream);
if(!(fr==FMOD_OK)) {
return false;
}
fr = fmodSystem->playSound(FMOD_CHANNEL_FREE,fmodStream,0,NULL);
return true;
}
void CFMODEx::DeInitStream()
{
if (fmodStream)
{
fmodStream->release();
fmodStream = NULL;
}
}
bool CFMODEx::InitFMODEx()
{
if(initDone)
return true;
FMOD_RESULT fr;
if(!(FMOD::System_Create(&fmodSystem)==FMOD_OK))
return false;
switch (GUI.SoundDriver)
{
default:
case WIN_FMODEX_DEFAULT_DRIVER:
fr = fmodSystem->setOutput(FMOD_OUTPUTTYPE_AUTODETECT);
break;
case WIN_FMODEX_ASIO_DRIVER:
fr = fmodSystem->setOutput(FMOD_OUTPUTTYPE_ASIO);
break;
#if FMOD_VERSION <= 0x00043100
case WIN_FMODEX_OPENAL_DRIVER:
fr = fmodSystem->setOutput(FMOD_OUTPUTTYPE_OPENAL);
break;
#endif
}
fr = fmodSystem->init(2,FMOD_INIT_NORMAL,0);
if(fr!=FMOD_OK)
return false;
initDone = true;
return true;
}
void CFMODEx::DeInitFMODEx()
{
initDone = false;
DeInitStream();
if(fmodSystem) {
fmodSystem->release();
fmodSystem = NULL;
}
}
bool CFMODEx::SetupSound()
{
if(!initDone)
return false;
DeInitStream();
return InitStream();
}
void CFMODEx::ProcessSound()
{
EnterCriticalSection(&GUI.SoundCritSect);
S9xFinalizeSamples();
LeaveCriticalSection(&GUI.SoundCritSect);
}
FMOD_RESULT F_CALLBACK CFMODEx::FMODExStreamCallback(
FMOD_SOUND * sound,
void * data,
unsigned int datalen
)
{
int sample_count = datalen;
sample_count >>= (Settings.SixteenBitSound?1:0);
EnterCriticalSection(&GUI.SoundCritSect);
S9xMixSamples((unsigned char *) data, sample_count);
LeaveCriticalSection(&GUI.SoundCritSect);
SetEvent(GUI.SoundSyncEvent);
return FMOD_OK;
}
#endif
#endif