Re: [Audacity-devel] Patch to fix freeze when using Shift+Play on a track that's not 44100Hz
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Maarten B. <maa...@ho...> - 2012-12-08 18:23:30
|
Index: src/Resample.h =================================================================== --- src/Resample.h (revision 12063) +++ src/Resample.h (working copy) @@ -115,6 +115,10 @@ protected: int mMethod; // resampler-specific enum for resampling method void* mHandle; // constant-rate or variable-rate resampler (XOR per instance) +#if USE_LIBSAMPLERATE + bool mShouldReset; // whether the resampler should be reset because lastFlag has been set previously + int mSamplesLeft; // number of samples left before a reset is needed +#endif }; class ConstRateResample : public Resample Index: src/Resample.cpp =================================================================== --- src/Resample.cpp (revision 12063) +++ src/Resample.cpp (working copy) @@ -205,6 +205,8 @@ int err; SRC_STATE *state = src_new(mMethod, 1, &err); mHandle = (void *)state; + mShouldReset = false; + mSamplesLeft = 0; } VarRateResample::~VarRateResample() @@ -264,6 +266,15 @@ src_set_ratio((SRC_STATE *)mHandle, factor); SRC_DATA data; + + if(mShouldReset) { + if(inBufferLen > mSamplesLeft) { + mShouldReset = false; + src_reset((SRC_STATE *)mHandle); + } else { + mSamplesLeft -= inBufferLen; + } + } data.data_in = inBuffer; data.data_out = outBuffer; @@ -279,6 +290,11 @@ wxFprintf(stderr, _("Libsamplerate error: %d\n"), err); return 0; } + + if(lastFlag) { + mShouldReset = true; + mSamplesLeft = inBufferLen - (int)data.input_frames_used; + } *inBufferUsed = (int)data.input_frames_used; return (int)data.output_frames_gen; |