From fbe9d42d8a48330bb3ccc3966d1d94b438565f35 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 29 Sep 2023 12:26:17 -0700 Subject: Ensure the WASAPI resample buffer is cleared when mixing starts Otherwise, stopping and restarting without resetting could leave it with invalid pointers. --- alc/backends/wasapi.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index b68439a8..71975b55 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1129,6 +1129,9 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() const uint frame_size{mFormat.Format.nChannels * mFormat.Format.wBitsPerSample / 8u}; const uint update_size{mOrigUpdateSize}; const UINT32 buffer_len{mOrigBufferSize}; + const void *resbufferptr{}; + + mBufferFilled = 0; while(!mKillNow.load(std::memory_order_relaxed)) { UINT32 written; @@ -1163,22 +1166,15 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() { mDevice->renderSamples(mResampleBuffer.get(), mDevice->UpdateSize, mFormat.Format.nChannels); + resbufferptr = mResampleBuffer.get(); mBufferFilled = mDevice->UpdateSize; } - const void *src{mResampleBuffer.get()}; - uint srclen{mBufferFilled}; - uint got{mResampler->convert(&src, &srclen, buffer, len-done)}; + uint got{mResampler->convert(&resbufferptr, &mBufferFilled, buffer, len-done)}; buffer += got*frame_size; done += got; mPadding.store(written + done, std::memory_order_relaxed); - if(srclen) - { - const char *bsrc{static_cast(src)}; - std::copy(bsrc, bsrc + srclen*frame_size, mResampleBuffer.get()); - } - mBufferFilled = srclen; } } else @@ -1228,6 +1224,7 @@ FORCE_ALIGN int WasapiPlayback::mixerSpatialProc() */ mPadding.store(mOrigBufferSize-mOrigUpdateSize, std::memory_order_release); + mBufferFilled = 0; while(!mKillNow.load(std::memory_order_relaxed)) { if(DWORD res{WaitForSingleObjectEx(mNotifyEvent, 1000, FALSE)}; res != WAIT_OBJECT_0) -- cgit v1.2.3