| 377 | } |
| 378 | |
| 379 | static 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 | |
| 427 | static void ndspThreadMain(void* arg) |
| 428 | { |
no test coverage detected