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

Function Spkr_SubmitWaveBuffer

source/Speaker.cpp:647–796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645//-----------------------------------------------------------------------------
646
647static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
648{
649 nDbgSpkrCnt++;
650
651 if(!SpeakerVoice.bActive)
652 return nNumSamples;
653
654 if(pSpeakerBuffer == NULL)
655 {
656 // Re-init from SpkrReset()
657 dwByteOffset = (uint32_t)-1;
658 nNumSamplesError = 0;
659
660 // Don't call DSZeroVoiceBuffer() - get noise with "VIA AC'97 Enhanced Audio Controller"
661 // . I guess SpeakerVoice.Stop() isn't really working and the new zero buffer causes noise corruption when submitted.
662 bool res = DSZeroVoiceWritableBuffer(&SpeakerVoice, g_dwDSSpkrBufferSize);
663 LogFileOutput("Spkr_SubmitWaveBuffer: DSZeroVoiceWritableBuffer, res=%d\n", res ? 1 : 0);
664
665 return 0;
666 }
667
668 //
669
670 DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1;
671 SHORT *pDSLockedBuffer0, *pDSLockedBuffer1;
672 bool bBufferError = false;
673
674 DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
675 HRESULT hr = SpeakerVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
676 if (FAILED(hr))
677 {
678 LogFileOutput("Spkr_SubmitWaveBuffer: GetCurrentPosition failed (%08X)\n", hr);
679 return nNumSamples;
680 }
681
682 if(dwByteOffset == (uint32_t)-1)
683 {
684 // First time in this func (probably after re-init (above))
685
686 dwByteOffset = dwCurrentPlayCursor + (g_dwDSSpkrBufferSize/8)*3; // Ideal: 0.375 is between 0.25 & 0.50 full
687 dwByteOffset %= g_dwDSSpkrBufferSize;
688 //LogOutput("[Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset);
689 }
690 else
691 {
692 // Check that our offset isn't between Play & Write positions
693
694 if(dwCurrentWriteCursor > dwCurrentPlayCursor)
695 {
696 // |-----PxxxxxW-----|
697 if((dwByteOffset > dwCurrentPlayCursor) && (dwByteOffset < dwCurrentWriteCursor))
698 {
699 double fTicksSecs = (double)GetTickCount() / 1000.0;
700 //LogOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
701 //LogFileOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
702
703 dwByteOffset = dwCurrentWriteCursor;
704 nNumSamplesError = 0;

Callers 2

SpkrResetFunction · 0.85
SpkrUpdateFunction · 0.85

Calls 8

LogFileOutputFunction · 0.85
SoundCore_GetErrorIncFunction · 0.85
SoundCore_GetErrorMaxFunction · 0.85
DSGetLockFunction · 0.85
RiffPutSamplesFunction · 0.85
GetCurrentPositionMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected