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
 Default implementation returns previewLength More...
 
bool Analyze (RegionList &silenceList, RegionList &trackSilences, const WaveTrack *wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=NULL, double *minInputLength=NULL) const
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- Public Member Functions inherited from StatefulEffect
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 ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 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
 
- 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...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
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...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
void ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool 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, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- 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...
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. 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...
 
- 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
 

Static Public Member Functions

static EffectTruncSilenceFetchParameters (EffectTruncSilence &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
static void IncEffectCounter ()
 
- 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 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 TrackList *list, const Track *firstTrack, const Track *lastTrack)
 
bool DoRemoval (const RegionList &silences, unsigned iGroup, unsigned nGroups, Track *firstTrack, Track *lastTrack, double &totalCutLen)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

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 Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
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...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)
 Add controls to effect panel; always succeeds. 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, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

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

Definition at line 30 of file TruncSilence.h.

Member Enumeration Documentation

◆ kActions

Enumerator
kTruncate 
kCompress 
nActions 

Definition at line 113 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:218
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 = NULL,
double *  minInputLength = NULL 
) const

Definition at line 508 of file TruncSilence.cpp.

516{
517 // Smallest silent region to detect in frames
518 auto minSilenceFrames = sampleCount(std::max( mInitialAllowedSilence, DEF_MinTruncMs) * wt->GetRate());
519
520 double truncDbSilenceThreshold = DB_TO_LINEAR( mThresholdDB );
521 auto blockLen = wt->GetMaxBlockSize();
522 auto start = wt->TimeToLongSamples(mT0);
523 auto end = wt->TimeToLongSamples(mT1);
524 sampleCount outLength = 0;
525
526 double previewLength;
527 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
528 // Minimum required length in samples.
529 const sampleCount previewLen( previewLength * wt->GetRate() );
530
531 // Keep position in overall silences list for optimization
532 RegionList::iterator rit(silenceList.begin());
533
534 // Allocate buffer
535 Floats buffer{ blockLen };
536
537 // Loop through current track
538 while (*index < end) {
539 if (inputLength && ((outLength >= previewLen) || (*index - start > wt->TimeToLongSamples(*minInputLength)))) {
540 *inputLength = std::min<double>(*inputLength, *minInputLength);
541 if (outLength >= previewLen) {
542 *minInputLength = *inputLength;
543 }
544 return true;
545 }
546
547 if (!inputLength) {
548 // Show progress dialog, test for cancellation
549 bool cancelled = TotalProgress(
550 detectFrac * (whichTrack +
551 (*index - start).as_double() /
552 (end - start).as_double()) /
553 (double)GetNumWaveTracks());
554 if (cancelled)
555 return false;
556 }
557
558 // Optimization: if not in a silent region skip ahead to the next one
559
560 double curTime = wt->LongSamplesToTime(*index);
561 for ( ; rit != silenceList.end(); ++rit) {
562 // Find the first silent region ending after current time
563 if (rit->end >= curTime) {
564 break;
565 }
566 }
567
568 if (rit == silenceList.end()) {
569 // No more regions -- no need to process the rest of the track
570 if (inputLength) {
571 // Add available samples up to previewLength.
572 auto remainingTrackSamples = wt->TimeToLongSamples(wt->GetEndTime()) - *index;
573 auto requiredTrackSamples = previewLen - outLength;
574 outLength += (remainingTrackSamples > requiredTrackSamples)? requiredTrackSamples : remainingTrackSamples;
575 }
576
577 break;
578 }
579 else if (rit->start > curTime) {
580 // End current silent region, skip ahead
581 if (*silentFrame >= minSilenceFrames) {
582 trackSilences.push_back(Region(
583 wt->LongSamplesToTime(*index - *silentFrame),
584 wt->LongSamplesToTime(*index)
585 ));
586 }
587 *silentFrame = 0;
588 auto newIndex = wt->TimeToLongSamples(rit->start);
589 if (inputLength) {
590 auto requiredTrackSamples = previewLen - outLength;
591 // Add non-silent sample to outLength
592 outLength += ((newIndex - *index) > requiredTrackSamples)? requiredTrackSamples : newIndex - *index;
593 }
594
595 *index = newIndex;
596 }
597 // End of optimization
598
599 // Limit size of current block if we've reached the end
600 auto count = limitSampleBufferSize( blockLen, end - *index );
601
602 // Fill buffer
603 wt->GetFloats((buffer.get()), *index, count);
604
605 // Look for silenceList in current block
606 for (decltype(count) i = 0; i < count; ++i) {
607 if (inputLength && ((outLength >= previewLen) || (outLength > wt->TimeToLongSamples(*minInputLength)))) {
608 *inputLength = wt->LongSamplesToTime(*index + i) - wt->LongSamplesToTime(start);
609 break;
610 }
611
612 if (fabs(buffer[i]) < truncDbSilenceThreshold) {
613 (*silentFrame)++;
614 }
615 else {
616 sampleCount allowed = 0;
617 if (*silentFrame >= minSilenceFrames) {
618 if (inputLength) {
619 switch (mActionIndex) {
620 case kTruncate:
622 break;
623 case kCompress:
625 outLength += sampleCount(
626 allowed.as_double() +
627 (*silentFrame - allowed).as_double()
629 );
630 break;
631 // default: // Not currently used.
632 }
633 }
634
635 // Record the silent region
636 trackSilences.push_back(Region(
637 wt->LongSamplesToTime(*index + i - *silentFrame),
638 wt->LongSamplesToTime(*index + i)
639 ));
640 }
641 else if (inputLength) { // included as part of non-silence
642 outLength += *silentFrame;
643 }
644 *silentFrame = 0;
645 if (inputLength) {
646 ++outLength; // Add non-silent sample to outLength
647 }
648 }
649 }
650 // Next block
651 *index += count;
652 }
653
654 if (inputLength) {
655 *inputLength = std::min<double>(*inputLength, *minInputLength);
656 if (outLength >= previewLen) {
657 *minInputLength = *inputLength;
658 }
659 }
660
661 return true;
662}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:535
FileConfig * gPrefs
Definition: Prefs.cpp:71
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
WaveTrack::Region Region
const double detectFrac
static const double DEF_MinTruncMs
double mT1
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:106
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:685
int GetNumWaveTracks() const
Definition: Effect.h:187
double mInitialAllowedSilence
Definition: TruncSilence.h:96
double mSilenceCompressPercent
Definition: TruncSilence.h:98
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:97
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:67
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:47
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1806
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:2015
double GetRate() const override
Definition: WaveTrack.cpp:479
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
double as_double() const
Definition: SampleCount.h:45
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References sampleCount::as_double(), DB_TO_LINEAR, DEF_MinTruncMs, detectFrac, PackedArray::end(), WaveTrack::GetEndTime(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), WaveTrack::GetRate(), gPrefs, kCompress, kTruncate, limitSampleBufferSize(), SampleTrack::LongSamplesToTime(), mActionIndex, mInitialAllowedSilence, mSilenceCompressPercent, EffectBase::mT0, EffectBase::mT1, mThresholdDB, mTruncLongestAllowedSilence, SampleTrack::TimeToLongSamples(), and Effect::TotalProgress().

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

