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
 
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
 ~StatefulEffect () override
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

Static Public Member Functions

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

Protected Member Functions

ComponentInterfaceSymbol GetSymbol () const override
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 

Protected Attributes

TranslatableString mProxyEffectName { XO("SBSMS Time / Pitch Stretch") }
 
- Protected Attributes inherited from EffectBase
std::shared_ptr< TrackListmOutputTracks
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

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 StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Attributes inherited from EffectBase
TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- 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 431 of file SBSMSEffect.cpp.

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

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

Implements ComponentInterface.

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

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