From 692c8f58b75d5e037c91676fb32320a3208ed26a Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Thu, 7 Jun 2018 09:42:25 -0500 Subject: [PATCH] Sanity check automatic input rate for deviations > 5%. --- gtk/src/gtk_s9xwindow.cpp | 9 ++++++++- win32/win32_display.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gtk/src/gtk_s9xwindow.cpp b/gtk/src/gtk_s9xwindow.cpp index f414139b..88494801 100644 --- a/gtk/src/gtk_s9xwindow.cpp +++ b/gtk/src/gtk_s9xwindow.cpp @@ -1620,7 +1620,14 @@ Snes9xWindow::get_refresh_rate (void) int Snes9xWindow::get_auto_input_rate (void) { - return (int) (get_refresh_rate () * 32040.0 / 60.09881389744051 + 0.5); + double new_input_rate = get_refresh_rate () * 32040.0 / 60.09881389744051 + 0.5; + + 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; + + return new_input_rate; } static void set_bypass_compositor (Display *dpy, Window window, unsigned char bypass) diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index e69f2740..0c9339a9 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -752,7 +752,14 @@ double WinGetRefreshRate(void) int WinGetAutomaticInputRate(void) { - return (int)(WinGetRefreshRate() * 32040.0 / 60.09881389744051 + 0.5); + double newInputRate = WinGetRefreshRate() * 32040.0 / 60.09881389744051 + 0.5; + + if (newInputRate > 32040.0 * 1.05) + newInputRate = 32040.0; + if (newInputRate < 32040.0 * 0.95) + newInputRate = 32040.0 * 0.95; + + return newInputRate; } /* Depth conversion functions begin */