40 {
wxT(
"-20 dB") }, {
wxT(
"-25 dB") }, {
wxT(
"-30 dB") }, {
wxT(
"-35 dB") },
41 {
wxT(
"-40 dB") }, {
wxT(
"-45 dB") }, {
wxT(
"-50 dB") }, {
wxT(
"-55 dB") },
42 {
wxT(
"-60 dB") }, {
wxT(
"-65 dB") }, {
wxT(
"-70 dB") }, {
wxT(
"-75 dB") },
49 return -(5.0 * val + 20.0);
62 {
XO(
"Truncate Detected Silence") }, {
XO(
"Compress Excess Silence") }
92 "Truncate Silence") };
126 "Automatically reduces the length of passages where the volume is below a specified level");
131 return L
"Truncate_Silence";
149 double myThreshold {};
150 bool newParams = [&] {
189 double inputLength =
mT1 -
mT0;
190 double minInputLength = inputLength;
200 for (
auto wt :
inputTracks()->Selected<const WaveTrack>())
204 auto index = wt->TimeToLongSamples(
mT0);
208 silences, trackSilences, *wt, &silentFrame, &index, whichTrack,
209 &inputLength, &minInputLength);
211 whichTrack += wt->NChannels();
225 unsigned nGroups = 0;
231 for (
auto track :
inputTracks()->Selected<const WaveTrack>())
238 [&](
const Track* pTrack) {
return pTrack == track; };
242 "When truncating independently, there may only be one selected audio track in each Sync-Locked Track Group."));
265 for (
auto track : outputs.Get().Selected<
WaveTrack>())
272 Track *groupFirst, *groupLast;
274 TrackList::SingletonRange<Track>(track);
275 double totalCutLen = 0.0;
276 if (!
DoRemoval(silences, range, iGroup, nGroups, totalCutLen))
278 newT1 = std::max(newT1,
mT1 - totalCutLen);
304 auto trackRange = outputs.Get().Any();
305 double totalCutLen = 0.0;
306 if (
DoRemoval(silences, trackRange, 0, 1, totalCutLen))
325 for (
auto wt : range)
336 auto index = wt->TimeToLongSamples(
mT0);
341 silences, trackSilences, *wt, &silentFrame, &index, whichTrack));
347 if (silentFrame >= minSilenceFrames)
350 trackSilences.push_back(
Region(
351 wt->LongSamplesToTime(index - silentFrame),
352 wt->LongSamplesToTime(index)));
365 unsigned iGroup,
unsigned nGroups,
double& totalCutLen)
375 RegionList::const_reverse_iterator rit;
376 for (rit = silences.rbegin(); rit != silences.rend(); ++rit)
378 const Region& region = *rit;
379 const Region*
const r = ®ion;
384 (iGroup + whichReg /
double(silences.size())) /
396 double inLength = r->
end - r->
start;
416 const double cutLen = std::max(0.0, inLength - outLength);
421 totalCutLen += cutLen;
424 double cutStart = (r->
start + r->
end - cutLen) / 2;
425 double cutEnd = cutStart + cutLen;
427 [&](
const Track* pTrack) {
430 pTrack->GetEndTime() < r->
start;
458 Buffers buffers[2] { blendFrames, blendFrames };
463 for (
const auto pChannel : wt.
Channels())
466 pChannel->GetFloats(buffer.buf1.get(), t1, blendFrames);
467 pChannel->GetFloats(buffer.buf2.get(), t2, blendFrames);
469 for (
decltype(blendFrames) i = 0; i < blendFrames; ++i)
471 buffer.buf1[i] = ((blendFrames - i) * buffer.buf1[i] +
472 i * buffer.buf2[i]) /
478 wt.
Clear(cutStart, cutEnd);
481 for (
const auto pChannel : wt.
Channels())
488 buffer.buf1.get(), t1, blendFrames,
499 t.SyncLockAdjust(cutEnd, cutStart);
512 double* inputLength,
double* minInputLength)
const
514 const auto rate = wt.
GetRate();
517 auto minSilenceFrames =
526 double previewLength;
527 gPrefs->
Read(
wxT(
"/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
529 const sampleCount previewLen(previewLength * rate);
532 RegionList::iterator rit(silenceList.begin());
542 ((outLength >= previewLen) ||
545 *inputLength = std::min<double>(*inputLength, *minInputLength);
546 if (outLength >= previewLen)
548 *minInputLength = *inputLength;
559 (*index - start).as_double() / (
end - start).as_double()) /
568 for (; rit != silenceList.end(); ++rit)
571 if (rit->end >= curTime)
577 if (rit == silenceList.end())
583 auto remainingTrackSamples =
585 auto requiredTrackSamples = previewLen - outLength;
586 outLength += (remainingTrackSamples > requiredTrackSamples) ?
587 requiredTrackSamples :
588 remainingTrackSamples;
593 else if (rit->start > curTime)
596 if (*silentFrame >= minSilenceFrames)
598 trackSilences.push_back(
Region(
606 auto requiredTrackSamples = previewLen - outLength;
608 outLength += ((newIndex - *index) > requiredTrackSamples) ?
609 requiredTrackSamples :
622 for (
const auto pChannel : wt.
Channels())
623 pChannel->GetFloats(buffers[
iChannel++].get(), *index, count);
626 for (
decltype(count) i = 0; i < count; ++i)
630 ((outLength >= previewLen) ||
639 std::all_of(buffers, buffers +
iChannel, [&](
const Floats& buffer) {
640 return fabs(buffer[i]) < truncDbSilenceThreshold;
647 if (*silentFrame >= minSilenceFrames)
661 (*silentFrame - allowed).as_double() *
669 trackSilences.push_back(
Region(
673 else if (inputLength)
675 outLength += *silentFrame;
690 *inputLength = std::min<double>(*inputLength, *minInputLength);
691 if (outLength >= previewLen)
693 *minInputLength = *inputLength;
705 RegionList::iterator destIter;
706 destIter = dest.begin();
708 if (destIter == dest.end())
710 RegionList::iterator curDest = destIter;
713 double nsStart = curDest->start;
715 bool lastRun =
false;
717 RegionList::const_iterator srcIter = src.begin();
721 if (srcIter == src.end())
726 while (srcIter != src.end() || lastRun)
729 RegionList::const_iterator curSrc;
734 nsEnd = std::numeric_limits<double>::max();
739 nsEnd = curSrc->start;
745 while (curDest->end <= nsStart)
748 if (destIter == dest.end())
756 if (nsStart > curDest->start && nsEnd < curDest->
end)
759 Region r(nsEnd, curDest->end);
762 curDest->end = nsStart;
765 RegionList::iterator nextIt(destIter);
772 if (nextIt == dest.end())
775 dest.insert(nextIt, r);
783 nsStart > curDest->start && nsStart < curDest->
end &&
784 nsEnd >= curDest->end)
786 curDest->end = nsStart;
789 if (destIter == dest.end())
797 while (nsStart <= curDest->start && nsEnd >= curDest->end)
799 destIter = dest.erase(destIter);
800 if (destIter == dest.end())
809 nsStart <= curDest->start && nsEnd > curDest->start &&
810 nsEnd < curDest->
end)
812 curDest->start = nsEnd;
824 nsStart = curSrc->end;
826 if (srcIter == src.end())
Toolkit-neutral facade for basic user interface services.
audacity::BasicSettings * gPrefs
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
static Settings & settings()
static CommandParameters::ObsoleteMap kObsoleteActions[]
static const size_t DEF_BlendFrameCount
static const size_t nObsoleteActions
static const double DEF_MinTruncMs
static double enumToDB(int val)
Generates EffectParameterMethods overrides from variadic template arguments.
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
std::pair< wxString, size_t > ObsoleteMap
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
void SetLinearEffectFlag(bool linearEffectFlag)
const TrackList * inputTracks() const
std::shared_ptr< TrackList > mTracks
const AudacityProject * FindProject() const
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
Restore settings from keys and values.
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
static const size_t NumDbChoices
static const EnumValueSymbol DbChoices[]
static TrackIterRange< Track > Group(Track &track)
static bool IsSelectedOrSyncLockSelectedP(const Track *pTrack)
bool IsSyncLocked() const
static SyncLockState & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Holds a msgid for the translation catalog; may also bind format arguments.
static constexpr EffectParameter Independent
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
Restore settings from keys and values.
bool FindSilences(RegionList &silences, const TrackIterRange< const WaveTrack > &range)
static constexpr EffectParameter Threshold
ComponentInterfaceSymbol GetSymbol() const override
EffectType GetType() const override
Type determines how it behaves.
bool DoRemoval(const RegionList &silences, const TrackIterRange< Track > &range, unsigned iGroup, unsigned nGroups, double &totalCutLen)
double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const override
bool ProcessIndependently()
const EffectParameterMethods & Parameters() const override
static constexpr EffectParameter Truncate
bool Process(EffectInstance &instance, EffectSettings &settings) override
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack &wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=nullptr, double *minInputLength=nullptr) const
double mSilenceCompressPercent
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
static constexpr EffectParameter Minimum
static constexpr EffectParameter Compress
static constexpr EnumParameter ActIndex
double mInitialAllowedSilence
static const EnumValueSymbol kActionStrings[nActions]
TranslatableString GetDescription() const override
void Intersect(RegionList &dest, const RegionList &src)
double mTruncLongestAllowedSilence
static const ComponentInterfaceSymbol Symbol
bool NeedsDither() const override
virtual ~TruncSilenceBase()
A Track that contains audio waveform data.
void Clear(double t0, double t1) override
double GetEndTime() const override
Implement WideSampleSequence.
double GetRate() const override
size_t GetMaxBlockSize() const
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
double SnapToSample(double t) const
virtual bool Read(const wxString &key, bool *value) const =0
Positions or offsets within audio files need a wide type.
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
const char * end(const char *str) noexcept
const wxChar *const key
Identifier in configuration file.
const Type def
Default value.
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.
Range between two TrackIters, usable in range-for statements, and with Visit member functions.
Structure to hold region of a wavetrack and a comparison function for sortability.