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
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
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 NumericFormatSymbol 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)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
- 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 void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly)=0
 Calculate temporary tracks of limited length with effect applied and play. More...
 
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 (EffectPlugin &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 void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public 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 (WaveTrack *track, double t0, double t1, int count)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

wxWeakRef< wxWindow > mUIParent
 
float mAmount
 
float mTime_resolution
 
double m_t1
 

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
TrackListmTracks {}
 
- 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, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly) final
 Calculate temporary tracks of limited length with effect applied and play. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

An Extreme Time Stretch and Time Smear effect.

Definition at line 20 of file Paulstretch.h.

Constructor & Destructor Documentation

◆ EffectPaulstretch()

EffectPaulstretch::EffectPaulstretch ( )

Definition at line 94 of file Paulstretch.cpp.

95{
96 Parameters().Reset(*this);
97
99}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:214
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override
Definition: Paulstretch.cpp:34

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectPaulstretch()

EffectPaulstretch::~EffectPaulstretch ( )
virtual

Definition at line 101 of file Paulstretch.cpp.

102{
103}

Member Function Documentation

◆ CalcPreviewInputLength()

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

Implements EffectBase.

Definition at line 131 of file Paulstretch.cpp.

133{
134 // FIXME: Preview is currently at the project rate, but should really be
135 // at the track rate (bugs 1284 and 852).
136 auto minDuration = GetBufferSize(mProjectRate) * 2 + 1;
137
138 // Preview playback may need to be trimmed but this is the smallest selection that we can use.
139 double minLength = std::max<double>(minDuration / mProjectRate, previewLength / mAmount);
140
141 return minLength;
142}
double mProjectRate
Definition: EffectBase.h:105
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 24 of file Paulstretch.h.

24{ return &e; }

◆ GetBufferSize()

size_t EffectPaulstretch::GetBufferSize ( double  rate) const
private

Definition at line 224 of file Paulstretch.cpp.

225{
226 // Audacity's fft requires a power of 2
227 float tmp = rate * mTime_resolution / 2.0;
228 tmp = log(tmp) / log(2.0);
229 tmp = pow(2.0, floor(tmp + 0.5));
230
231 auto stmp = size_t(tmp);
232 if (stmp != tmp)
233 // overflow
234 return 0;
235 if (stmp >= 2 * stmp)
236 // overflow
237 return 0;
238
239 return std::max<size_t>(stmp, 128);
240}
float mTime_resolution
Definition: Paulstretch.h:62

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 112 of file Paulstretch.cpp.

113{
114 return XO("Paulstretch is only for an extreme time-stretch or \"stasis\" effect");
115}
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 107 of file Paulstretch.cpp.

108{
109 return Symbol;
110}
static const ComponentInterfaceSymbol Symbol
Definition: Paulstretch.h:25

References Symbol.

◆ GetType()

EffectType EffectPaulstretch::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 124 of file Paulstretch.cpp.

125{
126 return EffectTypeProcess;
127}
@ EffectTypeProcess

References EffectTypeProcess.

◆ ManualPage()

ManualPageID EffectPaulstretch::ManualPage ( ) const
overridevirtual

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

Reimplemented from EffectDefinitionInterface.

Definition at line 117 of file Paulstretch.cpp.

118{
119 return L"Paulstretch";
120}

◆ OnText()

void EffectPaulstretch::OnText ( wxCommandEvent &  evt)
private

Definition at line 218 of file Paulstretch.cpp.

219{
221 mUIParent, mUIParent->TransferDataFromWindow());
222}
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:59

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 34 of file Paulstretch.cpp.

35{
38 > parameters;
39 return parameters;
40}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Time
Definition: Paulstretch.h:70
static constexpr EffectParameter Amount
Definition: Paulstretch.h:68

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 171 of file Paulstretch.cpp.

174{
175 mUIParent = S.GetParent();
176 S.StartMultiColumn(2, wxALIGN_CENTER);
177 {
178 S
179 .Validator<FloatingPointValidator<float>>(
180 1, &mAmount, NumValidatorStyle::DEFAULT, Amount.min)
181 /* i18n-hint: This is how many times longer the sound will be, e.g. applying
182 * the effect to a 1-second sample, with the default Stretch Factor of 10.0
183 * will give an (approximately) 10 second sound
184 */
185 .AddTextBox(XXO("&Stretch Factor:"), wxT(""), 10);
186
187 S
188 .Validator<FloatingPointValidator<float>>(
189 3, &mTime_resolution, NumValidatorStyle::ONE_TRAILING_ZERO, Time.min)
190 .AddTextBox(XXO("&Time Resolution (seconds):"), L"", 10);
191 }
192 S.EndMultiColumn();
193 return nullptr;
194};
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 145 of file Paulstretch.cpp.

