GBA Audio: Make larger buffer sizes than 2048 actually work properly
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Dec 2014 21:27:55 -0800
2 files changed,
8 insertions(+),
8 deletions(-)
M
CHANGES
→
CHANGES
@@ -21,6 +21,7 @@ - Qt: Fix window focus issues
- GBA Audio: Support 16-bit writes to FIFO audio - 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
M
src/gba/gba-audio.c
→
src/gba/gba-audio.c
@@ -91,17 +91,14 @@ CircleBufferDeinit(&audio->chB.fifo);
} void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) { - if (samples > GBA_AUDIO_SAMPLES) { - return; - } - GBASyncLockAudio(audio->p->sync); - int16_t buffer[GBA_AUDIO_SAMPLES]; + size_t oldCapacity = audio->left.capacity; + int16_t* buffer = malloc(oldCapacity); int16_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(int16_t)); for (i = 0; i * sizeof(int16_t) < read; ++i) {@@ -111,7 +108,7 @@ CircleBufferWrite16(&audio->left, buffer[i]);
} } - read = CircleBufferDump(&audio->right, buffer, sizeof(buffer)); + read = CircleBufferDump(&audio->right, buffer, oldCapacity); CircleBufferDeinit(&audio->right); CircleBufferInit(&audio->right, samples * sizeof(int16_t)); for (i = 0; i * sizeof(int16_t) < read; ++i) {@@ -120,6 +117,8 @@ CircleBufferRead16(&audio->right, &dummy);
CircleBufferWrite16(&audio->right, buffer[i]); } } + + free(buffer); GBASyncConsumeAudio(audio->p->sync); }@@ -779,7 +778,7 @@ struct GBAThread* thread = GBAThreadGetContext();
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) {