GBA Audio: Make larger buffer sizes than 2048 actually work properly

This commit is contained in:
Jeffrey Pfau 2014-12-21 21:27:55 -08:00
parent c7a49ce8f2
commit 892a5e5d5e
2 changed files with 8 additions and 8 deletions

View File

@ -21,6 +21,7 @@ Bugfixes:
- GBA Audio: Support 16-bit writes to FIFO audio - GBA Audio: Support 16-bit writes to FIFO audio
- GBA Memory: Properly initialize 1 Mb flash, and add debug logging - GBA Memory: Properly initialize 1 Mb flash, and add debug logging
- Qt: Properly set default video recording settings - Qt: Properly set default video recording settings
- GBA Audio: Make larger buffer sizes than 2048 actually work properly
Misc: Misc:
- Qt: Disable sync to video by default - Qt: Disable sync to video by default
- GBA: Exit cleanly on FATAL if the port supports it - GBA: Exit cleanly on FATAL if the port supports it

View File

@ -91,17 +91,14 @@ void GBAAudioDeinit(struct GBAAudio* audio) {
} }
void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) { void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) {
if (samples > GBA_AUDIO_SAMPLES) {
return;
}
GBASyncLockAudio(audio->p->sync); GBASyncLockAudio(audio->p->sync);
int16_t buffer[GBA_AUDIO_SAMPLES]; size_t oldCapacity = audio->left.capacity;
int16_t* buffer = malloc(oldCapacity);
int16_t dummy; int16_t dummy;
size_t read; size_t read;
size_t i; size_t i;
read = CircleBufferDump(&audio->left, buffer, sizeof(buffer)); read = CircleBufferDump(&audio->left, buffer, oldCapacity);
CircleBufferDeinit(&audio->left); CircleBufferDeinit(&audio->left);
CircleBufferInit(&audio->left, samples * sizeof(int16_t)); CircleBufferInit(&audio->left, samples * sizeof(int16_t));
for (i = 0; i * sizeof(int16_t) < read; ++i) { for (i = 0; i * sizeof(int16_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); CircleBufferDeinit(&audio->right);
CircleBufferInit(&audio->right, samples * sizeof(int16_t)); CircleBufferInit(&audio->right, samples * sizeof(int16_t));
for (i = 0; i * sizeof(int16_t) < read; ++i) { for (i = 0; i * sizeof(int16_t) < read; ++i) {
@ -121,6 +118,8 @@ void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) {
} }
} }
free(buffer);
GBASyncConsumeAudio(audio->p->sync); GBASyncConsumeAudio(audio->p->sync);
} }
@ -779,7 +778,7 @@ static void _sample(struct GBAAudio* audio) {
if (thread && thread->stream) { if (thread && thread->stream) {
thread->stream->postAudioFrame(thread->stream, sampleLeft, sampleRight); 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) { void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state) {