56 std::unique_ptr<SBSMSInterface>
iface;
72 Slide *rateSlide, Slide *pitchSlide,
74 const SampleCountType
samples,
long preSamples,
75 SBSMSQuality *quality)
76 : SBSMSInterfaceSliding(rateSlide,pitchSlide,bReferenceInput,
samples,preSamples,quality)
117 for(
decltype(blockSize) i=0; i<blockSize; i++) {
122 data->buf = r->
buf.get();
123 data->size = blockSize;
126 float t1 = (r->
processed + blockSize).as_float() / r->
iface->getSamplesToInput();
127 data->ratio0 = r->
iface->getStretch(t0);
128 data->ratio1 = r->
iface->getStretch(t1);
130 data->ratio0 = r->
ratio;
131 data->ratio1 = r->
ratio;
144 data->ratio0 = 1.0 / r->
ratio;
145 data->ratio1 = 1.0 / r->
ratio;
150 SlideType rateSlideTypeIn, SlideType pitchSlideTypeIn,
151 bool bLinkRatePitchIn,
bool bRateReferenceInputIn,
bool bPitchReferenceInputIn)
166 setParameters(tempoRatio, tempoRatio, pitchRatio, pitchRatio,
167 SlideConstant, SlideConstant,
false,
false,
false);
171 double rateStart,
double rateEnd, SlideType rateSlideType)
173 if (rateStart == rateEnd || rateSlideType == SlideConstant)
174 return std::make_unique<LinearTimeWarper>(
175 t0, t0, t1, t0 + duration);
176 else if(rateSlideType == SlideLinearInputRate)
177 return std::make_unique<LinearInputRateTimeWarper>(
178 t0, t1, rateStart, rateEnd);
179 else if(rateSlideType == SlideLinearOutputRate)
180 return std::make_unique<LinearOutputRateTimeWarper>(
181 t0, t1, rateStart, rateEnd);
182 else if(rateSlideType == SlideLinearInputStretch)
183 return std::make_unique<LinearInputStretchTimeWarper>(
184 t0, t1, rateStart, rateEnd);
185 else if(rateSlideType == SlideLinearOutputStretch)
186 return std::make_unique<LinearOutputStretchTimeWarper>(
187 t0, t1, rateStart, rateEnd);
188 else if(rateSlideType == SlideGeometricInput)
189 return std::make_unique<GeometricInputTimeWarper>(
190 t0, t1, rateStart, rateEnd);
191 else if(rateSlideType == SlideGeometricOutput)
192 return std::make_unique<GeometricOutputTimeWarper>(
193 t0, t1, rateStart, rateEnd);
195 return std::make_unique<IdentityTimeWarper>();
217 return slide.getInverseStretchedTime(outputTime);
223 return slide.getRate(t);
228 bool bGoodResult =
true;
235 double maxDuration = 0.0;
241 outputs.Get().Any().VisitWhile(bGoodResult,
242 [&](
auto &&fallthrough){
return [&](
LabelTrack <) {
244 return fallthrough();
248 [&](
auto &&fallthrough){
return [&](
WaveTrack &track) {
249 if (!track.GetSelected())
250 return fallthrough();
254 const auto start = track.TimeToLongSamples(
mT0);
255 const auto end = track.TimeToLongSamples(
mT1);
258 auto channels = track.Channels();
259 const auto leftTrack = (*channels.begin()).get();
260 const auto rightTrack = (channels.size() > 1)
261 ? (* ++ channels.first).get()
268 const float srTrack = track.GetRate();
277 rb.
rightTrack = rightTrack ? rightTrack : leftTrack;
282 const auto samplesIn =
end - start;
285 const auto samplesToProcess =
static_cast<sampleCount>(
286 samplesIn.as_float() * (srProcess/srTrack));
288 SlideType outSlideType;
289 SBSMSResampleCB outResampleCB;
299 sizeof(_sbsms_::SampleCountType),
300"Type _sbsms_::SampleCountType is too narrow to hold a sampleCount");
301 rb.
iface = std::make_unique<SBSMSInterfaceSliding>(
303 static_cast<_sbsms_::SampleCountType
>(
304 samplesToProcess.as_long_long()),
310 (srProcess == srTrack ? SlideIdentity : SlideConstant);
312 rb.
ratio = srProcess/srTrack;
313 rb.
quality = std::make_unique<SBSMSQuality>(&SBSMSQualityStandard);
315 srProcess == srTrack ? SlideIdentity : SlideConstant);
316 rb.
sbsms = std::make_unique<SBSMS>(
317 rightTrack ? 2 : 1, rb.
quality.get(),
true);
322 rb.
iface = std::make_unique<SBSMSEffectInterface>(
323 rb.
resampler.get(), &rateSlide, &pitchSlide,
325 static_cast<_sbsms_::SampleCountType
>(
326 samplesToProcess.as_long_long()),
331 Resampler resampler(outResampleCB, &rb, outSlideType);
342 samplesToOutput.
as_float() * (srTrack / srProcess));
347 if (duration > maxDuration)
348 maxDuration = duration;
354 auto iter = outputTrack->Channels().begin();
361 long outputCount = -1;
364 while (pos < samplesOut && outputCount) {
368 outputCount = resampler.read(outBuf, frames);
369 for (
int i = 0; i < outputCount; ++i) {
370 outBufLeft[i] = outBuf[i][0];
372 outBufRight[i] = outBuf[i][1];
381 double frac =
static_cast<double>(pos) / samplesOut.as_double();
407 std::rethrow_exception(pException);
411 Finalize(track, *outputTrack, *warper);
433 std::vector<std::pair<double, double>> gaps;
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();
442 if (st >=
mT0 || et <
mT1) {
443 if (
mT0 < st && clip == front) {
444 gaps.push_back(std::make_pair(
mT0, st));
446 else if (last < st &&
mT0 <= last ) {
447 gaps.push_back(std::make_pair(last, st));
450 if (et <
mT1 && clip == back) {
451 gaps.push_back(std::make_pair(et,
mT1));
461 for (
auto gap : gaps) {
464 if (st >=
mT0 && et <=
mT1 && st != et)
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)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
void reinit(Integral count, bool initialize=false)
std::shared_ptr< TrackList > mTracks
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
A LabelTrack is a Track that holds labels (LabelStruct).
void WarpLabels(const TimeWarper &warper)
No change before the specified region; during the region, warp according to the given warper; after t...
ArrayOf< audio > SBSMSBuf
WaveChannel * outputRightChannel
std::unique_ptr< SBSMSInterface > iface
ArrayOf< float > leftBuffer
std::unique_ptr< SBSMSQuality > quality
WaveChannel * outputLeftChannel
std::exception_ptr mpException
ArrayOf< float > rightBuffer
std::unique_ptr< SBSMS > sbsms
std::unique_ptr< Resampler > resampler
void Finalize(WaveTrack &orig, const WaveTrack &out, const TimeWarper &warper)
void setParameters(double rateStart, double rateEnd, double pitchStart, double pitchEnd, SlideType rateSlideType, SlideType pitchSlideType, bool bLinkRatePitch, bool bRateReferenceInput, bool bPitchReferenceInput)
bool Process(EffectInstance &instance, EffectSettings &settings) override
static double getInvertedStretchedTime(double rateStart, double rateEnd, SlideType slideType, double outputTime)
bool bPitchReferenceInput
static double getRate(double rateStart, double rateEnd, SlideType slideType, double t)
EffectType GetType() const override
Type determines how it behaves.
bool ProcessLabelTrack(LabelTrack *track)
long samples(audio *buf, long n)
virtual ~SBSMSEffectInterface()
SBSMSEffectInterface(Resampler *resampler, Slide *rateSlide, Slide *pitchSlide, bool bReferenceInput, const SampleCountType samples, long preSamples, SBSMSQuality *quality)
static bool IsSyncLockSelected(const Track &track)
Transforms one point in time to another point. For example, a time stretching effect might use one to...
virtual double Warp(double originalTime) const =0
Abstract base class for an object holding data associated with points on a time axis.
bool Append(constSamplePtr buffer, sampleFormat format, size_t len)
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=FillFormat::fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
"narrow" overload fetches from the unique channel
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
A Track that contains audio waveform data.
void SplitDelete(double t0, double t1)
IntervalHolders SortedIntervalArray()
Return all WaveClips sorted by clip play start time.
size_t NChannels() const override
A constant property.
std::shared_ptr< WaveTrack > Holder
void ClearAndPaste(double t0, double t1, const WaveTrack &src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=nullptr, bool clearByTrimming=false)
double SnapToSample(double t) const
Positions or offsets within audio files need a wide type.
constexpr auto maxBlockSize
const char * end(const char *str) noexcept
Externalized state of a plug-in.