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

An Extreme Time Stretch and Time Smear effect. More...

#include <Paulstretch.h>

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

Public Member Functions

 EffectPaulstretch ()
 
virtual ~EffectPaulstretch ()
 
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...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 
std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 
bool TransferDataFromWindow (EffectSettings &settings) override
 
- 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)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

Static Public Member Functions

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

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Paulstretch") }
 
- 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 Member Functions

void OnText (wxCommandEvent &evt)
 
size_t GetBufferSize (double rate) const
 
bool ProcessOne (const WaveChannel &track, WaveChannel &outputTrack, double t0, double t1, int count)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent
 
float mAmount
 
float mTime_resolution
 

Static Private Attributes

static constexpr EffectParameter Amount
 
static constexpr EffectParameter Time
 

Additional Inherited Members

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

Detailed Description

An Extreme Time Stretch and Time Smear effect.

Definition at line 21 of file Paulstretch.h.

Constructor & Destructor Documentation

◆ EffectPaulstretch()

EffectPaulstretch::EffectPaulstretch ( )

Definition at line 97 of file Paulstretch.cpp.

98{
99 Parameters().Reset(*this);
100
102}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:210
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override
Definition: Paulstretch.cpp:37

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectPaulstretch()

EffectPaulstretch::~EffectPaulstretch ( )
virtual

Definition at line 104 of file Paulstretch.cpp.

105{
106}

Member Function Documentation

◆ CalcPreviewInputLength()

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

Implements EffectBase.

Definition at line 134 of file Paulstretch.cpp.

136{
137 // FIXME: Preview is currently at the project rate, but should really be
138 // at the track rate (bugs 1284 and 852).
139 auto minDuration = GetBufferSize(mProjectRate) * 2 + 1;
140
141 // Preview playback may need to be trimmed but this is the smallest selection that we can use.
142 double minLength = std::max<double>(minDuration / mProjectRate, previewLength / mAmount);
143
144 return minLength;
145}
double mProjectRate
Definition: EffectBase.h:110
size_t GetBufferSize(double rate) const

References GetBufferSize(), mAmount, and EffectBase::mProjectRate.

Here is the call graph for this function:

◆ FetchParameters()

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

Definition at line 25 of file Paulstretch.h.

25{ return &e; }

◆ GetBufferSize()

size_t EffectPaulstretch::GetBufferSize ( double  rate) const
private

Definition at line 251 of file Paulstretch.cpp.

252{
253 // Audacity's fft requires a power of 2
254 float tmp = rate * mTime_resolution / 2.0;
255 tmp = log(tmp) / log(2.0);
256 tmp = pow(2.0, floor(tmp + 0.5));
257
258 auto stmp = size_t(tmp);
259 if (stmp != tmp)
260 // overflow
261 return 0;
262 if (stmp >= 2 * stmp)
263 // overflow
264 return 0;
265
266 return std::max<size_t>(stmp, 128);
267}
float mTime_resolution
Definition: Paulstretch.h:64

References mTime_resolution.

Referenced by CalcPreviewInputLength(), and ProcessOne().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString EffectPaulstretch::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 115 of file Paulstretch.cpp.

116{
117 return XO("Paulstretch is only for an extreme time-stretch or \"stasis\" effect");
118}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectPaulstretch::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 110 of file Paulstretch.cpp.

111{
112 return Symbol;
113}
static const ComponentInterfaceSymbol Symbol
Definition: Paulstretch.h:26

References Symbol.

◆ GetType()

EffectType EffectPaulstretch::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 127 of file Paulstretch.cpp.

128{
129 return EffectTypeProcess;
130}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ ManualPage()

ManualPageID EffectPaulstretch::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 120 of file Paulstretch.cpp.

121{
122 return L"Paulstretch";
123}

◆ OnText()

void EffectPaulstretch::OnText ( wxCommandEvent &  evt)
private

Definition at line 245 of file Paulstretch.cpp.

246{
248 mUIParent, mUIParent->TransferDataFromWindow());
249}
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
wxWeakRef< wxWindow > mUIParent
Definition: Paulstretch.h:61

