diff --git a/CHANGES b/CHANGES index 7ad95f8fc..492beafd5 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Bugfixes: - Qt: Fix window focus issues - GBA Memory: Properly initialize 1 Mb flash, and add debug logging - Qt: Properly set default video recording settings + - GBA Audio: Make larger buffer sizes than 2048 actually work properly Misc: - Qt: Disable sync to video by default - GBA: Exit cleanly on FATAL if the port supports it diff --git a/src/gba/gba-audio.c b/src/gba/gba-audio.c index 3d5a7c0b1..a5440c4d5 100644 --- a/src/gba/gba-audio.c +++ b/src/gba/gba-audio.c @@ -91,17 +91,14 @@ void GBAAudioDeinit(struct GBAAudio* audio) { } void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) { - if (samples > GBA_AUDIO_SAMPLES) { - return; - } - GBASyncLockAudio(audio->p->sync); - int32_t buffer[GBA_AUDIO_SAMPLES]; + size_t oldCapacity = audio->left.capacity; + int32_t* buffer = malloc(oldCapacity); int32_t dummy; size_t read; size_t i; - read = CircleBufferDump(&audio->left, buffer, sizeof(buffer)); + read = CircleBufferDump(&audio->left, buffer, oldCapacity); CircleBufferDeinit(&audio->left); CircleBufferInit(&audio->left, samples * sizeof(int32_t)); for (i = 0; i * sizeof(int32_t) < read; ++i) { @@ -111,7 +108,7 @@ void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) { } } - read = CircleBufferDump(&audio->right, buffer, sizeof(buffer)); + read = CircleBufferDump(&audio->right, buffer, oldCapacity); CircleBufferDeinit(&audio->right); CircleBufferInit(&audio->right, samples * sizeof(int32_t)); for (i = 0; i * sizeof(int32_t) < read; ++i) { @@ -121,6 +118,8 @@ void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) { } } + free(buffer); + GBASyncConsumeAudio(audio->p->sync); } @@ -755,7 +754,7 @@ static void _sample(struct GBAAudio* audio) { if (thread && thread->stream) { thread->stream->postAudioFrame(thread->stream, sampleLeft, sampleRight); } - GBASyncProduceAudio(audio->p->sync, produced >= CircleBufferCapacity(&audio->left) / sizeof(int32_t) * 3); + GBASyncProduceAudio(audio->p->sync, produced >= CircleBufferCapacity(&audio->left)); } void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state) {