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

Public Member Functions

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

Private Member Functions

void OnText (wxCommandEvent &evt)
 
size_t GetBufferSize (double rate)
 
bool ProcessOne (WaveTrack *track, double t0, double t1, int count)
 

Private Attributes

float mAmount
 
float mTime_resolution
 
double m_t1
 

Additional Inherited Members

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

Detailed Description

An Extreme Time Stretch and Time Smear effect.

Definition at line 21 of file Paulstretch.h.

Constructor & Destructor Documentation

EffectPaulstretch::EffectPaulstretch ( )

Definition at line 87 of file Paulstretch.cpp.

88 {
89  mAmount = DEF_Amount;
90  mTime_resolution = DEF_Time;
91 
92  SetLinearEffectFlag(true);
93 }
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
float mTime_resolution
Definition: Paulstretch.h:61
EffectPaulstretch::~EffectPaulstretch ( )
virtual

Definition at line 95 of file Paulstretch.cpp.

96 {
97 }

Member Function Documentation

double EffectPaulstretch::CalcPreviewInputLength ( double  previewLength)
overridevirtual

Reimplemented from Effect.

Definition at line 151 of file Paulstretch.cpp.

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

152 {
153  // FIXME: Preview is currently at the project rate, but should really be
154  // at the track rate (bugs 1284 and 852).
155  auto minDuration = GetBufferSize(mProjectRate) * 2 + 1;
156 
157  // Preview playback may need to be trimmed but this is the smallest selection that we can use.
158  double minLength = std::max<double>(minDuration / mProjectRate, previewLength / mAmount);
159 
160  return minLength;
161 }
double mProjectRate
Definition: Effect.h:453
size_t GetBufferSize(double rate)
bool EffectPaulstretch::DefineParams ( ShuttleParams S)
override

Definition at line 124 of file Paulstretch.cpp.

References mAmount, and mTime_resolution.

124  {
125  S.SHUTTLE_PARAM( mAmount, Amount );
126  S.SHUTTLE_PARAM( mTime_resolution, Time );
127  return true;
128 }
float mTime_resolution
Definition: Paulstretch.h:61
bool EffectPaulstretch::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 130 of file Paulstretch.cpp.

References mAmount, mTime_resolution, and CommandParameters::WriteFloat().

131 {
132  parms.WriteFloat(KEY_Amount, mAmount);
133  parms.WriteFloat(KEY_Time, mTime_resolution);
134 
135  return true;
136 }
bool WriteFloat(const wxString &key, float f)
float mTime_resolution
Definition: Paulstretch.h:61
size_t EffectPaulstretch::GetBufferSize ( double  rate)
private

Definition at line 240 of file Paulstretch.cpp.

References mTime_resolution.

Referenced by CalcPreviewInputLength(), and ProcessOne().

241 {
242  // Audacity's fft requires a power of 2
243  float tmp = rate * mTime_resolution / 2.0;
244  tmp = log(tmp) / log(2.0);
245  tmp = pow(2.0, floor(tmp + 0.5));
246 
247  auto stmp = size_t(tmp);
248  if (stmp != tmp)
249  // overflow
250  return 0;
251  if (stmp >= 2 * stmp)
252  // overflow
253  return 0;
254 
255  return std::max<size_t>(stmp, 128);
256 }
float mTime_resolution
Definition: Paulstretch.h:61
wxString EffectPaulstretch::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 106 of file Paulstretch.cpp.

References _().

