Fixed the throttle selection on the SDL and XAudio2 backends. On the other backends, the throttle is a switch (selects between no throttle and throttling at 100% speed). Sync game to audio is now always enabled and the menu option has been removed.

This commit is contained in:
skidau 2015-05-11 07:21:02 +00:00
parent 88dfc964a6
commit ef62b19775
19 changed files with 48 additions and 74 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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 ) {

View File

@ -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)

View File

@ -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();

View File

@ -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;

View File

@ -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" );

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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 ) {

View File

@ -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" );

View File

@ -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),

View File

@ -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;

View File

@ -235,10 +235,6 @@
<label>_VSync</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="SyncGameAudio">
<label>_Audio sync</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="FrameSkipAuto">
<label>_Auto skip frames</label>
<checkable>1</checkable>