Win32: use event for soundsync

This commit is contained in:
OV2 2012-01-22 20:18:15 +01:00
parent 8a8d7b5646
commit dce8f6a1ff
8 changed files with 16 additions and 13 deletions

View File

@ -490,6 +490,7 @@ void CDirectSound::MixSound()
} }
LeaveCriticalSection(&GUI.SoundCritSect); LeaveCriticalSection(&GUI.SoundCritSect);
SetEvent(GUI.SoundSyncEvent);
hResult = lpDSB -> Unlock (B1, S1, B2, S2); hResult = lpDSB -> Unlock (B1, S1, B2, S2);
if (!SUCCEEDED(hResult)) if (!SUCCEEDED(hResult))

View File

@ -357,6 +357,8 @@ F_CALLBACKAPI CFMOD::FMODStreamCallback (FSOUND_STREAM *stream, void *buff, int
LeaveCriticalSection(&GUI.SoundCritSect); LeaveCriticalSection(&GUI.SoundCritSect);
SetEvent(GUI.SoundSyncEvent);
#if defined (FSOUND_LOADRAW) #if defined (FSOUND_LOADRAW)

View File

@ -135,6 +135,8 @@ FMOD_RESULT F_CALLBACK CFMODEx::FMODExStreamCallback(
LeaveCriticalSection(&GUI.SoundCritSect); LeaveCriticalSection(&GUI.SoundCritSect);
SetEvent(GUI.SoundSyncEvent);
return FMOD_OK; return FMOD_OK;
} }
#endif #endif

View File

@ -308,6 +308,7 @@ pBufferContext - unused
void CXAudio2::OnBufferEnd(void *pBufferContext) void CXAudio2::OnBufferEnd(void *pBufferContext)
{ {
InterlockedDecrement(&bufferCount); InterlockedDecrement(&bufferCount);
SetEvent(GUI.SoundSyncEvent);
} }
/* CXAudio2::PushBuffer /* CXAudio2::PushBuffer

View File

@ -2624,7 +2624,7 @@ void RenderBlarggNTSCRgb( SSurface Src, SSurface Dst, RECT *rect)
void RenderBlarggNTSC( SSurface Src, SSurface Dst, RECT *rect) void RenderBlarggNTSC( SSurface Src, SSurface Dst, RECT *rect)
{ {
SetRect(rect, 256, 239, 2); SetRect(rect, 256, 239, 2);
rect->right = 604; rect->right = SNES_NTSC_OUT_WIDTH(256);
const unsigned int srcRowPixels = Src.Pitch/2; const unsigned int srcRowPixels = Src.Pitch/2;

View File

@ -986,6 +986,7 @@ void InitSnes9X( void)
GFX.Screen = (uint16*)(ScreenBuffer); GFX.Screen = (uint16*)(ScreenBuffer);
InitializeCriticalSection(&GUI.SoundCritSect); InitializeCriticalSection(&GUI.SoundCritSect);
GUI.SoundSyncEvent = CreateEvent(NULL,TRUE,TRUE,NULL);
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
S9xInitAPU(); S9xInitAPU();
@ -1005,6 +1006,7 @@ void DeinitS9x()
delete [] ScreenBuf; delete [] ScreenBuf;
DeleteCriticalSection(&GUI.SoundCritSect); DeleteCriticalSection(&GUI.SoundCritSect);
CloseHandle(GUI.SoundSyncEvent);
CoUninitialize(); CoUninitialize();
if(GUI.GunSight) if(GUI.GunSight)
DestroyCursor(GUI.GunSight);//= LoadCursor (hInstance, MAKEINTRESOURCE (IDC_CURSOR_SCOPE)); DestroyCursor(GUI.GunSight);//= LoadCursor (hInstance, MAKEINTRESOURCE (IDC_CURSOR_SCOPE));

View File

@ -3304,7 +3304,6 @@ int WINAPI WinMain(
ChangeInputDevice(); ChangeInputDevice();
DWORD lastTime = timeGetTime(); DWORD lastTime = timeGetTime();
DWORD sSyncTime,sSyncWaited;
MSG msg; MSG msg;
@ -3421,15 +3420,10 @@ int WINAPI WinMain(
{ {
ProcessInput(); ProcessInput();
sSyncTime=timeGetTime();
while(!S9xSyncSound()) { while(!S9xSyncSound()) {
Sleep(2); ResetEvent(GUI.SoundSyncEvent);
sSyncWaited=timeGetTime(); if(WaitForSingleObject(GUI.SoundSyncEvent,1000) != WAIT_OBJECT_0)
if(sSyncWaited-sSyncTime > 1000) {
S9xClearSamples(); S9xClearSamples();
break;
}
} }
S9xMainLoop(); S9xMainLoop();

View File

@ -369,6 +369,7 @@ struct sGUI {
bool Mute; bool Mute;
// used for sync sound synchronization // used for sync sound synchronization
CRITICAL_SECTION SoundCritSect; CRITICAL_SECTION SoundCritSect;
HANDLE SoundSyncEvent;
TCHAR RomDir [_MAX_PATH]; TCHAR RomDir [_MAX_PATH];
TCHAR ScreensDir [_MAX_PATH]; TCHAR ScreensDir [_MAX_PATH];