Fix for sound still playing while menu is opened.
While I'm at it, make snddx.cpp more C++.
This commit is contained in:
parent
2a0edb3c90
commit
1fcd48722a
|
@ -1198,8 +1198,8 @@ static void StepRunLoop_Core()
|
||||||
{
|
{
|
||||||
Lock lock;
|
Lock lock;
|
||||||
NDS_exec<false>();
|
NDS_exec<false>();
|
||||||
SPU_Emulate_user();
|
|
||||||
win_sound_samplecounter = 735;
|
win_sound_samplecounter = 735;
|
||||||
|
SPU_Emulate_user();
|
||||||
}
|
}
|
||||||
inFrameBoundary = true;
|
inFrameBoundary = true;
|
||||||
DRV_AviVideoUpdate((u16*)GPU_screen);
|
DRV_AviVideoUpdate((u16*)GPU_screen);
|
||||||
|
@ -2990,6 +2990,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||||
{
|
{
|
||||||
case WM_ENTERMENULOOP: //Update menu items that needs to be updated dynamically
|
case WM_ENTERMENULOOP: //Update menu items that needs to be updated dynamically
|
||||||
{
|
{
|
||||||
|
SPU_Pause(1);
|
||||||
|
|
||||||
UpdateHotkeyAssignments(); //Add current hotkey mappings to menu item names
|
UpdateHotkeyAssignments(); //Add current hotkey mappings to menu item names
|
||||||
|
|
||||||
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
||||||
|
@ -3125,11 +3127,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*case WM_EXITMENULOOP:
|
case WM_EXITMENULOOP:
|
||||||
{
|
{
|
||||||
if (tmp_execute==2) NDS_UnPause();
|
SPU_Pause(0);
|
||||||
return 0;
|
return 0;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,7 +70,7 @@ static int issoundmuted;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
extern volatile int win_sound_samplecounter;
|
//extern volatile int win_sound_samplecounter;
|
||||||
|
|
||||||
|
|
||||||
int SNDDXInit(int buffersize)
|
int SNDDXInit(int buffersize)
|
||||||
|
@ -87,7 +87,7 @@ int SNDDXInit(int buffersize)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = IDirectSound8_SetCooperativeLevel(lpDS8, MainWindow->getHWnd(), DSSCL_PRIORITY)) != DS_OK)
|
if ((ret = lpDS8->SetCooperativeLevel(MainWindow->getHWnd(), DSSCL_PRIORITY)) != DS_OK)
|
||||||
{
|
{
|
||||||
sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
||||||
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
||||||
|
@ -100,7 +100,7 @@ int SNDDXInit(int buffersize)
|
||||||
dsbdesc.dwBufferBytes = 0;
|
dsbdesc.dwBufferBytes = 0;
|
||||||
dsbdesc.lpwfxFormat = NULL;
|
dsbdesc.lpwfxFormat = NULL;
|
||||||
|
|
||||||
if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB, NULL)) != DS_OK)
|
if ((ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB, NULL)) != DS_OK)
|
||||||
{
|
{
|
||||||
sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
||||||
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
||||||
|
@ -117,7 +117,7 @@ int SNDDXInit(int buffersize)
|
||||||
wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
|
wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
|
||||||
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
||||||
|
|
||||||
if ((ret = IDirectSoundBuffer8_SetFormat(lpDSB, &wfx)) != DS_OK)
|
if ((ret = lpDSB->SetFormat(&wfx)) != DS_OK)
|
||||||
{
|
{
|
||||||
sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
||||||
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
||||||
|
@ -132,7 +132,7 @@ int SNDDXInit(int buffersize)
|
||||||
dsbdesc.dwBufferBytes = soundbufsize;
|
dsbdesc.dwBufferBytes = soundbufsize;
|
||||||
dsbdesc.lpwfxFormat = &wfx;
|
dsbdesc.lpwfxFormat = &wfx;
|
||||||
|
|
||||||
if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB2, NULL)) != DS_OK)
|
if ((ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)) != DS_OK)
|
||||||
{
|
{
|
||||||
if (ret == DSERR_CONTROLUNAVAIL ||
|
if (ret == DSERR_CONTROLUNAVAIL ||
|
||||||
ret == DSERR_INVALIDCALL ||
|
ret == DSERR_INVALIDCALL ||
|
||||||
|
@ -144,7 +144,7 @@ int SNDDXInit(int buffersize)
|
||||||
DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
|
DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
|
||||||
DSBCAPS_LOCSOFTWARE;
|
DSBCAPS_LOCSOFTWARE;
|
||||||
|
|
||||||
if ((ret = IDirectSound8_CreateSoundBuffer(lpDS8, &dsbdesc, &lpDSB2, NULL)) != DS_OK)
|
if ((ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)) != DS_OK)
|
||||||
{
|
{
|
||||||
sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
|
||||||
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION);
|
||||||
|
@ -159,9 +159,9 @@ int SNDDXInit(int buffersize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirectSoundBuffer8_Play(lpDSB2, 0, 0, DSBPLAY_LOOPING);
|
lpDSB2->Play(0, 0, DSBPLAY_LOOPING);
|
||||||
|
|
||||||
if ((stereodata16 = (s16 *)malloc(soundbufsize)) == NULL)
|
if ((stereodata16 = new s16[soundbufsize / sizeof(s16)]) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(stereodata16, 0, soundbufsize);
|
memset(stereodata16, 0, soundbufsize);
|
||||||
|
@ -180,24 +180,24 @@ void SNDDXDeInit()
|
||||||
|
|
||||||
if (lpDSB2)
|
if (lpDSB2)
|
||||||
{
|
{
|
||||||
IDirectSoundBuffer8_GetStatus(lpDSB2, &status);
|
lpDSB2->GetStatus(&status);
|
||||||
|
|
||||||
if(status == DSBSTATUS_PLAYING)
|
if(status == DSBSTATUS_PLAYING)
|
||||||
IDirectSoundBuffer8_Stop(lpDSB2);
|
lpDSB2->Stop();
|
||||||
|
|
||||||
IDirectSoundBuffer8_Release(lpDSB2);
|
lpDSB2->Release();
|
||||||
lpDSB2 = NULL;
|
lpDSB2 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpDSB)
|
if (lpDSB)
|
||||||
{
|
{
|
||||||
IDirectSoundBuffer8_Release(lpDSB);
|
lpDSB->Release();
|
||||||
lpDSB = NULL;
|
lpDSB = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpDS8)
|
if (lpDS8)
|
||||||
{
|
{
|
||||||
IDirectSound8_Release(lpDS8);
|
lpDS8->Release();
|
||||||
lpDS8 = NULL;
|
lpDS8 = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,27 +211,27 @@ void SNDDXUpdateAudio(s16 *buffer, u32 num_samples)
|
||||||
DWORD buffer1_size, buffer2_size;
|
DWORD buffer1_size, buffer2_size;
|
||||||
DWORD status;
|
DWORD status;
|
||||||
|
|
||||||
int samplecounter;
|
/* int samplecounter;
|
||||||
{
|
{
|
||||||
Lock lock;
|
Lock lock;
|
||||||
samplecounter = win_sound_samplecounter -= num_samples;
|
samplecounter = win_sound_samplecounter -= num_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool silence = (samplecounter<-44100*15/60); //behind by more than a quarter second -> silence
|
bool silence = (samplecounter<-44100*15/60); //behind by more than a quarter second -> silence
|
||||||
|
*/
|
||||||
IDirectSoundBuffer8_GetStatus(lpDSB2, &status);
|
lpDSB2->GetStatus(&status);
|
||||||
|
|
||||||
if (status & DSBSTATUS_BUFFERLOST)
|
if (status & DSBSTATUS_BUFFERLOST)
|
||||||
return; // fix me
|
return; // fix me
|
||||||
|
|
||||||
IDirectSoundBuffer8_Lock(lpDSB2, soundoffset, num_samples * sizeof(s16) * 2, &buffer1, &buffer1_size, &buffer2, &buffer2_size, 0);
|
lpDSB2->Lock(soundoffset, num_samples * sizeof(s16) * 2, &buffer1, &buffer1_size, &buffer2, &buffer2_size, 0);
|
||||||
|
|
||||||
if(silence) {
|
/* if(silence) {
|
||||||
memset(buffer1, 0, buffer1_size);
|
memset(buffer1, 0, buffer1_size);
|
||||||
if(buffer2)
|
if(buffer2)
|
||||||
memset(buffer2, 0, buffer2_size);
|
memset(buffer2, 0, buffer2_size);
|
||||||
}
|
}
|
||||||
else
|
else*/
|
||||||
{
|
{
|
||||||
memcpy(buffer1, buffer, buffer1_size);
|
memcpy(buffer1, buffer, buffer1_size);
|
||||||
if (buffer2)
|
if (buffer2)
|
||||||
|
@ -241,17 +241,18 @@ void SNDDXUpdateAudio(s16 *buffer, u32 num_samples)
|
||||||
soundoffset += buffer1_size + buffer2_size;
|
soundoffset += buffer1_size + buffer2_size;
|
||||||
soundoffset %= soundbufsize;
|
soundoffset %= soundbufsize;
|
||||||
|
|
||||||
IDirectSoundBuffer8_Unlock(lpDSB2, buffer1, buffer1_size, buffer2, buffer2_size);
|
lpDSB2->Unlock(buffer1, buffer1_size, buffer2, buffer2_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
u32 SNDDXGetAudioSpace()
|
u32 SNDDXGetAudioSpace()
|
||||||
{
|
{
|
||||||
|
//return 735;
|
||||||
DWORD playcursor, writecursor;
|
DWORD playcursor, writecursor;
|
||||||
u32 freespace=0;
|
u32 freespace=0;
|
||||||
|
|
||||||
if (IDirectSoundBuffer8_GetCurrentPosition (lpDSB2, &playcursor, &writecursor) != DS_OK)
|
if (lpDSB2->GetCurrentPosition(&playcursor, &writecursor) != DS_OK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (soundoffset > playcursor)
|
if (soundoffset > playcursor)
|
||||||
|
@ -270,7 +271,7 @@ u32 SNDDXGetAudioSpace()
|
||||||
void SNDDXMuteAudio()
|
void SNDDXMuteAudio()
|
||||||
{
|
{
|
||||||
issoundmuted = 1;
|
issoundmuted = 1;
|
||||||
IDirectSoundBuffer8_SetVolume (lpDSB2, DSBVOLUME_MIN);
|
lpDSB2->SetVolume(DSBVOLUME_MIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -278,7 +279,7 @@ void SNDDXMuteAudio()
|
||||||
void SNDDXUnMuteAudio()
|
void SNDDXUnMuteAudio()
|
||||||
{
|
{
|
||||||
issoundmuted = 0;
|
issoundmuted = 0;
|
||||||
IDirectSoundBuffer8_SetVolume (lpDSB2, soundvolume);
|
lpDSB2->SetVolume(soundvolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -288,7 +289,7 @@ void SNDDXSetVolume(int volume)
|
||||||
if (!lpDSB2) return ; /* might happen when changing sounddevice on the fly, caused a gpf */
|
if (!lpDSB2) return ; /* might happen when changing sounddevice on the fly, caused a gpf */
|
||||||
soundvolume = (((LONG)volume) - 100) * 100;
|
soundvolume = (((LONG)volume) - 100) * 100;
|
||||||
if (!issoundmuted)
|
if (!issoundmuted)
|
||||||
IDirectSoundBuffer8_SetVolume (lpDSB2, soundvolume);
|
lpDSB2->SetVolume(soundvolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue