Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EffectTruncSilence Class Referencefinal

Truncate Silence automatically reduces the length of passages where the volume is below a set threshold level. More...

#include <TruncSilence.h>

Inheritance diagram for EffectTruncSilence:
[legend]
Collaboration diagram for EffectTruncSilence:
[legend]

Public Member Functions

 EffectTruncSilence ()
 
virtual ~EffectTruncSilence ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 
bool Analyze (RegionList &silenceList, RegionList &trackSilences, const WaveTrack &wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=nullptr, double *minInputLength=nullptr) const
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 
std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
bool NeedsDither () const override
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

Static Public Member Functions

static EffectTruncSilenceFetchParameters (EffectTruncSilence &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
- Static Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public Member Functions inherited from EffectUIServices
static int DoMessageBox (const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Truncate Silence") }
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Types

enum  kActions { kTruncate , kCompress , nActions }
 

Private Member Functions

void Intersect (RegionList &dest, const RegionList &src)
 
void OnControlChange (wxCommandEvent &evt)
 
void UpdateUI ()
 
bool ProcessIndependently ()
 
bool ProcessAll ()
 
bool FindSilences (RegionList &silences, const TrackIterRange< const WaveTrack > &range)
 
bool DoRemoval (const RegionList &silences, const TrackIterRange< Track > &range, unsigned iGroup, unsigned nGroups, double &totalCutLen)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent {}
 
double mThresholdDB {}
 
int mActionIndex
 
double mInitialAllowedSilence
 
double mTruncLongestAllowedSilence
 
double mSilenceCompressPercent
 
bool mbIndependent
 
size_t mBlendFrameCount
 
wxTextCtrl * mThresholdText
 
wxChoice * mActionChoice
 
wxTextCtrl * mInitialAllowedSilenceT
 
wxTextCtrl * mTruncLongestAllowedSilenceT
 
wxTextCtrl * mSilenceCompressPercentT
 
wxCheckBox * mIndependent
 

Static Private Attributes

static const EnumValueSymbol kActionStrings [nActions]
 
static constexpr EffectParameter Threshold
 
static constexpr EnumParameter ActIndex
 
static constexpr EffectParameter Minimum
 
static constexpr EffectParameter Truncate
 
static constexpr EffectParameter Compress
 
static constexpr EffectParameter Independent
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Detailed Description

Truncate Silence automatically reduces the length of passages where the volume is below a set threshold level.

Definition at line 32 of file TruncSilence.h.

Member Enumeration Documentation

◆ kActions

Enumerator
kTruncate 
kCompress 
nActions 

Definition at line 125 of file TruncSilence.h.

Constructor & Destructor Documentation

◆ EffectTruncSilence()

EffectTruncSilence::EffectTruncSilence ( )

Definition at line 116 of file TruncSilence.cpp.

117{
118 Parameters().Reset(*this);
119
120 SetLinearEffectFlag(false);
121
122 // This used to be changeable via the audacity.cfg/registry. Doubtful that was
123 // ever done.
124 //
125 // Original comment:
126 //
127 // mBlendFrameCount only retrieved from prefs ... not using dialog
128 // Only way to change (for windows) is thru registry
129 // The values should be figured dynamically ... too many frames could be invalid
131}
static const size_t DEF_BlendFrameCount
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:214
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override

References DEF_BlendFrameCount.

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectTruncSilence()

EffectTruncSilence::~EffectTruncSilence ( )
virtual

Definition at line 133 of file TruncSilence.cpp.

134{
135}

Member Function Documentation

◆ Analyze()

bool EffectTruncSilence::Analyze ( RegionList silenceList,
RegionList trackSilences,
const WaveTrack wt,
sampleCount silentFrame,
sampleCount index,
int  whichTrack,
double *  inputLength = nullptr,
double *  minInputLength = nullptr 
) const
Precondition
wt.IsLeader()

Definition at line 514 of file TruncSilence.cpp.

518{
519 assert(wt.IsLeader());
520 const auto rate = wt.GetRate();
521
522 // Smallest silent region to detect in frames
523 auto minSilenceFrames =
525
526 double truncDbSilenceThreshold = DB_TO_LINEAR(mThresholdDB);
527 auto blockLen = wt.GetMaxBlockSize();
528 auto start = wt.TimeToLongSamples(mT0);
529 auto end = wt.TimeToLongSamples(mT1);
530 sampleCount outLength = 0;
531
532 double previewLength;
533 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
534 // Minimum required length in samples.
535 const sampleCount previewLen(previewLength * rate);
536
537 // Keep position in overall silences list for optimization
538 RegionList::iterator rit(silenceList.begin());
539
540 // Allocate buffers
541 Floats buffers[] {
542 Floats{ blockLen },
543 Floats{ blockLen }
544 };
545
546 // Loop through current track
547 while (*index < end) {
548 if (inputLength && ((outLength >= previewLen) ||
549 (*index - start > wt.TimeToLongSamples(*minInputLength)))
550 ) {
551 *inputLength = std::min<double>(*inputLength, *minInputLength);
552 if (outLength >= previewLen) {
553 *minInputLength = *inputLength;
554 }
555 return true;
556 }
557
558 if (!inputLength) {
559 // Show progress dialog, test for cancellation
560 bool cancelled = TotalProgress(
561 detectFrac * (whichTrack +
562 (*index - start).as_double() /
563 (end - start).as_double()) /
564 (double)GetNumWaveTracks());
565 if (cancelled)
566 return false;
567 }
568
569 // Optimization: if not in a silent region skip ahead to the next one
570
571 double curTime = wt.LongSamplesToTime(*index);
572 for ( ; rit != silenceList.end(); ++rit) {
573 // Find the first silent region ending after current time
574 if (rit->end >= curTime) {
575 break;
576 }
577 }
578
579 if (rit == silenceList.end()) {
580 // No more regions -- no need to process the rest of the track
581 if (inputLength) {
582 // Add available samples up to previewLength.
583 auto remainingTrackSamples =
584 wt.TimeToLongSamples(wt.GetEndTime()) - *index;
585 auto requiredTrackSamples = previewLen - outLength;
586 outLength += (remainingTrackSamples > requiredTrackSamples)
587 ? requiredTrackSamples
588 : remainingTrackSamples;
589 }
590
591 break;
592 }
593 else if (rit->start > curTime) {
594 // End current silent region, skip ahead
595 if (*silentFrame >= minSilenceFrames) {
596 trackSilences.push_back(Region(
597 wt.LongSamplesToTime(*index - *silentFrame),
598 wt.LongSamplesToTime(*index)
599 ));
600 }
601 *silentFrame = 0;
602 auto newIndex = wt.TimeToLongSamples(rit->start);
603 if (inputLength) {
604 auto requiredTrackSamples = previewLen - outLength;
605 // Add non-silent sample to outLength
606 outLength += ((newIndex - *index) > requiredTrackSamples)
607 ? requiredTrackSamples
608 : newIndex - *index;
609 }
610
611 *index = newIndex;
612 }
613 // End of optimization
614
615 // Limit size of current block if we've reached the end
616 auto count = limitSampleBufferSize( blockLen, end - *index );
617
618 // Fill buffers
619 size_t iChannel = 0;
620 for (const auto pChannel : wt.Channels())
621 pChannel->GetFloats(buffers[iChannel++].get(), *index, count);
622
623 // Look for silenceList in current block
624 for (decltype(count) i = 0; i < count; ++i) {
625 if (inputLength && ((outLength >= previewLen) ||
626 (outLength > wt.TimeToLongSamples(*minInputLength)))
627 ) {
628 *inputLength =
629 wt.LongSamplesToTime(*index + i) - wt.LongSamplesToTime(start);
630 break;
631 }
632
633 const bool silent = std::all_of(buffers, buffers + iChannel,
634 [&](const Floats &buffer){
635 return fabs(buffer[i]) < truncDbSilenceThreshold;
636 });
637 if (silent)
638 (*silentFrame)++;
639 else {
640 sampleCount allowed = 0;
641 if (*silentFrame >= minSilenceFrames) {
642 if (inputLength) {
643 switch (mActionIndex) {
644 case kTruncate:
645 outLength +=
647 break;
648 case kCompress:
649 allowed =
651 outLength += sampleCount(
652 allowed.as_double() +
653 (*silentFrame - allowed).as_double()
655 );
656 break;
657 // default: // Not currently used.
658 }
659 }
660
661 // Record the silent region
662 trackSilences.push_back(Region(
663 wt.LongSamplesToTime(*index + i - *silentFrame),
664 wt.LongSamplesToTime(*index + i)
665 ));
666 }
667 else if (inputLength) { // included as part of non-silence
668 outLength += *silentFrame;
669 }
670 *silentFrame = 0;
671 if (inputLength) {
672 ++outLength; // Add non-silent sample to outLength
673 }
674 }
675 }
676 // Next block
677 *index += count;
678 }
679
680 if (inputLength) {
681 *inputLength = std::min<double>(*inputLength, *minInputLength);
682 if (outLength >= previewLen) {
683 *minInputLength = *inputLength;
684 }
685 }
686
687 return true;
688}
wxT("CloseDown"))
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:561
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
WaveTrack::Region Region
const double detectFrac
static const double DEF_MinTruncMs
double mT1
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:115
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:341
int GetNumWaveTracks() const
Definition: Effect.h:139
double mInitialAllowedSilence
Definition: TruncSilence.h:108
double mSilenceCompressPercent
Definition: TruncSilence.h:110
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:109
auto Channels()
Definition: WaveTrack.h:268
bool IsLeader() const override
Definition: WaveTrack.cpp:2443
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:2717
double GetRate() const override
Definition: WaveTrack.cpp:868
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:2390
double LongSamplesToTime(sampleCount pos) const
sampleCount TimeToLongSamples(double t0) const
virtual bool Read(const wxString &key, bool *value) const =0
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
double as_double() const
Definition: SampleCount.h:46
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References sampleCount::as_double(), WaveTrack::Channels(), DB_TO_LINEAR, DEF_MinTruncMs, detectFrac, PackedArray::end(), WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), WaveTrack::GetRate(), gPrefs, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, WaveTrack::IsLeader(), kCompress, kTruncate, limitSampleBufferSize(), WideSampleSequence::LongSamplesToTime(), mActionIndex, mInitialAllowedSilence, mSilenceCompressPercent, EffectBase::mT0, EffectBase::mT1, mThresholdDB, mTruncLongestAllowedSilence, audacity::BasicSettings::Read(), WideSampleSequence::TimeToLongSamples(), Effect::TotalProgress(), and wxT().

