Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions | List of all members
ChangeSpeedBase Class Reference

An Effect that affects both pitch & speed. More...

#include <ChangeSpeedBase.h>

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

Public Member Functions

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

Static Public Member Functions

static ChangeSpeedBaseFetchParameters (ChangeSpeedBase &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
- Static Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol
 
- 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>")
 

Protected Member Functions

const EffectParameterMethodsParameters () const override
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 

Protected Attributes

int mCurTrackNum
 
double mCurT0
 
double mCurT1
 
double m_PercentChange
 
int mFromVinyl
 
double mFactor
 
double mFromLength
 
int mTimeCtrlFormat
 
double mMultiplier
 
bool mbLoopDetect
 
double mRate
 
int mToVinyl
 
double mToLength
 
NumericFormatID mFormat
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Static Protected Attributes

static constexpr EffectParameter Percentage
 

Private Types

using Gap = std::pair< double, double >
 
using Gaps = std::vector< Gap >
 

Private Member Functions

Gaps FindGaps (const WaveTrack &track, const double curT0, const double curT1)
 
bool ProcessOne (const WaveChannel &track, WaveChannel &outputTrack, sampleCount start, sampleCount end)
 
bool ProcessLabelTrack (LabelTrack *t)
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 

Detailed Description

An Effect that affects both pitch & speed.

Definition at line 20 of file ChangeSpeedBase.h.

Member Typedef Documentation

◆ Gap

using ChangeSpeedBase::Gap = std::pair<double, double>
private

Definition at line 54 of file ChangeSpeedBase.h.

◆ Gaps

using ChangeSpeedBase::Gaps = std::vector<Gap>
private

Definition at line 55 of file ChangeSpeedBase.h.

Constructor & Destructor Documentation

◆ ChangeSpeedBase()

ChangeSpeedBase::ChangeSpeedBase ( )

Definition at line 25 of file ChangeSpeedBase.cpp.

26{
27 Parameters().Reset(*this);
28
31 mFromLength = 0.0;
32 mToLength = 0.0;
34 mbLoopDetect = false;
35
37}
@ kVinyl_33AndAThird
NumericFormatID mFormat
const EffectParameterMethods & Parameters() const override
const wxString & Internal() const
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
virtual void Reset(Effect &effect) const =0
NUMERIC_FORMATS_API NumericFormatSymbol DefaultSelectionFormat()

References NumericConverterFormats::DefaultSelectionFormat(), ComponentInterfaceSymbol::Internal(), kVinyl_33AndAThird, mbLoopDetect, mFormat, mFromLength, mFromVinyl, mToLength, mToVinyl, Parameters(), EffectParameterMethods::Reset(), and EffectBase::SetLinearEffectFlag().

Here is the call graph for this function:

◆ ~ChangeSpeedBase()

ChangeSpeedBase::~ChangeSpeedBase ( )
virtual

Definition at line 39 of file ChangeSpeedBase.cpp.

40{
41}

Member Function Documentation

◆ CalcPreviewInputLength()

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

Implements EffectBase.

Definition at line 83 of file ChangeSpeedBase.cpp.

85{
86 return previewLength * (100.0 + m_PercentChange) / 100.0;
87}

References m_PercentChange.

◆ CheckWhetherSkipEffect()

bool ChangeSpeedBase::CheckWhetherSkipEffect ( const EffectSettings settings) const
overridevirtual

After Init(), tell whether Process() should be skipped.

Implements EffectBase.

Definition at line 78 of file ChangeSpeedBase.cpp.

79{
80 return (m_PercentChange == 0.0);
81}

References m_PercentChange.

◆ DoLoadFactoryDefaults()

OptionalMessage ChangeSpeedBase::DoLoadFactoryDefaults ( EffectSettings settings)

Definition at line 70 of file ChangeSpeedBase.cpp.

71{
74
76}
static Settings & settings()
Definition: TrackInfo.cpp:51
OptionalMessage LoadFactoryDefaults(EffectSettings &settings) const override
Definition: Effect.cpp:165

References NumericConverterFormats::DefaultSelectionFormat(), ComponentInterfaceSymbol::Internal(), kVinyl_33AndAThird, Effect::LoadFactoryDefaults(), mFormat, mFromVinyl, and settings().

Referenced by LoadFactoryDefaults().

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

◆ FetchParameters()

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

Definition at line 24 of file ChangeSpeedBase.h.

25 {
26 return &e;
27 }

◆ FindGaps()

auto ChangeSpeedBase::FindGaps ( const WaveTrack track,
const double  curT0,
const double  curT1 
)
private

Definition at line 97 of file ChangeSpeedBase.cpp.

99{
100 // Silenced samples will be inserted in gaps between clips, so capture where
101 // these gaps are for later deletion
102 Gaps gaps;
103 const auto newGap = [&](double st, double et) {
104 gaps.emplace_back(track.SnapToSample(st), track.SnapToSample(et));
105 };
106 double last = curT0;
107 auto clips = track.SortedIntervalArray();
108 auto front = clips.front();
109 auto back = clips.back();
110 for (auto& clip : clips)
111 {
112 auto st = clip->GetPlayStartTime();
113 auto et = clip->GetPlayEndTime();
114 if (st >= curT0 || et < curT1)
115 {
116 if (curT0 < st && clip == front)
117 newGap(curT0, st);
118 else if (last < st && curT0 <= last)
119 newGap(last, st);
120 if (et < curT1 && clip == back)
121 newGap(et, curT1);
122 }
123 last = et;
124 }
125 return gaps;
126}
std::vector< Gap > Gaps
IntervalHolders SortedIntervalArray()
Return all WaveClips sorted by clip play start time.
Definition: WaveTrack.cpp:3297
double SnapToSample(double t) const

Referenced by Process().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString ChangeSpeedBase::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 48 of file ChangeSpeedBase.cpp.

49{
50 return XO("Changes the speed of a track, also changing its pitch");
51}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol ChangeSpeedBase::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 43 of file ChangeSpeedBase.cpp.

44{
45 return Symbol;
46}
static const ComponentInterfaceSymbol Symbol

References Symbol.

◆ GetType()

EffectType ChangeSpeedBase::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 58 of file ChangeSpeedBase.cpp.

59{
60 return EffectTypeProcess;
61}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ Init()

bool ChangeSpeedBase::Init ( )
overridevirtual

Default implementation does nothing, returns true

Reimplemented from StatefulEffectBase.

Definition at line 89 of file ChangeSpeedBase.cpp.

90{
91 // The selection might have changed since the last time ChangeSpeedBase
92 // was invoked, so recalculate the Length parameters.
94 return true;
95}
double mT1
Definition: EffectBase.h:123
double mT0
Definition: EffectBase.h:122

References mFromLength, EffectBase::mT0, and EffectBase::mT1.

◆ LoadFactoryDefaults()

OptionalMessage ChangeSpeedBase::LoadFactoryDefaults ( EffectSettings settings) const
overridevirtual

Change settings back to "factory default"

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 64 of file ChangeSpeedBase.cpp.

65{
66 // To do: externalize state so const_cast isn't needed
67 return const_cast<ChangeSpeedBase&>(*this).DoLoadFactoryDefaults(settings);
68}
An Effect that affects both pitch & speed.
OptionalMessage DoLoadFactoryDefaults(EffectSettings &settings)

References DoLoadFactoryDefaults(), and settings().

Here is the call graph for this function:

◆ ManualPage()

ManualPageID ChangeSpeedBase::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 53 of file ChangeSpeedBase.cpp.

54{
55 return L"Change_Speed";
56}

◆ Parameters()

const EffectParameterMethods & ChangeSpeedBase::Parameters ( ) const
overrideprotectedvirtual

Reimplemented from Effect.

Definition at line 16 of file ChangeSpeedBase.cpp.

17{
19 return parameters;
20}
Generates EffectParameterMethods overrides from variadic template arguments.

Referenced by ChangeSpeedBase().

Here is the caller graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 128 of file ChangeSpeedBase.cpp.

129{
130 // Similar to SoundTouchBase::Process()
131
132 // Iterate over each track.
133 // All needed because this effect needs to introduce
134 // silence in the sync-lock group tracks to keep sync
135 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } }, true };
136 bool bGoodResult = true;
137
138 mCurTrackNum = 0;
139
140 mFactor = 100.0 / (100.0 + m_PercentChange);
141
142 outputs.Get().Any().VisitWhile(
143 bGoodResult,
144 [&](LabelTrack& lt) {
146 {
147 if (!ProcessLabelTrack(&lt))
148 bGoodResult = false;
149 }
150 },
151 [&](auto&& fallthrough) {
152 return [&](WaveTrack& outWaveTrack) {
153 if (!outWaveTrack.GetSelected())
154 return fallthrough();
155
156 // Get start and end times from track
157 mCurT0 = outWaveTrack.GetStartTime();
158 mCurT1 = outWaveTrack.GetEndTime();
159
160 // Set the current bounds to whichever left marker is
161 // greater and whichever right marker is less:
162 mCurT0 = std::max(mT0, mCurT0);
164
165 // Process only if the right marker is to the right of the left
166 // marker
167 if (mCurT1 > mCurT0)
168 {
169 // Transform the marker timepoints to samples
170 auto start = outWaveTrack.TimeToLongSamples(mCurT0);
171 auto end = outWaveTrack.TimeToLongSamples(mCurT1);
172
173 const auto gaps = FindGaps(outWaveTrack, mCurT0, mCurT1);
174
175 auto pNewTrack = outWaveTrack.EmptyCopy();
176 auto iter = pNewTrack->Channels().begin();
177 for (const auto pChannel : outWaveTrack.Channels())
178 {
179 // ProcessOne() (implemented below) processes a single channel
180 if (ProcessOne(*pChannel, **iter++, start, end))
181 ++mCurTrackNum;
182 else
183 {
184 pNewTrack.reset();
185 break;
186 }
187 }
188 if (!pNewTrack)
189 {
190 bGoodResult = false;
191 return;
192 }
193 pNewTrack->Flush();
194
195 const double newLength = pNewTrack->GetEndTime();
196 const LinearTimeWarper warper { mCurT0, mCurT0, mCurT1,
197 mCurT0 + newLength };
198
199 outWaveTrack.ClearAndPaste(
200 mCurT0, mCurT1, *pNewTrack, true, true, &warper);
201
202 // Finally, recreate the gaps
203 for (const auto [st, et] : gaps)
204 if (st >= mCurT0 && et <= mCurT1 && st != et)
205 outWaveTrack.SplitDelete(warper.Warp(st), warper.Warp(et));
206 }
207 else
208 mCurTrackNum += outWaveTrack.NChannels();
209 };
210 },
211 [&](Track& t) {
213 t.SyncLockAdjust(mT1, mT0 + (mT1 - mT0) * mFactor);
214 });
215
216 if (bGoodResult)
217 outputs.Commit();
218
219 // Update selection.
220 mT1 = mT0 + (((mT1 - mT0) * 100.0) / (100.0 + m_PercentChange));
221
222 return bGoodResult;
223}
int min(int a, int b)
bool ProcessLabelTrack(LabelTrack *t)
Gaps FindGaps(const WaveTrack &track, const double curT0, const double curT1)
bool ProcessOne(const WaveChannel &track, WaveChannel &outputTrack, sampleCount start, sampleCount end)
EffectType GetType() const override
Type determines how it behaves.
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:116
Use this object to copy the input tracks to tentative outputTracks.
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
Linear scaling, initialised by giving two points on the line.
Definition: TimeWarper.h:87
static bool IsSelectedOrSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:104
static bool IsSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:80
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References details::end(), FindGaps(), GetType(), SyncLock::IsSelectedOrSyncLockSelected(), SyncLock::IsSyncLockSelected(), m_PercentChange, mCurT0, mCurT1, mCurTrackNum, mFactor, min(), EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, ProcessLabelTrack(), and ProcessOne().

