Audacity  2.2.2
Public Member Functions | Private Member Functions | 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:
Effect EffectClientInterface EffectUIClientInterface EffectHostInterface EffectDefinitionInterface ConfigClientInterface IdentInterface ParamsInterface

Public Member Functions

 EffectTruncSilence ()
 
virtual ~EffectTruncSilence ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
EffectType GetType () override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
double CalcPreviewInputLength (double previewLength) override
 
bool Startup () override
 
bool Analyze (RegionList &silenceList, RegionList &trackSilences, const WaveTrack *wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=NULL, double *minInputLength=NULL)
 
bool Process () override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
IdentInterfaceSymbol GetFamilyId () override
 
bool IsInteractive () override
 
bool IsDefault () override
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool ShowInterface (wxWindow *parent, bool forceModal=false) override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
NumericFormatId GetDurationFormat () override
 
virtual NumericFormatId GetSelectionFormat ()
 
void SetDuration (double duration) override
 
bool Apply () override
 
void Preview () override
 
wxDialog * CreateUI (wxWindow *parent, EffectUIClientInterface *client) override
 
wxString GetUserPresetsGroup (const wxString &name) override
 
wxString GetCurrentSettingsGroup () override
 
wxString GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const wxString &group) override
 
bool GetSharedConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const wxString &group) override
 
bool RemoveSharedConfig (const wxString &group, const wxString &key) override
 
bool HasPrivateConfigGroup (const wxString &group) override
 
bool GetPrivateConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const wxString &group) override
 
