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

#include <SBSMSEffect.h>

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

Public Member Functions

bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
void setParameters (double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
 
void setParameters (double tempoRatio, double pitchRatio)
 
- 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, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 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
 
- 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...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
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...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) 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
 
void 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
 
bool 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
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=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 void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=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 void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool 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...
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. 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...
 
- 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 double getInvertedStretchedTime (double rateStart, double rateEnd, SlideType slideType, double outputTime)
 
static double getRate (double rateStart, double rateEnd, SlideType slideType, double t)
 
- 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...
 

Protected Member Functions

ComponentInterfaceSymbol GetSymbol () const override
 
- 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)
 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
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 

Protected Attributes

TranslatableString mProxyEffectName { XO("SBSMS Time / Pitch Stretch") }
 
- 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 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 

Private Member Functions

bool ProcessLabelTrack (LabelTrack *track)
 
void Finalize (WaveTrack *orig, WaveTrack *out, const TimeWarper *warper)
 

Private Attributes

double rateStart
 
double rateEnd
 
double pitchStart
 
double pitchEnd
 
bool bLinkRatePitch
 
bool bRateReferenceInput
 
bool bPitchReferenceInput
 
SlideType rateSlideType
 
SlideType pitchSlideType
 
int mCurTrackNum
 
double mCurT0
 
double mCurT1
 
float mTotalStretch
 

Friends

class EffectChangeTempo
 
class EffectChangePitch
 

Additional Inherited Members

- 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...
 
- 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>")
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

Definition at line 29 of file SBSMSEffect.h.

Member Function Documentation

◆ Finalize()

void EffectSBSMS::Finalize ( WaveTrack orig,
WaveTrack out,
const TimeWarper warper 
)
private

Definition at line 432 of file SBSMSEffect.cpp.