Referenced by CalcPreviewInputLength(), and FindSilences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CalcPreviewInputLength()

double EffectTruncSilence::CalcPreviewInputLength ( const EffectSettings settings,
double  previewLength 
) const
overridevirtual

Implements EffectBase.

Definition at line 204 of file TruncSilence.cpp.

206{
207 double inputLength = mT1 - mT0;
208 double minInputLength = inputLength;
209
210 // Master list of silent regions
211 RegionList silences;
212
213 // Start with the whole selection silent
214 silences.push_back(Region(mT0, mT1));
215
216 int whichTrack = 0;
217
218 for (auto wt : inputTracks()->Selected<const WaveTrack>()) {
219 RegionList trackSilences;
220
221 auto index = wt->TimeToLongSamples(mT0);
222 sampleCount silentFrame = 0; // length of the current silence
223
224 Analyze(silences, trackSilences, *wt, &silentFrame, &index, whichTrack,
225 &inputLength, &minInputLength);
226
227 whichTrack += wt->NChannels();
228 }
229 return inputLength;
230}
const TrackList * inputTracks() const
Definition: EffectBase.h:91
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack &wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=nullptr, double *minInputLength=nullptr) const

References Analyze(), EffectBase::inputTracks(), EffectBase::mT0, and EffectBase::mT1.

