try to have more stable sound failure handling
This commit is contained in:
parent
7740dbbaf4
commit
72706e995a
|
@ -33,6 +33,7 @@ public:
|
|||
}
|
||||
virtual ~DSVoice() {
|
||||
driver->freeVoiceInternal(this,true);
|
||||
if(ds_buf)
|
||||
ds_buf->Release();
|
||||
}
|
||||
DSVoice(OAKRA_Module_OutputDS *driver, OAKRA_Format &format, IDirectSound *ds_dev, bool global) {
|
||||
|
@ -66,9 +67,17 @@ public:
|
|||
HRESULT hr = ds_dev->CreateSoundBuffer(&dsbd,&ds_buf,0);
|
||||
cPlay = 0;
|
||||
|
||||
if(hr)
|
||||
{
|
||||
hr = ds_buf->Play(0,0,DSBPLAY_LOOPING);
|
||||
}
|
||||
|
||||
//if we couldnt create the voice, then a sound card is missing.
|
||||
//we'll use this in getVoice to catch the condition
|
||||
if(!hr)
|
||||
dead = true;
|
||||
}
|
||||
|
||||
//not supported
|
||||
virtual void volFade(int start, int end, int ms) {}
|
||||
|
||||
|
@ -165,13 +174,27 @@ OAKRA_Module_OutputDS::~OAKRA_Module_OutputDS() {
|
|||
|
||||
OAKRA_Voice *OAKRA_Module_OutputDS::getVoice(OAKRA_Format &format, OAKRA_Module *source) {
|
||||
DSVoice *dsv = (DSVoice *)getVoice(format);
|
||||
if(dsv->dead)
|
||||
{
|
||||
delete dsv;
|
||||
}
|
||||
else
|
||||
{
|
||||
dsv->setSource(source);
|
||||
}
|
||||
return dsv;
|
||||
}
|
||||
|
||||
OAKRA_Voice *OAKRA_Module_OutputDS::getVoice(OAKRA_Format &format) {
|
||||
DSVoice *voice = new DSVoice(this,format,((Data *)data)->ds_dev,((Data *)data)->global);
|
||||
if(voice->dead)
|
||||
{
|
||||
delete voice;
|
||||
}
|
||||
else
|
||||
{
|
||||
((Data *)data)->voices.push_back(voice);
|
||||
}
|
||||
return voice;
|
||||
}
|
||||
void OAKRA_Module_OutputDS::freeVoice(OAKRA_Voice *voice) {
|
||||
|
|
|
@ -265,8 +265,10 @@ void TrashSound() {
|
|||
void DoTrashSound() {
|
||||
if(dsout) delete dsout;
|
||||
if(player) delete player;
|
||||
if(player8) delete player8;
|
||||
dsout = 0;
|
||||
player = 0;
|
||||
player8 = 0;
|
||||
trashPending = false;
|
||||
}
|
||||
|
||||
|
@ -293,12 +295,15 @@ void win_Throttle() {
|
|||
player->throttle();
|
||||
}
|
||||
|
||||
static bool killsound;
|
||||
void win_SoundInit(int bits) {
|
||||
killsound = false;
|
||||
dsout = new OAKRA_Module_OutputDS();
|
||||
if(soundoptions&SO_GFOCUS)
|
||||
dsout->start(0);
|
||||
else
|
||||
dsout->start(hAppWnd);
|
||||
|
||||
dsout->beginThread();
|
||||
OAKRA_Format fmt;
|
||||
fmt.format = bits==8?OAKRA_U8:OAKRA_S16;
|
||||
|
@ -306,14 +311,22 @@ void win_SoundInit(int bits) {
|
|||
fmt.rate = soundrate;
|
||||
fmt.size = OAKRA_Module::calcSize(fmt);
|
||||
OAKRA_Voice *voice = dsout->getVoice(fmt);
|
||||
if(!voice)
|
||||
{
|
||||
killsound = true;
|
||||
FCEUD_PrintError("Couldn't initialize sound buffers. Sound disabled");
|
||||
}
|
||||
|
||||
player = new Player();
|
||||
player8 = new Player8(player);
|
||||
|
||||
if(voice)
|
||||
{
|
||||
dsout->lock();
|
||||
if(bits == 8) voice->setSource(player8);
|
||||
else voice->setSource(player);
|
||||
dsout->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -334,6 +347,8 @@ int InitSound() {
|
|||
}
|
||||
|
||||
win_SoundInit(bits);
|
||||
if(killsound)
|
||||
TrashSound();
|
||||
|
||||
FCEUI_Sound(soundrate);
|
||||
return 1;
|
||||
|
@ -354,6 +369,7 @@ void win_SoundWriteData(int32 *buffer, int count) {
|
|||
short *sbuf = (short *)tempbuf;
|
||||
for(int i=0;i<count;i++)
|
||||
sbuf[i] = buffer[i];
|
||||
if(player)
|
||||
player->receive(count*2,tempbuf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue