83 "Reduces (ducks) the volume of one or more tracks whenever the volume of a specified \"control\" track reaches a particular level");
107 bool lastWasSelectedWaveTrack =
false;
108 const WaveTrack* controlTrackCandidate =
nullptr;
111 if (lastWasSelectedWaveTrack && !t->GetSelected())
113 controlTrackCandidate =
dynamic_cast<const WaveTrack*
>(t);
115 lastWasSelectedWaveTrack =
false;
116 if (t->GetSelected())
120 lastWasSelectedWaveTrack =
true;
121 controlTrackCandidate =
nullptr;
130 XO(
"You selected a track which does not contain audio. "
131 "AutoDuck can only process audio tracks."),
140 if (!controlTrackCandidate)
147 XO(
"Auto Duck needs a control track which must be placed below the "
148 "selected track(s)."),
176 const auto t1 = pControlTrack->LongSamplesToTime(
end);
179 pFirstTrack = pControlTrack->Duplicate()->SharedPointer<
WaveTrack>();
184 pFirstTrack->ApplyPitchAndSpeed(
185 { { t0, t1 } }, reportProgress);
188 XO(
"Rendering Control-Track Time-Stretched Audio"));
189 pControlTrack = pFirstTrack.get();
202 auto minSamplesPause = pControlTrack->TimeToLongSamples(maxPause);
213 std::vector<AutoDuckRegion> regions;
214 bool inDuckRegion =
false;
221 double duckRegionStart = 0;
226 const auto pControlChannel = *pControlTrack->Channels().begin();
231 pControlChannel->GetFloats(buf.get(), pos, len);
233 for (
auto i = pos; i < pos + len; i++)
235 rmsSum -= rmsWindow[rmsPos];
237 auto index = (i - pos).as_size_t();
238 rmsWindow[rmsPos] = buf[index] * buf[index];
239 rmsSum += rmsWindow[rmsPos];
242 bool thresholdExceeded = rmsSum > threshold;
244 if (thresholdExceeded)
255 duckRegionStart = pControlTrack->LongSamplesToTime(i);
259 if (!thresholdExceeded && inDuckRegion)
264 curSamplesPause += 1;
266 if (curSamplesPause >= minSamplesPause)
269 double duckRegionEnd =
270 pControlTrack->LongSamplesToTime(i - curSamplesPause);
276 inDuckRegion =
false;
284 (pos - start).as_double() / (
end - start).as_double() /
295 double duckRegionEnd =
296 pControlTrack->LongSamplesToTime(
end - curSamplesPause);
309 for (
auto iterTrack : outputs.Get().Selected<
WaveTrack>())
311 for (
const auto pChannel : iterTrack->Channels())
312 for (
size_t i = 0; i < regions.size(); ++i)
338 int trackNum,
WaveChannel& track,
double t0,
double t1)
348 auto fadeDownSamples =
350 if (fadeDownSamples < 1)
355 if (fadeUpSamples < 1)
358 float fadeDownStep =
mDuckAmountDb / fadeDownSamples.as_double();
359 float fadeUpStep =
mDuckAmountDb / fadeUpSamples.as_double();
365 for (
auto i = pos; i < pos + len; ++i)
367 float gainDown = fadeDownStep * (i - start).as_float();
368 float gainUp = fadeUpStep * (
end - i).as_float();
371 if (gainDown > gainUp)
382 if (!track.
SetFloats(buf.get(), pos, len))
391 float fractionFinished = (curTime -
mT0) / (
mT1 -
mT0);
static const size_t kBufSize
static const size_t kRMSWindowSize
Toolkit-neutral facade for basic user interface services.
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
An AudacityException with no visible message.
static constexpr EffectParameter OuterFadeUpLen
const EffectParameterMethods & Parameters() const override
bool ApplyDuckFade(int trackNum, WaveChannel &track, double t0, double t1)
EffectType GetType() const override
Type determines how it behaves.
static const ComponentInterfaceSymbol Symbol
TranslatableString GetDescription() const override
static constexpr EffectParameter ThresholdDb
static constexpr EffectParameter MaximumPause
static constexpr EffectParameter InnerFadeDownLen
static constexpr EffectParameter InnerFadeUpLen
static constexpr EffectParameter DuckAmountDb
static constexpr EffectParameter OuterFadeDownLen
const WaveTrack * mControlTrack
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
bool Process(EffectInstance &instance, EffectSettings &settings) override
ComponentInterfaceSymbol GetSymbol() const override
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
void SetLinearEffectFlag(bool linearEffectFlag)
const TrackList * inputTracks() const
std::shared_ptr< TrackList > mTracks
bool TotalProgress(double frac, const TranslatableString &={}) const
int GetNumWaveTracks() const
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
Interface for manipulations of an Effect's settings.
virtual void Reset(Effect &effect) const =0
Abstract base class for an object holding data associated with points on a time axis.
R TypeSwitch(const Functions &...functions)
Holds a msgid for the translation catalog; may also bind format arguments.
static void WithCancellableProgress(std::function< void(const ProgressReporter &)> action, TranslatableString title, TranslatableString message)
A frequently useful convenience wraps a lambda and may throw this type.
bool SetFloats(const float *buffer, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Random-access assignment of a range of samples.
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
A Track that contains audio waveform data.
std::shared_ptr< WaveTrack > Holder
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
Positions or offsets within audio files need a wide type.
std::function< void(double)> ProgressReporter
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
WAVE_TRACK_API const TranslatableString defaultStretchRenderingTitle
WAVE_TRACK_API bool HasPitchOrSpeed(const WaveTrack &track, double t0, double t1)
const char * end(const char *str) noexcept
a struct that holds a start and end time.
AutoDuckRegion(double t0, double t1)
MessageBoxOptions && IconStyle(Icon style) &&
Externalized state of a plug-in.