Here is the call graph for this function:

◆ DoRemoval()

bool EffectTruncSilence::DoRemoval ( const RegionList silences,
const TrackIterRange< Track > &  range,
unsigned  iGroup,
unsigned  nGroups,
double &  totalCutLen 
)
private
Precondition
range visits leaders only

Definition at line 378 of file TruncSilence.cpp.

382{
383 //
384 // Now remove the silent regions from all selected / sync-lock selected tracks.
385 //
386
387 // Loop over detected regions in reverse (so cuts don't change time values
388 // down the line)
389 int whichReg = 0;
390 RegionList::const_reverse_iterator rit;
391 for (rit = silences.rbegin(); rit != silences.rend(); ++rit)
392 {
393 const Region &region = *rit;
394 const Region *const r = &region;
395
396 // Progress dialog and cancellation. Do additional cleanup before return.
397 const double frac = detectFrac +
398 (1 - detectFrac) * (iGroup + whichReg / double(silences.size())) / nGroups;
399 if (TotalProgress(frac))
400 return false;
401
402 // Intersection may create regions smaller than allowed; ignore them.
403 // Allow one nanosecond extra for consistent results with exact milliseconds of allowed silence.
404 if ((r->end - r->start) < (mInitialAllowedSilence - 0.000000001))
405 continue;
406
407 // Find NEW silence length as requested
408 double inLength = r->end - r->start;
409 double outLength;
410
411 switch (mActionIndex)
412 {
413 case kTruncate:
414 outLength = std::min(mTruncLongestAllowedSilence, inLength);
415 break;
416 case kCompress:
417 outLength = mInitialAllowedSilence +
418 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0;
419 break;
420 default: // Not currently used.
421 outLength = std::min(mInitialAllowedSilence +
422 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0,
424 }
425
426 const double cutLen = std::max(0.0, inLength - outLength);
427 // Don't waste time cutting nothing.
428 if( cutLen == 0.0 )
429 continue;
430
431 totalCutLen += cutLen;
432
433 bool success = true;
434 double cutStart = (r->start + r->end - cutLen) / 2;
435 double cutEnd = cutStart + cutLen;
436 (range
438 - [&](const Track *pTrack) { return
439 // Don't waste time past the end of a track
440 pTrack->GetEndTime() < r->start;
441 }
442 ).VisitWhile(success,
443 [&](WaveTrack &wt) {
444 assert(wt.IsLeader());
445 // In WaveTracks, clear with a cross-fade
446 auto blendFrames = mBlendFrameCount;
447 // Round start/end times to frame boundaries
448 cutStart = wt.SnapToSample(cutStart);
449 cutEnd = wt.SnapToSample(cutEnd);
450
451 // Make sure the cross-fade does not affect non-silent frames
452 if (wt.LongSamplesToTime(blendFrames) > inLength) {
453 // Result is not more than blendFrames:
454 blendFrames = wt.TimeToLongSamples(inLength).as_size_t();
455 }
456
457 // Perform cross-fade in memory
458 struct Buffers {
459 Buffers(size_t size)
460 : buf1{ size }, buf2 { size }
461 {}
462 Floats buf1, buf2;
463 };
464 Buffers buffers[2]{ blendFrames, blendFrames };
465 auto t1 = wt.TimeToLongSamples(cutStart) - blendFrames / 2;
466 auto t2 = wt.TimeToLongSamples(cutEnd) - blendFrames / 2;
467
468 size_t iChannel = 0;
469 for (const auto pChannel : wt.Channels()) {
470 auto &buffer = buffers[iChannel];
471 pChannel->GetFloats(buffer.buf1.get(), t1, blendFrames);
472 pChannel->GetFloats(buffer.buf2.get(), t2, blendFrames);
473
474 for (decltype(blendFrames) i = 0; i < blendFrames; ++i) {
475 buffer.buf1[i] =
476 ((blendFrames - i) * buffer.buf1[i] + i * buffer.buf2[i]) /
477 (double)blendFrames;
478 }
479 ++iChannel;
480 }
481
482 assert(wt.IsLeader()); // given range visits leaders only
483 wt.Clear(cutStart, cutEnd);
484
485 iChannel = 0;
486 for (const auto pChannel : wt.Channels()) {
487 // Write cross-faded data
488 auto &buffer = buffers[iChannel];
489 success = success &&
490 pChannel->Set((samplePtr)buffer.buf1.get(), floatSample, t1,
491 blendFrames,
492 // This effect mostly shifts samples to remove silences, and
493 // does only a little bit of floating point calculations to
494 // cross-fade the splices, over a 100 sample interval by default.
495 // Don't dither.
497 ++iChannel;
498 }
499 },
500 [&](Track &t) {
501 assert(t.IsLeader());
502 // Non-wave tracks: just do a sync-lock adjust
503 t.SyncLockAdjust(cutEnd, cutStart);
504 }
505 );
506 if (!success)
507 return false;
508 ++whichReg;
509 }
510
511 return true;
512}
int min(int a, int b)
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
char * samplePtr
Definition: SampleFormat.h:55
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:123
A Track that contains audio waveform data.
Definition: WaveTrack.h:220
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:1215
double SnapToSample(double t) const
size_t as_size_t() const
Definition: SampleCount.cpp:16
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:228

References sampleCount::as_size_t(), WaveTrack::Channels(), WaveTrack::Clear(), detectFrac, WaveTrack::Region::end, floatSample, anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, WaveTrack::IsLeader(), SyncLock::IsSelectedOrSyncLockSelected(), kCompress, kTruncate, WideSampleSequence::LongSamplesToTime(), mActionIndex, mBlendFrameCount, min(), mInitialAllowedSilence, mSilenceCompressPercent, mTruncLongestAllowedSilence, narrowestSampleFormat, size, WideSampleSequence::SnapToSample(), WaveTrack::Region::start, WideSampleSequence::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FetchParameters()

static EffectTruncSilence * EffectTruncSilence::FetchParameters ( EffectTruncSilence e,
EffectSettings  
)
inlinestatic

Definition at line 36 of file TruncSilence.h.

36{ return &e; }

◆ FindSilences()

bool EffectTruncSilence::FindSilences ( RegionList silences,
const TrackIterRange< const WaveTrack > &  range 
)
private
Precondition
range visits leaders only

Definition at line 330 of file TruncSilence.cpp.

332{
333 // Start with the whole selection silent
334 silences.push_back(Region(mT0, mT1));
335
336 // Remove non-silent regions in each track
337 int whichTrack = 0;
338 for (auto wt : range) {
339 assert(wt->IsLeader());
340 // Smallest silent region to detect in frames
341 auto minSilenceFrames =
343 * wt->GetRate());
344
345 //
346 // Scan the track for silences
347 //
348 RegionList trackSilences;
349
350 auto index = wt->TimeToLongSamples(mT0);
351 sampleCount silentFrame = 0;
352
353 // Detect silences
354 bool cancelled = !(Analyze(
355 silences, trackSilences, *wt, &silentFrame, &index, whichTrack));
356
357 // Buffer has been freed, so we're OK to return if cancelled
358 if (cancelled)
359 return false;
360
361 if (silentFrame >= minSilenceFrames)
362 {
363 // Track ended in silence -- record region
364 trackSilences.push_back(Region(
365 wt->LongSamplesToTime(index - silentFrame),
366 wt->LongSamplesToTime(index)
367 ));
368 }
369
370 // Intersect with the overall silent region list
371 Intersect(silences, trackSilences);
372 whichTrack++;
373 }
374
375 return true;
376}
void Intersect(RegionList &dest, const RegionList &src)

References Analyze(), DEF_MinTruncMs, Intersect(), mInitialAllowedSilence, EffectBase::mT0, and EffectBase::mT1.

Referenced by ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDescription()

TranslatableString EffectTruncSilence::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 144 of file TruncSilence.cpp.

145{
146 return XO("Automatically reduces the length of passages where the volume is below a specified level");
147}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectTruncSilence::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 139 of file TruncSilence.cpp.

140{
141 return Symbol;
142}
static const ComponentInterfaceSymbol Symbol
Definition: TruncSilence.h:37

References Symbol.

◆ GetType()

EffectType EffectTruncSilence::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 156 of file TruncSilence.cpp.

157{
158 return EffectTypeProcess;
159}
@ EffectTypeProcess

References EffectTypeProcess.

◆ Intersect()

void EffectTruncSilence::Intersect ( RegionList dest,
const RegionList src 
)
private

Definition at line 798 of file TruncSilence.cpp.

799{
800 RegionList::iterator destIter;
801 destIter = dest.begin();
802 // Any time we reach the end of the dest list we're finished
803 if (destIter == dest.end())
804 return;
805 RegionList::iterator curDest = destIter;
806
807 // Operation: find non-silent regions in src, remove them from dest.
808 double nsStart = curDest->start;
809 double nsEnd;
810 bool lastRun = false; // must run the loop one extra time
811
812 RegionList::const_iterator srcIter = src.begin();
813
814 // This logic, causing the loop to run once after end of src, must occur
815 // each time srcIter is updated
816 if (srcIter == src.end())
817 {
818 lastRun = true;
819 }
820
821 while (srcIter != src.end() || lastRun)
822 {
823 // Don't use curSrc unless lastRun is false!
824 RegionList::const_iterator curSrc;
825
826 if (lastRun)
827 {
828 // The last non-silent region extends as far as possible
829 nsEnd = std::numeric_limits<double>::max();
830 }
831 else
832 {
833 curSrc = srcIter;
834 nsEnd = curSrc->start;
835 }
836
837 if (nsEnd > nsStart)
838 {
839 // Increment through dest until we have a region that could be affected
840 while (curDest->end <= nsStart)
841 {
842 ++destIter;
843 if (destIter == dest.end())
844 {
845 return;
846 }
847 curDest = destIter;
848 }
849
850 // Check for splitting dest region in two
851 if (nsStart > curDest->start && nsEnd < curDest->end)
852 {
853 // The second region
854 Region r(nsEnd, curDest->end);
855
856 // The first region
857 curDest->end = nsStart;
858
859 // Insert second region after first
860 RegionList::iterator nextIt(destIter);
861 ++nextIt;
862
863 // This should just read: destIter = dest.insert(nextIt, r); but we
864 // work around two two wxList::insert() bugs. First, in some
865 // versions it returns the wrong value. Second, in some versions,
866 // it crashes when you insert at list end.
867 if (nextIt == dest.end())
868 dest.push_back(r);
869 else
870 dest.insert(nextIt, r);
871 ++destIter; // (now points at the newly-inserted region)
872
873 curDest = destIter;
874 }
875
876 // Check for truncating the end of dest region
877 if (nsStart > curDest->start && nsStart < curDest->end &&
878 nsEnd >= curDest->end)
879 {
880 curDest->end = nsStart;
881
882 ++destIter;
883 if (destIter == dest.end())
884 {
885 return;
886 }
887 curDest = destIter;
888 }
889
890 // Check for all dest regions that need to be removed completely
891 while (nsStart <= curDest->start && nsEnd >= curDest->end)
892 {
893 destIter = dest.erase(destIter);
894 if (destIter == dest.end())
895 {
896 return;
897 }
898 curDest = destIter;
899 }
900
901 // Check for truncating the beginning of dest region
902 if (nsStart <= curDest->start &&
903 nsEnd > curDest->start && nsEnd < curDest->end)
904 {
905 curDest->start = nsEnd;
906 }
907 }
908
909 if (lastRun)
910 {
911 // done
912 lastRun = false;
913 }
914 else
915 {
916 // Next non-silent region starts at the end of this silent region
917 nsStart = curSrc->end;
918 ++srcIter;
919 if (srcIter == src.end())
920 {
921 lastRun = true;
922 }
923 }
924 }
925}

References PackedArray::end().

Referenced by FindSilences().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSettings()

bool EffectTruncSilence::LoadSettings ( const CommandParameters parms,
EffectSettings settings 
) const
overridevirtual

Restore settings from keys and values.

Returns
true on success

Implements EffectSettingsManager.

Definition at line 161 of file TruncSilence.cpp.

163{
165
166 // A bit of special treatment for two parameters
167
168 // This control migrated from a choice to a text box in version 2.3.0
169 double myThreshold {};
170 bool newParams = [&] {
171 double temp;
172 if (!parms.ReadAndVerify(Threshold.key,
174 return false;
175 myThreshold = temp;
176 return true;
177 } ();
178
179 if ( !newParams ) {
180 int temp;
181 // Use legacy param:
182 if (!parms.ReadAndVerify(L"Db", &temp, 0,
184 return false;
185 myThreshold = enumToDB( temp );
186 }
187
188 {
189 int temp;
190 if (!parms.ReadAndVerify( ActIndex.key, &temp, ActIndex.def,
192 return false;
193
194 // TODO: fix this when settings are really externalized
195 const_cast<int&>(mActionIndex) = temp;
196 }
197 // TODO: fix this when settings are really externalized
198 const_cast<double&>(mThresholdDB) = myThreshold;
199 return true;
200}
static Settings & settings()
Definition: TrackInfo.cpp:83
static CommandParameters::ObsoleteMap kObsoleteActions[]
static const size_t nObsoleteActions
static double enumToDB(int val)
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
Restore settings from keys and values.
Definition: Effect.cpp:129
static constexpr EnumParameter ActIndex
Definition: TruncSilence.h:136
static const EnumValueSymbol kActionStrings[nActions]
Definition: TruncSilence.h:132
static constexpr EffectParameter Threshold
Definition: TruncSilence.h:134
static const size_t NumDbChoices
static const EnumValueSymbol DbChoices[]
const wxChar *const key
Identifier in configuration file.
const Type def
Default value.
const Type min
Minimum value.
const Type max
Maximum value.

References ActIndex, Enums::DbChoices, EffectParameter< Structure, Member, Type, Value >::def, enumToDB(), kActionStrings, EffectParameter< Structure, Member, Type, Value >::key, kObsoleteActions, Effect::LoadSettings(), mActionIndex, EffectParameter< Structure, Member, Type, Value >::max, EffectParameter< Structure, Member, Type, Value >::min, mThresholdDB, nActions, nObsoleteActions, Enums::NumDbChoices, CommandParameters::ReadAndVerify(), settings(), and Threshold.

Here is the call graph for this function:

◆ ManualPage()

ManualPageID EffectTruncSilence::ManualPage ( ) const
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 149 of file TruncSilence.cpp.

150{
151 return L"Truncate_Silence";
152}

◆ NeedsDither()

bool EffectTruncSilence::NeedsDither ( ) const
overridevirtual

Reimplemented from StatefulEffectBase.

Definition at line 972 of file TruncSilence.cpp.

973{
974 return false;
975}

◆ OnControlChange()

void EffectTruncSilence::OnControlChange ( wxCommandEvent &  evt)
private

Definition at line 959 of file TruncSilence.cpp.

960{
961 mActionChoice->GetValidator()->TransferFromWindow();
962
963 UpdateUI();
964
966 mUIParent, mUIParent->TransferDataFromWindow()))
967 {
968 return;
969 }
970}
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
wxChoice * mActionChoice
Definition: TruncSilence.h:116
wxWeakRef< wxWindow > mUIParent
Definition: TruncSilence.h:104

References EffectEditor::EnableApply(), mActionChoice, mUIParent, and UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectTruncSilence::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 89 of file TruncSilence.cpp.

90{
93 > parameters;
94 return parameters;
95}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Independent
Definition: TruncSilence.h:144
static constexpr EffectParameter Minimum
Definition: TruncSilence.h:138
static constexpr EffectParameter Truncate
Definition: TruncSilence.h:140
static constexpr EffectParameter Compress
Definition: TruncSilence.h:142

References ActIndex, Compress, EffectTruncSilence(), Independent, Minimum, Threshold, and Truncate.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectEditor > EffectTruncSilence::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access,
const EffectOutputs pOutputs 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from PopulateUI instead of a DefaultEffectEditor; default implementation returns null

Reimplemented from StatefulEffectUIServices.

Definition at line 691 of file TruncSilence.cpp.

694{
695 mUIParent = S.GetParent();
696 wxASSERT(nActions == WXSIZEOF(kActionStrings));
697
698 S.AddSpace(0, 5);
699
700 S.StartStatic(XO("Detect Silence"));
701 {
702 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
703 {
704 // Threshold
706 .Validator<FloatingPointValidator<double>>(
707 3, &mThresholdDB, NumValidatorStyle::NO_TRAILING_ZEROES,
709 .NameSuffix(XO("db"))
710 .AddTextBox(XXO("&Threshold:"), wxT(""), 0);
711 S.AddUnits(XO("dB"));
712
713 // Ignored silence
714 mInitialAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
716 NumValidatorStyle::NO_TRAILING_ZEROES,
718 .NameSuffix(XO("seconds"))
719 .AddTextBox(XXO("&Duration:"), wxT(""), 12);
720 S.AddUnits(XO("seconds"));
721 }
722 S.EndMultiColumn();
723 }
724 S.EndStatic();
725
726 S.StartStatic(XO("Action"));
727 {
728 S.StartHorizontalLay();
729 {
730 // Action choices
731 auto actionChoices = Msgids( kActionStrings, nActions );
733 .Validator<wxGenericValidator>(&mActionIndex)
734 .MinSize( { -1, -1 } )
735 .AddChoice( {}, actionChoices );
736 }
737 S.EndHorizontalLay();
738 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
739 {
740 // Truncation / Compression factor
741
742 mTruncLongestAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
744 NumValidatorStyle::NO_TRAILING_ZEROES,
746 .NameSuffix(XO("seconds"))
747 .AddTextBox(XXO("Tr&uncate to:"), wxT(""), 12);
748 S.AddUnits(XO("seconds"));
749
750 mSilenceCompressPercentT = S.Validator<FloatingPointValidator<double>>(
752 NumValidatorStyle::NO_TRAILING_ZEROES,
754 .NameSuffix(XO("%"))
755 .AddTextBox(XXO("C&ompress to:"), wxT(""), 12);
756 S.AddUnits(XO("%"));
757 }
758 S.EndMultiColumn();
759
760 S.StartMultiColumn(2, wxALIGN_CENTER_HORIZONTAL);
761 {
762 mIndependent = S.AddCheckBox(XXO("Trunc&ate tracks independently"),
764 }
765 S.EndMultiColumn();
766 }
767 S.EndStatic();
768
769 UpdateUI();
770 return nullptr;
771}
XXO("&Cut/Copy/Paste Toolbar")
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
wxTextCtrl * mThresholdText
Definition: TruncSilence.h:115
wxCheckBox * mIndependent
Definition: TruncSilence.h:120
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:118
wxTextCtrl * mInitialAllowedSilenceT
Definition: TruncSilence.h:117
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:119

References Compress, kActionStrings, mActionChoice, mActionIndex, EffectParameter< Structure, Member, Type, Value >::max, mbIndependent, EffectParameter< Structure, Member, Type, Value >::min, mIndependent, Minimum, mInitialAllowedSilence, mInitialAllowedSilenceT, Msgids(), mSilenceCompressPercent, mSilenceCompressPercentT, mThresholdDB, mThresholdText, mTruncLongestAllowedSilence, mTruncLongestAllowedSilenceT, mUIParent, nActions, S, Threshold, Truncate, UpdateUI(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ Process()

bool EffectTruncSilence::Process ( EffectInstance instance,
EffectSettings settings 
)
overridevirtual

Implements StatefulEffectBase.

Definition at line 233 of file TruncSilence.cpp.

234{
235 const bool success =
238 : ProcessAll();
239
240 return success;
241}

References mbIndependent, ProcessAll(), and ProcessIndependently().

Here is the call graph for this function:

◆ ProcessAll()

bool EffectTruncSilence::ProcessAll ( )
private

Definition at line 307 of file TruncSilence.cpp.

308{
309 // Copy tracks
310 EffectOutputTracks outputs{ *mTracks, {{ mT0, mT1 }}, true, true };
311
312 // Master list of silent regions.
313 // This list should always be kept in order.
314 RegionList silences;
315
316 if (FindSilences(silences, outputs.Get().Selected<const WaveTrack>()))
317 {
318 auto trackRange = outputs.Get().Any();
319 double totalCutLen = 0.0;
320 if (DoRemoval(silences, trackRange, 0, 1, totalCutLen)) {
321 mT1 -= totalCutLen;
322 outputs.Commit();
323 return true;
324 }
325 }
326
327 return false;
328}
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
Use this object to copy the input tracks to tentative outputTracks.
bool FindSilences(RegionList &silences, const TrackIterRange< const WaveTrack > &range)
bool DoRemoval(const RegionList &silences, const TrackIterRange< Track > &range, unsigned iGroup, unsigned nGroups, double &totalCutLen)

References DoRemoval(), FindSilences(), EffectBase::mT0, EffectBase::mT1, and EffectBase::mTracks.

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessIndependently()

bool EffectTruncSilence::ProcessIndependently ( )
private

Definition at line 243 of file TruncSilence.cpp.

244{
245 unsigned nGroups = 0;
246
247 const bool syncLock = SyncLockState::Get(*FindProject()).IsSyncLocked();
248
249 // Check if it's permissible
250 {
251 for (auto track : inputTracks()->Selected<const WaveTrack>()) {
252 if (syncLock) {
253 auto otherTracks =
254 SyncLock::Group(track).Filter<const WaveTrack>()
256 - [&](const Track *pTrack){ return pTrack == track; };
257 if (otherTracks) {
259 XO(
260"When truncating independently, there may only be one selected audio track in each Sync-Locked Track Group.") );
261 return false;
262 }
263 }
264
265 ++nGroups;
266 }
267 }
268
269 if (nGroups == 0)
270 // nothing to do
271 return true;
272
273 // Now do the work
274
275 // Copy tracks
276 EffectOutputTracks outputs{ *mTracks, {{ mT0, mT1 }}, true, true };
277 double newT1 = 0.0;
278
279 {
280 unsigned iGroup = 0;
281 for (auto track : outputs.Get().Selected<WaveTrack>()) {
282 RegionList silences;
283 if (!FindSilences(silences,
284 TrackList::SingletonRange(&as_const(*track))))
285 return false;
286 // Treat tracks in the sync lock group only
287 Track *groupFirst, *groupLast;
288 auto range = syncLock
289 ? SyncLock::Group(track)
290 : TrackList::SingletonRange<Track>(track);
291 double totalCutLen = 0.0;
292 if (!DoRemoval(silences, range, iGroup, nGroups, totalCutLen))
293 return false;
294 newT1 = std::max(newT1, mT1 - totalCutLen);
295
296 ++iGroup;
297 }
298 }
299
300 mT1 = newT1;
301
302 outputs.Commit();
303
304 return true;
305}
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:224
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
bool IsSelected() const
Definition: Track.cpp:295
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:987
static auto SingletonRange(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1122

References EffectUIServices::DoMessageBox(), DoRemoval(), EffectBase::FindProject(), FindSilences(), SyncLockState::Get(), SyncLock::Group(), EffectBase::inputTracks(), Track::IsSelected(), SyncLockState::IsSyncLocked(), EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, TrackList::SingletonRange(), and XO().

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransferDataFromWindow()

bool EffectTruncSilence::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 783 of file TruncSilence.cpp.

784{
785 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
786 {
787 return false;
788 }
789
790 mbIndependent = mIndependent->IsChecked();
791
792 return true;
793}

References mbIndependent, mIndependent, and mUIParent.

◆ TransferDataToWindow()

bool EffectTruncSilence::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings; default does nothing, returns true

Reimplemented from StatefulEffectUIServices.

Definition at line 773 of file TruncSilence.cpp.

774{
775 if (!mUIParent->TransferDataToWindow())
776 {
777 return false;
778 }
779
780 return true;
781}

References mUIParent.

◆ UpdateUI()

void EffectTruncSilence::UpdateUI ( )
private

Definition at line 945 of file TruncSilence.cpp.

946{
947 switch (mActionIndex)
948 {
949 case kTruncate:
950 mTruncLongestAllowedSilenceT->Enable(true);
951 mSilenceCompressPercentT->Enable(false);
952 break;
953 case kCompress:
954 mTruncLongestAllowedSilenceT->Enable(false);
955 mSilenceCompressPercentT->Enable(true);
956 }
957}

References kCompress, kTruncate, mActionIndex, mSilenceCompressPercentT, and mTruncLongestAllowedSilenceT.

Referenced by OnControlChange(), and PopulateOrExchange().

Here is the caller graph for this function:

Member Data Documentation

◆ ActIndex

constexpr EnumParameter EffectTruncSilence::ActIndex
staticconstexprprivate
Initial value:

Definition at line 136 of file TruncSilence.h.

Referenced by LoadSettings(), and Parameters().

◆ Compress

constexpr EffectParameter EffectTruncSilence::Compress
staticconstexprprivate
Initial value:
L"Compress", 50.0, 0.0, 99.9, 1 }

Definition at line 142 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Independent

constexpr EffectParameter EffectTruncSilence::Independent
staticconstexprprivate
Initial value:
L"Independent", false, false, true, 1 }

Definition at line 144 of file TruncSilence.h.

Referenced by Parameters().

◆ kActionStrings

const EnumValueSymbol EffectTruncSilence::kActionStrings
staticprivate
Initial value:
=
{
{ XO("Truncate Detected Silence") },
{ XO("Compress Excess Silence") }
}

Definition at line 132 of file TruncSilence.h.

Referenced by LoadSettings(), and PopulateOrExchange().

◆ mActionChoice

wxChoice* EffectTruncSilence::mActionChoice
private

Definition at line 116 of file TruncSilence.h.

Referenced by OnControlChange(), and PopulateOrExchange().

◆ mActionIndex

int EffectTruncSilence::mActionIndex
private

Definition at line 107 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), LoadSettings(), PopulateOrExchange(), and UpdateUI().

◆ mbIndependent

bool EffectTruncSilence::mbIndependent
private

Definition at line 111 of file TruncSilence.h.

Referenced by PopulateOrExchange(), Process(), and TransferDataFromWindow().

◆ mBlendFrameCount

size_t EffectTruncSilence::mBlendFrameCount
private

Definition at line 113 of file TruncSilence.h.

Referenced by DoRemoval().

◆ mIndependent

wxCheckBox* EffectTruncSilence::mIndependent
private

Definition at line 120 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and TransferDataFromWindow().

◆ Minimum

constexpr EffectParameter EffectTruncSilence::Minimum
staticconstexprprivate
Initial value:
L"Minimum", 0.5, 0.001, 10000.0, 1 }

Definition at line 138 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mInitialAllowedSilence

double EffectTruncSilence::mInitialAllowedSilence
private

Definition at line 108 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), FindSilences(), and PopulateOrExchange().

◆ mInitialAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mInitialAllowedSilenceT
private

Definition at line 117 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mSilenceCompressPercent

double EffectTruncSilence::mSilenceCompressPercent
private

Definition at line 110 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), and PopulateOrExchange().

◆ mSilenceCompressPercentT

wxTextCtrl* EffectTruncSilence::mSilenceCompressPercentT
private

Definition at line 119 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mThresholdDB

double EffectTruncSilence::mThresholdDB {}
private

Definition at line 106 of file TruncSilence.h.

Referenced by Analyze(), LoadSettings(), and PopulateOrExchange().

◆ mThresholdText

wxTextCtrl* EffectTruncSilence::mThresholdText
private

Definition at line 115 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mTruncLongestAllowedSilence

double EffectTruncSilence::mTruncLongestAllowedSilence
private

Definition at line 109 of file TruncSilence.h.

Referenced by Analyze(), DoRemoval(), and PopulateOrExchange().

◆ mTruncLongestAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mTruncLongestAllowedSilenceT
private

Definition at line 118 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mUIParent

wxWeakRef<wxWindow> EffectTruncSilence::mUIParent {}
private

◆ Symbol

const ComponentInterfaceSymbol EffectTruncSilence::Symbol { XO("Truncate Silence") }
static

Definition at line 37 of file TruncSilence.h.

Referenced by GetSymbol().

◆ Threshold

constexpr EffectParameter EffectTruncSilence::Threshold
staticconstexprprivate
Initial value:
L"Threshold", -20.0, -80.0, -20.0, 1 }

Definition at line 134 of file TruncSilence.h.

Referenced by LoadSettings(), Parameters(), and PopulateOrExchange().

◆ Truncate

constexpr EffectParameter EffectTruncSilence::Truncate
staticconstexprprivate
Initial value:
L"Truncate", 0.5, 0.0, 10000.0, 1 }

Definition at line 140 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().


The documentation for this class was generated from the following files: