Sanity check input rate better.

This commit is contained in:
Brandon Wright 2018-06-07 15:49:41 -05:00
parent 4b6130262e
commit 83480765f1
8 changed files with 47 additions and 19 deletions

View File

@ -199,7 +199,7 @@
#include "snes/snes.hpp"
#define APU_DEFAULT_INPUT_RATE 31987 // 60hz
#define APU_DEFAULT_INPUT_RATE 31950 // ~ 59.94Hz
#define APU_MINIMUM_SAMPLE_COUNT 512
#define APU_MINIMUM_SAMPLE_BLOCK 128
#define APU_NUMERATOR_NTSC 15664

View File

@ -1620,12 +1620,23 @@ Snes9xWindow::get_refresh_rate (void)
int
Snes9xWindow::get_auto_input_rate (void)
{
double new_input_rate = get_refresh_rate () * 32040.0 / 60.09881389744051 + 0.5;
double refresh_rate = get_refresh_rate ();
if (new_input_rate > 32040.0 * 1.05)
new_input_rate = 32040.0;
if (new_input_rate < 32040.0 * 0.95)
new_input_rate = 32040.0 * 0.95;
if (refresh_rate == 0.0)
return 0;
// Try for a close multiple of 60hz
if (refresh_rate > 119.0 && refresh_rate < 121.0)
refresh_rate /= 2.0;
if (refresh_rate > 179.0 && refresh_rate < 181.0)
refresh_rate /= 3.0;
if (refresh_rate > 239.0 && refresh_rate < 241.0)
refresh_rate /= 4.0;
double new_input_rate = refresh_rate * 32040.0 / 60.09881389744051 + 0.5;
if (new_input_rate > 32040.0 * 1.05 || new_input_rate < 32040.0 * 0.95)
new_input_rate = 0.0;
return new_input_rate;
}

View File

@ -133,7 +133,7 @@ S9xPortSoundInit (void)
}
else
{
Settings.SoundInputRate = CLAMP (gui_config->sound_input_rate, 8000, 48000);
Settings.SoundInputRate = CLAMP (gui_config->sound_input_rate, 31700, 32300);
}
Settings.SoundPlaybackRate = playback_rates[gui_config->sound_playback_rate];

View File

@ -424,7 +424,7 @@ void S9xLoadConfigFiles (char **argv, int argc)
Settings.Stereo = conf.GetBool("Sound::Stereo", true);
Settings.ReverseStereo = conf.GetBool("Sound::ReverseStereo", false);
Settings.SoundPlaybackRate = conf.GetUInt("Sound::Rate", 32000);
Settings.SoundInputRate = conf.GetUInt("Sound::InputRate", 32000);
Settings.SoundInputRate = conf.GetUInt("Sound::InputRate", 31950);
Settings.Mute = conf.GetBool("Sound::Mute", false);
Settings.DynamicRateControl = conf.GetBool("Sound::DynamicRateControl", false);
Settings.DynamicRateLimit = conf.GetInt ("Sound::DynamicRateLimit", 5);
@ -692,8 +692,10 @@ char * S9xParseArgs (char **argv, int argc)
if (i + 1 < argc)
{
Settings.SoundInputRate = atoi(argv[++i]);
if (Settings.SoundInputRate < 8192)
Settings.SoundInputRate = 8192;
if (Settings.SoundInputRate < 31700)
Settings.SoundInputRate = 31700;
if (Settings.SoundInputRate > 32300)
Settings.SoundInputRate = 32300;
}
else
S9xUsage();

View File

@ -1671,7 +1671,7 @@ int main (int argc, char **argv)
Settings.SixteenBitSound = TRUE;
Settings.Stereo = TRUE;
Settings.SoundPlaybackRate = 32000;
Settings.SoundInputRate = 32000;
Settings.SoundInputRate = 31950;
Settings.SupportHiRes = TRUE;
Settings.Transparency = TRUE;
Settings.AutoDisplayMessages = TRUE;

View File

@ -982,8 +982,8 @@ void WinRegisterConfigItems()
AddIntC("Sync", Settings.SoundSync, 1, "1 to sync emulation to sound output, 0 to disable.");
AddBool2("Stereo", Settings.Stereo, true);
AddBool("SixteenBitSound", Settings.SixteenBitSound, true);
AddUIntC("Rate", Settings.SoundPlaybackRate, 32000, "sound playback quality, in Hz");
AddUIntC("InputRate", Settings.SoundInputRate, 31900, "for each 'Input rate' samples generated by the SNES, 'Playback rate' samples will produced. If you experience crackling you can try to lower this setting.");
AddUIntC("Rate", Settings.SoundPlaybackRate, 44100, "sound playback quality, in Hz");
AddUIntC("InputRate", Settings.SoundInputRate, 31950, "for each 'Input rate' samples generated by the SNES, 'Playback rate' samples will produced. If you experience crackling you can try to lower this setting.");
AddBoolC("ReverseStereo", Settings.ReverseStereo, false, "true to swap speaker outputs");
AddBoolC("Mute", GUI.Mute, false, "true to mute sound output (does not disable the sound CPU)");
AddBool("DynamicRateControl", Settings.DynamicRateControl, false);

View File

@ -752,12 +752,23 @@ double WinGetRefreshRate(void)
int WinGetAutomaticInputRate(void)
{
double newInputRate = WinGetRefreshRate() * 32040.0 / 60.09881389744051 + 0.5;
double refreshRate = WinGetRefreshRate();
if (newInputRate > 32040.0 * 1.05)
newInputRate = 32040.0;
if (newInputRate < 32040.0 * 0.95)
newInputRate = 32040.0 * 0.95;
if (refreshRate == 0.0)
return 0;
// Try for a close multiple of 60hz
if (refreshRate > 119.0 && refreshRate < 121.0)
refreshRate /= 2.0;
if (refreshRate > 179.0 && refreshRate < 181.0)
refreshRate /= 3.0;
if (refreshRate > 239.0 && refreshRate < 241.0)
refreshRate /= 4.0;
double newInputRate = refreshRate * 32040.0 / 60.09881389744051 + 0.5;
if (newInputRate > 32040.0 * 1.05 || newInputRate < 32040.0 * 0.95)
newInputRate = 0.0;
return newInputRate;
}

View File

@ -224,9 +224,13 @@ bool ReInitSound()
if (rate)
Settings.SoundInputRate = rate;
else
{
GUI.AutomaticInputRate = false;
Settings.SoundInputRate = 31950;
}
}
Settings.SoundInputRate = CLAMP(Settings.SoundInputRate,8000, 48000);
Settings.SoundInputRate = CLAMP(Settings.SoundInputRate,31700, 32300);
Settings.SoundPlaybackRate = CLAMP(Settings.SoundPlaybackRate,8000, 48000);
S9xSetSoundMute(GUI.Mute);
if(S9xSoundOutput)