From 0d6d13425015d78606232874498327cabcb0e4e2 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 22 Nov 2025 14:22:11 -0500 Subject: Fixes and cleanup around synced gapless Signed-off-by: Andrew Opalach --- src/mixer/audio_miniaudio.c | 2 +- src/mixer/mixer.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/mixer') diff --git a/src/mixer/audio_miniaudio.c b/src/mixer/audio_miniaudio.c index 9355f35..993bcca 100644 --- a/src/mixer/audio_miniaudio.c +++ b/src/mixer/audio_miniaudio.c @@ -167,7 +167,7 @@ static void data_callback(ma_device *device, void *output, const void *input, u3 #define DEFAULT_PERIOD_SIZE_IN_MILLISECONDS 8 #else #define DEFAULT_PERIODS 3 -#define DEFAULT_PERIOD_SIZE_IN_MILLISECONDS 64 +#define DEFAULT_PERIOD_SIZE_IN_MILLISECONDS 48 #endif static bool audio_miniaudio_configure_stream(struct camu_audio *audio, void *opaque) diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 26471c9..7fa75ae 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -40,6 +40,7 @@ static s32 data_callback(void *userdata, u8 *data, s32 frame_count, bool *silenc camu_audio_buffer_read(buf, data, req); } } + struct camu_audio_buffer *probed_for_swap = NULL; for (;;) { if (!mixer->buffers.count) { al_memset(data, 0, req); @@ -48,6 +49,12 @@ static s32 data_callback(void *userdata, u8 *data, s32 frame_count, bool *silenc *silence = false; ptrdiff_t signal; if ((signal = camu_audio_buffer_read(buf, data, req)) < req) { + // In the case of a swap, two successive buffers cannot share + // the same pointer. + if (buf == probed_for_swap) { + al_memset(data, 0, req); + break; + } #ifdef CAMU_MIXER_THREADED if (al_atomic_load(u8)(&mixer->queued, AL_ATOMIC_RELAXED)) { camu_mixer_run_queue(mixer); @@ -55,6 +62,7 @@ static s32 data_callback(void *userdata, u8 *data, s32 frame_count, bool *silenc #endif data += signal; req = req - signal; + probed_for_swap = buf; continue; } } -- cgit v1.2.3-101-g0448