bool RemovePrivateConfig (const wxString &group, const wxString &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual wxArrayString GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual wxString GetPreset (wxWindow *parent, const wxString &parms)
 
virtual wxString HelpPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (wxWindow *parent, double projectRate, TrackList *list, TrackFactory *factory, SelectedRegion *selectedRegion, bool shouldPrompt=true)
 
bool Delegate (Effect &delegate, wxWindow *parent, bool shouldPrompt)
 
bool RealtimeAddProcessor (int group, unsigned chans, float rate)
 
size_t RealtimeProcess (int group, unsigned chans, float **inbuf, float **outbuf, size_t numSamples)
 
bool IsRealtimeActive ()
 
virtual bool IsHidden ()
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 
- Public Member Functions inherited from ConfigClientInterface
virtual ~ConfigClientInterface ()
 

Private Member Functions

void Intersect (RegionList &dest, const RegionList &src)
 
void OnControlChange (wxCommandEvent &evt)
 
void UpdateUI ()
 
bool ProcessIndependently ()
 
bool ProcessAll ()
 
bool FindSilences (RegionList &silences, TrackList *list, Track *firstTrack, Track *lastTrack)
 
bool DoRemoval (const RegionList &silences, unsigned iGroup, unsigned nGroups, Track *firstTrack, Track *lastTrack, double &totalCutLen)
 

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
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Member Functions inherited from Effect
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool CheckWhetherSkipEffect ()
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual void Preview (bool dryOnly)
 
virtual bool EnableApply (bool enable=true)
 
virtual bool EnablePreview (bool enable=true)
 
virtual void EnableDebug (bool enable=true)
 
bool TotalProgress (double frac)
 
bool TrackProgress (int whichTrack, double frac, const wxString &=wxEmptyString)
 
bool TrackGroupProgress (int whichGroup, double frac, const wxString &=wxEmptyString)
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetSamples (const WaveTrack *track, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks ()
 
void CopyInputTracks (int trackType)
 
std::shared_ptr
< AddedAnalysisTrack
AddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (std::unique_ptr< Track > &&t)
 
TrackListinputTracks () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
SelectedRegionmpSelectedRegion {}
 
TrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
double mF0
 
double mF1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
sampleCount mSampleCnt
 
int mOutputTracksType
 

Detailed Description

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

Definition at line 36 of file TruncSilence.h.

Constructor & Destructor Documentation

EffectTruncSilence::EffectTruncSilence ( )

Definition at line 125 of file TruncSilence.cpp.

References DEF_BlendFrameCount.

126 {
127  mInitialAllowedSilence = DEF_Minimum;
128  mTruncLongestAllowedSilence = DEF_Truncate;
129  mSilenceCompressPercent = DEF_Compress;
130  mThresholdDB = DEF_Threshold;
131  mActionIndex = DEF_ActIndex;
132  mbIndependent = DEF_Independent;
133 
134  SetLinearEffectFlag(false);
135 
136  // This used to be changeable via the audacity.cfg/registery. Doubtful that was
137  // ever done.
138  //
139  // Original comment:
140  //
141  // mBlendFrameCount only retrieved from prefs ... not using dialog
142  // Only way to change (for windows) is thru registry
143  // The values should be figured dynamically ... too many frames could be invalid
145 }
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
static const size_t DEF_BlendFrameCount
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
EffectTruncSilence::~EffectTruncSilence ( )
virtual

Definition at line 147 of file TruncSilence.cpp.

148 {
149 }

Member Function Documentation

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

Definition at line 599 of file TruncSilence.cpp.

References sampleCount::as_double(), DB_TO_LINEAR(), floatSample, WaveTrack::Get(), WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), Effect::GetNumWaveTracks(), WaveTrack::GetRate(), gPrefs, kCompress, kTruncate, limitSampleBufferSize(), WaveTrack::LongSamplesToTime(), mActionIndex, mInitialAllowedSilence, mSilenceCompressPercent, Effect::mT0, Effect::mT1, mThresholdDB, mTruncLongestAllowedSilence, Region, WaveTrack::TimeToLongSamples(), and Effect::TotalProgress().

Referenced by CalcPreviewInputLength().

607 {
608  // Smallest silent region to detect in frames
609  auto minSilenceFrames = sampleCount(std::max( mInitialAllowedSilence, DEF_MinTruncMs) * wt->GetRate());
610 
611  double truncDbSilenceThreshold = DB_TO_LINEAR( mThresholdDB );
612  auto blockLen = wt->GetMaxBlockSize();
613  auto start = wt->TimeToLongSamples(mT0);
614  auto end = wt->TimeToLongSamples(mT1);
615  sampleCount outLength = 0;
616 
617  double previewLength;
618  gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
619  // Minimum required length in samples.
620  const sampleCount previewLen( previewLength * wt->GetRate() );
621 
622  // Keep position in overall silences list for optimization
623  RegionList::iterator rit(silenceList.begin());
624 
625  // Allocate buffer
626  Floats buffer{ blockLen };
627 
628  // Loop through current track
629  while (*index < end) {
630  if (inputLength && ((outLength >= previewLen) || (*index - start > wt->TimeToLongSamples(*minInputLength)))) {
631  *inputLength = std::min<double>(*inputLength, *minInputLength);
632  if (outLength >= previewLen) {
633  *minInputLength = *inputLength;
634  }
635  return true;
636  }
637 
638  if (!inputLength) {
639  // Show progress dialog, test for cancellation
640  bool cancelled = TotalProgress(
641  detectFrac * (whichTrack +
642  (*index - start).as_double() /
643  (end - start).as_double()) /
644  (double)GetNumWaveTracks());
645  if (cancelled)
646  return false;
647  }
648 
649  // Optimization: if not in a silent region skip ahead to the next one
650 
651  double curTime = wt->LongSamplesToTime(*index);
652  for ( ; rit != silenceList.end(); ++rit) {
653  // Find the first silent region ending after current time
654  if (rit->end >= curTime) {
655  break;
656  }
657  }
658 
659  if (rit == silenceList.end()) {
660  // No more regions -- no need to process the rest of the track
661  if (inputLength) {
662  // Add available samples up to previewLength.
663  auto remainingTrackSamples = wt->TimeToLongSamples(wt->GetEndTime()) - *index;
664  auto requiredTrackSamples = previewLen - outLength;
665  outLength += (remainingTrackSamples > requiredTrackSamples)? requiredTrackSamples : remainingTrackSamples;
666  }
667 
668  break;
669  }
670  else if (rit->start > curTime) {
671  // End current silent region, skip ahead
672  if (*silentFrame >= minSilenceFrames) {
673  trackSilences.push_back(Region(
674  wt->LongSamplesToTime(*index - *silentFrame),
675  wt->LongSamplesToTime(*index)
676  ));
677  }
678  *silentFrame = 0;
679  auto newIndex = wt->TimeToLongSamples(rit->start);
680  if (inputLength) {
681  auto requiredTrackSamples = previewLen - outLength;
682  // Add non-silent sample to outLength
683  outLength += ((newIndex - *index) > requiredTrackSamples)? requiredTrackSamples : newIndex - *index;
684  }
685 
686  *index = newIndex;
687  }
688  // End of optimization
689 
690  // Limit size of current block if we've reached the end
691  auto count = limitSampleBufferSize( blockLen, end - *index );
692 
693  // Fill buffer
694  wt->Get((samplePtr)(buffer.get()), floatSample, *index, count);
695 
696  // Look for silenceList in current block
697  for (decltype(count) i = 0; i < count; ++i) {
698  if (inputLength && ((outLength >= previewLen) || (outLength > wt->TimeToLongSamples(*minInputLength)))) {
699  *inputLength = wt->LongSamplesToTime(*index + i) - wt->LongSamplesToTime(start);
700  break;
701  }
702 
703  if (fabs(buffer[i]) < truncDbSilenceThreshold) {
704  (*silentFrame)++;
705  }
706  else {
707  sampleCount allowed = 0;
708  if (*silentFrame >= minSilenceFrames) {
709  if (inputLength) {
710  switch (mActionIndex) {
711  case kTruncate:
713  break;
714  case kCompress:
716  outLength += sampleCount(
717  allowed.as_double() +
718  (*silentFrame - allowed).as_double()
719  * mSilenceCompressPercent / 100.0
720  );
721  break;
722  // default: // Not currently used.
723  }
724  }
725 
726  // Record the silent region
727  trackSilences.push_back(Region(
728  wt->LongSamplesToTime(*index + i - *silentFrame),
729  wt->LongSamplesToTime(*index + i)
730  ));
731  }
732  else if (inputLength) { // included as part of non-silence
733  outLength += *silentFrame;
734  }
735  *silentFrame = 0;
736  if (inputLength) {
737  ++outLength; // Add non-silent sample to outLength
738  }
739  }
740  }
741  // Next block
742  *index += count;
743  }
744 
745  if (inputLength) {
746  *inputLength = std::min<double>(*inputLength, *minInputLength);
747  if (outLength >= previewLen) {
748  *minInputLength = *inputLength;
749  }
750  }
751 
752  return true;
753 }
double mT1
Definition: Effect.h:461
const double detectFrac
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool TotalProgress(double frac)
Definition: Effect.cpp:1977
double as_double() const
Definition: Types.h:88
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1873
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
#define Region
Definition: VSTControlGTK.h:15
char * samplePtr
Definition: Types.h:203
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1625
int GetNumWaveTracks()
Definition: Effect.h:343
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
double GetRate() const
Definition: WaveTrack.cpp:398
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1848
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
double mT0
Definition: Effect.h:460
static const double DEF_MinTruncMs
double EffectTruncSilence::CalcPreviewInputLength ( double  previewLength)
overridevirtual

Reimplemented from Effect.

Definition at line 235 of file TruncSilence.cpp.

References Analyze(), TrackListCondIterator::First(), Effect::inputTracks(), Effect::mT0, Effect::mT1, TrackListCondIterator::Next(), Region, WaveTrack::TimeToLongSamples(), and Track::Wave.

236 {
237  double inputLength = mT1 - mT0;
238  double minInputLength = inputLength;
239 
240  // Master list of silent regions
241  RegionList silences;
242 
243  // Start with the whole selection silent
244  silences.push_back(Region(mT0, mT1));
245 
247  int whichTrack = 0;
248 
249  for (Track *t = iter.First(); t; t = iter.Next()) {
250  WaveTrack *const wt = static_cast<WaveTrack *>(t);
251 
252  RegionList trackSilences;
253 
254  auto index = wt->TimeToLongSamples(mT0);
255  sampleCount silentFrame = 0; // length of the current silence
256 
257  Analyze(silences, trackSilences, wt, &silentFrame, &index, whichTrack, &inputLength, &minInputLength);
258 
259  whichTrack++;
260  }
261  return inputLength;
262 }
double mT1
Definition: Effect.h:461
TrackList * inputTracks() const
Definition: Effect.h:458
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack *wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=NULL, double *minInputLength=NULL)
#define Region
Definition: VSTControlGTK.h:15
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
double mT0
Definition: Effect.h:460
bool EffectTruncSilence::DefineParams ( ShuttleParams S)
override

