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
 
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 NumericFormatID 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 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 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, sampleCount *start, sampleCount *len)
 
- 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
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 

Private Member Functions

EffectType GetType () const override
 Type determines how it behaves. More...
 
bool ProcessLabelTrack (LabelTrack *track)
 
void Finalize (WaveTrack &orig, const 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
 
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
std::shared_ptr< 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>")
 

Detailed Description

Definition at line 29 of file SBSMSEffect.h.

Member Function Documentation

◆ Finalize()

void EffectSBSMS::Finalize ( WaveTrack orig,
const WaveTrack out,
const TimeWarper warper 
)
private
Precondition
orig.NChannels() == out.NChannels()

Definition at line 427 of file SBSMSEffect.cpp.

429{
430 assert(orig.NChannels() == out.NChannels());
431 // Silenced samples will be inserted in gaps between clips, so capture where these
432 // gaps are for later deletion
433 std::vector<std::pair<double, double>> gaps;
434 double last = mT0;
435 auto clips = orig.SortedIntervalArray();
436 auto front = clips.front();
437 auto back = clips.back();
438 for (auto &clip : clips) {
439 auto st = clip->GetPlayStartTime();
440 auto et = clip->GetPlayEndTime();
441
442 if (st >= mT0 || et < mT1) {
443 if (mT0 < st && clip == front) {
444 gaps.push_back(std::make_pair(mT0, st));
445 }
446 else if (last < st && mT0 <= last ) {
447 gaps.push_back(std::make_pair(last, st));
448 }
449
450 if (et < mT1 && clip == back) {
451 gaps.push_back(std::make_pair(et, mT1));
452 }
453 }
454 last = et;
455 }
456
457 // Take the output track and insert it in place of the original sample data
458 orig.ClearAndPaste(mT0, mT1, out, true, true, &warper);
459
460 // Finally, recreate the gaps
461 for (auto gap : gaps) {
462 const auto st = orig.SnapToSample(gap.first);
463 const auto et = orig.SnapToSample(gap.second);
464 if (st >= mT0 && et <= mT1 && st != et)
465 orig.SplitDelete(warper.Warp(st), warper.Warp(et));
466 }
467}
static const int gap
Definition: MeterPanel.cpp:257
double mT1
Definition: EffectBase.h:114
double mT0
Definition: EffectBase.h:113
virtual double Warp(double originalTime) const =0
void SplitDelete(double t0, double t1)
Definition: WaveTrack.cpp:1503
IntervalHolders SortedIntervalArray()
Return all WaveClips sorted by clip play start time.
Definition: WaveTrack.cpp:3270
size_t NChannels() const override
A constant property.
Definition: WaveTrack.cpp:532
void ClearAndPaste(double t0, double t1, const WaveTrack &src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=nullptr, bool clearByTrimming=false)
Definition: WaveTrack.cpp:1196
double SnapToSample(double t) const

References WaveTrack::ClearAndPaste(), gap, EffectBase::mT0, EffectBase::mT1, WaveTrack::NChannels(), WideSampleSequence::SnapToSample(), WaveTrack::SortedIntervalArray(), WaveTrack::SplitDelete(), 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 214 of file SBSMSEffect.cpp.

215{
216 Slide slide(slideType,rateStart,rateEnd,0);
217 return slide.getInverseStretchedTime(outputTime);
218}
double rateStart
Definition: SBSMSEffect.h:57
double rateEnd
Definition: SBSMSEffect.h:57

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 220 of file SBSMSEffect.cpp.

221{
222 Slide slide(slideType,rateStart,rateEnd,0);
223 return slide.getRate(t);
224}

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.

◆ GetType()

EffectType EffectSBSMS::GetType ( ) const
overrideprivatevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Reimplemented in EffectTimeScale.

Definition at line 198 of file SBSMSEffect.cpp.

199{
200 return EffectTypeProcess;
201}
@ EffectTypeProcess

References EffectTypeProcess.

Referenced by Process().

Here is the caller graph for this function:

◆ Process()

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

Implements StatefulEffectBase.

Reimplemented in EffectTimeScale.

Definition at line 226 of file SBSMSEffect.cpp.

227{
228 bool bGoodResult = true;
229
230 //Iterate over each track
231 //all needed because this effect needs to introduce silence in the group tracks to keep sync
232 EffectOutputTracks outputs { *mTracks, GetType(), { { mT0, mT1 } }, true };
233 mCurTrackNum = 0;
234
235 double maxDuration = 0.0;
236
237 Slide rateSlide(rateSlideType,rateStart,rateEnd);
238 Slide pitchSlide(pitchSlideType,pitchStart,pitchEnd);
239 mTotalStretch = rateSlide.getTotalStretch();
240
241 outputs.Get().Any().VisitWhile(bGoodResult,
242 [&](auto &&fallthrough){ return [&](LabelTrack &lt) {
243 if (!(lt.GetSelected() || SyncLock::IsSyncLockSelected(lt)))
244 return fallthrough();
245 if (!ProcessLabelTrack(&lt))
246 bGoodResult = false;
247 }; },
248 [&](auto &&fallthrough){ return [&](WaveTrack &track) {
249 if (!track.GetSelected())
250 return fallthrough();
251
252 // Process only if the right marker is to the right of the left marker
253 if (mT1 > mT0) {
254 const auto start = track.TimeToLongSamples(mT0);
255 const auto end = track.TimeToLongSamples(mT1);
256
257 // TODO: more-than-two-channels
258 auto channels = track.Channels();
259 const auto leftTrack = (*channels.begin()).get();
260 const auto rightTrack = (channels.size() > 1)
261 ? (* ++ channels.first).get()
262 : nullptr;
263 if (rightTrack)
264 mCurTrackNum++; // Increment for rightTrack, too.
265
266 // SBSMS has a fixed sample rate - we just convert to its sample
267 // rate and then convert back
268 const float srTrack = track.GetRate();
269 const float srProcess = bLinkRatePitch ? srTrack : 44100.0;
270
271 // the resampler needs a callback to supply its samples
272 ResampleBuf rb;
273 const auto maxBlockSize = track.GetMaxBlockSize();
275 rb.buf.reinit(rb.blockSize, true);
276 rb.leftTrack = leftTrack;
277 rb.rightTrack = rightTrack ? rightTrack : leftTrack;
280
281 // Samples in selection
282 const auto samplesIn = end - start;
283
284 // Samples for SBSMS to process after resampling
285 const auto samplesToProcess = static_cast<sampleCount>(
286 samplesIn.as_float() * (srProcess/srTrack));
287
288 SlideType outSlideType;
289 SBSMSResampleCB outResampleCB;
290
291 if (bLinkRatePitch) {
292 rb.bPitch = true;
293 outSlideType = rateSlideType;
294 outResampleCB = resampleCB;
295 rb.offset = start;
296 rb.end = end;
297 // Third party library has its own type alias, check it
298 static_assert(sizeof(sampleCount::type) <=
299 sizeof(_sbsms_::SampleCountType),
300"Type _sbsms_::SampleCountType is too narrow to hold a sampleCount");
301 rb.iface = std::make_unique<SBSMSInterfaceSliding>(
302 &rateSlide, &pitchSlide, bPitchReferenceInput,
303 static_cast<_sbsms_::SampleCountType>(
304 samplesToProcess.as_long_long()),
305 0, nullptr);
306 }
307 else {
308 rb.bPitch = false;
309 outSlideType =
310 (srProcess == srTrack ? SlideIdentity : SlideConstant);
311 outResampleCB = postResampleCB;
312 rb.ratio = srProcess/srTrack;
313 rb.quality = std::make_unique<SBSMSQuality>(&SBSMSQualityStandard);
314 rb.resampler = std::make_unique<Resampler>(resampleCB, &rb,
315 srProcess == srTrack ? SlideIdentity : SlideConstant);
316 rb.sbsms = std::make_unique<SBSMS>(
317 rightTrack ? 2 : 1, rb.quality.get(), true);
318 rb.SBSMSBlockSize = rb.sbsms->getInputFrameSize();
319 rb.SBSMSBuf.reinit(static_cast<size_t>(rb.SBSMSBlockSize), true);
320 rb.offset = start;
321 rb.end = end;
322 rb.iface = std::make_unique<SBSMSEffectInterface>(
323 rb.resampler.get(), &rateSlide, &pitchSlide,
325 static_cast<_sbsms_::SampleCountType>(
326 samplesToProcess.as_long_long()),
327 0,
328 rb.quality.get());
329 }
330
331 Resampler resampler(outResampleCB, &rb, outSlideType);
332
333 audio outBuf[SBSMSOutBlockSize];
334 float outBufLeft[2 * SBSMSOutBlockSize];
335 float outBufRight[2 * SBSMSOutBlockSize];
336
337 // Samples in output after SBSMS
338 const sampleCount samplesToOutput = rb.iface->getSamplesToOutput();
339
340 // Samples in output after resampling back
341 const auto samplesOut = static_cast<sampleCount>(
342 samplesToOutput.as_float() * (srTrack / srProcess));
343
344 // Duration in track time
345 const double duration = (mT1 - mT0) * mTotalStretch;
346
347 if (duration > maxDuration)
348 maxDuration = duration;
349
350 const auto warper = createTimeWarper(
351 mT0, mT1, maxDuration, rateStart, rateEnd, rateSlideType);
352
353 WaveTrack::Holder outputTrack = track.EmptyCopy();
354 auto iter = outputTrack->Channels().begin();
355 rb.outputTrack = outputTrack.get();
356 rb.outputLeftChannel = (*iter++).get();
357 if (rightTrack)
358 rb.outputRightChannel = (*iter).get();
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;
376 (samplePtr)outBufLeft, floatSample, outputCount);
377 if (rightTrack)
379 (samplePtr)outBufRight, floatSample, outputCount);
380
381 double frac = static_cast<double>(pos) / samplesOut.as_double();
382 int nWhichTrack = mCurTrackNum;
383 if (rightTrack) {
384 nWhichTrack = 2 * (mCurTrackNum / 2);
385 if (frac < 0.5)
386 // Show twice as far for each track,
387 // because we're doing 2 at once.
388 frac *= 2.0;
389 else {
390 nWhichTrack++;
391 frac -= 0.5;
392 // Show twice as far for each track,
393 // because we're doing 2 at once.
394 frac *= 2.0;
395 }
396 }
397 if (TrackProgress(nWhichTrack, frac)) {
398 bGoodResult = false;
399 return;
400 }
401 }
402
403 {
404 auto pException = rb.mpException;
405 rb.mpException = {};
406 if (pException)
407 std::rethrow_exception(pException);
408 }
409
410 rb.outputTrack->Flush();
411 Finalize(track, *outputTrack, *warper);
412 }
413 mCurTrackNum++;
414 }; },
415 [&](Track &t) {
417 t.SyncLockAdjust(mT1, mT0 + (mT1 - mT0) * mTotalStretch);
418 }
419 );
420
421 if (bGoodResult)
422 outputs.Commit();
423
424 return bGoodResult;
425}
@ SBSMSOutBlockSize
Definition: SBSMSEffect.cpp:28
std::unique_ptr< TimeWarper > createTimeWarper(double t0, double t1, double duration, double rateStart, double rateEnd, SlideType rateSlideType)
long postResampleCB(void *cb_data, SBSMSFrame *data)
long resampleCB(void *cb_data, SBSMSFrame *data)
Definition: SBSMSEffect.cpp:90
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
char * samplePtr
Definition: SampleFormat.h:57
MockedAudio audio
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:59
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:107
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:343
Use this object to copy the input tracks to tentative outputTracks.
SlideType rateSlideType
Definition: SBSMSEffect.h:59
bool bLinkRatePitch
Definition: SBSMSEffect.h:58
double pitchStart
Definition: SBSMSEffect.h:57
bool ProcessLabelTrack(LabelTrack *track)
int mCurTrackNum
Definition: SBSMSEffect.h:61
bool bPitchReferenceInput
Definition: SBSMSEffect.h:58
float mTotalStretch
Definition: SBSMSEffect.h:62
EffectType GetType() const override
Type determines how it behaves.
SlideType pitchSlideType
Definition: SBSMSEffect.h:60
double pitchEnd
Definition: SBSMSEffect.h:57
void Finalize(WaveTrack &orig, const WaveTrack &out, const TimeWarper &warper)
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95
ArrayOf< audio > SBSMSBuf
Definition: SBSMSEffect.cpp:57
sampleCount offset
Definition: SBSMSEffect.cpp:49
WaveChannel * outputRightChannel
Definition: SBSMSEffect.cpp:64
std::unique_ptr< SBSMSInterface > iface
Definition: SBSMSEffect.cpp:56
ArrayOf< audio > buf
Definition: SBSMSEffect.cpp:44
ArrayOf< float > leftBuffer
Definition: SBSMSEffect.cpp:51
long SBSMSBlockSize
Definition: SBSMSEffect.cpp:48
std::unique_ptr< SBSMSQuality > quality
Definition: SBSMSEffect.cpp:61
WaveChannel * outputLeftChannel
Definition: SBSMSEffect.cpp:63
std::exception_ptr mpException
Definition: SBSMSEffect.cpp:66
WaveChannel * leftTrack
Definition: SBSMSEffect.cpp:53
WaveChannel * rightTrack
Definition: SBSMSEffect.cpp:54
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 * outputTrack
Definition: SBSMSEffect.cpp:62
static bool IsSyncLockSelected(const Track &track)
Definition: SyncLock.cpp:80
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
Definition: WaveTrack.cpp:2216
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
void Flush() override
Definition: WaveTrack.cpp:2294
std::shared_ptr< WaveTrack > Holder
Definition: WaveTrack.h:247
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
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References WaveChannel::Append(), sampleCount::as_float(), audio, bLinkRatePitch, ResampleBuf::blockSize, ResampleBuf::bPitch, bPitchReferenceInput, ResampleBuf::buf, createTimeWarper(), details::end(), ResampleBuf::end, Finalize(), floatSample, WaveTrack::Flush(), GetType(), ResampleBuf::iface, SyncLock::IsSyncLockSelected(), ResampleBuf::leftBuffer, ResampleBuf::leftTrack, limitSampleBufferSize(), anonymous_namespace{StaffPadTimeAndPitch.cpp}::maxBlockSize, mCurTrackNum, ResampleBuf::mpException, EffectBase::mT0, EffectBase::mT1, mTotalStretch, EffectBase::mTracks, ResampleBuf::offset, ResampleBuf::outputLeftChannel, ResampleBuf::outputRightChannel, ResampleBuf::outputTrack, pitchEnd, pitchSlideType, pitchStart, postResampleCB(), ProcessLabelTrack(), ResampleBuf::quality, rateEnd, rateSlideType, rateStart, ResampleBuf::ratio, ArrayOf< X >::reinit(), resampleCB(), ResampleBuf::resampler, ResampleBuf::rightBuffer, ResampleBuf::rightTrack, ResampleBuf::sbsms, ResampleBuf::SBSMSBlockSize, ResampleBuf::SBSMSBuf, SBSMSOutBlockSize, 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 205 of file SBSMSEffect.cpp.

