Improve audio quality on the SDL port by being more forgiving to system with bigger buffer sizes

This commit is contained in:
Lior Halphon 2019-06-22 19:01:35 +03:00
parent 970a5f562b
commit 080fde08b6

View File

@ -33,7 +33,6 @@ static double clock_mutliplier = 1.0;
static char *filename = NULL; static char *filename = NULL;
static typeof(free) *free_function = NULL; static typeof(free) *free_function = NULL;
static char *battery_save_path_ptr; static char *battery_save_path_ptr;
static bool skip_audio;
SDL_AudioDeviceID device_id; SDL_AudioDeviceID device_id;
@ -337,8 +336,6 @@ static void vblank(GB_gameboy_t *gb)
} }
do_rewind = rewind_down; do_rewind = rewind_down;
handle_events(gb); handle_events(gb);
skip_audio = (SDL_GetQueuedAudioSize(device_id) / sizeof(GB_sample_t)) > have_aspec.freq / 20;
} }
@ -360,7 +357,9 @@ static void debugger_interrupt(int ignore)
static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample)
{ {
if (skip_audio) return; if ((SDL_GetQueuedAudioSize(device_id) / sizeof(GB_sample_t)) > have_aspec.freq / 12) {
return;
}
SDL_QueueAudio(device_id, sample, sizeof(*sample)); SDL_QueueAudio(device_id, sample, sizeof(*sample));
} }