diff options
author | neonloop | 2022-03-27 17:46:39 +0000 |
---|---|---|
committer | neonloop | 2022-03-27 17:46:39 +0000 |
commit | 700befc8ac877c5c9ee74c69841d31d5f570ee9e (patch) | |
tree | 424035110cfe5745b0180d93eacee552dfa0e9ef | |
parent | 5a5baa280f725d25f38f1025d92fb521fdba8940 (diff) | |
download | picoarch-700befc8ac877c5c9ee74c69841d31d5f570ee9e.tar.gz picoarch-700befc8ac877c5c9ee74c69841d31d5f570ee9e.tar.bz2 picoarch-700befc8ac877c5c9ee74c69841d31d5f570ee9e.zip |
Changes capacity to occupancy and return whole number as percent
Avoids float operations and redundant "1 -"
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | plat.h | 2 | ||||
-rw-r--r-- | plat_sdl.c | 18 |
3 files changed, 15 insertions, 13 deletions
@@ -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); } } @@ -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); @@ -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; } |