Definition at line 177 of file TruncSilence.cpp.

References mActionIndex, mbIndependent, mInitialAllowedSilence, mSilenceCompressPercent, mThresholdDB, mTruncLongestAllowedSilence, and nActions.

177  {
178  S.SHUTTLE_PARAM( mThresholdDB, Threshold );
179  S.SHUTTLE_ENUM_PARAM( mActionIndex, ActIndex, kActionStrings, nActions );
180  S.SHUTTLE_PARAM( mInitialAllowedSilence, Minimum );
181  S.SHUTTLE_PARAM( mTruncLongestAllowedSilence, Truncate );
182  S.SHUTTLE_PARAM( mSilenceCompressPercent, Compress );
183  S.SHUTTLE_PARAM( mbIndependent, Independent );
184  return true;
185 }
static const IdentInterfaceSymbol kActionStrings[nActions]
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
bool EffectTruncSilence::DoRemoval ( const RegionList silences,
unsigned  iGroup,
unsigned  nGroups,
Track firstTrack,
Track lastTrack,
double &  totalCutLen 
)
private

Definition at line 482 of file TruncSilence.cpp.

References sampleCount::as_size_t(), WaveTrack::Clear(), detectFrac, Region::end, floatSample, WaveTrack::Get(), kCompress, kTruncate, WaveTrack::LongSamplesToTime(), min(), WaveTrack::Set(), Region::start, WaveTrack::TimeToLongSamples(), and Track::Wave.

Referenced by ProcessAll(), and ProcessIndependently().

