From 700befc8ac877c5c9ee74c69841d31d5f570ee9e Mon Sep 17 00:00:00 2001 From: neonloop Date: Sun, 27 Mar 2022 17:46:39 +0000 Subject: Changes capacity to occupancy and return whole number as percent Avoids float operations and redundant "1 -" --- main.c | 8 ++++---- plat.h | 2 +- plat_sdl.c | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index e91b832..e004101 100644 --- a/main.c +++ b/main.c @@ -31,7 +31,7 @@ static int last_screenshot = 0; static uint32_t vsyncs; static uint32_t renders; -#define UNDERRUN_THRESHOLD 0.5 +#define UNDERRUN_THRESHOLD 50 static void toggle_fast_forward(int force_off) { @@ -498,11 +498,11 @@ static void adjust_audio(void) { } if (current_core.retro_audio_buffer_status) { - float occupancy = 1.0 - plat_sound_capacity(); + int occupancy = plat_sound_occupancy(); if (enable_drc) - occupancy = MIN(1.0, occupancy * 2.0); + occupancy = MIN(100, occupancy * 2); - current_core.retro_audio_buffer_status(true, (int)(occupancy * 100), occupancy < UNDERRUN_THRESHOLD); + current_core.retro_audio_buffer_status(true, occupancy, occupancy < UNDERRUN_THRESHOLD); } } diff --git a/plat.h b/plat.h index fdcb1a9..84e4d1e 100644 --- a/plat.h +++ b/plat.h @@ -27,7 +27,7 @@ void plat_video_close(void); unsigned plat_cpu_ticks(void); -float plat_sound_capacity(void); +int plat_sound_occupancy(void); extern void (*plat_sound_write)(const struct audio_frame *data, int frames); void plat_sound_resize_buffer(void); diff --git a/plat_sdl.c b/plat_sdl.c index 817a47e..af2d6bf 100644 --- a/plat_sdl.c +++ b/plat_sdl.c @@ -28,8 +28,8 @@ static void plat_sound_select_resampler(void); void (*plat_sound_write)(const struct audio_frame *data, int frames); #define DRC_MAX_ADJUSTMENT 0.003 -#define DRC_ADJ_BELOW 0.4 -#define DRC_ADJ_ABOVE 0.6 +#define DRC_ADJ_BELOW 40 +#define DRC_ADJ_ABOVE 60 static char msg[HUD_LEN]; static unsigned msg_priority = 0; @@ -357,11 +357,11 @@ static int plat_sound_init(void) return 0; } -float plat_sound_capacity(void) +int plat_sound_occupancy(void) { int buffered = 0; if (audio.buf_len == 0) - return 1.0; + return 0; if (audio.buf_w != audio.buf_r) { buffered = audio.buf_w > audio.buf_r ? @@ -369,7 +369,7 @@ float plat_sound_capacity(void) (audio.buf_w + audio.buf_len) - audio.buf_r; } - return 1.0 - (float)buffered / audio.buf_len; + return buffered * 100 / audio.buf_len; } #define BATCH_SIZE 100 @@ -380,10 +380,12 @@ void plat_sound_write_resample(const struct audio_frame *data, int frames, int ( return; if (drc) { - if (plat_sound_capacity() < DRC_ADJ_BELOW) { - audio.adj_out_sample_rate = audio.out_sample_rate - audio.sample_rate_adj; - } else if (plat_sound_capacity() > DRC_ADJ_ABOVE) { + int occupancy = plat_sound_occupancy(); + + if (occupancy < DRC_ADJ_BELOW) { audio.adj_out_sample_rate = audio.out_sample_rate + audio.sample_rate_adj; + } else if (occupancy > DRC_ADJ_ABOVE) { + audio.adj_out_sample_rate = audio.out_sample_rate - audio.sample_rate_adj; } else { audio.adj_out_sample_rate = audio.out_sample_rate; } -- cgit v1.2.3