diff --git a/src/core/hle/DSOUND/DirectSound/DirectSound.cpp b/src/core/hle/DSOUND/DirectSound/DirectSound.cpp index a079ef8a4..934a19e2b 100644 --- a/src/core/hle/DSOUND/DirectSound/DirectSound.cpp +++ b/src/core/hle/DSOUND/DirectSound/DirectSound.cpp @@ -486,11 +486,15 @@ static void dsound_thread_worker(LPVOID nullPtr) // Stream sound buffer audio // because the title may change the content of sound buffers at any time for (auto& pBuffer : g_pDSoundBufferCache) { - DWORD status; - HRESULT hRet = pBuffer->emuDSBuffer->EmuDirectSoundBuffer8->GetStatus(&status); - if (hRet == 0 && status & DSBSTATUS_PLAYING) { - auto streamMs = g_dsBufferStreaming.streamInterval + g_dsBufferStreaming.streamAhead; - StreamBufferAudio(pBuffer, streamMs); + // Avoid expensive calls to DirectSound on buffers unless they've been played at least once + // Since some titles create a large amount of buffers, but only use a few + if (pBuffer->emuDSBuffer->EmuStreamingInfo.playRequested) { + DWORD status; + HRESULT hRet = pBuffer->emuDSBuffer->EmuDirectSoundBuffer8->GetStatus(&status); + if (hRet == 0 && status & DSBSTATUS_PLAYING) { + auto streamMs = g_dsBufferStreaming.streamInterval + g_dsBufferStreaming.streamAhead; + StreamBufferAudio(pBuffer, streamMs); + } } } } @@ -1057,6 +1061,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(CDirectSound_SynchPlayback) DSoundBufferSynchPlaybackFlagRemove(pDSBuffer->EmuFlags); EmuLog(LOG_LEVEL::DEBUG, "SynchPlayback - pDSBuffer: %08X; EmuPlayFlags: %08X", *ppDSBuffer, pDSBuffer->EmuPlayFlags); pDSBuffer->EmuDirectSoundBuffer8->Play(0, 0, pDSBuffer->EmuPlayFlags); + pDSBuffer->EmuStreamingInfo.playRequested = true; } } diff --git a/src/core/hle/DSOUND/DirectSound/DirectSound.hpp b/src/core/hle/DSOUND/DirectSound/DirectSound.hpp index cefdaf186..abb56bd77 100644 --- a/src/core/hle/DSOUND/DirectSound/DirectSound.hpp +++ b/src/core/hle/DSOUND/DirectSound/DirectSound.hpp @@ -110,6 +110,10 @@ struct EmuDirectSoundBuffer X_DSENVOLOPEDESC Xb_EnvolopeDesc; X_DSVOICEPROPS Xb_VoiceProperties; DWORD Xb_Flags; + struct { + // True if the buffer has been played, and should be considered for streaming + bool playRequested = false; + } EmuStreamingInfo; }; struct XbHybridDSBuffer : DSBUFFER_S::DSBUFFER_I { diff --git a/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp b/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp index 14398b175..ab4865b0a 100644 --- a/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp +++ b/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp @@ -80,6 +80,7 @@ void DirectSoundDoWork_Buffer(xbox::LARGE_INTEGER &time) pThis->Xb_rtPauseEx = 0LL; pThis->EmuFlags &= ~DSE_FLAG_PAUSE; pThis->EmuDirectSoundBuffer8->Play(0, 0, pThis->EmuPlayFlags); + pThis->EmuStreamingInfo.playRequested = true; } if (pThis->Xb_rtStopEx != 0LL && pThis->Xb_rtStopEx <= time.QuadPart) { @@ -601,6 +602,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IDirectSoundBuffer_Play) } if ((pThis->EmuFlags & DSE_FLAG_SYNCHPLAYBACK_CONTROL) == 0) { hRet = pThis->EmuDirectSoundBuffer8->Play(0, 0, pThis->EmuPlayFlags); + pThis->EmuStreamingInfo.playRequested = true; } }