Default implementation returns previewLength

Reimplemented from Effect.

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, &inputLength, &minInputLength);
225
226 whichTrack++;
227 }
228 return inputLength;
229}
const TrackList * inputTracks() const
Definition: EffectBase.h:102
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack *wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=NULL, double *minInputLength=NULL) 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,
unsigned  iGroup,
unsigned  nGroups,
Track firstTrack,
Track lastTrack,
double &  totalCutLen 
)
private

Definition at line 394 of file TruncSilence.cpp.

397{
398 //
399 // Now remove the silent regions from all selected / sync-lock selected tracks.
400 //
401
402 // Loop over detected regions in reverse (so cuts don't change time values
403 // down the line)
404 int whichReg = 0;
405 RegionList::const_reverse_iterator rit;
406 for (rit = silences.rbegin(); rit != silences.rend(); ++rit)
407 {
408 const Region &region = *rit;
409 const Region *const r = &region;
410
411 // Progress dialog and cancellation. Do additional cleanup before return.
412 const double frac = detectFrac +
413 (1 - detectFrac) * (iGroup + whichReg / double(silences.size())) / nGroups;
414 if (TotalProgress(frac))
415 {
417 return false;
418 }
419
420 // Intersection may create regions smaller than allowed; ignore them.
421 // Allow one nanosecond extra for consistent results with exact milliseconds of allowed silence.
422 if ((r->end - r->start) < (mInitialAllowedSilence - 0.000000001))
423 continue;
424
425 // Find NEW silence length as requested
426 double inLength = r->end - r->start;
427 double outLength;
428
429 switch (mActionIndex)
430 {
431 case kTruncate:
432 outLength = std::min(mTruncLongestAllowedSilence, inLength);
433 break;
434 case kCompress:
435 outLength = mInitialAllowedSilence +
436 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0;
437 break;
438 default: // Not currently used.
439 outLength = std::min(mInitialAllowedSilence +
440 (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0,
442 }
443
444 const double cutLen = std::max(0.0, inLength - outLength);
445 // Don't waste time cutting nothing.
446 if( cutLen == 0.0 )
447 continue;
448
449 totalCutLen += cutLen;
450
451 double cutStart = (r->start + r->end - cutLen) / 2;
452 double cutEnd = cutStart + cutLen;
453 (mOutputTracks->Any()
454 .StartingWith(firstTrack).EndingAfter(lastTrack)
456 - [&](const Track *pTrack) { return
457 // Don't waste time past the end of a track
458 pTrack->GetEndTime() < r->start;
459 }
460 ).Visit(
461 [&](WaveTrack *wt) {
462
463 // In WaveTracks, clear with a cross-fade
464 auto blendFrames = mBlendFrameCount;
465 // Round start/end times to frame boundaries
466 cutStart = wt->LongSamplesToTime(wt->TimeToLongSamples(cutStart));
467 cutEnd = wt->LongSamplesToTime(wt->TimeToLongSamples(cutEnd));
468
469 // Make sure the cross-fade does not affect non-silent frames
470 if (wt->LongSamplesToTime(blendFrames) > inLength)
471 {
472 // Result is not more than blendFrames:
473 blendFrames = wt->TimeToLongSamples(inLength).as_size_t();
474 }
475
476 // Perform cross-fade in memory
477 Floats buf1{ blendFrames };
478 Floats buf2{ blendFrames };
479 auto t1 = wt->TimeToLongSamples(cutStart) - blendFrames / 2;
480 auto t2 = wt->TimeToLongSamples(cutEnd) - blendFrames / 2;
481
482 wt->GetFloats(buf1.get(), t1, blendFrames);
483 wt->GetFloats(buf2.get(), t2, blendFrames);
484
485 for (decltype(blendFrames) i = 0; i < blendFrames; ++i)
486 {
487 buf1[i] = ((blendFrames-i) * buf1[i] + i * buf2[i]) /
488 (double)blendFrames;
489 }
490
491 // Perform the cut
492 wt->Clear(cutStart, cutEnd);
493
494 // Write cross-faded data
495 wt->Set((samplePtr)buf1.get(), floatSample, t1, blendFrames);
496 },
497 [&](Track *t) {
498 // Non-wave tracks: just do a sync-lock adjust
499 t->SyncLockAdjust(cutEnd, cutStart);
500 }
501 );
502 ++whichReg;
503 }
504
505 return true;
506}
int min(int a, int b)
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
Definition: MemoryX.h:603
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:73
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:788
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2195
size_t as_size_t() const
Definition: SampleCount.cpp:17
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:62

References sampleCount::as_size_t(), WaveTrack::Clear(), detectFrac, WaveTrack::Region::end, floatSample, SampleTrack::GetFloats(), SyncLock::IsSelectedOrSyncLockSelected(), kCompress, kTruncate, SampleTrack::LongSamplesToTime(), mActionIndex, mBlendFrameCount, min(), mInitialAllowedSilence, EffectBase::mOutputTracks, mSilenceCompressPercent, mTruncLongestAllowedSilence, EffectBase::ReplaceProcessedTracks(), WaveTrack::Set(), WaveTrack::Region::start, SampleTrack::TimeToLongSamples(), Effect::TotalProgress(), and Visit().

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 34 of file TruncSilence.h.

34{ return &e; }

◆ FindSilences()

bool EffectTruncSilence::FindSilences ( RegionList silences,
const TrackList list,
const Track firstTrack,
const Track lastTrack 
)
private

Definition at line 342 of file TruncSilence.cpp.

345{
346 // Start with the whole selection silent
347 silences.push_back(Region(mT0, mT1));
348
349 // Remove non-silent regions in each track
350 int whichTrack = 0;
351 for (auto wt :
352 list->Selected< const WaveTrack >()
353 .StartingWith( firstTrack ).EndingAfter( lastTrack ) )
354 {
355 // Smallest silent region to detect in frames
356 auto minSilenceFrames =
357 sampleCount(std::max(mInitialAllowedSilence, DEF_MinTruncMs) * wt->GetRate());
358
359 //
360 // Scan the track for silences
361 //
362 RegionList trackSilences;
363
364 auto index = wt->TimeToLongSamples(mT0);
365 sampleCount silentFrame = 0;
366
367 // Detect silences
368 bool cancelled = !(Analyze(silences, trackSilences, wt, &silentFrame, &index, whichTrack));
369
370 // Buffer has been freed, so we're OK to return if cancelled
371 if (cancelled)
372 {
374 return false;
375 }
376
377 if (silentFrame >= minSilenceFrames)
378 {
379 // Track ended in silence -- record region
380 trackSilences.push_back(Region(
381 wt->LongSamplesToTime(index - silentFrame),
382 wt->LongSamplesToTime(index)
383 ));
384 }
385
386 // Intersect with the overall silent region list
387 Intersect(silences, trackSilences);
388 whichTrack++;
389 }
390
391 return true;
392}
void Intersect(RegionList &dest, const RegionList &src)
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1452

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

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

Reimplemented from Effect.

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}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectTruncSilence::GetSymbol ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 139 of file TruncSilence.cpp.

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

References Symbol.

◆ GetType()

EffectType EffectTruncSilence::GetType ( ) const
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

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 754 of file TruncSilence.cpp.

755{
756 RegionList::iterator destIter;
757 destIter = dest.begin();
758 // Any time we reach the end of the dest list we're finished
759 if (destIter == dest.end())
760 return;
761 RegionList::iterator curDest = destIter;
762
763 // Operation: find non-silent regions in src, remove them from dest.
764 double nsStart = curDest->start;
765 double nsEnd;
766 bool lastRun = false; // must run the loop one extra time
767
768 RegionList::const_iterator srcIter = src.begin();
769
770 // This logic, causing the loop to run once after end of src, must occur
771 // each time srcIter is updated
772 if (srcIter == src.end())
773 {
774 lastRun = true;
775 }
776
777 while (srcIter != src.end() || lastRun)
778 {
779 // Don't use curSrc unless lastRun is false!
780 RegionList::const_iterator curSrc;
781
782 if (lastRun)
783 {
784 // The last non-silent region extends as far as possible
785 nsEnd = std::numeric_limits<double>::max();
786 }
787 else
788 {
789 curSrc = srcIter;
790 nsEnd = curSrc->start;
791 }
792
793 if (nsEnd > nsStart)
794 {
795 // Increment through dest until we have a region that could be affected
796 while (curDest->end <= nsStart)
797 {
798 ++destIter;
799 if (destIter == dest.end())
800 {
801 return;
802 }
803 curDest = destIter;
804 }
805
806 // Check for splitting dest region in two
807 if (nsStart > curDest->start && nsEnd < curDest->end)
808 {
809 // The second region
810 Region r(nsEnd, curDest->end);
811
812 // The first region
813 curDest->end = nsStart;
814
815 // Insert second region after first
816 RegionList::iterator nextIt(destIter);
817 ++nextIt;
818
819 // This should just read: destIter = dest.insert(nextIt, r); but we
820 // work around two two wxList::insert() bugs. First, in some
821 // versions it returns the wrong value. Second, in some versions,
822 // it crashes when you insert at list end.
823 if (nextIt == dest.end())
824 dest.push_back(r);
825 else
826 dest.insert(nextIt, r);
827 ++destIter; // (now points at the newly-inserted region)
828
829 curDest = destIter;
830 }
831
832 // Check for truncating the end of dest region
833 if (nsStart > curDest->start && nsStart < curDest->end &&
834 nsEnd >= curDest->end)
835 {
836 curDest->end = nsStart;
837
838 ++destIter;
839 if (destIter == dest.end())
840 {
841 return;
842 }
843 curDest = destIter;
844 }
845
846 // Check for all dest regions that need to be removed completely
847 while (nsStart <= curDest->start && nsEnd >= curDest->end)
848 {
849 destIter = dest.erase(destIter);
850 if (destIter == dest.end())
851 {
852 return;
853 }
854 curDest = destIter;
855 }
856
857 // Check for truncating the beginning of dest region
858 if (nsStart <= curDest->start &&
859 nsEnd > curDest->start && nsEnd < curDest->end)
860 {
861 curDest->start = nsEnd;
862 }
863 }
864
865 if (lastRun)
866 {
867 // done
868 lastRun = false;
869 }
870 else
871 {
872 // Next non-silent region starts at the end of this silent region
873 nsStart = curSrc->end;
874 ++srcIter;
875 if (srcIter == src.end())
876 {
877 lastRun = true;
878 }
879 }
880 }
881}

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

Reimplemented from Effect.

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:87
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:237
static constexpr EnumParameter ActIndex
Definition: TruncSilence.h:124
static const EnumValueSymbol kActionStrings[nActions]
Definition: TruncSilence.h:120
static constexpr EffectParameter Threshold
Definition: TruncSilence.h:122
static const size_t NumDbChoices
static const EnumValueSymbol DbChoices[]
const wxChar *const key
Identifier in configuration file.
Definition: Shuttle.h:28
const Type def
Default value.
Definition: Shuttle.h:29
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31

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}

