diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 41c132954..3473448a3 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -1198,8 +1198,8 @@ static void StepRunLoop_Core() { Lock lock; NDS_exec(); - SPU_Emulate_user(); win_sound_samplecounter = 735; + SPU_Emulate_user(); } inFrameBoundary = true; 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 { + SPU_Pause(1); + UpdateHotkeyAssignments(); //Add current hotkey mappings to menu item names MENUITEMINFO mii; @@ -3125,11 +3127,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM return 0; } - /*case WM_EXITMENULOOP: + case WM_EXITMENULOOP: { - if (tmp_execute==2) NDS_UnPause(); - return 0; - }*/ + SPU_Pause(0); + return 0; + } case WM_CREATE: { diff --git a/desmume/src/windows/snddx.cpp b/desmume/src/windows/snddx.cpp index acf7e7369..8aad1d8f4 100755 --- a/desmume/src/windows/snddx.cpp +++ b/desmume/src/windows/snddx.cpp @@ -70,7 +70,7 @@ static int issoundmuted; ////////////////////////////////////////////////////////////////////////////// -extern volatile int win_sound_samplecounter; +//extern volatile int win_sound_samplecounter; int SNDDXInit(int buffersize) @@ -87,7 +87,7 @@ int SNDDXInit(int buffersize) 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)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); @@ -100,7 +100,7 @@ int SNDDXInit(int buffersize) dsbdesc.dwBufferBytes = 0; 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)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); @@ -117,7 +117,7 @@ int SNDDXInit(int buffersize) wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels; 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)); MessageBox (NULL, tempstr, "Error", MB_OK | MB_ICONINFORMATION); @@ -132,7 +132,7 @@ int SNDDXInit(int buffersize) dsbdesc.dwBufferBytes = soundbufsize; 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 || ret == DSERR_INVALIDCALL || @@ -144,7 +144,7 @@ int SNDDXInit(int buffersize) DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 | 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)); 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; memset(stereodata16, 0, soundbufsize); @@ -180,24 +180,24 @@ void SNDDXDeInit() if (lpDSB2) { - IDirectSoundBuffer8_GetStatus(lpDSB2, &status); + lpDSB2->GetStatus(&status); if(status == DSBSTATUS_PLAYING) - IDirectSoundBuffer8_Stop(lpDSB2); + lpDSB2->Stop(); - IDirectSoundBuffer8_Release(lpDSB2); + lpDSB2->Release(); lpDSB2 = NULL; } if (lpDSB) { - IDirectSoundBuffer8_Release(lpDSB); + lpDSB->Release(); lpDSB = NULL; } if (lpDS8) { - IDirectSound8_Release(lpDS8); + lpDS8->Release(); lpDS8 = NULL; } } @@ -211,27 +211,27 @@ void SNDDXUpdateAudio(s16 *buffer, u32 num_samples) DWORD buffer1_size, buffer2_size; DWORD status; - int samplecounter; +/* int samplecounter; { Lock lock; samplecounter = win_sound_samplecounter -= num_samples; } 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) 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); if(buffer2) memset(buffer2, 0, buffer2_size); } - else + else*/ { memcpy(buffer1, buffer, buffer1_size); if (buffer2) @@ -241,17 +241,18 @@ void SNDDXUpdateAudio(s16 *buffer, u32 num_samples) soundoffset += buffer1_size + buffer2_size; soundoffset %= soundbufsize; - IDirectSoundBuffer8_Unlock(lpDSB2, buffer1, buffer1_size, buffer2, buffer2_size); + lpDSB2->Unlock(buffer1, buffer1_size, buffer2, buffer2_size); } ////////////////////////////////////////////////////////////////////////////// u32 SNDDXGetAudioSpace() { + //return 735; DWORD playcursor, writecursor; u32 freespace=0; - if (IDirectSoundBuffer8_GetCurrentPosition (lpDSB2, &playcursor, &writecursor) != DS_OK) + if (lpDSB2->GetCurrentPosition(&playcursor, &writecursor) != DS_OK) return 0; if (soundoffset > playcursor) @@ -270,7 +271,7 @@ u32 SNDDXGetAudioSpace() void SNDDXMuteAudio() { issoundmuted = 1; - IDirectSoundBuffer8_SetVolume (lpDSB2, DSBVOLUME_MIN); + lpDSB2->SetVolume(DSBVOLUME_MIN); } ////////////////////////////////////////////////////////////////////////////// @@ -278,7 +279,7 @@ void SNDDXMuteAudio() void SNDDXUnMuteAudio() { 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 */ soundvolume = (((LONG)volume) - 100) * 100; if (!issoundmuted) - IDirectSoundBuffer8_SetVolume (lpDSB2, soundvolume); + lpDSB2->SetVolume(soundvolume); } //////////////////////////////////////////////////////////////////////////////