484 {
485  //
486  // Now remove the silent regions from all selected / sync-lock selected tracks.
487  //
488 
489  // Loop over detected regions in reverse (so cuts don't change time values
490  // down the line)
491  int whichReg = 0;
492  RegionList::const_reverse_iterator rit;
493  for (rit = silences.rbegin(); rit != silences.rend(); ++rit)
494  {
495  const Region &region = *rit;
496  const Region *const r = &region;
497 
498  // Progress dialog and cancellation. Do additional cleanup before return.
499  const double frac = detectFrac +
500  (1 - detectFrac) * (iGroup + whichReg / double(silences.size())) / nGroups;
501  if (TotalProgress(frac))
502  {
503  ReplaceProcessedTracks(false);
504  return false;
505  }
506 
507  // Intersection may create regions smaller than allowed; ignore them.
508  // Allow one nanosecond extra for consistent results with exact milliseconds of allowed silence.
509  if ((r->end - r->start) < (mInitialAllowedSilence - 0.000000001))
510  continue;
511 
512  // Find NEW silence length as requested
513  double inLength = r->end - r->start;
514  double outLength;
515 
516  switch (mActionIndex)
517  {
518  case kTruncate:
519  outLength = std::min(mTruncLongestAllowedSilence, inLength);
520  break;
521  case kCompress:
522  outLength = mInitialAllowedSilence +
523  (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0;
524  break;
525  default: // Not currently used.
526  outLength = std::min(mInitialAllowedSilence +
527  (inLength - mInitialAllowedSilence) * mSilenceCompressPercent / 100.0,
529  }
530 
531  double cutLen = std::max(0.0, inLength - outLength);
532  totalCutLen += cutLen;
533 
534  TrackListIterator iterOut(mOutputTracks.get());
535  bool lastSeen = false;
536  for (Track *t = iterOut.StartWith(firstTrack); t && !lastSeen; t = iterOut.Next())
537  {
538  lastSeen = (t == lastTrack);
539  if (!(t->GetSelected() || t->IsSyncLockSelected()))
540  continue;
541 
542  // Don't waste time past the end of a track
543  if (t->GetEndTime() < r->start)
544  continue;
545 
546  // Don't waste time cutting nothing.
547  if( cutLen == 0.0 )
548  continue;
549 
550  double cutStart = (r->start + r->end - cutLen) / 2;
551  double cutEnd = cutStart + cutLen;
552  if (t->GetKind() == Track::Wave)
553  {
554  // In WaveTracks, clear with a cross-fade
555  WaveTrack *const wt = static_cast<WaveTrack*>(t);
556  auto blendFrames = mBlendFrameCount;
557  // Round start/end times to frame boundaries
558  cutStart = wt->LongSamplesToTime(wt->TimeToLongSamples(cutStart));
559  cutEnd = wt->LongSamplesToTime(wt->TimeToLongSamples(cutEnd));
560 
561  // Make sure the cross-fade does not affect non-silent frames
562  if (wt->LongSamplesToTime(blendFrames) > inLength)
563  {
564  // Result is not more than blendFrames:
565  blendFrames = wt->TimeToLongSamples(inLength).as_size_t();
566  }
567 
568  // Perform cross-fade in memory
569  Floats buf1{ blendFrames };
570  Floats buf2{ blendFrames };
571  auto t1 = wt->TimeToLongSamples(cutStart) - blendFrames / 2;
572  auto t2 = wt->TimeToLongSamples(cutEnd) - blendFrames / 2;
573 
574  wt->Get((samplePtr)buf1.get(), floatSample, t1, blendFrames);
575  wt->Get((samplePtr)buf2.get(), floatSample, t2, blendFrames);
576 
577  for (decltype(blendFrames) i = 0; i < blendFrames; ++i)
578  {
579  buf1[i] = ((blendFrames-i) * buf1[i] + i * buf2[i]) /
580  (double)blendFrames;
581  }
582 
583  // Perform the cut
584  wt->Clear(cutStart, cutEnd);
585 
586  // Write cross-faded data
587  wt->Set((samplePtr)buf1.get(), floatSample, t1, blendFrames);
588  }
589  else
590  // Non-wave tracks: just do a sync-lock adjust
591  t->SyncLockAdjust(cutEnd, cutStart);
592  }
593  ++whichReg;
594  }
595 
596  return true;
597 }
const double detectFrac
bool TotalProgress(double frac)
Definition: Effect.cpp:1977
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:678
void Set(samplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2052
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:42
char * samplePtr
Definition: Types.h:203
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
double start
Definition: WaveTrack.h:47
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
int min(int a, int b)
An iterator for a TrackList.
Definition: Track.h:402
double end
Definition: WaveTrack.h:47
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1848
size_t as_size_t() const
Definition: Types.h:92
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
bool EffectTruncSilence::FindSilences ( RegionList silences,
TrackList list,
Track firstTrack,
Track lastTrack 
)
private

Definition at line 428 of file TruncSilence.cpp.

References WaveTrack::GetRate(), WaveTrack::LongSamplesToTime(), TrackListCondIterator::Next(), Region, TrackListCondIterator::StartWith(), WaveTrack::TimeToLongSamples(), and Track::Wave.

Referenced by ProcessAll(), and ProcessIndependently().

429 {
430  // Start with the whole selection silent
431  silences.push_back(Region(mT0, mT1));
432 
433  // Remove non-silent regions in each track
435  int whichTrack = 0;
436  bool lastSeen = false;
437  for (Track *t = iter.StartWith(firstTrack); !lastSeen && t; t = iter.Next())
438  {
439  lastSeen = (t == lastTrack);
440  WaveTrack *const wt = static_cast<WaveTrack *>(t);
441 
442  // Smallest silent region to detect in frames
443  auto minSilenceFrames =
445 
446  //
447  // Scan the track for silences
448  //
449  RegionList trackSilences;
450 
451  auto index = wt->TimeToLongSamples(mT0);
452  sampleCount silentFrame = 0;
453 
454  // Detect silences
455  bool cancelled = !(Analyze(silences, trackSilences, wt, &silentFrame, &index, whichTrack));
456 
457  // Buffer has been freed, so we're OK to return if cancelled
458  if (cancelled)
459  {
460  ReplaceProcessedTracks(false);
461  return false;
462  }
463 
464  if (silentFrame >= minSilenceFrames)
465  {
466  // Track ended in silence -- record region
467  trackSilences.push_back(Region(
468  wt->LongSamplesToTime(index - silentFrame),
469  wt->LongSamplesToTime(index)
470  ));
471  }
472 
473  // Intersect with the overall silent region list
474  Intersect(silences, trackSilences);
475  whichTrack++;
476  }
477 
478  return true;
479 }
double mT1
Definition: Effect.h:461
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
bool Analyze(RegionList &silenceList, RegionList &trackSilences, const WaveTrack *wt, sampleCount *silentFrame, sampleCount *index, int whichTrack, double *inputLength=NULL, double *minInputLength=NULL)
#define Region
Definition: VSTControlGTK.h:15
void Intersect(RegionList &dest, const RegionList &src)
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
double mInitialAllowedSilence
Definition: TruncSilence.h:102
double GetRate() const
Definition: WaveTrack.cpp:398
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1848
double mT0
Definition: Effect.h:460
static const double DEF_MinTruncMs
bool EffectTruncSilence::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 187 of file TruncSilence.cpp.

References mActionIndex, mbIndependent, mInitialAllowedSilence, mSilenceCompressPercent, mThresholdDB, and mTruncLongestAllowedSilence.

188 {
189  parms.Write(KEY_Threshold, mThresholdDB);
190  parms.Write(KEY_ActIndex, kActionStrings[mActionIndex].Internal());
191  parms.Write(KEY_Minimum, mInitialAllowedSilence);
192  parms.Write(KEY_Truncate, mTruncLongestAllowedSilence);
193  parms.Write(KEY_Compress, mSilenceCompressPercent);
194  parms.Write(KEY_Independent, mbIndependent);
195 
196  return true;
197 }
static const IdentInterfaceSymbol kActionStrings[nActions]
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
wxString EffectTruncSilence::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 158 of file TruncSilence.cpp.

References _().

159 {
160  return _("Automatically reduces the length of passages where the volume is below a specified level");
161 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol EffectTruncSilence::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 153 of file TruncSilence.cpp.

References TRUNCATESILENCE_PLUGIN_SYMBOL.

154 {
156 }
#define TRUNCATESILENCE_PLUGIN_SYMBOL
Definition: TruncSilence.h:32
EffectType EffectTruncSilence::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 170 of file TruncSilence.cpp.

References EffectTypeProcess.

171 {
172  return EffectTypeProcess;
173 }
void EffectTruncSilence::Intersect ( RegionList dest,
const RegionList src 
)
private

Definition at line 851 of file TruncSilence.cpp.

852 {
853  RegionList::iterator destIter;
854  destIter = dest.begin();
855  // Any time we reach the end of the dest list we're finished
856  if (destIter == dest.end())
857  return;
858  RegionList::iterator curDest = destIter;
859 
860  // Operation: find non-silent regions in src, remove them from dest.
861  double nsStart = curDest->start;
862  double nsEnd;
863  bool lastRun = false; // must run the loop one extra time
864 
865  RegionList::const_iterator srcIter = src.begin();
866 
867  // This logic, causing the loop to run once after end of src, must occur
868  // each time srcIter is updated
869  if (srcIter == src.end())
870  {
871  lastRun = true;
872  }
873 
874  while (srcIter != src.end() || lastRun)
875  {
876  // Don't use curSrc unless lastRun is false!
877  RegionList::const_iterator curSrc;
878 
879  if (lastRun)
880  {
881  // The last non-silent region extends as far as possible
882  nsEnd = std::numeric_limits<double>::max();
883  }
884  else
885  {
886  curSrc = srcIter;
887  nsEnd = curSrc->start;
888  }
889 
890  if (nsEnd > nsStart)
891  {
892  // Increment through dest until we have a region that could be affected
893  while (curDest->end <= nsStart)
894  {
895  ++destIter;
896  if (destIter == dest.end())
897  {
898  return;
899  }
900  curDest = destIter;
901  }
902 
903  // Check for splitting dest region in two
904  if (nsStart > curDest->start && nsEnd < curDest->end)
905  {
906  // The second region
907  Region r(nsEnd, curDest->end);
908 
909  // The first region
910  curDest->end = nsStart;
911 
912  // Insert second region after first
913  RegionList::iterator nextIt(destIter);
914  ++nextIt;
915 
916  // This should just read: destIter = dest.insert(nextIt, r); but we
917  // work around two two wxList::insert() bugs. First, in some
918  // versions it returns the wrong value. Second, in some versions,
919  // it crashes when you insert at list end.
920  if (nextIt == dest.end())
921  dest.push_back(r);
922  else
923  dest.insert(nextIt, r);
924  ++destIter; // (now points at the newly-inserted region)
925 
926  curDest = destIter;
927  }
928 
929  // Check for truncating the end of dest region
930  if (nsStart > curDest->start && nsStart < curDest->end &&
931  nsEnd >= curDest->end)
932  {
933  curDest->end = nsStart;
934 
935  ++destIter;
936  if (destIter == dest.end())
937  {
938  return;
939  }
940  curDest = destIter;
941  }
942 
943  // Check for all dest regions that need to be removed completely
944  while (nsStart <= curDest->start && nsEnd >= curDest->end)
945  {
946  destIter = dest.erase(destIter);
947  if (destIter == dest.end())
948  {
949  return;
950  }
951  curDest = destIter;
952  }
953 
954  // Check for truncating the beginning of dest region
955  if (nsStart <= curDest->start &&
956  nsEnd > curDest->start && nsEnd < curDest->end)
957  {
958  curDest->start = nsEnd;
959  }
960  }
961 
962  if (lastRun)
963  {
964  // done
965  lastRun = false;
966  }
967  else
968  {
969  // Next non-silent region starts at the end of this silent region
970  nsStart = curSrc->end;
971  ++srcIter;
972  if (srcIter == src.end())
973  {
974  lastRun = true;
975  }
976  }
977  }
978 }
Structure to hold region of a wavetrack and a comparison function for sortability.
Definition: WaveTrack.h:42
wxString EffectTruncSilence::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 163 of file TruncSilence.cpp.

164 {
165  return wxT("Truncate_Silence");
166 }
void EffectTruncSilence::OnControlChange ( wxCommandEvent &  evt)
private

Definition at line 1012 of file TruncSilence.cpp.

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

1013 {
1014  mActionChoice->GetValidator()->TransferFromWindow();
1015 
1016  UpdateUI();
1017 
1018  if (!EnableApply(mUIParent->TransferDataFromWindow()))
1019  {
1020  return;
1021  }
1022 }
wxChoice * mActionChoice
Definition: TruncSilence.h:110
wxWindow * mUIParent
Definition: Effect.h:472
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
void EffectTruncSilence::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 756 of file TruncSilence.cpp.

References _(), ShuttleGuiBase::AddCheckBox(), ShuttleGuiBase::AddChoice(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddUnits(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndStatic(), LocalizedStrings(), mActionChoice, mActionIndex, mbIndependent, mIndependent, mInitialAllowedSilence, mInitialAllowedSilenceT, mSilenceCompressPercent, mSilenceCompressPercentT, mThresholdDB, mThresholdText, mTruncLongestAllowedSilence, mTruncLongestAllowedSilenceT, nActions, ShuttleGuiBase::SetSizeHints(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartStatic(), and UpdateUI().

757 {
758  wxASSERT(nActions == WXSIZEOF(kActionStrings));
759 
760  S.AddSpace(0, 5);
761 
762  S.StartStatic(_("Detect Silence"));
763  {
764  S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
765  {
766  // Threshold
767  FloatingPointValidator<double> vldThreshold(3, &mThresholdDB,
768  NumValidatorStyle::NO_TRAILING_ZEROES);
769  vldThreshold.SetRange(MIN_Threshold, MAX_Threshold);
770  mThresholdText = S.AddTextBox(_("Threshold:"), wxT(""), 0);
771  mThresholdText->SetValidator(vldThreshold);
772  S.AddUnits(_("dB"));
773 
774  // Ignored silence
775  FloatingPointValidator<double> vldDur(3, &mInitialAllowedSilence, NumValidatorStyle::NO_TRAILING_ZEROES);
776  vldDur.SetRange(MIN_Minimum, MAX_Minimum);
777  mInitialAllowedSilenceT = S.AddTextBox(_("Duration:"), wxT(""), 12);
778  mInitialAllowedSilenceT->SetValidator(vldDur);
779  S.AddUnits(_("seconds"));
780  }
781  S.EndMultiColumn();
782  }
783  S.EndStatic();
784 
785  S.StartStatic(_("Action"));
786  {
787  S.StartHorizontalLay();
788  {
789  // Action choices
790  auto actionChoices = LocalizedStrings(kActionStrings, nActions);
791  mActionChoice = S.AddChoice( {}, wxT(""), &actionChoices);
792  mActionChoice->SetValidator(wxGenericValidator(&mActionIndex));
793  S.SetSizeHints(-1, -1);
794  }
795  S.EndHorizontalLay();
796  S.StartMultiColumn(3, wxALIGN_CENTER_HORIZONTAL);
797  {
798  // Truncation / Compression factor
799 
800  FloatingPointValidator<double> vldTrunc(3, &mTruncLongestAllowedSilence, NumValidatorStyle::NO_TRAILING_ZEROES);
801  vldTrunc.SetRange(MIN_Truncate, MAX_Truncate);
802  mTruncLongestAllowedSilenceT = S.AddTextBox(_("Truncate to:"), wxT(""), 12);
803  mTruncLongestAllowedSilenceT->SetValidator(vldTrunc);
804  S.AddUnits(_("seconds"));
805 
806  FloatingPointValidator<double> vldComp(3, &mSilenceCompressPercent, NumValidatorStyle::NO_TRAILING_ZEROES);
807  vldComp.SetRange(MIN_Compress, MAX_Compress);
808  mSilenceCompressPercentT = S.AddTextBox(_("Compress to:"), wxT(""), 12);
809  mSilenceCompressPercentT->SetValidator(vldComp);
810  S.AddUnits(_("%"));
811  }
812  S.EndMultiColumn();
813 
814  S.StartMultiColumn(2, wxALIGN_CENTER_HORIZONTAL);
815  {
816  mIndependent = S.AddCheckBox(_("Truncate tracks independently"),
817  mbIndependent ? wxT("true") : wxT("false"));
818  }
819  S.EndMultiColumn();
820 }
821  S.EndStatic();
822 
823  UpdateUI();
824 }
void SetSizeHints(int minX, int minY)
Used to modify an already placed Window.
Definition: ShuttleGui.cpp:194
wxArrayString LocalizedStrings(const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
void EndMultiColumn()
void EndHorizontalLay()
static const IdentInterfaceSymbol kActionStrings[nActions]
void AddUnits(const wxString &Prompt)
Left aligned text string.
Definition: ShuttleGui.cpp:260
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:298
wxChoice * mActionChoice
Definition: TruncSilence.h:110
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:112
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
wxChoice * AddChoice(const wxString &Prompt, const wxString &Selected, const wxArrayString *pChoices)
Definition: ShuttleGui.cpp:371
wxCheckBox * mIndependent
Definition: TruncSilence.h:114
wxTextCtrl * mInitialAllowedSilenceT
Definition: TruncSilence.h:111
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxTextCtrl * mThresholdText
Definition: TruncSilence.h:109
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
double mSilenceCompressPercent
Definition: TruncSilence.h:104
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:113
double mInitialAllowedSilence
Definition: TruncSilence.h:102
wxSizerItem * AddSpace(int width, int height)
bool EffectTruncSilence::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 316 of file TruncSilence.cpp.

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

317 {
318  const bool success =
321  : ProcessAll();
322 
323  if (success)
325 
326  return success;
327 }
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
bool EffectTruncSilence::ProcessAll ( )
private

Definition at line 404 of file TruncSilence.cpp.

References Track::All, Effect::CopyInputTracks(), DoRemoval(), FindSilences(), TrackListCondIterator::First(), Effect::inputTracks(), TrackListCondIterator::Last(), Effect::mOutputTracks, Effect::mT1, and Track::Wave.

Referenced by Process().

405 {
406  // Copy tracks
408 
409  // Master list of silent regions.
410  // This list should always be kept in order.
411  RegionList silences;
412 
414  if (FindSilences(silences, inputTracks(), iter.First(), iter.Last())) {
415  TrackListIterator iterOut(mOutputTracks.get());
416  double totalCutLen = 0.0;
417  Track *const first = iterOut.First();
418  if (DoRemoval(silences, 0, 1, first, iterOut.Last(), totalCutLen)) {
419  mT1 -= totalCutLen;
420  return true;
421  }
422  }
423 
424  return false;
425 }
double mT1
Definition: Effect.h:461
void CopyInputTracks()
Definition: Effect.cpp:2036
TrackList * inputTracks() const
Definition: Effect.h:458
bool DoRemoval(const RegionList &silences, unsigned iGroup, unsigned nGroups, Track *firstTrack, Track *lastTrack, double &totalCutLen)
bool FindSilences(RegionList &silences, TrackList *list, Track *firstTrack, Track *lastTrack)
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
An iterator for a TrackList.
Definition: Track.h:402
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
bool EffectTruncSilence::ProcessIndependently ( )
private

Definition at line 329 of file TruncSilence.cpp.

References _(), Track::All, Effect::CopyInputTracks(), DoRemoval(), FindSilences(), TrackListCondIterator::First(), GetActiveProject(), Track::GetLink(), Effect::inputTracks(), AudacityProject::IsSyncLocked(), Effect::MessageBox(), Effect::mOutputTracks, Effect::mT1, TrackListCondIterator::Next(), SyncLockedTracksIterator::Next(), SyncLockedTracksIterator::StartWith(), and Track::Wave.

Referenced by Process().

330 {
331  unsigned nGroups = 0;
332 
333  const bool syncLock = ::GetActiveProject()->IsSyncLocked();
334 
335  // Check if it's permissible
336  {
338  for (Track *track = iter.First(); track;
339  track = iter.Next(true) // skip linked tracks
340  ) {
341  if (syncLock) {
342  Track *const link = track->GetLink();
344  for (Track *track2 = syncIter.StartWith(track); track2; track2 = syncIter.Next()) {
345  if (track2->GetKind() == Track::Wave &&
346  !(track2 == track || track2 == link) &&
347  track2->GetSelected()) {
348  ::Effect::MessageBox(_("When truncating independently, there may only be one selected audio track in each Sync-Locked Track Group."));
349  return false;
350  }
351  }
352  }
353 
354  ++nGroups;
355  }
356  }
357 
358  if (nGroups == 0)
359  // nothing to do
360  return true;
361 
362  // Now do the work
363 
364  // Copy tracks
366  double newT1 = 0.0;
367 
368  {
369  unsigned iGroup = 0;
371  for (Track *track = iter.First(); track;
372  ++iGroup, track = iter.Next(true) // skip linked tracks
373  ) {
374  Track *const link = track->GetLink();
375  Track *const last = link ? link : track;
376 
377  RegionList silences;
378 
379  if (!FindSilences(silences, mOutputTracks.get(), track, last))
380  return false;
381  // Treat tracks in the sync lock group only
382  Track *groupFirst, *groupLast;
383  if (syncLock) {
384  SyncLockedTracksIterator syncIter(mOutputTracks.get());
385  groupFirst = syncIter.StartWith(track);
386  groupLast = syncIter.Last();
387  }
388  else {
389  groupFirst = track;
390  groupLast = last;
391  }
392  double totalCutLen = 0.0;
393  if (!DoRemoval(silences, iGroup, nGroups, groupFirst, groupLast, totalCutLen))
394  return false;
395  newT1 = std::max(newT1, mT1 - totalCutLen);
396  }
397  }
398 
399  mT1 = newT1;
400 
401  return true;
402 }
double mT1
Definition: Effect.h:461
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
void CopyInputTracks()
Definition: Effect.cpp:2036
TrackList * inputTracks() const
Definition: Effect.h:458
bool DoRemoval(const RegionList &silences, unsigned iGroup, unsigned nGroups, Track *firstTrack, Track *lastTrack, double &totalCutLen)
bool FindSilences(RegionList &silences, TrackList *list, Track *firstTrack, Track *lastTrack)
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Track * GetLink() const
Definition: Track.cpp:269
bool IsSyncLocked()
Definition: Project.cpp:5658
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
bool EffectTruncSilence::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 199 of file TruncSilence.cpp.

References enumToDB(), kObsoleteActions, mActionIndex, mbIndependent, mInitialAllowedSilence, mSilenceCompressPercent, mThresholdDB, mTruncLongestAllowedSilence, nActions, nObsoleteActions, Enums::NumDbChoices, ReadAndVerifyBool, ReadAndVerifyDouble, ReadAndVerifyEnum, and ReadAndVerifyEnumWithObsoletes.

200 {
201  ReadAndVerifyDouble(Minimum);
202  ReadAndVerifyDouble(Truncate);
203  ReadAndVerifyDouble(Compress);
204 
205  // This control migrated from a choice to a text box in version 2.3.0
206  double myThreshold {};
207  bool newParams = [&] {
208  ReadAndVerifyDouble(Threshold); // macro may return false
209  myThreshold = Threshold;
210  return true;
211  } ();
212 
213  if ( !newParams ) {
214  // Use legacy param:
216  myThreshold = enumToDB( DbIndex );
217  }
218 
221  ReadAndVerifyBool(Independent);
222 
223  mInitialAllowedSilence = Minimum;
224  mTruncLongestAllowedSilence = Truncate;
225  mSilenceCompressPercent = Compress;
226  mThresholdDB = myThreshold;
227  mActionIndex = ActIndex;
228  mbIndependent = Independent;
229 
230  return true;
231 }
static const IdentInterfaceSymbol kActionStrings[nActions]
static CommandParameters::ObsoleteMap kObsoleteActions[]
#define ReadAndVerifyEnum(name, list, listSize)
Definition: Effect.h:786
static const size_t NumDbChoices
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
#define ReadAndVerifyDouble(name)
Definition: Effect.h:798
#define ReadAndVerifyEnumWithObsoletes(name, list, listSize, obsoleteList, nObsolete)
Definition: Effect.h:791
static const size_t nObsoleteActions
static double enumToDB(int val)
static const IdentInterfaceSymbol DbChoices[]
#define ReadAndVerifyBool(name)
Definition: Effect.h:800
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
bool EffectTruncSilence::Startup ( )
overridevirtual

Reimplemented from Effect.

Definition at line 265 of file TruncSilence.cpp.

References enumToDB(), Effect::GetCurrentSettingsGroup(), gPrefs, mActionIndex, mInitialAllowedSilence, mSilenceCompressPercent, mThresholdDB, mTruncLongestAllowedSilence, Enums::NumDbChoices, and Effect::SaveUserPreset().

266 {
267  wxString base = wxT("/Effects/TruncateSilence/");
268 
269  // Migrate settings from 2.1.0 or before
270 
271  // Already migrated, so bail
272  if (gPrefs->Exists(base + wxT("Migrated")))
273  {
274  return true;
275  }
276 
277  // Load the old "current" settings
278  if (gPrefs->Exists(base))
279  {
280  int truncDbChoiceIndex = gPrefs->Read(base + wxT("DbChoiceIndex"), 4L);
281  if ((truncDbChoiceIndex < 0) || (truncDbChoiceIndex >= Enums::NumDbChoices))
282  { // corrupted Prefs?
283  truncDbChoiceIndex = 4L;
284  }
285  mThresholdDB = enumToDB( truncDbChoiceIndex );
286  mActionIndex = gPrefs->Read(base + wxT("ProcessChoice"), 0L);
287  if ((mActionIndex < 0) || (mActionIndex > 1))
288  { // corrupted Prefs?
289  mActionIndex = 0L;
290  }
291  gPrefs->Read(base + wxT("InitialAllowedSilence"), &mInitialAllowedSilence, 0.5);
292  if ((mInitialAllowedSilence < 0.001) || (mInitialAllowedSilence > 10000.0))
293  { // corrupted Prefs?
295  }
296  gPrefs->Read(base + wxT("LongestAllowedSilence"), &mTruncLongestAllowedSilence, 0.5);
297  if ((mTruncLongestAllowedSilence < 0.0) || (mTruncLongestAllowedSilence > 10000.0))
298  { // corrupted Prefs?
300  }
301  gPrefs->Read(base + wxT("CompressPercent"), &mSilenceCompressPercent, 50.0);
302  if ((mSilenceCompressPercent < 0.0) || (mSilenceCompressPercent > 100.0))
303  { // corrupted Prefs?
305  }
306 
308  }
309 
310  // Do not migrate again
311  gPrefs->Write(base + wxT("Migrated"), true);
312 
313  return true;
314 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:600
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:801
static const size_t NumDbChoices
double mTruncLongestAllowedSilence
Definition: TruncSilence.h:103
static double enumToDB(int val)
double mSilenceCompressPercent
Definition: TruncSilence.h:104
double mInitialAllowedSilence
Definition: TruncSilence.h:102
bool EffectTruncSilence::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 836 of file TruncSilence.cpp.

References mbIndependent, mIndependent, and Effect::mUIParent.

837 {
838  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
839  {
840  return false;
841  }
842 
843  mbIndependent = mIndependent->IsChecked();
844 
845  return true;
846 }
wxCheckBox * mIndependent
Definition: TruncSilence.h:114
wxWindow * mUIParent
Definition: Effect.h:472
bool EffectTruncSilence::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 826 of file TruncSilence.cpp.

References Effect::mUIParent.

827 {
828  if (!mUIParent->TransferDataToWindow())
829  {
830  return false;
831  }
832 
833  return true;
834 }
wxWindow * mUIParent
Definition: Effect.h:472
void EffectTruncSilence::UpdateUI ( void  )
private

Definition at line 998 of file TruncSilence.cpp.

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

Referenced by OnControlChange(), and PopulateOrExchange().

999 {
1000  switch (mActionIndex)
1001  {
1002  case kTruncate:
1003  mTruncLongestAllowedSilenceT->Enable(true);
1004  mSilenceCompressPercentT->Enable(false);
1005  break;
1006  case kCompress:
1007  mTruncLongestAllowedSilenceT->Enable(false);
1008  mSilenceCompressPercentT->Enable(true);
1009  }
1010 }
wxTextCtrl * mTruncLongestAllowedSilenceT
Definition: TruncSilence.h:112
wxTextCtrl * mSilenceCompressPercentT
Definition: TruncSilence.h:113

Member Data Documentation

wxChoice* EffectTruncSilence::mActionChoice
private

Definition at line 110 of file TruncSilence.h.

Referenced by OnControlChange(), and PopulateOrExchange().

int EffectTruncSilence::mActionIndex
private
bool EffectTruncSilence::mbIndependent
private
size_t EffectTruncSilence::mBlendFrameCount
private

Definition at line 107 of file TruncSilence.h.

wxCheckBox* EffectTruncSilence::mIndependent
private

Definition at line 114 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and TransferDataFromWindow().

double EffectTruncSilence::mInitialAllowedSilence
private
wxTextCtrl* EffectTruncSilence::mInitialAllowedSilenceT
private

Definition at line 111 of file TruncSilence.h.

Referenced by PopulateOrExchange().

double EffectTruncSilence::mSilenceCompressPercent
private
wxTextCtrl* EffectTruncSilence::mSilenceCompressPercentT
private

Definition at line 113 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().

double EffectTruncSilence::mThresholdDB {}
private
wxTextCtrl* EffectTruncSilence::mThresholdText
private

Definition at line 109 of file TruncSilence.h.

Referenced by PopulateOrExchange().

double EffectTruncSilence::mTruncLongestAllowedSilence
private
wxTextCtrl* EffectTruncSilence::mTruncLongestAllowedSilenceT
private

Definition at line 112 of file TruncSilence.h.

Referenced by PopulateOrExchange(), and UpdateUI().


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