From 8870de89ba1ad9ae08e5f4c7602007b05fab5f3e Mon Sep 17 00:00:00 2001 From: neonloop Date: Sun, 27 Mar 2022 16:33:44 +0000 Subject: Adds dynamic audio rate control option When DRC is on, game syncs to frame rate instead of audio buffer capacity. Audio is resampled to generate more samples when buffer is low and less when buffer is high, to keep buffer 40%-60% full. Buffer size doubled to keep same avg. audio latency value. Audio can distort when buffer is out of range, not often during gameplay. Better resampler could improve but would be slower. When buffer is always out of range (heavy frameskip), it is better to leave off, DRC doesn't help anyway then. Idea from RetroArch audio_driver.c and https://near.sh/articles/audio/dynamic-rate-control --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index af55f0f..e91b832 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,8 @@ static int last_screenshot = 0; static uint32_t vsyncs; static uint32_t renders; +#define UNDERRUN_THRESHOLD 0.5 + static void toggle_fast_forward(int force_off) { static int frameskip_style_was; @@ -198,6 +200,7 @@ void set_defaults(void) show_hud = 1; limit_frames = 1; enable_audio = 1; + enable_drc = 1; audio_buffer_size = 5; scale_size = SCALE_SIZE_NONE; scale_filter = SCALE_FILTER_NEAREST; @@ -496,7 +499,10 @@ static void adjust_audio(void) { if (current_core.retro_audio_buffer_status) { float occupancy = 1.0 - plat_sound_capacity(); - current_core.retro_audio_buffer_status(true, (int)(occupancy * 100), occupancy < 0.50); + if (enable_drc) + occupancy = MIN(1.0, occupancy * 2.0); + + current_core.retro_audio_buffer_status(true, (int)(occupancy * 100), occupancy < UNDERRUN_THRESHOLD); } } -- cgit v1.2.3