From 5f58323c017fbbec292bcb5e922e8bfe950a2bd7 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 10 Jul 2018 21:33:03 +0300 Subject: [PATCH] Attempt to improve audio quality on frontend with big audio buffers --- Core/apu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Core/apu.c b/Core/apu.c index b5574c9f..dee4c006 100644 --- a/Core/apu.c +++ b/Core/apu.c @@ -417,6 +417,14 @@ void GB_apu_copy_buffer(GB_gameboy_t *gb, GB_sample_t *dest, size_t count) dest[gb->apu_output.buffer_position + i] = output; } + if (gb->apu_output.buffer_position) { + if (gb->apu_output.buffer_size + (count - gb->apu_output.buffer_position) < count * 3) { + gb->apu_output.buffer_size += count - gb->apu_output.buffer_position; + gb->apu_output.buffer = realloc(gb->apu_output.buffer, + gb->apu_output.buffer_size * sizeof(*gb->apu_output.buffer)); + gb->apu_output.stream_started = false; + } + } count = gb->apu_output.buffer_position; } memcpy(dest, gb->apu_output.buffer, count * sizeof(*gb->apu_output.buffer));