From 14051f04cf33aca9feeead5b7ed192f811c30798 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 11 Jun 2018 14:05:00 -0400 Subject: [PATCH] Bug1887: crash or hang loop-playing with WASAPI; libsoxr 0.1.3 to blame... ... probably? This is a workaround to prevent crashes in libsoxr that did not happen with the previous version. --- src/Mix.cpp | 29 +++++++++++++++++++++-------- src/Mix.h | 3 +++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Mix.cpp b/src/Mix.cpp index 4e0b2fd6c..57638e414 100644 --- a/src/Mix.cpp +++ b/src/Mix.cpp @@ -313,32 +313,34 @@ Mixer::Mixer(const WaveTrackConstArray &inputTracks, // For each queue, the number of available samples after the queue start. mQueueLen.reinit(mNumInputTracks); mResample.reinit(mNumInputTracks); - for(size_t i=0; iGetRate()); - double minFactor, maxFactor; if (mTimeTrack) { // variable rate resampling mbVariableRates = true; - minFactor = factor / mTimeTrack->GetRangeUpper(); - maxFactor = factor / mTimeTrack->GetRangeLower(); + mMinFactor[i] = factor / mTimeTrack->GetRangeUpper(); + mMaxFactor[i] = factor / mTimeTrack->GetRangeLower(); } else if (warpOptions.minSpeed > 0.0 && warpOptions.maxSpeed > 0.0) { // variable rate resampling mbVariableRates = true; - minFactor = factor / warpOptions.maxSpeed; - maxFactor = factor / warpOptions.minSpeed; + mMinFactor[i] = factor / warpOptions.maxSpeed; + mMaxFactor[i] = factor / warpOptions.minSpeed; } else { // constant rate resampling mbVariableRates = false; - minFactor = maxFactor = factor; + mMinFactor[i] = mMaxFactor[i] = factor; } - mResample[i] = std::make_unique(mHighQuality, minFactor, maxFactor); mQueueStart[i] = 0; mQueueLen[i] = 0; } + MakeResamplers(); + const auto envLen = std::max(mQueueMaxLen, mInterleavedBufferSize); mEnvValues.reinit(envLen); } @@ -347,6 +349,12 @@ Mixer::~Mixer() { } +void Mixer::MakeResamplers() +{ + for (size_t i = 0; i < mNumInputTracks; i++) + mResample[i] = std::make_unique(mHighQuality, mMinFactor[i], mMaxFactor[i]); +} + void Mixer::ApplyTrackGains(bool apply) { mApplyTrackGains = apply; @@ -709,6 +717,11 @@ void Mixer::Restart() mQueueStart[i] = 0; mQueueLen[i] = 0; } + + // Bug 1887: libsoxr 0.1.3, first used in Audacity 2.3.0, crashes with + // constant rate resampling if you try to reuse the resampler after it has + // flushed. Should that be considered a bug in sox? This works around it: + MakeResamplers(); } void Mixer::Reposition(double t) diff --git a/src/Mix.h b/src/Mix.h index b5fc823f6..394f45910 100644 --- a/src/Mix.h +++ b/src/Mix.h @@ -157,6 +157,8 @@ class AUDACITY_DLL_API Mixer { int *queueStart, int *queueLen, Resample * pResample); + void MakeResamplers(); + private: // Input @@ -192,6 +194,7 @@ class AUDACITY_DLL_API Mixer { double mRate; double mSpeed; bool mHighQuality; + std::vector mMinFactor, mMaxFactor; bool mMayThrow; };