Avoid expensive calls to DirectSound on buffers unless they've been played at least once

This commit is contained in:
Anthony 2022-03-06 20:59:42 +13:00
parent 4c30264136
commit 4186d4ba8b
3 changed files with 16 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;
}
}