diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 373d7450..1411484b 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -221,7 +221,6 @@ int speedupToggle; int sunBars; int surfaceSizeX; int surfaceSizeY; -int synchronize = false; int threadPriority; int tripleBuffering; int useBios = 0; @@ -524,7 +523,6 @@ void LoadConfig() soundFiltering = (float)ReadPref("gbaSoundFiltering", 50) / 100.0f; soundInterpolation = ReadPref("gbaSoundInterpolation", 1); soundRecordDir = ReadPrefString("soundRecordDir"); - synchronize = ReadPref("synchronize", 1); threadPriority = ReadPref("priority", 2); throttle = ReadPref("throttle", 0); tripleBuffering = ReadPref("tripleBuffering", 0); @@ -1038,13 +1036,6 @@ int ReadOpts(int argc, char ** argv) } break; - case OPT_SYNCHRONIZE: - // --synchronize - if (optarg) { - synchronize = atoi(optarg); - } - break; - case OPT_VIDEO_OPTION: // --video-option if (optarg) { diff --git a/src/common/ConfigManager.h b/src/common/ConfigManager.h index 9853134d..1da026bd 100644 --- a/src/common/ConfigManager.h +++ b/src/common/ConfigManager.h @@ -117,7 +117,6 @@ extern int speedupToggle; extern int sunBars; extern int surfaceSizeX; extern int surfaceSizeY; -extern int synchronize; extern int threadPriority; extern int tripleBuffering; extern int useBios; diff --git a/src/common/SoundSDL.cpp b/src/common/SoundSDL.cpp index e459ef26..a85550ba 100644 --- a/src/common/SoundSDL.cpp +++ b/src/common/SoundSDL.cpp @@ -18,15 +18,17 @@ #include "SoundSDL.h" #include "ConfigManager.h" #include "../gba/Globals.h" +#include "../gba/Sound.h" extern int emulating; -// Hold up to 100 ms of data in the ring buffer -const float SoundSDL::_delay = 0.1f; +// Hold up to 32 ms of data in the ring buffer +const float SoundSDL::_delay = 0.032f; SoundSDL::SoundSDL(): _rbuf(0), - _initialized(false) + _initialized(false), + current_rate(0) { } @@ -45,7 +47,7 @@ void SoundSDL::read(u16 * stream, int length) /* since this is running in a different thread, speedup and * throttle can change at any time; save the value so locks * stay in sync */ - bool lock = (emulating && !speedup && synchronize && !gba_joybus_active) ? true : false; + bool lock = (emulating && !speedup && throttle && !gba_joybus_active) ? true : false; if (lock) SDL_SemWait (_semBufferFull); @@ -74,7 +76,7 @@ void SoundSDL::write(u16 * finalWave, int length) std::size_t avail; while ((avail = _rbuf.avail() / 2) < samples) { - bool lock = (emulating && !speedup && synchronize && !gba_joybus_active) ? true : false; + bool lock = (emulating && !speedup && throttle && !gba_joybus_active) ? true : false; _rbuf.write(finalWave, avail * 2); @@ -86,6 +88,12 @@ void SoundSDL::write(u16 * finalWave, int length) if (lock) { SDL_SemWait(_semBufferEmpty); + if (throttle > 0 && throttle != current_rate) + { + SDL_CloseAudio(); + init(soundGetSampleRate() * throttle / 100); + current_rate = throttle; + } } else { @@ -119,10 +127,13 @@ bool SoundSDL::init(long sampleRate) _rbuf.reset(_delay * sampleRate * 2); - _mutex = SDL_CreateMutex(); - _semBufferFull = SDL_CreateSemaphore (0); - _semBufferEmpty = SDL_CreateSemaphore (1); - _initialized = true; + if (!_initialized) + { + _mutex = SDL_CreateMutex(); + _semBufferFull = SDL_CreateSemaphore (0); + _semBufferEmpty = SDL_CreateSemaphore (1); + _initialized = true; + } return true; } @@ -132,24 +143,9 @@ SoundSDL::~SoundSDL() if (!_initialized) return; - SDL_mutexP(_mutex); - int iSave = emulating; - emulating = 0; - SDL_SemPost(_semBufferFull); - SDL_SemPost(_semBufferEmpty); - SDL_mutexV(_mutex); + reset(); - SDL_DestroySemaphore(_semBufferFull); - SDL_DestroySemaphore(_semBufferEmpty); - _semBufferFull = NULL; - _semBufferEmpty = NULL; - - SDL_DestroyMutex(_mutex); - _mutex = NULL; - - SDL_CloseAudio(); - - emulating = iSave; + _initialized = false; } void SoundSDL::pause() @@ -170,4 +166,22 @@ void SoundSDL::resume() void SoundSDL::reset() { + SDL_mutexP(_mutex); + int iSave = emulating; + emulating = 0; + SDL_SemPost(_semBufferFull); + SDL_SemPost(_semBufferEmpty); + SDL_mutexV(_mutex); + + SDL_DestroySemaphore(_semBufferFull); + SDL_DestroySemaphore(_semBufferEmpty); + _semBufferFull = NULL; + _semBufferEmpty = NULL; + + SDL_DestroyMutex(_mutex); + _mutex = NULL; + + SDL_CloseAudio(); + + emulating = iSave; } diff --git a/src/common/SoundSDL.h b/src/common/SoundSDL.h index 2336a1db..5e3dcc01 100644 --- a/src/common/SoundSDL.h +++ b/src/common/SoundSDL.h @@ -42,6 +42,8 @@ private: SDL_sem *_semBufferFull; SDL_sem *_semBufferEmpty; + int current_rate; + bool _initialized; // Defines what delay in seconds we keep in the sound buffer diff --git a/src/win32/DirectSound.cpp b/src/win32/DirectSound.cpp index c8c4fc27..29cdca66 100644 --- a/src/win32/DirectSound.cpp +++ b/src/win32/DirectSound.cpp @@ -240,7 +240,7 @@ void DirectSound::write(u16 * finalWave, int length) LPVOID lpvPtr2; DWORD dwBytes2 = 0; - if( !speedup && synchronize && !throttle && !gba_joybus_active) { + if( !speedup && throttle && !gba_joybus_active) { hr = dsbSecondary->GetStatus(&status); if( status & DSBSTATUS_PLAYING ) { if( !soundPaused ) { diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index d8858087..e384d88d 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -160,8 +160,6 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd) ON_COMMAND(ID_OPTIONS_EMULATOR_DIRECTORIES, OnOptionsEmulatorDirectories) ON_COMMAND(ID_OPTIONS_EMULATOR_DISABLESTATUSMESSAGES, OnOptionsEmulatorDisablestatusmessages) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_DISABLESTATUSMESSAGES, OnUpdateOptionsEmulatorDisablestatusmessages) - ON_COMMAND(ID_OPTIONS_EMULATOR_SYNCHRONIZE, OnOptionsEmulatorSynchronize) - ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SYNCHRONIZE, OnUpdateOptionsEmulatorSynchronize) ON_COMMAND(ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE, OnOptionsEmulatorPausewheninactive) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_PAUSEWHENINACTIVE, OnUpdateOptionsEmulatorPausewheninactive) ON_COMMAND(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnOptionsEmulatorSpeeduptoggle) diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index 6b7bb2b5..1b7627df 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -164,8 +164,6 @@ protected: afx_msg void OnOptionsEmulatorDirectories(); afx_msg void OnOptionsEmulatorDisablestatusmessages(); afx_msg void OnUpdateOptionsEmulatorDisablestatusmessages(CCmdUI* pCmdUI); - afx_msg void OnOptionsEmulatorSynchronize(); - afx_msg void OnUpdateOptionsEmulatorSynchronize(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorPausewheninactive(); afx_msg void OnUpdateOptionsEmulatorPausewheninactive(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorSpeeduptoggle(); diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index ccc64d7a..cf27cfef 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -581,18 +581,6 @@ void MainWnd::OnUpdateOptionsEmulatorDisablestatusmessages(CCmdUI* pCmdUI) pCmdUI->SetCheck(disableStatusMessages); } -void MainWnd::OnOptionsEmulatorSynchronize() -{ - synchronize = !synchronize; - if (synchronize) - throttle = false; -} - -void MainWnd::OnUpdateOptionsEmulatorSynchronize(CCmdUI* pCmdUI) -{ - pCmdUI->SetCheck(synchronize); -} - void MainWnd::OnOptionsEmulatorPausewheninactive() { pauseWhenInactive = !pauseWhenInactive; diff --git a/src/win32/OpenAL.cpp b/src/win32/OpenAL.cpp index 4b390daf..c88a91b8 100644 --- a/src/win32/OpenAL.cpp +++ b/src/win32/OpenAL.cpp @@ -281,7 +281,7 @@ void OpenAL::write(u16 * finalWave, int length) } } - if( !speedup && synchronize && !throttle && !gba_joybus_active) { + if( !speedup && throttle && !gba_joybus_active) { // wait until at least one buffer has finished while( nBuffersProcessed == 0 ) { winlog( " waiting...\n" ); diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index afcd54ee..3c0ea6e0 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -1403,7 +1403,6 @@ void VBA::loadSettings() autoFrameSkip = regQueryDwordValue("autoFrameSkip", FALSE) ? TRUE : FALSE; vsync = regQueryDwordValue("vsync", false) ? true : false ; - synchronize = regQueryDwordValue("synchronize", 1) ? true : false; fullScreenStretch = regQueryDwordValue("stretch", 0) ? true : false; videoOption = regQueryDwordValue("video", VIDEO_3X); @@ -2487,7 +2486,6 @@ void VBA::saveSettings() regSetDwordValue("autoFrameSkip", autoFrameSkip); regSetDwordValue("vsync", vsync); - regSetDwordValue("synchronize", synchronize); regSetDwordValue("stretch", fullScreenStretch); regSetDwordValue("video", videoOption); diff --git a/src/win32/VBA.rc b/src/win32/VBA.rc index 9415ce7d..d078b3f2 100644 --- a/src/win32/VBA.rc +++ b/src/win32/VBA.rc @@ -1760,8 +1760,6 @@ BEGIN MENUITEM " Configuration...", ID_OUTPUTAPI_OALCONFIGURATION MENUITEM SEPARATOR MENUITEM "DirectSound 8", ID_OUTPUTAPI_DIRECTSOUND - MENUITEM SEPARATOR - MENUITEM "&Sync game to audio", ID_OPTIONS_EMULATOR_SYNCHRONIZE END MENUITEM SEPARATOR MENUITEM "Core Settings...", ID_AUDIO_CORE_SETTINGS diff --git a/src/win32/XAudio2.cpp b/src/win32/XAudio2.cpp index 132608c6..da411c91 100644 --- a/src/win32/XAudio2.cpp +++ b/src/win32/XAudio2.cpp @@ -451,7 +451,7 @@ void XAudio2_Output::write(u16 * finalWave, int length) break; } else { // the maximum number of buffers is currently queued - if( synchronize && !speedup && !throttle && !gba_joybus_active ) { + if( !speedup && throttle && !gba_joybus_active ) { // wait for one buffer to finish playing if (WaitForSingleObject( notify.hBufferEndEvent, 10000 ) == WAIT_TIMEOUT) { device_changed = true; diff --git a/src/win32/resource.h b/src/win32/resource.h index 53fa3b61..242cefae 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -733,7 +733,6 @@ #define ID_OPTIONS_VIDEO_X5 40014 #define ID_OPTIONS_VIDEO_X6 40015 #define ID_OPTIONS_JOYPAD 40016 -#define ID_OPTIONS_EMULATOR_SYNCHRONIZE 40017 #define ID_FILE_RESET 40018 #define ID_FILE_LOAD 40019 #define ID_OPTIONS_SOUND_DIRECTSOUNDA 40020 diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index a2fc7a3d..f0ab969f 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -2323,12 +2323,6 @@ EVT_HANDLER(SkipIntro, "Skip BIOS initialization") update_opts(); } -EVT_HANDLER(SyncGameAudio, "Synchronize game to audio") -{ - GetMenuOptionInt("SyncGameAudio", synchronize, 1); - update_opts(); -} - EVT_HANDLER(BootRomEn, "Use the specified BIOS file for GBA") { GetMenuOptionInt("BootRomEn", useBiosFileGBA, 1); diff --git a/src/wx/dsound.cpp b/src/wx/dsound.cpp index fe322e86..cdca4566 100644 --- a/src/wx/dsound.cpp +++ b/src/wx/dsound.cpp @@ -239,7 +239,7 @@ void DirectSound::write(u16 * finalWave, int length) LPVOID lpvPtr2; DWORD dwBytes2 = 0; - if (!speedup && synchronize && !throttle && !gba_joybus_active) { + if (!speedup && throttle && !gba_joybus_active) { hr = dsbSecondary->GetStatus(&status); if( status & DSBSTATUS_PLAYING ) { if( !soundPaused ) { diff --git a/src/wx/openal.cpp b/src/wx/openal.cpp index ad537934..8e6734e5 100644 --- a/src/wx/openal.cpp +++ b/src/wx/openal.cpp @@ -290,7 +290,7 @@ void OpenAL::write(u16 * finalWave, int length) } } - if (!speedup && synchronize && !throttle && !gba_joybus_active) { + if (!speedup && throttle && !gba_joybus_active) { // wait until at least one buffer has finished while( nBuffersProcessed == 0 ) { winlog( " waiting...\n" ); diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index e0dd07e1..a1312d9b 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -225,7 +225,6 @@ opt_desc opts[] = { INTOPT ("preferences/skipBios", "SkipIntro", wxTRANSLATE("Skip BIOS initialization"), skipBios, 0, 1), INTOPT ("preferences/skipSaveGameCheats", "", wxTRANSLATE("Do not overwrite cheat list when loading state"), skipSaveGameCheats, 0, 1), INTOPT ("preferences/skipSaveGameBattery", "", wxTRANSLATE("Do not overwrite native (battery) save when loading state"), skipSaveGameBattery, 0, 1), - INTOPT ("preferences/synchronize", "SyncGameAudio", wxTRANSLATE("Synchronize game to audio"), synchronize, 0, 1), INTOPT ("preferences/throttle", "", wxTRANSLATE("Throttle game speed, even when accelerated (0-1000%, 0 = disabled)"), throttle, 0, 1000), INTOPT ("preferences/useBiosGB", "BootRomGB", wxTRANSLATE("Use the specified BIOS file for GB"), useBiosFileGB, 0, 1), INTOPT ("preferences/useBiosGBA", "BootRomEn", wxTRANSLATE("Use the specified BIOS file"), useBiosFileGBA, 0, 1), diff --git a/src/wx/xaudio2.cpp b/src/wx/xaudio2.cpp index 3fe0d47c..103f3506 100644 --- a/src/wx/xaudio2.cpp +++ b/src/wx/xaudio2.cpp @@ -506,7 +506,7 @@ void XAudio2_Output::write(u16 * finalWave, int length) break; } else { // the maximum number of buffers is currently queued - if( synchronize && !speedup && !throttle && !gba_joybus_active ) { + if( !speedup && throttle && !gba_joybus_active ) { // wait for one buffer to finish playing if (WaitForSingleObject( notify.hBufferEndEvent, 10000 ) == WAIT_TIMEOUT) { device_changed = true; diff --git a/src/wx/xrc/MainMenu.xrc b/src/wx/xrc/MainMenu.xrc index 70dd59bc..24aaa6e5 100644 --- a/src/wx/xrc/MainMenu.xrc +++ b/src/wx/xrc/MainMenu.xrc @@ -235,10 +235,6 @@ 1 - - - 1 - 1