From b8b2f4380efa2a42df6275482b6e718bbfe0cf0a Mon Sep 17 00:00:00 2001 From: David Bailes Date: Fri, 15 Mar 2019 10:03:46 +0000 Subject: [PATCH] Bug 2080: Using WASAPI, after recording, playback can fail The bug: 1. Set Audio host to WASAPI 2. choose recording and playback devices which have different default sample rates in shared mode. 3. Set overdub, and playthrough to off. 4. make a short recording. 5. playback. Fails with error dialog. Cause of bug: In AudioIO::GetBestRate, the last returned sample rate is cached. If the function is called again, with the same requested sample rate, then the cached value is returned. So in the above steps, when GetBestRate is called for playback, the sample rate of the recording device is returned. Fix: Include in the conditions for returning the cached rate that the values of playing and capturing as the same as in the previous call. --- src/AudioIO.cpp | 7 ++++++- src/AudioIO.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index d35cec479..7dcf76e92 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -503,6 +503,8 @@ std::vector AudioIoCallback::mCachedCaptureRates; std::vector AudioIoCallback::mCachedSampleRates; double AudioIoCallback::mCachedBestRateIn = 0.0; double AudioIoCallback::mCachedBestRateOut; +bool AudioIoCallback::mCachedBestRatePlaying; +bool AudioIoCallback::mCachedBestRateCapturing; enum { // This is the least positive latency we can @@ -3105,7 +3107,8 @@ int AudioIO::GetOptimalSupportedSampleRate() double AudioIO::GetBestRate(bool capturing, bool playing, double sampleRate) { // Check if we can use the cached value - if (mCachedBestRateIn != 0.0 && mCachedBestRateIn == sampleRate) { + if (mCachedBestRateIn != 0.0 && mCachedBestRateIn == sampleRate + && mCachedBestRatePlaying == playing && mCachedBestRateCapturing == capturing) { return mCachedBestRateOut; } @@ -3174,6 +3177,8 @@ double AudioIO::GetBestRate(bool capturing, bool playing, double sampleRate) finished: mCachedBestRateIn = sampleRate; mCachedBestRateOut = retval; + mCachedBestRatePlaying = playing; + mCachedBestRateCapturing = capturing; return retval; } diff --git a/src/AudioIO.h b/src/AudioIO.h index a91272a80..7423a5de8 100644 --- a/src/AudioIO.h +++ b/src/AudioIO.h @@ -585,6 +585,8 @@ protected: static std::vector mCachedSampleRates; static double mCachedBestRateIn; static double mCachedBestRateOut; + static bool mCachedBestRatePlaying; + static bool mCachedBestRateCapturing; // Serialize main thread and PortAudio thread's attempts to pause and change // the state used by the third, Audio thread.