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, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. 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, 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
 
- 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
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) 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
 
OptionalMessage 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
 
OptionalMessage 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
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=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 OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=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 EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=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, 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...
 
- 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
 

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 StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- 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, const EffectOutputs *pOutputs)
 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
 
- 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 }
 
- 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 114 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:222
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}
wxT("CloseDown"))
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:543
FileConfig * gPrefs
Definition: Prefs.cpp:71
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:109
double mT0
Definition: EffectBase.h:108
bool TotalProgress(double frac, const TranslatableString &={}) const
Definition: Effect.cpp:675
int GetNumWaveTracks() const
Definition: Effect.h:224
double mInitialAllowedSilence
Definition: TruncSilence.h:97
double mSilenceCompressPercent
Definition: TruncSilence.h:99
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:98
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:1816
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:2025
double GetRate() const override
Definition: WaveTrack.cpp:479
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(), 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(), 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

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:104
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:611
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:107
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:240
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:2205
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: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:1454

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

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

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:230
static constexpr EnumParameter ActIndex
Definition: TruncSilence.h:125
static const EnumValueSymbol kActionStrings[nActions]
Definition: TruncSilence.h:121
static constexpr EffectParameter Threshold
Definition: TruncSilence.h:123
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 932 of file TruncSilence.cpp.

933{
934 mActionChoice->GetValidator()->TransferFromWindow();
935
936 UpdateUI();
937
938 if (!EnableApply(mUIParent->TransferDataFromWindow()))
939 {
940 return;
941 }
942}
bool EnableApply(bool enable=true)
Definition: Effect.cpp:612
wxWindow * mUIParent
Definition: Effect.h:307
wxChoice * mActionChoice
Definition: TruncSilence.h:105

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:133
static constexpr EffectParameter Minimum
Definition: TruncSilence.h:127
static constexpr EffectParameter Truncate
Definition: TruncSilence.h:129
static constexpr EffectParameter Compress
Definition: TruncSilence.h:131

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,
const EffectOutputs pOutputs 
)
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.

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

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(), wxT(), 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:733
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:1390

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:319
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:863
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:1541

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

757{
758 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
759 {
760 return false;
761 }
762
763 mbIndependent = mIndependent->IsChecked();
764
765 return true;
766}

References mbIndependent, mIndependent, and Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectTruncSilence::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Reimplemented from Effect.

Definition at line 746 of file TruncSilence.cpp.

747{
748 if (!mUIParent->TransferDataToWindow())
749 {
750 return false;
751 }
752
753 return true;
754}

References Effect::mUIParent.

◆ UpdateUI()

void EffectTruncSilence::UpdateUI ( )
private

Definition at line 918 of file TruncSilence.cpp.

919{
920 switch (mActionIndex)
921 {
922 case kTruncate:
923 mTruncLongestAllowedSilenceT->Enable(true);
924 mSilenceCompressPercentT->Enable(false);
925 break;
926 case kCompress:
927 mTruncLongestAllowedSilenceT->Enable(false);
928 mSilenceCompressPercentT->Enable(true);
929 }
930}

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 125 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 131 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 133 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 121 of file TruncSilence.h.

Referenced by LoadSettings(), and PopulateOrExchange().

◆ mActionChoice

wxChoice* EffectTruncSilence::mActionChoice
private

Definition at line 105 of file TruncSilence.h.

Referenced by OnControlChange(), and PopulateOrExchange().

◆ mActionIndex

int EffectTruncSilence::mActionIndex
private

Definition at line 96 of file TruncSilence.h.

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

◆ mbIndependent

bool EffectTruncSilence::mbIndependent
private

Definition at line 100 of file TruncSilence.h.

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

◆ mBlendFrameCount

size_t EffectTruncSilence::mBlendFrameCount
private

Definition at line 102 of file TruncSilence.h.

Referenced by DoRemoval().

◆ mIndependent

wxCheckBox* EffectTruncSilence::mIndependent
private

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

Referenced by Parameters(), and PopulateOrExchange().

◆ mInitialAllowedSilence

double EffectTruncSilence::mInitialAllowedSilence
private

Definition at line 97 of file TruncSilence.h.

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

◆ mInitialAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mInitialAllowedSilenceT
private

Definition at line 106 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mSilenceCompressPercent

double EffectTruncSilence::mSilenceCompressPercent
private

Definition at line 99 of file TruncSilence.h.

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

◆ mSilenceCompressPercentT

wxTextCtrl* EffectTruncSilence::mSilenceCompressPercentT
private

Definition at line 108 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

◆ mThresholdDB

double EffectTruncSilence::mThresholdDB {}
private

Definition at line 95 of file TruncSilence.h.

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

◆ mThresholdText

wxTextCtrl* EffectTruncSilence::mThresholdText
private

Definition at line 104 of file TruncSilence.h.

Referenced by PopulateOrExchange().

◆ mTruncLongestAllowedSilence

double EffectTruncSilence::mTruncLongestAllowedSilence
private

Definition at line 98 of file TruncSilence.h.

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

◆ mTruncLongestAllowedSilenceT

wxTextCtrl* EffectTruncSilence::mTruncLongestAllowedSilenceT
private

Definition at line 107 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 123 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 129 of file TruncSilence.h.

Referenced by Parameters(), and PopulateOrExchange().


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