107 {
108  return _("Paulstretch is only for an extreme time-stretch or \"stasis\" effect");
109 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol EffectPaulstretch::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 101 of file Paulstretch.cpp.

References PAULSTRETCH_PLUGIN_SYMBOL.

102 {
104 }
#define PAULSTRETCH_PLUGIN_SYMBOL
Definition: Paulstretch.h:19
EffectType EffectPaulstretch::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 118 of file Paulstretch.cpp.

References EffectTypeProcess.

119 {
120  return EffectTypeProcess;
121 }
wxString EffectPaulstretch::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 111 of file Paulstretch.cpp.

112 {
113  return wxT("Paulstretch");
114 }
void EffectPaulstretch::OnText ( wxCommandEvent &  evt)
private

Definition at line 235 of file Paulstretch.cpp.

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

236 {
237  EnableApply(mUIParent->TransferDataFromWindow());
238 }
wxWindow * mUIParent
Definition: Effect.h:472
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
void EffectPaulstretch::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 193 of file Paulstretch.cpp.

References _(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::EndMultiColumn(), mAmount, mTime_resolution, and ShuttleGuiBase::StartMultiColumn().

194 {
195  S.StartMultiColumn(2, wxALIGN_CENTER);
196  {
197  FloatingPointValidator<float> vldAmount(1, &mAmount);
198  vldAmount.SetMin(MIN_Amount);
199 
200  /* i18n-hint: This is how many times longer the sound will be, e.g. applying
201  * the effect to a 1-second sample, with the default Stretch Factor of 10.0
202  * will give an (approximately) 10 second sound
203  */
204  S.AddTextBox(_("Stretch Factor:"), wxT(""), 10)->SetValidator(vldAmount);
205 
206  FloatingPointValidator<float> vldTime(3, &mTime_resolution, NumValidatorStyle::ONE_TRAILING_ZERO);
207  vldTime.SetMin(MIN_Time);
208  S.AddTextBox(_("Time Resolution (seconds):"), wxT(""), 10)->SetValidator(vldTime);
209  }
210  S.EndMultiColumn();
211 };
void EndMultiColumn()
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
float mTime_resolution
Definition: Paulstretch.h:61
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool EffectPaulstretch::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 164 of file Paulstretch.cpp.

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

165 {
166  CopyInputTracks();
168  WaveTrack *track = (WaveTrack *) iter.First();
169  m_t1=mT1;
170  int count=0;
171  while (track) {
172  double trackStart = track->GetStartTime();
173  double trackEnd = track->GetEndTime();
174  double t0 = mT0 < trackStart? trackStart: mT0;
175  double t1 = mT1 > trackEnd? trackEnd: mT1;
176 
177  if (t1 > t0) {
178  if (!ProcessOne(track, t0,t1,count))
179  return false;
180  }
181 
182  track = (WaveTrack *) iter.Next();
183  count++;
184  }
185  mT1=m_t1;
186 
188 
189  return true;
190 }
double mT1
Definition: Effect.h:461
void CopyInputTracks()
Definition: Effect.cpp:2036
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
bool ProcessOne(WaveTrack *track, double t0, double t1, int count)
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
double mT0
Definition: Effect.h:460
bool EffectPaulstretch::ProcessOne ( WaveTrack track,
double  t0,
double  t1,
int  count 
)
private

Definition at line 258 of file Paulstretch.cpp.

References _(), WaveTrack::Clear(), floatSample, WaveTrack::Get(), PaulStretch::get_nsamples_for_fill(), GetBufferSize(), WaveTrack::GetRate(), WaveTrack::GetSampleFormat(), gPrefs, Effect::IsPreviewing(), m_t1, mAmount, Effect::MessageBox(), Effect::mFactory, Effect::mProjectRate, Effect::mT0, TrackFactory::NewWaveTrack(), WaveTrack::Paste(), WaveTrack::TimeToLongSamples(), and Effect::TrackProgress().

Referenced by Process().

259 {
260  auto badAllocMessage = _("Requested value exceeds memory capacity.");
261 
262  const auto stretch_buf_size = GetBufferSize(track->GetRate());
263  if (stretch_buf_size == 0) {
264  ::Effect::MessageBox( badAllocMessage );
265  return false;
266  }
267 
268  double amount = this->mAmount;
269 
270  auto start = track->TimeToLongSamples(t0);
271  auto end = track->TimeToLongSamples(t1);
272  auto len = end - start;
273 
274  const auto minDuration = stretch_buf_size * 2 + 1;
275  if (minDuration < stretch_buf_size) {
276  // overflow!
277  ::Effect::MessageBox( badAllocMessage );
278  return false;
279  }
280 
281  if (len < minDuration) { //error because the selection is too short
282 
283  float maxTimeRes = log( len.as_double() ) / log(2.0);
284  maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5);
285  maxTimeRes = maxTimeRes / track->GetRate();
286 
287  if (this->IsPreviewing()) {
288  double defaultPreviewLen;
289  gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &defaultPreviewLen, 6.0);
290 
291  /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
292  if ((minDuration / mProjectRate) < defaultPreviewLen) {
293  ::Effect::MessageBox (wxString::Format(_("Audio selection too short to preview.\n\n"
294  "Try increasing the audio selection to at least %.1f seconds,\n"
295  "or reducing the 'Time Resolution' to less than %.1f seconds."),
296  (minDuration / track->GetRate()) + 0.05, // round up to 1/10 s.
297  floor(maxTimeRes * 10.0) / 10.0),
298  wxOK | wxICON_EXCLAMATION);
299  }
300  else {
301  /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
302  ::Effect::MessageBox (wxString::Format(_("Unable to Preview.\n\n"
303  "For the current audio selection, the maximum\n"
304  "'Time Resolution' is %.1f seconds."),
305  floor(maxTimeRes * 10.0) / 10.0),
306  wxOK | wxICON_EXCLAMATION);
307  }
308  }
309  else {
310  /* i18n-hint: 'Time Resolution' is the name of a control in the Paulstretch effect.*/
311  ::Effect::MessageBox (wxString::Format(_("The 'Time Resolution' is too long for the selection.\n\n"
312  "Try increasing the audio selection to at least %.1f seconds,\n"
313  "or reducing the 'Time Resolution' to less than %.1f seconds."),
314  (minDuration / track->GetRate()) + 0.05, // round up to 1/10 s.
315  floor(maxTimeRes * 10.0) / 10.0),
316  wxOK | wxICON_EXCLAMATION);
317  }
318 
319  return false;
320  }
321 
322 
323  auto dlen = len.as_double();
324  double adjust_amount = dlen /
325  (dlen - ((double)stretch_buf_size * 2.0));
326  amount = 1.0 + (amount - 1.0) * adjust_amount;
327 
328  auto outputTrack = mFactory->NewWaveTrack(track->GetSampleFormat(),track->GetRate());
329 
330  try {
331  // This encloses all the allocations of buffers, including those in
332  // the constructor of the PaulStretch object
333 
334  PaulStretch stretch(amount, stretch_buf_size, track->GetRate());
335 
336  auto nget = stretch.get_nsamples_for_fill();
337 
338  auto bufsize = stretch.poolsize;
339  Floats buffer0{ bufsize };
340  float *bufferptr0 = buffer0.get();
341  bool first_time = true;
342 
343  const auto fade_len = std::min<size_t>(100, bufsize / 2 - 1);
344  bool cancelled = false;
345 
346  {
347  Floats fade_track_smps{ fade_len };
348  decltype(len) s=0;
349 
350  while (s < len) {
351  track->Get((samplePtr)bufferptr0, floatSample, start + s, nget);
352  stretch.process(buffer0.get(), nget);
353 
354  if (first_time) {
355  stretch.process(buffer0.get(), 0);
356  };
357 
358  s += nget;
359 
360  if (first_time){//blend the the start of the selection
361  track->Get((samplePtr)fade_track_smps.get(), floatSample, start, fade_len);
362  first_time = false;
363  for (size_t i = 0; i < fade_len; i++){
364  float fi = (float)i / (float)fade_len;
365  stretch.out_buf[i] =
366  stretch.out_buf[i] * fi + (1.0 - fi) * fade_track_smps[i];
367  }
368  }
369  if (s >= len){//blend the end of the selection
370  track->Get((samplePtr)fade_track_smps.get(), floatSample, end - fade_len, fade_len);
371  for (size_t i = 0; i < fade_len; i++){
372  float fi = (float)i / (float)fade_len;
373  auto i2 = bufsize / 2 - 1 - i;
374  stretch.out_buf[i2] =
375  stretch.out_buf[i2] * fi + (1.0 - fi) *
376  fade_track_smps[fade_len - 1 - i];
377  }
378  }
379 
380  outputTrack->Append((samplePtr)stretch.out_buf.get(), floatSample, stretch.out_bufsize);
381 
382  nget = stretch.get_nsamples();
383  if (TrackProgress(count,
384  s.as_double() / len.as_double()
385  )) {
386  cancelled = true;
387  break;
388  }
389  }
390  }
391 
392  if (!cancelled){
393  outputTrack->Flush();
394 
395  track->Clear(t0,t1);
396  track->Paste(t0, outputTrack.get());
397  m_t1 = mT0 + outputTrack->GetEndTime();
398  }
399 
400  return !cancelled;
401  }
402  catch ( const std::bad_alloc& ) {
403  ::Effect::MessageBox( badAllocMessage );
404  return false;
405  }
406 };
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
bool IsPreviewing()
Definition: Effect.h:361
void Clear(double t0, double t1) override
Definition: WaveTrack.cpp:678
char * samplePtr
Definition: Types.h:203
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1192
std::unique_ptr< WaveTrack > NewWaveTrack(sampleFormat format=(sampleFormat) 0, double rate=0)
Definition: WaveTrack.cpp:78
double mProjectRate
Definition: Effect.h:453
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
TrackFactory * mFactory
Definition: Effect.h:457
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
sampleFormat GetSampleFormat() const
Definition: WaveTrack.h:146
size_t GetBufferSize(double rate)
double GetRate() const
Definition: WaveTrack.cpp:398
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
double mT0
Definition: Effect.h:460
size_t get_nsamples_for_fill()
bool EffectPaulstretch::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 138 of file Paulstretch.cpp.

References mAmount, mTime_resolution, and ReadAndVerifyFloat.

139 {
140  ReadAndVerifyFloat(Amount);
141  ReadAndVerifyFloat(Time);
142 
143  mAmount = Amount;
144  mTime_resolution = Time;
145 
146  return true;
147 }
#define ReadAndVerifyFloat(name)
Definition: Effect.h:799
float mTime_resolution
Definition: Paulstretch.h:61
bool EffectPaulstretch::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 223 of file Paulstretch.cpp.

References Effect::mUIParent.

224 {
225  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
226  {
227  return false;
228  }
229 
230  return true;
231 }
wxWindow * mUIParent
Definition: Effect.h:472
bool EffectPaulstretch::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 213 of file Paulstretch.cpp.

References Effect::mUIParent.

214 {
215  if (!mUIParent->TransferDataToWindow())
216  {
217  return false;
218  }
219 
220  return true;
221 }
wxWindow * mUIParent
Definition: Effect.h:472

Member Data Documentation

double EffectPaulstretch::m_t1
private

Definition at line 62 of file Paulstretch.h.

Referenced by Process(), and ProcessOne().

float EffectPaulstretch::mAmount
private
float EffectPaulstretch::mTime_resolution
private

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