From ebad126fc0130d9d901f8be6b6daa1e52278a373 Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 24 Oct 2015 00:54:57 +0200 Subject: [PATCH] Fix NDSP wavebuf synchronization issue (thanks to Lectem) --- libctru/include/3ds/synchronization.h | 2 +- libctru/source/ndsp/ndsp-channel.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libctru/include/3ds/synchronization.h b/libctru/include/3ds/synchronization.h index eb0ee84..c919757 100644 --- a/libctru/include/3ds/synchronization.h +++ b/libctru/include/3ds/synchronization.h @@ -18,7 +18,7 @@ typedef struct /// Performs a clrex operation. static inline void __clrex(void) { - __asm__ __volatile__("clrex"); + __asm__ __volatile__("clrex" ::: "memory"); } /** diff --git a/libctru/source/ndsp/ndsp-channel.c b/libctru/source/ndsp/ndsp-channel.c index 4970bde..36880db 100644 --- a/libctru/source/ndsp/ndsp-channel.c +++ b/libctru/source/ndsp/ndsp-channel.c @@ -143,12 +143,12 @@ void ndspChnWaveBufClear(int id) void ndspChnWaveBufAdd(int id, ndspWaveBuf* buf) { ndspChnSt* chn = &ndspChn[id]; - ndspWaveBuf* cb = chn->waveBuf; if (!buf->nsamples) return; buf->next = NULL; buf->status = NDSP_WBUF_QUEUED; LightLock_Lock(&chn->lock); + ndspWaveBuf* cb = chn->waveBuf; if (cb) { @@ -360,13 +360,13 @@ void ndspiReadChnState(void) if (chn->syncCount == st->syncCount) { u16 seqId = st->curSeqId; + LightLock_Lock(&chn->lock); + ndspWaveBuf* wb = chn->waveBuf; chn->samplePos = ndspiRotateVal(st->samplePos); if ((st->flags & 0xFF00) && wb) { - LightLock_Lock(&chn->lock); - while (wb->sequence_id != seqId) { chn->wavBufCount--; @@ -382,9 +382,9 @@ void ndspiReadChnState(void) chn->wavBufCount = 0; chn->waveBuf = wb; chn->waveBufSeqPos = seqId; - LightLock_Unlock(&chn->lock); } + LightLock_Unlock(&chn->lock); } chn->playing = (st->flags & 0xFF) ? true : false; }