References EffectEditor::EnableApply(), and mUIParent.

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectPaulstretch::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 37 of file Paulstretch.cpp.

38{
41 > parameters;
42 return parameters;
43}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Time
Definition: Paulstretch.h:71
static constexpr EffectParameter Amount
Definition: Paulstretch.h:69

References Amount, EffectPaulstretch(), and Time.

Here is the call graph for this function:

◆ PopulateOrExchange()

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

Add controls to effect panel; always succeeds.

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

Reimplemented from StatefulEffectUIServices.

Definition at line 198 of file Paulstretch.cpp.

201{
202 mUIParent = S.GetParent();
203 S.StartMultiColumn(2, wxALIGN_CENTER);
204 {
205 S
206 .Validator<FloatingPointValidator<float>>(
207 1, &mAmount, NumValidatorStyle::DEFAULT, Amount.min)
208 /* i18n-hint: This is how many times longer the sound will be, e.g. applying
209 * the effect to a 1-second sample, with the default Stretch Factor of 10.0
210 * will give an (approximately) 10 second sound
211 */
212 .AddTextBox(XXO("&Stretch Factor:"), wxT(""), 10);
213
214 S
215 .Validator<FloatingPointValidator<float>>(
216 3, &mTime_resolution, NumValidatorStyle::ONE_TRAILING_ZERO, Time.min)
217 .AddTextBox(XXO("&Time Resolution (seconds):"), L"", 10);
218 }
219 S.EndMultiColumn();
220 return nullptr;
221};
wxT("CloseDown"))
XXO("&Cut/Copy/Paste Toolbar")
#define S(N)
Definition: ToChars.cpp:64
const Type min
Minimum value.

References Amount, mAmount, EffectParameter< Structure, Member, Type, Value >::min, mTime_resolution, mUIParent, S, Time, wxT(), and XXO().

Here is the call graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 148 of file Paulstretch.cpp.

149{
150 // Pass true because sync lock adjustment is needed
151 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } }, true };
152 auto newT1 = mT1;
153 int count = 0;
154 // Process selected wave tracks first, to find the new t1 value
155 for (const auto track : outputs.Get().Selected<WaveTrack>()) {
156 double trackStart = track->GetStartTime();
157 double trackEnd = track->GetEndTime();
158 double t0 = mT0 < trackStart ? trackStart : mT0;
159 double t1 = mT1 > trackEnd ? trackEnd : mT1;
160 if (t1 > t0) {
161 auto tempTrack = track->EmptyCopy();
162 const auto channels = track->Channels();
163 auto iter = tempTrack->Channels().begin();
164 for (const auto pChannel : channels) {
165 if (!ProcessOne(*pChannel, **iter++, t0, t1, count++))
166 return false;
167 }
168 tempTrack->Flush();
169 newT1 = std::max(newT1, mT0 + tempTrack->GetEndTime());
170 PasteTimeWarper warper { t1, t0 + tempTrack->GetEndTime() };
171 constexpr auto preserve = false;
172 constexpr auto merge = true;
173 track->ClearAndPaste(t0, t1, *tempTrack, preserve, merge, &warper);
174 }
175 else
176 count += track->NChannels();
177 }
178
179 // Sync lock adjustment of other tracks
180 outputs.Get().Any().Visit(
181 [&](auto &&fallthrough){ return [&](WaveTrack &track) {
182 if (!track.IsSelected())
183 fallthrough();
184 }; },
185 [&](Track &track) {
187 track.SyncLockAdjust(mT1, newT1);
188 }
189 );
190 mT1 = newT1;
191
192 outputs.Commit();
193
194 return true;
195}
double mT1
Definition: EffectBase.h:114
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:113
Use this object to copy the input tracks to tentative outputTracks.
bool ProcessOne(const WaveChannel &track, WaveChannel &outputTrack, double t0, double t1, int count)
EffectType GetType() const override
Type determines how it behaves.
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
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

References GetType(), SyncLock::IsSyncLockSelected(), EffectBase::mT0, EffectBase::mT1, EffectBase::mTracks, and ProcessOne().

Here is the call graph for this function:

◆ ProcessOne()

