Add audio_monitor.c files

This commit is contained in:
twinaphex 2015-01-18 18:47:53 +01:00
parent 5c32acf91f
commit 0703b3c867
6 changed files with 98 additions and 13 deletions

View File

@ -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 \

52
audio/audio_monitor.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}

39
audio/audio_monitor.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __AUDIO_MONITOR_H
#define __AUDIO_MONITOR_H
#include <boolean.h>
#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

View File

@ -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();
}

View File

@ -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();
}
/**

View File

@ -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"