Fix to DirectSound not working in modern environments. Need to use FAILED() instead of boolean check. (PR #951)

This commit is contained in:
Henri Asseily 2021-05-16 22:03:59 +03:00 committed by GitHub
parent 110a706535
commit 1b9a769332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 20 deletions

View File

@ -1007,10 +1007,11 @@ static void MB_UpdateInt(void)
DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1; DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1;
SHORT *pDSLockedBuffer0, *pDSLockedBuffer1; SHORT *pDSLockedBuffer0, *pDSLockedBuffer1;
if(!DSGetLock(MockingboardVoice.lpDSBvoice, hr = DSGetLock(MockingboardVoice.lpDSBvoice,
dwByteOffset, (DWORD)nNumSamples*sizeof(short)*g_nMB_NumChannels, dwByteOffset, (DWORD)nNumSamples * sizeof(short) * g_nMB_NumChannels,
&pDSLockedBuffer0, &dwDSLockedBufferSize0, &pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1)) &pDSLockedBuffer1, &dwDSLockedBufferSize1);
if (FAILED(hr))
return; return;
memcpy(pDSLockedBuffer0, &g_nMixBuffer[0], dwDSLockedBufferSize0); memcpy(pDSLockedBuffer0, &g_nMixBuffer[0], dwDSLockedBufferSize0);

View File

@ -614,10 +614,11 @@ void SSI263::Update(void)
DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1; DWORD dwDSLockedBufferSize0, dwDSLockedBufferSize1;
short *pDSLockedBuffer0, *pDSLockedBuffer1; short *pDSLockedBuffer0, *pDSLockedBuffer1;
if (!DSGetLock(SSI263SingleVoice.lpDSBvoice, hr = DSGetLock(SSI263SingleVoice.lpDSBvoice,
m_byteOffset, (DWORD)nNumSamples*sizeof(short)*m_kNumChannels, m_byteOffset, (DWORD)nNumSamples * sizeof(short) * m_kNumChannels,
&pDSLockedBuffer0, &dwDSLockedBufferSize0, &pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1)) &pDSLockedBuffer1, &dwDSLockedBufferSize1);
if (FAILED(hr))
return; return;
memcpy(pDSLockedBuffer0, &m_mixBufferSSI263[0], dwDSLockedBufferSize0); memcpy(pDSLockedBuffer0, &m_mixBufferSSI263[0], dwDSLockedBufferSize0);

View File

@ -124,14 +124,14 @@ static const char *DirectSound_ErrorText (HRESULT error)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes, HRESULT DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes,
SHORT** ppDSLockedBuffer0, DWORD* pdwDSLockedBufferSize0, SHORT** ppDSLockedBuffer0, DWORD* pdwDSLockedBufferSize0,
SHORT** ppDSLockedBuffer1, DWORD* pdwDSLockedBufferSize1) SHORT** ppDSLockedBuffer1, DWORD* pdwDSLockedBufferSize1)
{ {
DWORD nStatus; DWORD nStatus;
HRESULT hr = pVoice->GetStatus(&nStatus); HRESULT hr = pVoice->GetStatus(&nStatus);
if(hr != DS_OK) if(hr != DS_OK)
return false; return hr;
if(nStatus & DSBSTATUS_BUFFERLOST) if(nStatus & DSBSTATUS_BUFFERLOST)
{ {
@ -151,7 +151,7 @@ bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes,
(void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0, (void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0,
(void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1, (void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1,
DSBLOCK_ENTIREBUFFER))) DSBLOCK_ENTIREBUFFER)))
return false; return hr;
} }
else else
{ {
@ -159,10 +159,10 @@ bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes,
(void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0, (void**)ppDSLockedBuffer0, pdwDSLockedBufferSize0,
(void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1, (void**)ppDSLockedBuffer1, pdwDSLockedBufferSize1,
0))) 0)))
return false; return hr;
} }
return true; return hr;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -38,7 +38,7 @@ struct VOICE
typedef VOICE* PVOICE; typedef VOICE* PVOICE;
bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes, HRESULT DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes,
SHORT** ppDSLockedBuffer0, DWORD* pdwDSLockedBufferSize0, SHORT** ppDSLockedBuffer0, DWORD* pdwDSLockedBufferSize0,
SHORT** ppDSLockedBuffer1, DWORD* pdwDSLockedBufferSize1); SHORT** ppDSLockedBuffer1, DWORD* pdwDSLockedBufferSize1);

View File

@ -576,10 +576,11 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
if(nNumSamplesToUse >= 128) // Limit the buffer unlock/locking to a minimum if(nNumSamplesToUse >= 128) // Limit the buffer unlock/locking to a minimum
{ {
if(!DSGetLock(SpeakerVoice.lpDSBvoice, hr = DSGetLock(SpeakerVoice.lpDSBvoice,
dwByteOffset, (DWORD)nNumSamplesToUse*sizeof(short), dwByteOffset, (DWORD)nNumSamplesToUse * sizeof(short),
&pDSLockedBuffer0, &dwDSLockedBufferSize0, &pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1)) &pDSLockedBuffer1, &dwDSLockedBufferSize1);
if (FAILED(hr))
return nNumSamples; return nNumSamples;
// //
@ -777,10 +778,11 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
{ {
//sprintf(szDbg, "[Submit] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X +++\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamplesToUse); OutputDebugString(szDbg); //sprintf(szDbg, "[Submit] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X +++\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamplesToUse); OutputDebugString(szDbg);
if (!DSGetLock(SpeakerVoice.lpDSBvoice, hr = DSGetLock(SpeakerVoice.lpDSBvoice,
dwByteOffset, (DWORD)nNumSamplesToUse * sizeof(short), dwByteOffset, (DWORD)nNumSamplesToUse * sizeof(short),
&pDSLockedBuffer0, &dwDSLockedBufferSize0, &pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1)) &pDSLockedBuffer1, &dwDSLockedBufferSize1);
if (FAILED(hr))
{ {
LogFileOutput("Spkr_SubmitWaveBuffer: DSGetLock failed\n"); LogFileOutput("Spkr_SubmitWaveBuffer: DSGetLock failed\n");
return nNumSamples; return nNumSamples;