206{
207 auto warper1 = createTimeWarper(
209 RegionTimeWarper warper{ mT0, mT1, std::move(warper1) };
210 lt->WarpLabels(warper);
211 return true;
212}
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 149 of file SBSMSEffect.cpp.

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

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 164 of file SBSMSEffect.cpp.

165{
166 setParameters(tempoRatio, tempoRatio, pitchRatio, pitchRatio,
167 SlideConstant, SlideConstant, false, false, false);
168}
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 65 of file SBSMSEffect.h.

◆ EffectChangeTempo

friend class EffectChangeTempo
friend

Definition at line 64 of file SBSMSEffect.h.

Member Data Documentation

◆ bLinkRatePitch

bool EffectSBSMS::bLinkRatePitch
private

Definition at line 58 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ bPitchReferenceInput

bool EffectSBSMS::bPitchReferenceInput
private

Definition at line 58 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ bRateReferenceInput

bool EffectSBSMS::bRateReferenceInput
private

Definition at line 58 of file SBSMSEffect.h.

Referenced by setParameters().

◆ mCurTrackNum

int EffectSBSMS::mCurTrackNum
private

Definition at line 61 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 62 of file SBSMSEffect.h.

Referenced by Process(), and ProcessLabelTrack().

◆ pitchEnd

double EffectSBSMS::pitchEnd
private

Definition at line 57 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ pitchSlideType

SlideType EffectSBSMS::pitchSlideType
private

Definition at line 60 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ pitchStart

double EffectSBSMS::pitchStart
private

Definition at line 57 of file SBSMSEffect.h.

Referenced by Process(), and setParameters().

◆ rateEnd

double EffectSBSMS::rateEnd
private

◆ rateSlideType

SlideType EffectSBSMS::rateSlideType
private

Definition at line 59 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: