all repos — mgba @ 892a5e5d5e1845a6ece184a8bb46cb5e45892c28

mGBA Game Boy Advance Emulator

GBA Audio: Make larger buffer sizes than 2048 actually work properly
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Dec 2014 21:27:55 -0800
commit

892a5e5d5e1845a6ece184a8bb46cb5e45892c28

parent

c7a49ce8f2a8c1a9ffc587e8f322331e4668fc21

2 files changed, 8 insertions(+), 8 deletions(-)

jump to
M CHANGESCHANGES

@@ -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.csrc/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) {