Bug 2367 - Change Pitch effect may create spurious clip at end

Fixes residual mentioned in Comment #11
This commit is contained in:
Leland Lucius 2020-09-06 03:37:57 -05:00
parent 90a69a0173
commit 5342d980fb
5 changed files with 18 additions and 12 deletions

View File

@ -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<soundtouch::SoundTouch>();
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);
}
}

View File

@ -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)

View File

@ -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<soundtouch::SoundTouch>();
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<LinearTimeWarper>(mT0, mT0, mT1, mT1Dashed ) };
success = EffectSoundTouch::ProcessWithTimeWarper(warper);
success = EffectSoundTouch::ProcessWithTimeWarper(initer, warper);
}
if(success)

View File

@ -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<soundtouch::SoundTouch>();
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++;
},

View File

@ -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<soundtouch::SoundTouch> mSoundTouch;
double mCurT0;