From 1369d724f7c760ef12c6fc36a9a9b1ed8ccd01df Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 24 Nov 2017 13:03:24 -0600 Subject: [PATCH] Update config variable and sanitize input. --- apu/apu.cpp | 2 +- gtk/src/gtk_config.cpp | 5 +++-- snes9x.cpp | 2 +- snes9x.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index bd0974d2..144d6942 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -475,7 +475,7 @@ void S9xSetSamplesAvailableCallback (apu_callback callback, void *data) void S9xUpdateDynamicRate (int avail, int buffer_size) { - spc::dynamic_rate_multiplier = 1.0 + ((int) Settings.DynamicRateLimit * (buffer_size - 2 * avail)) / + spc::dynamic_rate_multiplier = 1.0 + (Settings.DynamicRateLimit * (buffer_size - 2 * avail)) / (double)(1000 * buffer_size); UpdatePlaybackRate(); diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index 3c37482d..54393e59 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -253,8 +253,8 @@ Snes9xConfig::load_defaults (void) Settings.FrameTime = Settings.FrameTimeNTSC; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.SoundSync = 1; - Settings.DynamicRateControl = 0; - Settings.DynamicRateLimit = 1000; + Settings.DynamicRateControl = 1; + Settings.DynamicRateLimit = 5; Settings.HDMATimingHack = 100; Settings.ApplyCheats = 1; @@ -675,6 +675,7 @@ Snes9xConfig::set_option (const char *name, const char *value) else if (!strcasecmp (name, "dynamic_rate_limit")) { Settings.DynamicRateLimit = atoi (value); + Settings.DynamicRateLimit = CLAMP (Settings.DynamicRateLimit, 1, 1000); } else if (!strcasecmp (name, "gaussian_interpolation")) { diff --git a/snes9x.cpp b/snes9x.cpp index 46652d8d..1d6f6d7e 100644 --- a/snes9x.cpp +++ b/snes9x.cpp @@ -423,7 +423,7 @@ void S9xLoadConfigFiles (char **argv, int argc) Settings.SoundInputRate = conf.GetUInt("Sound::InputRate", 32000); Settings.Mute = conf.GetBool("Sound::Mute", false); Settings.DynamicRateControl = conf.GetBool("Sound::DynamicRateControl", false); - Settings.DynamicRateLimit = conf.GetUInt("Sound::DynamicRateLimit", 1000); + Settings.DynamicRateLimit = conf.GetInt ("Sound::DynamicRateLimit", 5); // Display diff --git a/snes9x.h b/snes9x.h index 3f2b50ec..443e2585 100644 --- a/snes9x.h +++ b/snes9x.h @@ -408,7 +408,7 @@ struct SSettings bool8 ReverseStereo; bool8 Mute; bool8 DynamicRateControl; - uint32 DynamicRateLimit; /* Multiplied by 1000 */ + int32 DynamicRateLimit; /* Multiplied by 1000 */ bool8 SupportHiRes; bool8 Transparency;