146{
148 m_t1=mT1;
149 int count=0;
150 for( auto track : mOutputTracks->Selected< WaveTrack >() ) {
151 double trackStart = track->GetStartTime();
152 double trackEnd = track->GetEndTime();
153 double t0 = mT0 < trackStart? trackStart: mT0;
154 double t1 = mT1 > trackEnd? trackEnd: mT1;
155
156 if (t1 > t0) {
157 if (!ProcessOne(track, t0,t1,count))
158 return false;
159 }
160
161 count++;
162 }
163 mT1=m_t1;
164
166
167 return true;
168}
double mT1
Definition: EffectBase.h:113
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:111
double mT0
Definition: EffectBase.h:112
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:232
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:396
bool ProcessOne(WaveTrack *track, double t0, double t1, int count)
A Track that contains audio waveform data.
Definition: WaveTrack.h:51

References Effect::CopyInputTracks(), m_t1, EffectBase::mOutputTracks, EffectBase::mT0, EffectBase::mT1, ProcessOne(), and EffectBase::ReplaceProcessedTracks().

Here is the call graph for this function:

◆ ProcessOne()

bool EffectPaulstretch::ProcessOne ( WaveTrack track,
double  t0,
double  t1,
int  count 
)
private

Definition at line 242 of file Paulstretch.cpp.