433{
434 // Silenced samples will be inserted in gaps between clips, so capture where these
435 // gaps are for later deletion
436 std::vector<std::pair<double, double>> gaps;
437 double last = mCurT0;
438 auto clips = orig->SortedClipArray();
439 auto front = clips.front();
440 auto back = clips.back();
441 for (auto &clip : clips) {
442 auto st = clip->GetPlayStartTime();
443 auto et = clip->GetPlayEndTime();
444
445 if (st >= mCurT0 || et < mCurT1) {
446 if (mCurT0 < st && clip == front) {
447 gaps.push_back(std::make_pair(mCurT0, st));
448 }
449 else if (last < st && mCurT0 <= last ) {
450 gaps.push_back(std::make_pair(last, st));
451 }
452
453 if (et < mCurT1 && clip == back) {
454 gaps.push_back(std::make_pair(et, mCurT1));
455 }
456 }
457 last = et;
458 }
459
460 // Take the output track and insert it in place of the original sample data
461 orig->ClearAndPaste(mCurT0, mCurT1, out, true, true, warper);
462
463 // Finally, recreate the gaps
464 for (auto gap : gaps) {
465 auto st = orig->LongSamplesToTime(orig->TimeToLongSamples(gap.first));
466 auto et = orig->LongSamplesToTime(orig->TimeToLongSamples(gap.second));
467 if (st >= mCurT0 && et <= mCurT1 && st != et)
468 {
469 orig->SplitDelete(warper->Warp(st), warper->Warp(et));
470 }
471 }
472}
static const int gap
Definition: MeterPanel.cpp:259
double mCurT0
Definition: SBSMSEffect.h:56
double mCurT1
Definition: SBSMSEffect.h:57
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:47
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
virtual double Warp(double originalTime) const =0
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1165
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2723
void ClearAndPaste(double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
Definition: WaveTrack.cpp:915

References WaveTrack::ClearAndPaste(), gap, SampleTrack::LongSamplesToTime(), mCurT0, mCurT1, WaveTrack::SortedClipArray(), WaveTrack::SplitDelete(), SampleTrack::TimeToLongSamples(), and TimeWarper::Warp().

Referenced by Process().

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

◆ getInvertedStretchedTime()

double EffectSBSMS::getInvertedStretchedTime ( double  rateStart,
double  rateEnd,
SlideType  slideType,
double  outputTime 
)
static

Definition at line 201 of file SBSMSEffect.cpp.

202{
203 Slide slide(slideType,rateStart,rateEnd,0);
204 return slide.getInverseStretchedTime(outputTime);
205}
double rateStart
Definition: SBSMSEffect.h:51
double rateEnd
Definition: SBSMSEffect.h:51

References rateEnd, and rateStart.

Referenced by EffectTimeScale::CalcPreviewInputLength().

Here is the caller graph for this function:

◆ getRate()

double EffectSBSMS::getRate ( double  rateStart,
double  rateEnd,
SlideType  slideType,
double  t 
)
static

Definition at line 207 of file SBSMSEffect.cpp.

208{
209 Slide slide(slideType,rateStart,rateEnd,0);
210 return slide.getRate(t);
211}

References rateEnd, and rateStart.

Referenced by EffectTimeScale::Process().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectSBSMS::GetSymbol ( ) const
inlineoverrideprotectedvirtual

Reimplemented from Effect.

Reimplemented in EffectTimeScale.

Definition at line 45 of file SBSMSEffect.h.

45{ return mProxyEffectName; }
TranslatableString mProxyEffectName
Definition: SBSMSEffect.h:41

References mProxyEffectName.

◆ Process()

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

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Reimplemented in EffectTimeScale.

Definition at line 213 of file SBSMSEffect.cpp.

214{
215 bool bGoodResult = true;
216
217 //Iterate over each track
218 //all needed because this effect needs to introduce silence in the group tracks to keep sync
219 this->CopyInputTracks(true); // Set up mOutputTracks.
220 mCurTrackNum = 0;
221
222 double maxDuration = 0.0;
223
224 // Must sync if selection length will change
225 bool mustSync = (rateStart != rateEnd);
226 Slide rateSlide(rateSlideType,rateStart,rateEnd);
227 Slide pitchSlide(pitchSlideType,pitchStart,pitchEnd);
228 mTotalStretch = rateSlide.getTotalStretch();
229
230 mOutputTracks->Leaders().VisitWhile( bGoodResult,
231 [&](LabelTrack *lt, const Track::Fallthrough &fallthrough) {
232 if (!(lt->GetSelected() ||
233 (mustSync && SyncLock::IsSyncLockSelected(lt))))
234 return fallthrough();
235 if (!ProcessLabelTrack(lt))
236 bGoodResult = false;
237 },
238 [&](WaveTrack *leftTrack, const Track::Fallthrough &fallthrough) {
239 if (!leftTrack->GetSelected())
240 return fallthrough();
241
242 //Get start and end times from selection
243 mCurT0 = mT0;
244 mCurT1 = mT1;
245
246 //Set the current bounds to whichever left marker is
247 //greater and whichever right marker is less
248 mCurT0 = wxMax(mT0, mCurT0);
249 mCurT1 = wxMin(mT1, mCurT1);
250
251 // Process only if the right marker is to the right of the left marker
252 if (mCurT1 > mCurT0) {
253 auto start = leftTrack->TimeToLongSamples(mCurT0);
254 auto end = leftTrack->TimeToLongSamples(mCurT1);
255
256 // TODO: more-than-two-channels
257 auto channels = TrackList::Channels(leftTrack);
258 WaveTrack *rightTrack = (channels.size() > 1)
259 ? * ++ channels.first
260 : nullptr;
261 if (rightTrack) {
262 double t;
263
264 //Adjust bounds by the right tracks markers
265 t = rightTrack->GetStartTime();
266 t = wxMax(mT0, t);
267 mCurT0 = wxMin(mCurT0, t);
268 t = rightTrack->GetEndTime();
269 t = wxMin(mT1, t);
270 mCurT1 = wxMax(mCurT1, t);
271
272 //Transform the marker timepoints to samples
273 start = leftTrack->TimeToLongSamples(mCurT0);
274 end = leftTrack->TimeToLongSamples(mCurT1);
275
276 mCurTrackNum++; // Increment for rightTrack, too.
277 }
278
279 // SBSMS has a fixed sample rate - we just convert to its sample rate and then convert back
280 float srTrack = leftTrack->GetRate();
281 float srProcess = bLinkRatePitch ? srTrack : 44100.0;
282
283 // the resampler needs a callback to supply its samples
284 ResampleBuf rb;
285 auto maxBlockSize = leftTrack->GetMaxBlockSize();
286 rb.blockSize = maxBlockSize;
287 rb.buf.reinit(rb.blockSize, true);
288 rb.leftTrack = leftTrack;
289 rb.rightTrack = rightTrack?rightTrack:leftTrack;
290 rb.leftBuffer.reinit(maxBlockSize, true);
291 rb.rightBuffer.reinit(maxBlockSize, true);
292
293 // Samples in selection
294 auto samplesIn = end - start;
295
296 // Samples for SBSMS to process after resampling
297 auto samplesToProcess = (sampleCount) (samplesIn.as_float() * (srProcess/srTrack));
298
299 SlideType outSlideType;
300 SBSMSResampleCB outResampleCB;
301
302 if(bLinkRatePitch) {
303 rb.bPitch = true;
304 outSlideType = rateSlideType;
305 outResampleCB = resampleCB;
306 rb.offset = start;
307 rb.end = end;
308 // Third party library has its own type alias, check it
309 static_assert(sizeof(sampleCount::type) <=
310 sizeof(_sbsms_::SampleCountType),
311 "Type _sbsms_::SampleCountType is too narrow to hold a sampleCount");
312 rb.iface = std::make_unique<SBSMSInterfaceSliding>
313 (&rateSlide, &pitchSlide, bPitchReferenceInput,
314 static_cast<_sbsms_::SampleCountType>
315 ( samplesToProcess.as_long_long() ),
316 0, nullptr);
317
318 }
319 else {
320 rb.bPitch = false;
321 outSlideType = (srProcess==srTrack?SlideIdentity:SlideConstant);
322 outResampleCB = postResampleCB;
323 rb.ratio = srProcess/srTrack;
324 rb.quality = std::make_unique<SBSMSQuality>(&SBSMSQualityStandard);
325 rb.resampler = std::make_unique<Resampler>(resampleCB, &rb, srProcess==srTrack?SlideIdentity:SlideConstant);
326 rb.sbsms = std::make_unique<SBSMS>(rightTrack ? 2 : 1, rb.quality.get(), true);
327 rb.SBSMSBlockSize = rb.sbsms->getInputFrameSize();
328 rb.SBSMSBuf.reinit(static_cast<size_t>(rb.SBSMSBlockSize), true);
329 rb.offset = start;
330 rb.end = end;
331 rb.iface = std::make_unique<SBSMSEffectInterface>
332 (rb.resampler.get(), &rateSlide, &pitchSlide,
334 static_cast<_sbsms_::SampleCountType>( samplesToProcess.as_long_long() ),
335 0,
336 rb.quality.get());
337 }
338
339 Resampler resampler(outResampleCB,&rb,outSlideType);
340
341 audio outBuf[SBSMSOutBlockSize];
342 float outBufLeft[2*SBSMSOutBlockSize];
343 float outBufRight[2*SBSMSOutBlockSize];
344
345 // Samples in output after SBSMS
346 sampleCount samplesToOutput = rb.iface->getSamplesToOutput();
347
348 // Samples in output after resampling back
349 auto samplesOut = (sampleCount) (samplesToOutput.as_float() * (srTrack/srProcess));
350
351 // Duration in track time
352 double duration = (mCurT1-mCurT0) * mTotalStretch;
353
354 if(duration > maxDuration)
355 maxDuration = duration;
356
357 auto warper = createTimeWarper(mCurT0,mCurT1,maxDuration,rateStart,rateEnd,rateSlideType);
358
359 rb.outputLeftTrack = leftTrack->EmptyCopy();
360 if(rightTrack)
361 rb.outputRightTrack = rightTrack->EmptyCopy();
362
363 long pos = 0;
364 long outputCount = -1;
365
366 // process
367 while(pos<samplesOut && outputCount) {
368 const auto frames =
369 limitSampleBufferSize( SBSMSOutBlockSize, samplesOut - pos );
370
371 outputCount = resampler.read(outBuf,frames);
372 for(int i = 0; i < outputCount; i++) {
373 outBufLeft[i] = outBuf[i][0];
374 if(rightTrack)
375 outBufRight[i] = outBuf[i][1];
376 }
377 pos += outputCount;
378 rb.outputLeftTrack->Append((samplePtr)outBufLeft, floatSample, outputCount);
379 if(rightTrack)
380 rb.outputRightTrack->Append((samplePtr)outBufRight, floatSample, outputCount);
381
382 double frac = (double)pos / samplesOut.as_double();
383 int nWhichTrack = mCurTrackNum;
384 if(rightTrack) {
385 nWhichTrack = 2*(mCurTrackNum/2);
386 if (frac < 0.5)
387 frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
388 else {
389 nWhichTrack++;
390 frac -= 0.5;
391 frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
392 }
393 }
394 if (TrackProgress(nWhichTrack, frac)) {
395 bGoodResult = false;
396 return;
397 }
398 }
399
400 {
401 auto pException = rb.mpException;
402 rb.mpException = {};
403 if (pException)
404 std::rethrow_exception(pException);
405 }
406
407 rb.outputLeftTrack->Flush();
408 if(rightTrack)
409 rb.outputRightTrack->Flush();
410
411 Finalize(leftTrack, rb.outputLeftTrack.get(), warper.get());
412 if(rightTrack)
413 Finalize(rightTrack, rb.outputRightTrack.get(), warper.get());
414 }
415 mCurTrackNum++;
416 },
417 [&](Track *t) {
418 if (mustSync && SyncLock::IsSyncLockSelected(t))
419 {
420 t->SyncLockAdjust(mCurT1, mCurT0 + (mCurT1 - mCurT0) * mTotalStretch);
421 }
422 }
423 );
424
425 if (bGoodResult) {
426 ReplaceProcessedTracks(bGoodResult);
427 }
428
429 return bGoodResult;
430}
std::unique_ptr< TimeWarper > createTimeWarper(double t0, double t1, double duration, double rateStart, double rateEnd, SlideType rateSlideType)
@ SBSMSOutBlockSize
Definition: SBSMSEffect.cpp:28
long postResampleCB(void *cb_data, SBSMSFrame *data)
long resampleCB(void *cb_data, SBSMSFrame *data)
Definition: SBSMSEffect.cpp:89
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
double mT1
Definition: EffectBase.h:107
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
double mT0
Definition: EffectBase.h:106
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:741
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:693
SlideType rateSlideType
Definition: SBSMSEffect.h:53
bool bLinkRatePitch
Definition: SBSMSEffect.h:52
double pitchStart
Definition: SBSMSEffect.h:51
bool ProcessLabelTrack(LabelTrack *track)
int mCurTrackNum
Definition: SBSMSEffect.h:55
bool bPitchReferenceInput
Definition: SBSMSEffect.h:52
float mTotalStretch
Definition: SBSMSEffect.h:58
SlideType pitchSlideType
Definition: SBSMSEffect.h:54
void Finalize(WaveTrack *orig, WaveTrack *out, const TimeWarper *warper)
double pitchEnd
Definition: SBSMSEffect.h:51
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
ArrayOf< audio > SBSMSBuf
Definition: SBSMSEffect.cpp:57
sampleCount offset
Definition: SBSMSEffect.cpp:49
std::shared_ptr< WaveTrack > outputRightTrack
Definition: SBSMSEffect.cpp:63
std::unique_ptr< SBSMSInterface > iface
Definition: SBSMSEffect.cpp:56
ArrayOf< audio > buf
Definition: SBSMSEffect.cpp:44
WaveTrack * rightTrack
Definition: SBSMSEffect.cpp:54
ArrayOf< float > leftBuffer
Definition: SBSMSEffect.cpp:51
long SBSMSBlockSize
Definition: SBSMSEffect.cpp:48
std::unique_ptr< SBSMSQuality > quality
Definition: SBSMSEffect.cpp:61
std::shared_ptr< WaveTrack > outputLeftTrack
Definition: SBSMSEffect.cpp:62
std::exception_ptr mpException
Definition: SBSMSEffect.cpp:65
ArrayOf< float > rightBuffer
Definition: SBSMSEffect.cpp:52
double ratio
Definition: SBSMSEffect.cpp:45
std::unique_ptr< SBSMS > sbsms
Definition: SBSMSEffect.cpp:55
std::unique_ptr< Resampler > resampler
Definition: SBSMSEffect.cpp:60
size_t blockSize
Definition: SBSMSEffect.cpp:47
sampleCount end
Definition: SBSMSEffect.cpp:50
WaveTrack * leftTrack
Definition: SBSMSEffect.cpp:53
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:43
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
bool GetSelected() const
Definition: Track.h:469
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
Definition: Track.h:541
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1539
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1995
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1806
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:2015
double GetRate() const override
Definition: WaveTrack.cpp:479
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}, bool keepLink=true) const
Definition: WaveTrack.cpp:705
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
long long type
Definition: SampleCount.h:20
float as_float() const
Definition: SampleCount.h:44
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References sampleCount::as_float(), bLinkRatePitch, ResampleBuf::blockSize, ResampleBuf::bPitch, bPitchReferenceInput, ResampleBuf::buf, TrackList::Channels(), Effect::CopyInputTracks(), createTimeWarper(), WaveTrack::EmptyCopy(), PackedArray::end(), ResampleBuf::end, Finalize(), floatSample, WaveTrack::GetEndTime(), WaveTrack::GetMaxBlockSize(), WaveTrack::GetRate(), Track::GetSelected(), WaveTrack::GetStartTime(), ResampleBuf::iface, SyncLock::IsSyncLockSelected(), ResampleBuf::leftBuffer, ResampleBuf::leftTrack, limitSampleBufferSize(), mCurT0, mCurT1, mCurTrackNum, EffectBase::mOutputTracks, ResampleBuf::mpException, EffectBase::mT0, EffectBase::mT1, mTotalStretch, ResampleBuf::offset, ResampleBuf::outputLeftTrack, ResampleBuf::outputRightTrack, pitchEnd, pitchSlideType, pitchStart, postResampleCB(), ProcessLabelTrack(), ResampleBuf::quality, rateEnd, rateSlideType, rateStart, ResampleBuf::ratio, ArrayOf< X >::reinit(), EffectBase::ReplaceProcessedTracks(), resampleCB(), ResampleBuf::resampler, ResampleBuf::rightBuffer, ResampleBuf::rightTrack, ResampleBuf::sbsms, ResampleBuf::SBSMSBlockSize, ResampleBuf::SBSMSBuf, SBSMSOutBlockSize, SampleTrack::TimeToLongSamples(), and Effect::TrackProgress().