◆ OnControlChange()

void EffectTruncSilence::OnControlChange ( wxCommandEvent &  evt)
private

Definition at line 915 of file TruncSilence.cpp.

916{
917 mActionChoice->GetValidator()->TransferFromWindow();
918
919 UpdateUI();
920
921 if (!EnableApply(mUIParent->TransferDataFromWindow()))
922 {
923 return;
924 }
925}
bool EnableApply(bool enable=true)
Definition: Effect.cpp:613
wxWindow * mUIParent
Definition: Effect.h:270
wxChoice * mActionChoice
Definition: TruncSilence.h:104

References Effect::EnableApply(), mActionChoice, Effect::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:132
static constexpr EffectParameter Minimum
Definition: TruncSilence.h:126
static constexpr EffectParameter Truncate
Definition: TruncSilence.h:128
static constexpr EffectParameter Compress
Definition: TruncSilence.h:130

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

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > EffectTruncSilence::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access 
)
overridevirtual

Add controls to effect panel; always succeeds.

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

Reimplemented from Effect.

Definition at line 665 of file TruncSilence.cpp.

667{
668 wxASSERT(nActions == WXSIZEOF(kActionStrings));
669
670 S.AddSpace(0, 5);
671
672 S.StartStatic(XO("Detect Silence"));
673 {
674 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
675 {
676 // Threshold
678 .Validator<FloatingPointValidator<double>>(
679 3, &mThresholdDB, NumValidatorStyle::NO_TRAILING_ZEROES,
681 .NameSuffix(XO("db"))
682 .AddTextBox(XXO("&Threshold:"), wxT(""), 0);
683 S.AddUnits(XO("dB"));
684
685 // Ignored silence
686 mInitialAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
688 NumValidatorStyle::NO_TRAILING_ZEROES,
690 .NameSuffix(XO("seconds"))
691 .AddTextBox(XXO("&Duration:"), wxT(""), 12);
692 S.AddUnits(XO("seconds"));
693 }
694 S.EndMultiColumn();
695 }
696 S.EndStatic();
697
698 S.StartStatic(XO("Action"));
699 {
700 S.StartHorizontalLay();
701 {
702 // Action choices
703 auto actionChoices = Msgids( kActionStrings, nActions );
705 .Validator<wxGenericValidator>(&mActionIndex)
706 .MinSize( { -1, -1 } )
707 .AddChoice( {}, actionChoices );
708 }
709 S.EndHorizontalLay();
710 S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
711 {
712 // Truncation / Compression factor
713
714 mTruncLongestAllowedSilenceT = S.Validator<FloatingPointValidator<double>>(
716 NumValidatorStyle::NO_TRAILING_ZEROES,
718 .NameSuffix(XO("seconds"))
719 .AddTextBox(XXO("Tr&uncate to:"), wxT(""), 12);
720 S.AddUnits(XO("seconds"));
721
722 mSilenceCompressPercentT = S.Validator<FloatingPointValidator<double>>(
724 NumValidatorStyle::NO_TRAILING_ZEROES,
726 .NameSuffix(XO("%"))
727 .AddTextBox(XXO("C&ompress to:"), wxT(""), 12);
728 S.AddUnits(XO("%"));
729 }
730 S.EndMultiColumn();
731
732 S.StartMultiColumn(2, wxALIGN_CENTER_HORIZONTAL);
733 {
734 mIndependent = S.AddCheckBox(XXO("Trunc&ate tracks independently"),
736 }
737 S.EndMultiColumn();
738 }
739 S.EndStatic();
740
741 UpdateUI();
742 return nullptr;
743}
#define XXO(s)
Definition: Internat.h:44
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:103
wxCheckBox * mIndependent
Definition: TruncSilence.h:108
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:106
wxTextCtrl * mInitialAllowedSilenceT
Definition: TruncSilence.h:105
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:107

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, nActions, S, Threshold, Truncate, UpdateUI(), XO, and XXO.

Here is the call graph for this function:

◆ Process()

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

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Definition at line 232 of file TruncSilence.cpp.

233{
234 const bool success =
237 : ProcessAll();
238
239 if (success)
241
242 return success;
243}

References mbIndependent, ProcessAll(), ProcessIndependently(), and EffectBase::ReplaceProcessedTracks().

Here is the call graph for this function:

◆ ProcessAll()

bool EffectTruncSilence::ProcessAll ( )
private

Definition at line 318 of file TruncSilence.cpp.

319{
320 // Copy tracks
321 CopyInputTracks(true);
322
323 // Master list of silent regions.
324 // This list should always be kept in order.
325 RegionList silences;
326
327 auto trackRange0 = inputTracks()->Selected< const WaveTrack >();
328 if (FindSilences(
329 silences, inputTracks(), *trackRange0.begin(), *trackRange0.rbegin())) {
330 auto trackRange = mOutputTracks->Any();
331 double totalCutLen = 0.0;
332 if (DoRemoval(silences, 0, 1,
333 *trackRange.begin(), *trackRange.rbegin(), totalCutLen)) {
334 mT1 -= totalCutLen;
335 return true;
336 }
337 }
338
339 return false;
340}
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:741
bool FindSilences(RegionList &silences, const TrackList *list, const Track *firstTrack, const Track *lastTrack)
bool DoRemoval(const RegionList &silences, unsigned iGroup, unsigned nGroups, Track *firstTrack, Track *lastTrack, double &totalCutLen)
iterator begin()
Definition: Track.h:1388

References TrackList::begin(), Effect::CopyInputTracks(), DoRemoval(), FindSilences(), EffectBase::inputTracks(), EffectBase::mOutputTracks, EffectBase::mT1, and TrackList::Selected().

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 245 of file TruncSilence.cpp.

246{
247 unsigned nGroups = 0;
248
249 const auto &settings = ProjectSettings::Get( *FindProject() );
250 const bool syncLock = settings.IsSyncLocked();
251
252 // Check if it's permissible
253 {
254 for (auto track : inputTracks()->SelectedLeaders< const WaveTrack >() ) {
255 if (syncLock) {
256 auto channels = TrackList::Channels(track);
257 auto otherTracks =
258 SyncLock::Group(track).Filter<const WaveTrack>()
260 - [&](const Track *pTrack){
261 return channels.contains(pTrack); };
262 if (otherTracks) {
264 XO(
265"When truncating independently, there may only be one selected audio track in each Sync-Locked Track Group.") );
266 return false;
267 }
268 }
269
270 ++nGroups;
271 }
272 }
273
274 if (nGroups == 0)
275 // nothing to do
276 return true;
277
278 // Now do the work
279
280 // Copy tracks
281 CopyInputTracks(true);
282 double newT1 = 0.0;
283
284 {
285 unsigned iGroup = 0;
286 for (auto track : mOutputTracks->SelectedLeaders< WaveTrack >() ) {
287 Track *const last = *TrackList::Channels(track).rbegin();
288
289 RegionList silences;
290
291 if (!FindSilences(silences, mOutputTracks.get(), track, last))
292 return false;
293 // Treat tracks in the sync lock group only
294 Track *groupFirst, *groupLast;
295 if (syncLock) {
296 auto trackRange = SyncLock::Group(track);
297 groupFirst = *trackRange.begin();
298 groupLast = *trackRange.rbegin();
299 }
300 else {
301 groupFirst = track;
302 groupLast = last;
303 }
304 double totalCutLen = 0.0;
305 if (!DoRemoval(silences, iGroup, nGroups, groupFirst, groupLast, totalCutLen))
306 return false;
307 newT1 = std::max(newT1, mT1 - totalCutLen);
308
309 ++iGroup;
310 }
311 }
312
313 mT1 = newT1;
314
315 return true;
316}
const AudacityProject * FindProject() const
Definition: EffectBase.cpp:315
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:871
static ProjectSettings & Get(AudacityProject &project)
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:122
bool IsSelected() const
Definition: Track.cpp:402
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1539

References TrackList::Channels(), Effect::CopyInputTracks(), DoRemoval(), EffectBase::FindProject(), FindSilences(), ProjectSettings::Get(), SyncLock::Group(), EffectBase::inputTracks(), Track::IsSelected(), Effect::MessageBox(), EffectBase::mOutputTracks, EffectBase::mT1, settings(), 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.

Reimplemented from Effect.

Definition at line 745 of file TruncSilence.cpp.

746{
747 mbIndependent = mIndependent->IsChecked();
748 return true;
749}

References mbIndependent, and mIndependent.

◆ UpdateUI()

void EffectTruncSilence::UpdateUI ( )
private

Definition at line 901 of file TruncSilence.cpp.

902{
903 switch (mActionIndex)
904 {
905 case kTruncate:
906 mTruncLongestAllowedSilenceT->Enable(true);
907 mSilenceCompressPercentT->Enable(false);
908 break;
909 case kCompress:
910 mTruncLongestAllowedSilenceT->Enable(false);
911 mSilenceCompressPercentT->Enable(true);
912 }
913}

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 124 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 130 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 132 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 120 of file TruncSilence.h.

Referenced by LoadSettings(), and PopulateOrExchange().

◆ mActionChoice

wxChoice* EffectTruncSilence::mActionChoice
private

Definition at line 104 of file TruncSilence.h.

Referenced by OnControlChange(), and PopulateOrExchange().

◆ mActionIndex

int EffectTruncSilence::mActionIndex
private

Definition at line 95 of file TruncSilence.h.

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

◆ mbIndependent

bool EffectTruncSilence::mbIndependent
private

Definition at line 99 of file TruncSilence.h.

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

◆ mBlendFrameCount

size_t EffectTruncSilence::mBlendFrameCount
private

Definition at line 101 of file TruncSilence.h.

Referenced by DoRemoval().

◆ mIndependent

wxCheckBox* EffectTruncSilence::mIndependent
private

Definition at line 108 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 126 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mInitialAllowedSilence

double EffectTruncSilence::mInitialAllowedSilence
private

Definition at line 96 of file TruncSilence.h.

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

◆ mInitialAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mInitialAllowedSilenceT
private

Definition at line 105 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mSilenceCompressPercent

double EffectTruncSilence::mSilenceCompressPercent
private

Definition at line 98 of file TruncSilence.h.

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

◆ mSilenceCompressPercentT

wxTextCtrl* EffectTruncSilence::mSilenceCompressPercentT
private

Definition at line 107 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mThresholdDB

double EffectTruncSilence::mThresholdDB {}
private

Definition at line 94 of file TruncSilence.h.

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

◆ mThresholdText

wxTextCtrl* EffectTruncSilence::mThresholdText
private

Definition at line 103 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mTruncLongestAllowedSilence

double EffectTruncSilence::mTruncLongestAllowedSilence
private

Definition at line 97 of file TruncSilence.h.

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

◆ mTruncLongestAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mTruncLongestAllowedSilenceT
private

Definition at line 106 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ Symbol

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

Definition at line 35 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 122 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 128 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().


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