243{
244 const auto badAllocMessage =
245 XO("Requested value exceeds memory capacity.");
246
247 const auto stretch_buf_size = GetBufferSize(track->GetRate());
248 if (stretch_buf_size == 0) {
249 EffectUIServices::DoMessageBox(*this, badAllocMessage);
250 return false;
251 }
252
253 double amount = this->mAmount;
254
255 auto start = track->TimeToLongSamples(t0);
256 auto end = track->TimeToLongSamples(t1);
257 auto len = end - start;
258
259 const auto minDuration = stretch_buf_size * 2 + 1;
260 if (minDuration < stretch_buf_size) {
261 // overflow!
262 EffectUIServices::DoMessageBox(*this, badAllocMessage);
263 return false;
264 }
265
266 if (len < minDuration) { //error because the selection is too short
267
268 float maxTimeRes = log( len.as_double() ) / log(2.0);
269 maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5);
270 maxTimeRes = maxTimeRes / track->GetRate();
271
272 if (this->IsPreviewing()) {
273 double defaultPreviewLen;
274 gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &defaultPreviewLen, 6.0);
275
276 if ((minDuration / mProjectRate) < defaultPreviewLen) {
278 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
279 XO("Audio selection too short to preview.\n\n"
280 "Try increasing the audio selection to at least %.1f seconds,\n"
281 "or reducing the 'Time Resolution' to less than %.1f seconds.")
282 .Format(
283 (minDuration / track->GetRate()) + 0.05, // round up to 1/10 s.
284 floor(maxTimeRes * 10.0) / 10.0),
285 wxOK | wxICON_EXCLAMATION );
286 }
287 else {
289 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
290 XO("Unable to Preview.\n\n"
291 "For the current audio selection, the maximum\n"
292 "'Time Resolution' is %.1f seconds.")
293 .Format( floor(maxTimeRes * 10.0) / 10.0 ),
294 wxOK | wxICON_EXCLAMATION );
295 }
296 }
297 else {
299 /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
300 XO("The 'Time Resolution' is too long for the selection.\n\n"
301 "Try increasing the audio selection to at least %.1f seconds,\n"
302 "or reducing the 'Time Resolution' to less than %.1f seconds.")
303 .Format(
304 (minDuration / track->GetRate()) + 0.05, // round up to 1/10 s.
305 floor(maxTimeRes * 10.0) / 10.0),
306 wxOK | wxICON_EXCLAMATION );
307 }
308
309 return false;
310 }
311
312
313 auto dlen = len.as_double();
314 double adjust_amount = dlen /
315 (dlen - ((double)stretch_buf_size * 2.0));
316 amount = 1.0 + (amount - 1.0) * adjust_amount;
317
318 auto outputTrack = track->EmptyCopy();
319
320 try {
321 // This encloses all the allocations of buffers, including those in
322 // the constructor of the PaulStretch object
323
324 PaulStretch stretch(amount, stretch_buf_size, track->GetRate());
325
326 auto nget = stretch.get_nsamples_for_fill();
327
328 auto bufsize = stretch.poolsize;
329 Floats buffer0{ bufsize };
330 float *bufferptr0 = buffer0.get();
331 bool first_time = true;
332
333 const auto fade_len = std::min<size_t>(100, bufsize / 2 - 1);
334 bool cancelled = false;
335
336 {
337 Floats fade_track_smps{ fade_len };
338 decltype(len) s=0;
339
340 while (s < len) {
341 track->GetFloats(bufferptr0, start + s, nget);
342 stretch.process(buffer0.get(), nget);
343
344 if (first_time) {
345 stretch.process(buffer0.get(), 0);
346 };
347
348 s += nget;
349
350 if (first_time){//blend the start of the selection
351 track->GetFloats(fade_track_smps.get(), start, fade_len);
352 first_time = false;
353 for (size_t i = 0; i < fade_len; i++){
354 float fi = (float)i / (float)fade_len;
355 stretch.out_buf[i] =
356 stretch.out_buf[i] * fi + (1.0 - fi) * fade_track_smps[i];
357 }
358 }
359 if (s >= len){//blend the end of the selection
360 track->GetFloats(fade_track_smps.get(), end - fade_len, fade_len);
361 for (size_t i = 0; i < fade_len; i++){
362 float fi = (float)i / (float)fade_len;
363 auto i2 = bufsize / 2 - 1 - i;
364 stretch.out_buf[i2] =
365 stretch.out_buf[i2] * fi + (1.0 - fi) *
366 fade_track_smps[fade_len - 1 - i];
367 }
368 }
369
370 outputTrack->Append((samplePtr)stretch.out_buf.get(), floatSample, stretch.out_bufsize);
371
372 nget = stretch.get_nsamples();
373 if (TrackProgress(count,
374 s.as_double() / len.as_double()
375 )) {
376 cancelled = true;
377 break;
378 }
379 }
380 }
381
382 if (!cancelled){
383 outputTrack->Flush();
384
385 track->Clear(t0,t1);
386 track->Paste(t0, outputTrack.get());
387 m_t1 = mT0 + outputTrack->GetEndTime();
388 }
389
390 return !cancelled;
391 }
392 catch ( const std::bad_alloc& ) {
393 EffectUIServices::DoMessageBox(*this, badAllocMessage);
394 return false;
395 }
396};
FileConfig * gPrefs
Definition: Prefs.cpp:70
char * samplePtr
Definition: SampleFormat.h:55
bool IsPreviewing() const
Definition: EffectBase.h:89
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:346
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:45
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:82
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1367
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:652
double GetRate() const override
Definition: WaveTrack.cpp:360
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}, bool keepLink=true) const
Definition: WaveTrack.cpp:574
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References WaveTrack::Clear(), EffectUIServices::DoMessageBox(), WaveTrack::EmptyCopy(), PackedArray::end(), floatSample, PaulStretch::get_nsamples(), PaulStretch::get_nsamples_for_fill(), GetBufferSize(), SampleTrack::GetFloats(), WaveTrack::GetRate(), gPrefs, EffectBase::IsPreviewing(), m_t1, mAmount, EffectBase::mProjectRate, EffectBase::mT0, PaulStretch::out_buf, PaulStretch::out_bufsize, WaveTrack::Paste(), PaulStretch::poolsize, PaulStretch::process(), SampleTrack::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 206 of file Paulstretch.cpp.

207{
208 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
209 {
210 return false;
211 }
212
213 return true;
214}

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 196 of file Paulstretch.cpp.

197{
198 if (!mUIParent->TransferDataToWindow())
199 {
200 return false;
201 }
202
203 return true;
204}

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 68 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ m_t1

double EffectPaulstretch::m_t1
private

Definition at line 63 of file Paulstretch.h.

Referenced by Process(), and ProcessOne().

◆ mAmount

float EffectPaulstretch::mAmount
private

Definition at line 61 of file Paulstretch.h.

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

◆ mTime_resolution

float EffectPaulstretch::mTime_resolution
private

Definition at line 62 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 25 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 70 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().


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