aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorneonloop2022-03-27 16:33:44 +0000
committerneonloop2022-03-27 16:33:44 +0000
commit8870de89ba1ad9ae08e5f4c7602007b05fab5f3e (patch)
tree21447aa0ef726eb04317cdd9f0d9481fcb69f297 /main.c
parentcaa956d120b34e4c0deadb9e61af509a88debd09 (diff)
downloadpicoarch-8870de89ba1ad9ae08e5f4c7602007b05fab5f3e.tar.gz
picoarch-8870de89ba1ad9ae08e5f4c7602007b05fab5f3e.tar.bz2
picoarch-8870de89ba1ad9ae08e5f4c7602007b05fab5f3e.zip
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
Diffstat (limited to 'main.c')
-rw-r--r--main.c8
1 files changed, 7 insertions, 1 deletions
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);
}
}