From 8fa02e0ea2b4bbb8c0cdc735663a327377662264 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Wed, 13 Jul 2022 15:54:57 +0200 Subject: [PATCH] Make sure that audio resumes playing after clearing the queue --- SDL/audio/openal.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/SDL/audio/openal.c b/SDL/audio/openal.c index 88f0ceb..5cde557 100644 --- a/SDL/audio/openal.c +++ b/SDL/audio/openal.c @@ -119,17 +119,6 @@ static bool _audio_is_playing(void) return state == AL_PLAYING; } -static void _audio_clear_queue(void) -{ - alSourceStop(al_source); - if (AL_ERROR(NULL)) { - _audio_deinit(); - return; - } - - free_processed_buffers(); -} - static void _audio_set_paused(bool paused) { if (paused) { @@ -144,6 +133,25 @@ static void _audio_set_paused(bool paused) } } +static void _audio_clear_queue(void) +{ + bool is_playing = _audio_is_playing(); + + // Stopping a source clears its queue + alSourceStop(al_source); + if (AL_ERROR(NULL)) { + _audio_deinit(); + return; + } + + free_processed_buffers(); + buffer_pos = 0; + + if (is_playing) { + _audio_set_paused(false); + } +} + static unsigned _audio_get_frequency(void) { return sample_rate;