Here is the call graph for this function:

◆ ProcessLabelTrack()

bool ChangeSpeedBase::ProcessLabelTrack ( LabelTrack t)
private

Definition at line 227 of file ChangeSpeedBase.cpp.

228{
229 RegionTimeWarper warper { mT0, mT1,
230 std::make_unique<LinearTimeWarper>(
231 mT0, mT0, mT1, mT0 + (mT1 - mT0) * mFactor) };
232 lt->WarpLabels(warper);
233 return true;
234}
No change before the specified region; during the region, warp according to the given warper; after t...
Definition: TimeWarper.h:192

References mFactor, EffectBase::mT0, EffectBase::mT1, and LabelTrack::WarpLabels().

Referenced by Process().

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

◆ ProcessOne()

bool ChangeSpeedBase::ProcessOne ( const WaveChannel track,
WaveChannel outputTrack,
sampleCount  start,
sampleCount  end 
)
private

Definition at line 238 of file ChangeSpeedBase.cpp.

241{
242 // Get the length of the selection (as double). len is
243 // used simple to calculate a progress meter, so it is easier
244 // to make it a double now than it is to do it later
245 auto len = (end - start).as_double();
246
247 // Initiate processing buffers, most likely shorter than
248 // the length of the selection being processed.
249 auto inBufferSize = track.GetMaxBlockSize();
250
251 Floats inBuffer { inBufferSize };
252
253 // mFactor is at most 100-fold so this shouldn't overflow size_t
254 auto outBufferSize = size_t(mFactor * inBufferSize + 10);
255 Floats outBuffer { outBufferSize };
256
257 // Set up the resampling stuff for this track.
258 Resample resample(true, mFactor, mFactor); // constant rate resampling
259
260 // Go through the track one buffer at a time. samplePos counts which
261 // sample the current buffer starts at.
262 bool bResult = true;
263 auto samplePos = start;
264 while (samplePos < end)
265 {
266 // Get a blockSize of samples (smaller than the size of the buffer)
267 auto blockSize = limitSampleBufferSize(
268 track.GetBestBlockSize(samplePos), end - samplePos);
269
270 // Get the samples from the track and put them in the buffer
271 track.GetFloats(inBuffer.get(), samplePos, blockSize);
272
273 const auto results = resample.Process(
274 mFactor, inBuffer.get(), blockSize, ((samplePos + blockSize) >= end),
275 outBuffer.get(), outBufferSize);
276 const auto outgen = results.second;
277
278 if (outgen > 0)
279 outputTrack.Append((samplePtr)outBuffer.get(), floatSample, outgen);
280
281 // Increment samplePos
282 samplePos += results.first;
283
284 // Update the Progress meter
285 if (TrackProgress(mCurTrackNum, (samplePos - start).as_double() / len))
286 {
287 bResult = false;
288 break;
289 }
290 }
291
292 return bResult;
293}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:57
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:343
Interface to libsoxr.
Definition: Resample.h:27
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2237
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
Definition: WaveTrack.h:129
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:851
size_t GetMaxBlockSize() const
Definition: WaveTrack.h:859

