]> Chaos Git - corbenik/ctrulib.git/commitdiff
Really really fix NDSP wavebuf scheduling, this time for real
authorfincs <fincs.alt1@gmail.com>
Fri, 23 Oct 2015 23:47:23 +0000 (01:47 +0200)
committerfincs <fincs.alt1@gmail.com>
Fri, 23 Oct 2015 23:47:23 +0000 (01:47 +0200)
libctru/source/ndsp/ndsp-channel.c
libctru/source/ndsp/ndsp.c

index fe5f2b802cc21592917391d7b6a48bc792ca9da2..84ddc832a1b0ead98edf6b8784625225de09bd6d 100644 (file)
@@ -360,31 +360,35 @@ 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);
                        chn->waveBufSeqPos = seqId;
 
-                       if ((st->flags & 0xFF00) && wb)
+                       if (st->flags & 0xFF00)
                        {
-                               while (wb->sequence_id != seqId)
+                               LightLock_Lock(&chn->lock);
+                               ndspWaveBuf* wb = chn->waveBuf;
+                               if (wb)
                                {
-                                       chn->wavBufCount--;
-                                       bool shouldBreak = seqId == 0 && (wb->sequence_id == st->lastSeqId || st->lastSeqId == 0);
-                                       wb->status = NDSP_WBUF_DONE;
-                                       wb = wb->next;
-                                       if (!wb || shouldBreak || chn->wavBufCount == 0)
-                                               break;
+                                       if (chn->wavBufCount)
+                                       {
+                                               while (wb->sequence_id != seqId)
+                                               {
+                                                       chn->wavBufCount--;
+                                                       bool shouldBreak = seqId == 0 && (wb->sequence_id == st->lastSeqId || st->lastSeqId == 0);
+                                                       wb->status = NDSP_WBUF_DONE;
+                                                       wb = wb->next;
+                                                       if (!wb || shouldBreak || chn->wavBufCount == 0)
+                                                               break;
+                                               }
+                                               if (wb && wb->status != NDSP_WBUF_DONE)
+                                                       wb->status = NDSP_WBUF_PLAYING;
+                                       }
+                                       if (seqId == 0)
+                                               chn->wavBufCount = 0;
+                                       chn->waveBuf = wb;
                                }
-                               if (wb && wb->status != NDSP_WBUF_DONE)
-                                       wb->status = NDSP_WBUF_PLAYING;
-                               if (seqId == 0)
-                                       chn->wavBufCount = 0;
-                               chn->waveBuf = wb;
+                               LightLock_Unlock(&chn->lock);
                        }
-
-                       LightLock_Unlock(&chn->lock);
                }
                chn->playing = (st->flags & 0xFF) ? true : false;
        }
index acaabbf05a83b682e96afe95366b16da8c8e46c1..a28dfcdb1fe7039ab8719904950024324a09800c 100644 (file)
@@ -461,7 +461,7 @@ Result ndspInit(void)
        ndspiInitChn();
 
        rc = initCfgu();
-       if (rc)
+       if (rc==0)
        {
                u8 outMode;
                CFGU_GetConfigInfoBlk2(sizeof(outMode), 0x70001, &outMode);