From aa867abcd3ef9b36ecabee648eeb14c89bd6d126 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Tue, 19 Feb 2019 17:50:25 -0600 Subject: [PATCH] Use nominal frequency ratio for APU. --- apu/apu.cpp | 10 +++++----- gtk/src/gtk_preferences.cpp | 2 +- gtk/src/gtk_s9xwindow.cpp | 4 ++-- libretro/libretro.cpp | 6 +++--- msu1.cpp | 6 +++--- snes9x.h | 2 +- win32/win32_display.cpp | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index c6eb3660..efa815e6 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -17,10 +17,10 @@ static const int APU_DEFAULT_INPUT_RATE = 31950; // ~59.94Hz static const int APU_SAMPLE_BLOCK = 48; -static const int APU_NUMERATOR_NTSC = 15664; -static const int APU_DENOMINATOR_NTSC = 328125; -static const int APU_NUMERATOR_PAL = 34176; -static const int APU_DENOMINATOR_PAL = 709379; +static const int APU_NUMERATOR_NTSC = 5632; +static const int APU_DENOMINATOR_NTSC = 118125; +static const int APU_NUMERATOR_PAL = 35527; +static const int APU_DENOMINATOR_PAL = 738343; // Max number of samples we'll ever generate before call to port API and // moving the samples to the resampler. @@ -176,7 +176,7 @@ static void UpdatePlaybackRate(void) if (Settings.MSU1) { - time_ratio = (44100.0 / Settings.SoundPlaybackRate) * (Settings.SoundInputRate / 32040.0); + time_ratio = (44100.0 / Settings.SoundPlaybackRate) * (Settings.SoundInputRate / 32000.0); msu::resampler->time_ratio(time_ratio); } } diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index 95a3974a..4f8cd65f 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -418,7 +418,7 @@ event_input_rate_changed (GtkRange *range, gpointer data) { char text[256]; GtkLabel *label = GTK_LABEL (data); - double value = gtk_range_get_value (range) / 32040.0 * 60.09881389744051; + double value = gtk_range_get_value (range) / 32000.0 * 60.09881389744051; snprintf (text, 256, "%.4f hz", value); diff --git a/gtk/src/gtk_s9xwindow.cpp b/gtk/src/gtk_s9xwindow.cpp index 5525aa89..73224cbe 100644 --- a/gtk/src/gtk_s9xwindow.cpp +++ b/gtk/src/gtk_s9xwindow.cpp @@ -1595,9 +1595,9 @@ Snes9xWindow::get_auto_input_rate () 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; + double new_input_rate = refresh_rate * 32000.0 / 60.09881389744051 + 0.5; - if (new_input_rate > 32040.0 * 1.05 || new_input_rate < 32040.0 * 0.95) + if (new_input_rate > 32000.0 * 1.05 || new_input_rate < 32000.0 * 0.95) new_input_rate = 0.0; return new_input_rate; diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 462bd9dd..eb13615e 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -690,7 +690,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.max_width = MAX_SNES_WIDTH; info->geometry.max_height = MAX_SNES_HEIGHT; info->geometry.aspect_ratio = get_aspect_ratio(width, height); - info->timing.sample_rate = 32040; + info->timing.sample_rate = 32000; info->timing.fps = retro_get_region() == RETRO_REGION_NTSC ? 21477272.0 / 357366.0 : 21281370.0 / 425568.0; g_screen_gun_width = width; @@ -1202,8 +1202,8 @@ void retro_init(void) Settings.FrameTimeNTSC = 16667; Settings.SixteenBitSound = TRUE; Settings.Stereo = TRUE; - Settings.SoundPlaybackRate = 32040; - Settings.SoundInputRate = 32040; + Settings.SoundPlaybackRate = 32000; + Settings.SoundInputRate = 32000; Settings.SupportHiRes = TRUE; Settings.Transparency = TRUE; Settings.AutoDisplayMessages = TRUE; diff --git a/msu1.cpp b/msu1.cpp index f0481c06..c51238d9 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -230,7 +230,7 @@ void S9xMSU1Generate(size_t sample_count) { partial_frames += 4410 * (sample_count / 2); - while (partial_frames >= 3204) + while (partial_frames >= 3200) { if (MSU1.MSU1_STATUS & AudioPlaying && audioStream) { @@ -246,7 +246,7 @@ void S9xMSU1Generate(size_t sample_count) msu_resampler->push_sample(*left, *right); MSU1.MSU1_AUDIO_POS += 4; - partial_frames -= 3204; + partial_frames -= 3200; } else if (bytes_read >= 0) @@ -270,7 +270,7 @@ void S9xMSU1Generate(size_t sample_count) else { MSU1.MSU1_STATUS &= ~(AudioPlaying | AudioRepeating); - partial_frames -= 3204; + partial_frames -= 3200; msu_resampler->push_sample(0, 0); } } diff --git a/snes9x.h b/snes9x.h index f1c22f85..05e282c3 100644 --- a/snes9x.h +++ b/snes9x.h @@ -61,7 +61,7 @@ #define IMAGE_WIDTH (Settings.SupportHiRes ? MAX_SNES_WIDTH : SNES_WIDTH) #define IMAGE_HEIGHT (Settings.SupportHiRes ? MAX_SNES_HEIGHT : SNES_HEIGHT_EXTENDED) -#define NTSC_MASTER_CLOCK 21477272.0 +#define NTSC_MASTER_CLOCK 21477272.727272 // 21477272 + 8/11 exact #define PAL_MASTER_CLOCK 21281370.0 #define SNES_MAX_NTSC_VCOUNTER 262 diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index a2466970..6236855d 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -622,9 +622,9 @@ int WinGetAutomaticInputRate(void) if (refreshRate > 239.0 && refreshRate < 241.0) refreshRate /= 4.0; - double newInputRate = refreshRate * 32040.0 / 60.09881389744051 + 0.5; + double newInputRate = refreshRate * 32000.0 / 60.09881389744051 + 0.5; - if (newInputRate > 32040.0 * 1.05 || newInputRate < 32040.0 * 0.95) + if (newInputRate > 32000.0 * 1.05 || newInputRate < 32000.0 * 0.95) newInputRate = 0.0; return (int)newInputRate;