24#undef PACKAGE_BUGREPORT
27#include "SoundTouch.h"
44 e.Calc_SemitonesChange_fromPercentChange();
53ChangePitchBase::ChangePitchBase()
57 Parameters().Reset(*
this);
59 m_dSemitonesChange = 0.0;
60 m_dStartFrequency = 0.0;
61 m_bLoopDetect =
false;
63 SetLinearEffectFlag(
true);
66ChangePitchBase::~ChangePitchBase()
79 return XO(
"Changes the pitch of a track without changing its tempo");
84 return L
"Change_Pitch";
98 return const_cast<ChangePitchBase&
>(*this).DoLoadFactoryDefaults(
settings);
115 double pitchRatio = 1.0 + m_dPercentChange / 100.0;
127 Calc_SemitonesChange_fromPercentChange();
129 auto initer = [&](soundtouch::SoundTouch* soundtouch) {
130 soundtouch->setPitchSemiTones((
float)(m_dSemitonesChange));
145 mSemitones = m_dSemitonesChange;
147 return SoundTouchBase::ProcessWithTimeWarper(initer, warper,
true);
151bool ChangePitchBase::CheckWhetherSkipEffect(
const EffectSettings&)
const
153 return (m_dPercentChange == 0.0);
160void ChangePitchBase::DeduceFrequencies()
162 auto FirstTrack = [&]() ->
const WaveTrack* {
163 if (IsBatchProcessing() || !inputTracks())
165 return *(inputTracks()->Selected<
const WaveTrack>()).first;
168 m_dStartFrequency = 261.265;
172 auto track = FirstTrack();
175 double rate = track->GetRate();
181 const size_t windowSize =
184 256, wxRound(pow(2.0, floor((log(rate / 20.0) / log(2.0)) + 0.5))));
188 const unsigned numWindows =
189 std::max(1, wxRound((
double)(rate / (5.0f * windowSize))));
191 double trackStart = track->GetStartTime();
192 double t0 = mT0 < trackStart ? trackStart : mT0;
193 auto start = track->TimeToLongSamples(t0);
195 auto analyzeSize = windowSize * numWindows;
196 Floats buffer { analyzeSize };
198 Floats freq { windowSize / 2 };
199 Floats freqa { windowSize / 2,
true };
202 (*track->Channels().begin())->GetFloats(buffer.get(), start, analyzeSize);
203 for (
unsigned i = 0; i < numWindows; i++)
206 buffer.get() + i * windowSize, windowSize, windowSize, freq.get(),
208 for (
size_t j = 0; j < windowSize / 2; j++)
212 for (
size_t j = 1; j < windowSize / 2; j++)
213 if (freqa[j] > freqa[argmax])
216 auto lag = (windowSize / 2 - 1) - argmax;
217 m_dStartFrequency = rate / lag;
221 double dToMIDInote = dFromMIDInote + m_dSemitonesChange;
227 m_FromFrequency = m_dStartFrequency;
234void ChangePitchBase::Calc_ToPitch()
236 int nSemitonesChange =
237 (int)(m_dSemitonesChange + ((m_dSemitonesChange < 0.0) ? -0.5 : 0.5));
238 m_nToPitch = (m_nFromPitch + nSemitonesChange) % 12;
243void ChangePitchBase::Calc_ToOctave()
248void ChangePitchBase::Calc_SemitonesChange_fromPitches()
254void ChangePitchBase::Calc_SemitonesChange_fromPercentChange()
259 (12.0 * log((100.0 + m_dPercentChange) / 100.0)) / log(2.0);
262void ChangePitchBase::Calc_ToFrequency()
264 m_ToFrequency = (m_FromFrequency * (100.0 + m_dPercentChange)) / 100.0;
267void ChangePitchBase::Calc_PercentChange()
269 m_dPercentChange = 100.0 * (pow(2.0, (m_dSemitonesChange / 12.0)) - 1.0);
Change Pitch effect provides raising or lowering the pitch without changing the tempo.
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
unsigned int PitchIndex(const double dMIDInote)
double PitchToMIDInote(const unsigned int nPitchIndex, const int nPitchOctave)
int PitchOctave(const double dMIDInote)
double FreqToMIDInote(const double freq)
bool ComputeSpectrum(const float *data, size_t width, size_t windowSize, float *output, bool autocorrelation, int windowFunc)
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
static Settings & settings()
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
OptionalMessage LoadFactoryDefaults(EffectSettings &settings) const override
Performs effect computation.
Interface for manipulations of an Effect's settings.
No change to time at all.
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
TranslatableString mProxyEffectName
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Externalized state of a plug-in.