References WaveChannel::Append(), details::end(), floatSample, WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), WaveChannel::GetMaxBlockSize(), limitSampleBufferSize(), mCurTrackNum, mFactor, Resample::Process(), and Effect::TrackProgress().

Referenced by Process().

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

Member Data Documentation

◆ m_PercentChange

double ChangeSpeedBase::m_PercentChange
protected

◆ mbLoopDetect

bool ChangeSpeedBase::mbLoopDetect
protected

◆ mCurT0

double ChangeSpeedBase::mCurT0
protected

Definition at line 67 of file ChangeSpeedBase.h.

Referenced by Process().

◆ mCurT1

double ChangeSpeedBase::mCurT1
protected

Definition at line 68 of file ChangeSpeedBase.h.

Referenced by Process().

◆ mCurTrackNum

int ChangeSpeedBase::mCurTrackNum
protected

Definition at line 66 of file ChangeSpeedBase.h.

Referenced by Process(), and ProcessOne().

◆ mFactor

double ChangeSpeedBase::mFactor
protected

Definition at line 76 of file ChangeSpeedBase.h.

Referenced by Process(), ProcessLabelTrack(), and ProcessOne().

◆ mFormat

NumericFormatID ChangeSpeedBase::mFormat
protected

◆ mFromLength

double ChangeSpeedBase::mFromLength
protected