bool EffectPaulstretch::ProcessOne ( const WaveChannel track,
WaveChannel outputTrack,
double  t0,
double  t1,
int  count 
)
private

Definition at line 269 of file Paulstretch.cpp.

271{
272 const auto badAllocMessage =
273 XO("Requested value exceeds memory capacity.");
274
275 const auto rate = track.GetTrack().GetRate();
276 const auto stretch_buf_size = GetBufferSize(rate);
277 if (stretch_buf_size == 0) {
278 EffectUIServices::DoMessageBox(*this, badAllocMessage);
279 return {};
280 }
281
282 double amount = this->mAmount;
283
284 auto start = track.TimeToLongSamples(t0);
285 auto end = track.TimeToLongSamples(t1);
286 auto len = end - start;
287
288 const auto minDuration = stretch_buf_size * 2 + 1;
289 if (minDuration < stretch_buf_size) {
290 // overflow!
291 EffectUIServices::DoMessageBox(*this, badAllocMessage);
292 return {};
293 }
294
295 if (len < minDuration) { //error because the selection is too short
296
297 float maxTimeRes = log( len.as_double() ) / log(2.0);
298 maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5);
299 maxTimeRes = maxTimeRes / rate;
300
301 if (this->IsPreviewing()) {
302 double defaultPreviewLen;
303 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &defaultPreviewLen, 6.0);
304
305 if ((minDuration / mProjectRate) < defaultPreviewLen) {
307 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
308 XO("Audio selection too short to preview.\n\n"
309 "Try increasing the audio selection to at least %.1f seconds,\n"
310 "or reducing the 'Time Resolution' to less than %.1f seconds.")
311 .Format(
312 (minDuration / rate) + 0.05, // round up to 1/10 s.
313 floor(maxTimeRes * 10.0) / 10.0),
314 wxOK | wxICON_EXCLAMATION );
315 }
316 else {
318 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
319 XO("Unable to Preview.\n\n"
320 "For the current audio selection, the maximum\n"
321 "'Time Resolution' is %.1f seconds.")
322 .Format( floor(maxTimeRes * 10.0) / 10.0 ),
323 wxOK | wxICON_EXCLAMATION );
324 }
325 }
326 else {
328 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
329 XO("The 'Time Resolution' is too long for the selection.\n\n"
330 "Try increasing the audio selection to at least %.1f seconds,\n"
331 "or reducing the 'Time Resolution' to less than %.1f seconds.")
332 .Format(
333 (minDuration / rate) + 0.05, // round up to 1/10 s.
334 floor(maxTimeRes * 10.0) / 10.0),
335 wxOK | wxICON_EXCLAMATION );
336 }
337
338 return {};
339 }
340
341 auto dlen = len.as_double();
342 double adjust_amount = dlen /
343 (dlen - ((double)stretch_buf_size * 2.0));
344 amount = 1.0 + (amount - 1.0) * adjust_amount;
345
346 try {
347 // This encloses all the allocations of buffers, including those in
348 // the constructor of the PaulStretch object
349
350 PaulStretch stretch(amount, stretch_buf_size, rate);
351
352 auto nget = stretch.get_nsamples_for_fill();
353
354 auto bufsize = stretch.poolsize;
355 Floats buffer0{ bufsize };
356 float *bufferptr0 = buffer0.get();
357 bool first_time = true;
358
359 const auto fade_len = std::min<size_t>(100, bufsize / 2 - 1);
360 bool cancelled = false;
361
362 {
363 Floats fade_track_smps{ fade_len };
364 decltype(len) s=0;
365
366 while (s < len) {
367 track.GetFloats(bufferptr0, start + s, nget);
368 stretch.process(buffer0.get(), nget);
369
370 if (first_time) {
371 stretch.process(buffer0.get(), 0);
372 };
373
374 s += nget;
375
376 if (first_time){//blend the start of the selection
377 track.GetFloats(fade_track_smps.get(), start, fade_len);
378 first_time = false;
379 for (size_t i = 0; i < fade_len; i++){
380 float fi = (float)i / (float)fade_len;
381 stretch.out_buf[i] =
382 stretch.out_buf[i] * fi + (1.0 - fi) * fade_track_smps[i];
383 }
384 }
385 if (s >= len){//blend the end of the selection
386 track.GetFloats(fade_track_smps.get(), end - fade_len, fade_len);
387 for (size_t i = 0; i < fade_len; i++){
388 float fi = (float)i / (float)fade_len;
389 auto i2 = bufsize / 2 - 1 - i;
390 stretch.out_buf[i2] =
391 stretch.out_buf[i2] * fi + (1.0 - fi) *
392 fade_track_smps[fade_len - 1 - i];
393 }
394 }
395
396 outputTrack.Append((samplePtr)stretch.out_buf.get(), floatSample, stretch.out_bufsize);
397
398 nget = stretch.get_nsamples();
399 if (TrackProgress(count,
400 s.as_double() / len.as_double()
401 )) {
402 cancelled = true;
403 break;
404 }
405 }
406 }
407
408 if (!cancelled)
409 return true;
410 }
411 catch ( const std::bad_alloc& ) {
412 EffectUIServices::DoMessageBox(*this, badAllocMessage);
413 }
414 return false;
415};
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
char * samplePtr
Definition: SampleFormat.h:57
bool IsPreviewing() const
Definition: EffectBase.h:89
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:343
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Abstract base class used in importing a file.
Class that helps EffectPaulStretch. It does the FFTs and inner loop of the effect.
Definition: Paulstretch.cpp:48
WaveTrack & GetTrack()
Definition: WaveTrack.h:840
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2216
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
double GetRate() const override
Definition: WaveTrack.cpp:798
sampleCount TimeToLongSamples(double t0) const
virtual bool Read(const wxString &key, bool *value) const =0
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References WaveChannel::Append(), EffectUIServices::DoMessageBox(), details::end(), floatSample, PaulStretch::get_nsamples(), PaulStretch::get_nsamples_for_fill(), GetBufferSize(), WaveChannel::GetFloats(), WaveTrack::GetRate(), WaveChannel::GetTrack(), gPrefs, EffectBase::IsPreviewing(), mAmount, EffectBase::mProjectRate, PaulStretch::out_buf, PaulStretch::out_bufsize, PaulStretch::poolsize, PaulStretch::process(), audacity::BasicSettings::Read(), WideSampleSequence::TimeToLongSamples(), Effect::TrackProgress(), wxT(), and XO().