Referenced by EffectTimeScale::Process().

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

◆ ProcessLabelTrack()

bool EffectSBSMS::ProcessLabelTrack ( LabelTrack track)
private

Definition at line 193 of file SBSMSEffect.cpp.

194{
196 RegionTimeWarper warper{ mT0, mT1, std::move(warper1) };
197 lt->WarpLabels(warper);
198 return true;
199}
No change before the specified region; during the region, warp according to the given warper; after t...
Definition: TimeWarper.h:192

References createTimeWarper(), EffectBase::mT0, EffectBase::mT1, mTotalStretch, rateEnd, rateSlideType, rateStart, and LabelTrack::WarpLabels().

Referenced by Process().

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

◆ setParameters() [1/2]

void EffectSBSMS::setParameters ( double  rateStart,
double  rateEnd,
double  pitchStart,
double  pitchEnd,
SlideType  rateSlideType,
SlideType  pitchSlideType,
bool  bLinkRatePitch,
bool  bRateReferenceInput,
bool  bPitchReferenceInput 
)

Definition at line 148 of file SBSMSEffect.cpp.

151{
152 this->rateStart = rateStartIn;
153 this->rateEnd = rateEndIn;
154 this->pitchStart = pitchStartIn;
155 this->pitchEnd = pitchEndIn;
156 this->bLinkRatePitch = bLinkRatePitchIn;
157 this->rateSlideType = rateSlideTypeIn;
158 this->pitchSlideType = pitchSlideTypeIn;
159 this->bRateReferenceInput = bRateReferenceInputIn;
160 this->bPitchReferenceInput = bPitchReferenceInputIn;
161}
bool bRateReferenceInput
Definition: SBSMSEffect.h:52