◆ mFromVinyl

int ChangeSpeedBase::mFromVinyl
protected

◆ mMultiplier

double ChangeSpeedBase::mMultiplier
protected

◆ mRate

double ChangeSpeedBase::mRate
protected

Definition at line 83 of file ChangeSpeedBase.h.

◆ mTimeCtrlFormat

int ChangeSpeedBase::mTimeCtrlFormat
protected

Definition at line 78 of file ChangeSpeedBase.h.

◆ mToLength

double ChangeSpeedBase::mToLength
protected

◆ mToVinyl

int ChangeSpeedBase::mToVinyl
protected

◆ Percentage

constexpr EffectParameter ChangeSpeedBase::Percentage
staticconstexprprotected
Initial value:
{
&ChangeSpeedBase::m_PercentChange, L"Percentage", 0.0, -99.0, 4900.0, 1
}

Definition at line 92 of file ChangeSpeedBase.h.

Referenced by EffectChangeSpeed::Update_Slider_PercentChange(), and EffectChangeSpeed::UpdateUI().

◆ Symbol

const ComponentInterfaceSymbol ChangeSpeedBase::Symbol
static
Initial value:
{ XO(
"Change Speed and Pitch") }

Definition at line 28 of file ChangeSpeedBase.h.

Referenced by GetSymbol().


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