From 8dd6a822010619310836f65f42cd67ae756aae7b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 6 Aug 2015 01:52:15 -0700 Subject: [PATCH] Wii: Triple buffer audio until I can figure out why double buffering is garbage --- src/platform/wii/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index dc2429a19..dcbc80cf4 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -42,9 +42,9 @@ static GXTexObj tex; static void* framebuffer[2]; static int whichFb = 0; -static struct GBAStereoSample audioBuffer[2][SAMPLES] __attribute__ ((__aligned__(32))); -static size_t audioBufferSize = 0; -static int currentAudioBuffer = 0; +static struct GBAStereoSample audioBuffer[3][SAMPLES] __attribute__((__aligned__(32))); +static volatile size_t audioBufferSize = 0; +static volatile int currentAudioBuffer = 0; int main() { VIDEO_Init(); @@ -164,6 +164,7 @@ int main() { if (available + audioBufferSize > SAMPLES) { available = SAMPLES - audioBufferSize; } + available &= ~((32 / sizeof(struct GBAStereoSample)) - 1); // Force align to 32 bytes if (available > 0) { blip_read_samples(gba.audio.left, &audioBuffer[currentAudioBuffer][audioBufferSize].left, available, true); blip_read_samples(gba.audio.right, &audioBuffer[currentAudioBuffer][audioBufferSize].right, available, true); @@ -317,6 +318,6 @@ static void _audioDMA(void) { } DCFlushRange(audioBuffer[currentAudioBuffer], audioBufferSize * sizeof(struct GBAStereoSample)); AUDIO_InitDMA((u32) audioBuffer[currentAudioBuffer], audioBufferSize * sizeof(struct GBAStereoSample)); - currentAudioBuffer = !currentAudioBuffer; + currentAudioBuffer = (currentAudioBuffer + 1) % 3; audioBufferSize = 0; }