diff --git a/Makefile.common b/Makefile.common
index eb79feed87..ceb563462e 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -98,6 +98,7 @@ OBJ += frontend/frontend.o \
libretro-sdk/file/file_path.o \
hash.o \
audio/audio_driver.o \
+ audio/audio_monitor.o \
input/input_driver.o \
gfx/video_driver.o \
gfx/video_monitor.o \
diff --git a/audio/audio_monitor.c b/audio/audio_monitor.c
new file mode 100644
index 0000000000..5a6cffbda7
--- /dev/null
+++ b/audio/audio_monitor.c
@@ -0,0 +1,52 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2015 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#include "audio_monitor.h"
+#include "../driver.h"
+#include "../general.h"
+#include "../retroarch.h"
+
+void audio_monitor_adjust_system_rates(void)
+{
+ float timing_skew;
+ const struct retro_system_timing *info =
+ (const struct retro_system_timing*)&g_extern.system.av_info.timing;
+
+ if (info->sample_rate <= 0.0)
+ return;
+
+ timing_skew = fabs(1.0f - info->fps /
+ g_settings.video.refresh_rate);
+ g_extern.audio_data.in_rate = info->sample_rate;
+
+ if (timing_skew <= g_settings.audio.max_timing_skew)
+ g_extern.audio_data.in_rate *= (g_settings.video.refresh_rate / info->fps);
+
+ RARCH_LOG("Set audio input rate to: %.2f Hz.\n",
+ g_extern.audio_data.in_rate);
+}
+
+/**
+ * audio_monitor_set_refresh_rate:
+ *
+ * Sets audio monitor refresh rate to new value.
+ **/
+void audio_monitor_set_refresh_rate(void)
+{
+ g_extern.audio_data.orig_src_ratio =
+ g_extern.audio_data.src_ratio =
+ (double)g_settings.audio.out_rate / g_extern.audio_data.in_rate;
+}
diff --git a/audio/audio_monitor.h b/audio/audio_monitor.h
new file mode 100644
index 0000000000..0ea41fcf54
--- /dev/null
+++ b/audio/audio_monitor.h
@@ -0,0 +1,39 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2015 - Daniel De Matteis
+ *
+ * RetroArch is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with RetroArch.
+ * If not, see .
+ */
+
+#ifndef __AUDIO_MONITOR_H
+#define __AUDIO_MONITOR_H
+
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void audio_monitor_adjust_system_rates(void);
+
+/**
+ * audio_monitor_set_refresh_rate:
+ *
+ * Sets audio monitor refresh rate to new value.
+ **/
+void audio_monitor_set_refresh_rate(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/driver.c b/driver.c
index 3e7564f993..94c4cd7293 100644
--- a/driver.c
+++ b/driver.c
@@ -22,6 +22,7 @@
#include "compat/posix_string.h"
#include "gfx/video_thread_wrapper.h"
#include "gfx/video_monitor.h"
+#include "audio/audio_monitor.h"
#include "gfx/gfx_common.h"
#ifdef HAVE_X11
@@ -205,6 +206,7 @@ void init_drivers_pre(void)
void driver_adjust_system_rates(void)
{
+ audio_monitor_adjust_system_rates();
video_monitor_adjust_system_rates();
}
diff --git a/gfx/video_monitor.c b/gfx/video_monitor.c
index 9805f58fa0..a11fce4832 100644
--- a/gfx/video_monitor.c
+++ b/gfx/video_monitor.c
@@ -15,6 +15,7 @@
*/
#include "video_monitor.h"
+#include "../audio/audio_monitor.h"
#include "../driver.h"
#include "../general.h"
#include "../retroarch.h"
@@ -27,7 +28,7 @@ void video_monitor_adjust_system_rates(void)
g_extern.system.force_nonblock = false;
- if (info->fps <= 0.0 || info->sample_rate <= 0.0)
+ if (info->fps <= 0.0)
return;
timing_skew = fabs(1.0f - info->fps / g_settings.video.refresh_rate);
@@ -46,15 +47,7 @@ void video_monitor_adjust_system_rates(void)
g_extern.system.force_nonblock = true;
RARCH_LOG("Game FPS > Monitor FPS. Cannot rely on VSync.\n");
}
-
- g_extern.audio_data.in_rate = info->sample_rate;
}
- else
- g_extern.audio_data.in_rate = info->sample_rate *
- (g_settings.video.refresh_rate / info->fps);
-
- RARCH_LOG("Set audio input rate to: %.2f Hz.\n",
- g_extern.audio_data.in_rate);
if (!driver.video_data)
return;
@@ -80,10 +73,7 @@ void video_monitor_set_refresh_rate(float hz)
g_settings.video.refresh_rate = hz;
driver_adjust_system_rates();
-
- g_extern.audio_data.orig_src_ratio =
- g_extern.audio_data.src_ratio =
- (double)g_settings.audio.out_rate / g_extern.audio_data.in_rate;
+ audio_monitor_set_refresh_rate();
}
/**
diff --git a/griffin/griffin.c b/griffin/griffin.c
index 188172b2a8..b15dbfbd20 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -508,6 +508,7 @@ DRIVERS
#include "../gfx/video_monitor.c"
#include "../input/input_driver.c"
#include "../audio/audio_driver.c"
+#include "../audio/audio_monitor.c"
#include "../osk/osk_driver.c"
#include "../camera/camera_driver.c"
#include "../location/location_driver.c"