MCPcopy Create free account
hub / github.com/devkitPro/libctru / ndspSync

Function ndspSync

libctru/source/ndsp/ndsp.c:379–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377}
378
379static void ndspSync(void)
380{
381 // If we are about to sleep...
382 if (bEnteringSleep)
383 {
384 // Check whether the DSP is still running by attempting to wait with a timeout
385 if (ndspWaitForIrq(9776000)) // 9.776ms (approx. two sound frames)
386 goto _receiveState; // it's not, so just proceed as usual
387
388 // The wait failed, so the DSP is indeed sleeping
389 bSleeping = true;
390 }
391
392 // If we are sleeping, wait for the DSP to wake up
393 if (bSleeping)
394 {
395 LightEvent_Wait(&sleepEvent);
396 LightEvent_Clear(&sleepEvent);
397 }
398
399 // If we were cancelled, do a dummy wait instead
400 if (bCancelReceived)
401 {
402 svcSleepThread(4888000); // 4.888ms (approx. one sound frame)
403 return;
404 }
405
406 // In any other case - wait for the DSP to notify us
407 ndspWaitForIrq(U64_MAX);
408
409_receiveState:
410 // Receive and update state (if the DSP is ready)
411 if (bDspReady)
412 {
413 int counter = ndspGetCounter(~ndspFrameId & 1);
414 if (counter)
415 {
416 int next = (counter + 1) & 0xFFFF;
417 ndspFrameId = next ? next : 2;
418 ndspBufferId = ndspFrameId & 1;
419 ndspiReadChnState();
420 //memcpy(dspVar9Backup, dspVars[9][ndspBufferId], sizeof(dspVar9Backup));
421 ndspUpdateCapture((s16*)ndspVars[6][ndspBufferId], 160);
422 droppedFrames += *((u16*)ndspVars[5][ndspBufferId] + 1);
423 }
424 }
425}
426
427static void ndspThreadMain(void* arg)
428{

Callers 1

ndspThreadMainFunction · 0.85

Calls 6

ndspWaitForIrqFunction · 0.85
LightEvent_WaitFunction · 0.85
LightEvent_ClearFunction · 0.85
ndspGetCounterFunction · 0.85
ndspiReadChnStateFunction · 0.85
ndspUpdateCaptureFunction · 0.85

Tested by

no test coverage detected