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
 Default implementation returns previewLength More...
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- Public Member Functions inherited from StatefulEffect
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Member Functions

static 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 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

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 Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

An Extreme Time Stretch and Time Smear effect.

Definition at line 19 of file Paulstretch.h.

Constructor & Destructor Documentation

◆ EffectPaulstretch()

EffectPaulstretch::EffectPaulstretch ( )

Definition at line 96 of file Paulstretch.cpp.

97{
98 Parameters().Reset(*this);
99
101}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:222
virtual void Reset(Effect &effect) const =0
const EffectParameterMethods & Parameters() const override
Definition: Paulstretch.cpp:36

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectPaulstretch()

EffectPaulstretch::~EffectPaulstretch ( )
virtual

Definition at line 103 of file Paulstretch.cpp.

104{
105}

Member Function Documentation

◆ CalcPreviewInputLength()

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

Default implementation returns previewLength

Reimplemented from Effect.

Definition at line 133 of file Paulstretch.cpp.

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

23{ 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:59

References mTime_resolution.

Referenced by CalcPreviewInputLength(), and ProcessOne().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString EffectPaulstretch::GetDescription ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 114 of file Paulstretch.cpp.

115{
116 return XO("Paulstretch is only for an extreme time-stretch or \"stasis\" effect");
117}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectPaulstretch::GetSymbol ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 109 of file Paulstretch.cpp.

110{
111 return Symbol;
112}
static const ComponentInterfaceSymbol Symbol
Definition: Paulstretch.h:24

References Symbol.

◆ GetType()

EffectType EffectPaulstretch::GetType ( ) const
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 126 of file Paulstretch.cpp.

127{
128 return EffectTypeProcess;
129}
@ 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 119 of file Paulstretch.cpp.

120{
121 return L"Paulstretch";
122}

◆ OnText()

void EffectPaulstretch::OnText ( wxCommandEvent &  evt)
private

Definition at line 219 of file Paulstretch.cpp.

220{
221 EnableApply(mUIParent->TransferDataFromWindow());
222}
bool EnableApply(bool enable=true)
Definition: Effect.cpp:612
wxWindow * mUIParent
Definition: Effect.h:307

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

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectPaulstretch::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 36 of file Paulstretch.cpp.

37{
40 > parameters;
41 return parameters;
42}
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Time
Definition: Paulstretch.h:67
static constexpr EffectParameter Amount
Definition: Paulstretch.h:65

References Amount, EffectPaulstretch(), and Time.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > 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 Effect::PopulateUI instead of a DefaultEffectUIValidator; default implementation returns null

Reimplemented from Effect.

Definition at line 173 of file Paulstretch.cpp.

176{
177 S.StartMultiColumn(2, wxALIGN_CENTER);
178 {
179 S
180 .Validator<FloatingPointValidator<float>>(
181 1, &mAmount, NumValidatorStyle::DEFAULT, Amount.min)
182 /* i18n-hint: This is how many times longer the sound will be, e.g. applying
183 * the effect to a 1-second sample, with the default Stretch Factor of 10.0
184 * will give an (approximately) 10 second sound
185 */
186 .AddTextBox(XXO("&Stretch Factor:"), wxT(""), 10);
187
188 S
189 .Validator<FloatingPointValidator<float>>(
190 3, &mTime_resolution, NumValidatorStyle::ONE_TRAILING_ZERO, Time.min)
191 .AddTextBox(XXO("&Time Resolution (seconds):"), L"", 10);
192 }
193 S.EndMultiColumn();
194 return nullptr;
195};
wxT("CloseDown"))
#define XXO(s)
Definition: Internat.h:44
#define S(N)
Definition: ToChars.cpp:64
const Type min
Minimum value.
Definition: Shuttle.h:30

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

Here is the call graph for this function:

◆ Process()

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

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Definition at line 147 of file Paulstretch.cpp.

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

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 ::Effect::MessageBox( 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 ::Effect::MessageBox( 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 ::Effect::MessageBox( badAllocMessage );
394 return false;
395 }
396};
FileConfig * gPrefs
Definition: Prefs.cpp:71
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
bool IsPreviewing() const
Definition: EffectBase.h:85
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
Definition: Effect.cpp:863
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:683
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:47
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:67
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1573
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:788
double GetRate() const override
Definition: WaveTrack.cpp:479
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}, bool keepLink=true) const
Definition: WaveTrack.cpp:705
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References WaveTrack::Clear(), WaveTrack::EmptyCopy(), PackedArray::end(), floatSample, PaulStretch::get_nsamples(), PaulStretch::get_nsamples_for_fill(), GetBufferSize(), SampleTrack::GetFloats(), WaveTrack::GetRate(), gPrefs, EffectBase::IsPreviewing(), m_t1, mAmount, Effect::MessageBox(), 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.

Reimplemented from Effect.

Definition at line 207 of file Paulstretch.cpp.

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

References Effect::mUIParent.

◆ TransferDataToWindow()

bool EffectPaulstretch::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Reimplemented from Effect.

Definition at line 197 of file Paulstretch.cpp.

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

References Effect::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 65 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ m_t1

double EffectPaulstretch::m_t1
private

Definition at line 60 of file Paulstretch.h.

Referenced by Process(), and ProcessOne().

◆ mAmount

float EffectPaulstretch::mAmount
private

Definition at line 58 of file Paulstretch.h.

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

◆ mTime_resolution

float EffectPaulstretch::mTime_resolution
private

Definition at line 59 of file Paulstretch.h.

Referenced by GetBufferSize(), and PopulateOrExchange().

◆ Symbol

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

Definition at line 24 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 67 of file Paulstretch.h.

Referenced by Parameters(), and PopulateOrExchange().


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