References bLinkRatePitch, bPitchReferenceInput, bRateReferenceInput, pitchEnd, pitchSlideType, pitchStart, rateEnd, rateSlideType, and rateStart.

Referenced by EffectTimeScale::Process(), and setParameters().

Here is the caller graph for this function:

◆ setParameters() [2/2]

void EffectSBSMS::setParameters ( double  tempoRatio,
double  pitchRatio 
)

Definition at line 163 of file SBSMSEffect.cpp.

164{
165 setParameters(tempoRatio, tempoRatio, pitchRatio, pitchRatio,
166 SlideConstant, SlideConstant, false, false, false);
167}
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)

References setParameters().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ EffectChangePitch

friend class EffectChangePitch
friend

Definition at line 61 of file SBSMSEffect.h.

◆ EffectChangeTempo

friend class EffectChangeTempo
friend

Definition at line 60 of file SBSMSEffect.h.

Member Data Documentation

◆ bLinkRatePitch

bool EffectSBSMS::bLinkRatePitch
private

Definition at line 52 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ bPitchReferenceInput

bool EffectSBSMS::bPitchReferenceInput
private

Definition at line 52 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ bRateReferenceInput

bool EffectSBSMS::bRateReferenceInput
private

Definition at line 52 of file SBSMSEffect.h.