Referenced by Process().

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

◆ TransferDataFromWindow()

bool EffectPaulstretch::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

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

Reimplemented from StatefulEffectUIServices.

Definition at line 233 of file Paulstretch.cpp.

234{
235 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
236 {
237 return false;
238 }
239
240 return true;
241}

References mUIParent.

◆ TransferDataToWindow()

bool EffectPaulstretch::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

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

Reimplemented from StatefulEffectUIServices.

Definition at line 223 of file Paulstretch.cpp.

224{
225 if (!mUIParent->TransferDataToWindow())
226 {
227 return false;
228 }
229
230 return true;
231}

References mUIParent.

Member Data Documentation

◆ Amount

constexpr EffectParameter EffectPaulstretch::Amount
staticconstexprprivate
Initial value:
L"Stretch Factor", 10.0f, 1.0, FLT_MAX, 1 }

Definition at line 69 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ mAmount

float EffectPaulstretch::mAmount
private

Definition at line 63 of file Paulstretch.h.

Referenced by CalcPreviewInputLength(), PopulateOrExchange(), and ProcessOne().

◆ mTime_resolution

float EffectPaulstretch::mTime_resolution
private

Definition at line 64 of file Paulstretch.h.

Referenced by GetBufferSize(), and PopulateOrExchange().

◆ mUIParent

wxWeakRef<wxWindow> EffectPaulstretch::mUIParent
private

◆ Symbol

const ComponentInterfaceSymbol EffectPaulstretch::Symbol { XO("Paulstretch") }
static

Definition at line 26 of file Paulstretch.h.

Referenced by GetSymbol().

◆ Time

constexpr EffectParameter EffectPaulstretch::Time
staticconstexprprivate
Initial value:
L"Time Resolution", 0.25f, 0.00099f, FLT_MAX, 1 }

Definition at line 71 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().


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