Wii: Triple buffer audio until I can figure out why double buffering is garbage
Jeffrey Pfau jeffrey@endrift.com
Thu, 06 Aug 2015 01:52:15 -0700
1 files changed,
5 insertions(+),
4 deletions(-)
jump to
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -42,9 +42,9 @@
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 available = blip_samples_avail(gba.audio.left);
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 @@ return;
} DCFlushRange(audioBuffer[currentAudioBuffer], audioBufferSize * sizeof(struct GBAStereoSample)); AUDIO_InitDMA((u32) audioBuffer[currentAudioBuffer], audioBufferSize * sizeof(struct GBAStereoSample)); - currentAudioBuffer = !currentAudioBuffer; + currentAudioBuffer = (currentAudioBuffer + 1) % 3; audioBufferSize = 0; }