MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / Spkr_SubmitWaveBuffer_FullSpeed

Function Spkr_SubmitWaveBuffer_FullSpeed

source/Speaker.cpp:489–643  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487// - Output these before outputting zero-pad samples.
488
489static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSamples)
490{
491 nDbgSpkrCnt++;
492
493 if(!SpeakerVoice.bActive)
494 return nNumSamples;
495
496 // pSpeakerBuffer can't be NULL, as reset clears g_bFullSpeed, so 1st SpkrUpdate() never calls here
497 _ASSERT(pSpeakerBuffer != NULL);
498
499 //
500
501 DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1;
502 SHORT *pDSLockedBuffer0, *pDSLockedBuffer1;
503 //bool bBufferError = false;
504
505 DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
506 HRESULT hr = SpeakerVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
507 if(FAILED(hr))
508 return nNumSamples;
509
510 if(dwByteOffset == (uint32_t)-1)
511 {
512 // First time in this func (probably after re-init (Spkr_SubmitWaveBuffer()))
513
514 dwByteOffset = dwCurrentPlayCursor + (g_dwDSSpkrBufferSize/8)*3; // Ideal: 0.375 is between 0.25 & 0.50 full
515 dwByteOffset %= g_dwDSSpkrBufferSize;
516 //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
517 }
518 else
519 {
520 // Check that our offset isn't between Play & Write positions
521
522 if(dwCurrentWriteCursor > dwCurrentPlayCursor)
523 {
524 // |-----PxxxxxW-----|
525 if((dwByteOffset > dwCurrentPlayCursor) && (dwByteOffset < dwCurrentWriteCursor))
526 {
527 //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
528 dwByteOffset = dwCurrentWriteCursor;
529 }
530 }
531 else
532 {
533 // |xxW----------Pxxx|
534 if((dwByteOffset > dwCurrentPlayCursor) || (dwByteOffset < dwCurrentWriteCursor))
535 {
536 //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
537 dwByteOffset = dwCurrentWriteCursor;
538 }
539 }
540 }
541
542 // Calc bytes remaining to be played
543 int nBytesRemaining = dwByteOffset - dwCurrentPlayCursor;
544 if(nBytesRemaining < 0)
545 nBytesRemaining += g_dwDSSpkrBufferSize;
546 if((nBytesRemaining == 0) && (dwCurrentPlayCursor != dwCurrentWriteCursor))

Callers 2

SpkrUpdateFunction · 0.85
SpkrUpdate_TimerFunction · 0.85

Calls 5

DSGetLockFunction · 0.85
RiffPutSamplesFunction · 0.85
PadNFramesFunction · 0.85
GetCurrentPositionMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected