diff --git a/src/effects/ChangePitch.cpp b/src/effects/ChangePitch.cpp index 9fa23c19f..9762a7681 100644 --- a/src/effects/ChangePitch.cpp +++ b/src/effects/ChangePitch.cpp @@ -207,7 +207,6 @@ bool EffectChangePitch::LoadFactoryDefaults() bool EffectChangePitch::Init() { - mSoundTouch.reset(); return true; } @@ -230,9 +229,11 @@ bool EffectChangePitch::Process() // ensure that m_dSemitonesChange is set. Calc_SemitonesChange_fromPercentChange(); - mSoundTouch = std::make_unique(); + auto initer = [&](soundtouch::SoundTouch *soundtouch) + { + soundtouch->setPitchSemiTones((float)(m_dSemitonesChange)); + }; IdentityTimeWarper warper; - mSoundTouch->setPitchSemiTones((float)(m_dSemitonesChange)); #ifdef USE_MIDI // Pitch shifting note tracks is currently only supported by SoundTouchEffect // and non-real-time-preview effects require an audio track selection. @@ -246,7 +247,7 @@ bool EffectChangePitch::Process() // eliminate the next line: mSemitones = m_dSemitonesChange; #endif - return EffectSoundTouch::ProcessWithTimeWarper(warper); + return EffectSoundTouch::ProcessWithTimeWarper(initer, warper); } } diff --git a/src/effects/ChangeSpeed.cpp b/src/effects/ChangeSpeed.cpp index c5e48e7a9..1833b6cae 100644 --- a/src/effects/ChangeSpeed.cpp +++ b/src/effects/ChangeSpeed.cpp @@ -553,7 +553,7 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track, { LinearTimeWarper warper { mCurT0, mCurT0, mCurT1, mCurT0 + newLength }; track->ClearAndPaste( - mCurT0, mCurT1, outputTrack.get(), false, true, &warper); + mCurT0, mCurT1, outputTrack.get(), true, false, &warper); } if (newLength > mMaxNewLength) diff --git a/src/effects/ChangeTempo.cpp b/src/effects/ChangeTempo.cpp index 141a32168..c3450b60e 100644 --- a/src/effects/ChangeTempo.cpp +++ b/src/effects/ChangeTempo.cpp @@ -191,8 +191,6 @@ bool EffectChangeTempo::Init() m_FromLength = mT1 - mT0; m_ToLength = (m_FromLength * 100.0) / (100.0 + m_PercentChange); - mSoundTouch.reset(); - return true; } @@ -212,12 +210,14 @@ bool EffectChangeTempo::Process() else #endif { - mSoundTouch = std::make_unique(); - mSoundTouch->setTempoChange(m_PercentChange); + auto initer = [&](soundtouch::SoundTouch *soundtouch) + { + soundtouch->setTempoChange(m_PercentChange); + }; double mT1Dashed = mT0 + (mT1 - mT0)/(m_PercentChange/100.0 + 1.0); RegionTimeWarper warper{ mT0, mT1, std::make_unique(mT0, mT0, mT1, mT1Dashed ) }; - success = EffectSoundTouch::ProcessWithTimeWarper(warper); + success = EffectSoundTouch::ProcessWithTimeWarper(initer, warper); } if(success) diff --git a/src/effects/SoundTouchEffect.cpp b/src/effects/SoundTouchEffect.cpp index b81867eef..ceafadc5d 100644 --- a/src/effects/SoundTouchEffect.cpp +++ b/src/effects/SoundTouchEffect.cpp @@ -67,7 +67,7 @@ bool EffectSoundTouch::ProcessNoteTrack(NoteTrack *nt, const TimeWarper &warper) } #endif -bool EffectSoundTouch::ProcessWithTimeWarper(const TimeWarper &warper) +bool EffectSoundTouch::ProcessWithTimeWarper(InitFunction initer, const TimeWarper &warper) { // Assumes that mSoundTouch has already been initialized // by the subclass for subclass-specific parameters. The @@ -118,6 +118,8 @@ bool EffectSoundTouch::ProcessWithTimeWarper(const TimeWarper &warper) // Process only if the right marker is to the right of the left marker if (mCurT1 > mCurT0) { + mSoundTouch = std::make_unique(); + initer(mSoundTouch.get()); // TODO: more-than-two-channels auto channels = TrackList::Channels(leftTrack); @@ -158,6 +160,8 @@ bool EffectSoundTouch::ProcessWithTimeWarper(const TimeWarper &warper) if (!ProcessOne(leftTrack, start, end, warper)) bGoodResult = false; } + + mSoundTouch.reset(); } mCurTrackNum++; }, diff --git a/src/effects/SoundTouchEffect.h b/src/effects/SoundTouchEffect.h index 6b045cf96..6b64ba557 100644 --- a/src/effects/SoundTouchEffect.h +++ b/src/effects/SoundTouchEffect.h @@ -48,7 +48,8 @@ public: protected: // Effect implementation - bool ProcessWithTimeWarper(const TimeWarper &warper); + using InitFunction = std::function< void(soundtouch::SoundTouch *soundtouch) >; + bool ProcessWithTimeWarper(InitFunction initer, const TimeWarper &warper); std::unique_ptr mSoundTouch; double mCurT0;