Referenced by setParameters().

◆ mCurT0

double EffectSBSMS::mCurT0
private

Definition at line 56 of file SBSMSEffect.h.

Referenced by Finalize(), and Process().

◆ mCurT1

double EffectSBSMS::mCurT1
private

Definition at line 57 of file SBSMSEffect.h.

Referenced by Finalize(), and Process().

◆ mCurTrackNum

int EffectSBSMS::mCurTrackNum
private

Definition at line 55 of file SBSMSEffect.h.

Referenced by Process().

◆ mProxyEffectName

TranslatableString EffectSBSMS::mProxyEffectName { XO("SBSMS Time / Pitch Stretch") }
protected

Definition at line 41 of file SBSMSEffect.h.

Referenced by GetSymbol().

◆ mTotalStretch

float EffectSBSMS::mTotalStretch
private

Definition at line 58 of file SBSMSEffect.h.

Referenced by Process(), and ProcessLabelTrack().

◆ pitchEnd

double EffectSBSMS::pitchEnd
private

Definition at line 51 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ pitchSlideType

SlideType EffectSBSMS::pitchSlideType
private

Definition at line 54 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ pitchStart

double EffectSBSMS::pitchStart
private

Definition at line 51 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ rateEnd

double EffectSBSMS::rateEnd
private

◆ rateSlideType

SlideType EffectSBSMS::rateSlideType
private

Definition at line 53 of file SBSMSEffect.h.

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

◆ rateStart

double EffectSBSMS::rateStart
private

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