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