Audacity 3.2.0
Classes | Enumerations | Functions
SBSMSBase.cpp File Reference
#include "SBSMSBase.h"
#include "EffectOutputTracks.h"
#include <math.h>
#include "LabelTrack.h"
#include "SyncLock.h"
#include "WaveClip.h"
#include "WaveTrack.h"
#include "TimeWarper.h"
#include <cassert>
Include dependency graph for SBSMSBase.cpp:

Go to the source code of this file.

Classes

class  ResampleBuf
 
class  SBSMSEffectInterface
 

Enumerations

enum  { SBSMSOutBlockSize = 512 }
 

Functions

long resampleCB (void *cb_data, SBSMSFrame *data)
 
long postResampleCB (void *cb_data, SBSMSFrame *data)
 
std::unique_ptr< TimeWarpercreateTimeWarper (double t0, double t1, double duration, double rateStart, double rateEnd, SlideType rateSlideType)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SBSMSOutBlockSize 

Definition at line 27 of file SBSMSBase.cpp.

27 {
29};
@ SBSMSOutBlockSize
Definition: SBSMSBase.cpp:28

Function Documentation

◆ createTimeWarper()

std::unique_ptr< TimeWarper > createTimeWarper ( double  t0,
double  t1,
double  duration,
double  rateStart,
double  rateEnd,
SlideType  rateSlideType 
)

Definition at line 170 of file SBSMSBase.cpp.

172{
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);
194 else
195 return std::make_unique<IdentityTimeWarper>();
196}

Referenced by SBSMSBase::Process(), and SBSMSBase::ProcessLabelTrack().

Here is the caller graph for this function:

◆ postResampleCB()

long postResampleCB ( void *  cb_data,
SBSMSFrame *  data 
)

Definition at line 138 of file SBSMSBase.cpp.

139{
140 ResampleBuf *r = (ResampleBuf*) cb_data;
141 auto count = r->sbsms->read(r->iface.get(), r->SBSMSBuf.get(), r->SBSMSBlockSize);
142 data->buf = r->SBSMSBuf.get();
143 data->size = count;
144 data->ratio0 = 1.0 / r->ratio;
145 data->ratio1 = 1.0 / r->ratio;
146 return count;
147}
ArrayOf< audio > SBSMSBuf
Definition: SBSMSBase.cpp:57
std::unique_ptr< SBSMSInterface > iface
Definition: SBSMSBase.cpp:56
long SBSMSBlockSize
Definition: SBSMSBase.cpp:48
double ratio
Definition: SBSMSBase.cpp:45
std::unique_ptr< SBSMS > sbsms
Definition: SBSMSBase.cpp:55

References ResampleBuf::iface, ResampleBuf::ratio, ResampleBuf::sbsms, ResampleBuf::SBSMSBlockSize, and ResampleBuf::SBSMSBuf.

Referenced by SBSMSBase::Process().

Here is the caller graph for this function:

◆ resampleCB()

long resampleCB ( void *  cb_data,
SBSMSFrame *  data 
)

Definition at line 90 of file SBSMSBase.cpp.

91{
92 ResampleBuf *r = (ResampleBuf*) cb_data;
93
94 auto blockSize = limitSampleBufferSize(
96 r->end - r->offset
97 );
98
99 // Get the samples from the tracks and put them in the buffers.
100 // I don't know if we can safely propagate errors through sbsms, and it
101 // does not seem to let us report error codes, so use this roundabout to
102 // stop the effect early.
103 try {
105 (r->leftBuffer.get()), r->offset, blockSize);
107 (r->rightBuffer.get()), r->offset, blockSize);
108 }
109 catch ( ... ) {
110 // Save the exception object for re-throw when out of the library
111 r->mpException = std::current_exception();
112 data->size = 0;
113 return 0;
114 }
115
116 // convert to sbsms audio format
117 for(decltype(blockSize) i=0; i<blockSize; i++) {
118 r->buf[i][0] = r->leftBuffer[i];
119 r->buf[i][1] = r->rightBuffer[i];
120 }
121
122 data->buf = r->buf.get();
123 data->size = blockSize;
124 if(r->bPitch) {
125 float t0 = r->processed.as_float() / r->iface->getSamplesToInput();
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);
129 } else {
130 data->ratio0 = r->ratio;
131 data->ratio1 = r->ratio;
132 }
133 r->processed += blockSize;
134 r->offset += blockSize;
135 return blockSize;
136}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
sampleCount offset
Definition: SBSMSBase.cpp:49
ArrayOf< audio > buf
Definition: SBSMSBase.cpp:44
ArrayOf< float > leftBuffer
Definition: SBSMSBase.cpp:51
sampleCount processed
Definition: SBSMSBase.cpp:46
std::exception_ptr mpException
Definition: SBSMSBase.cpp:66
WaveChannel * leftTrack
Definition: SBSMSBase.cpp:53
WaveChannel * rightTrack
Definition: SBSMSBase.cpp:54
ArrayOf< float > rightBuffer
Definition: SBSMSBase.cpp:52
sampleCount end
Definition: SBSMSBase.cpp:50
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
Definition: WaveTrack.h:129
size_t GetBestBlockSize(sampleCount t) const
A hint for sizing of well aligned fetches.
Definition: WaveTrack.h:851
float as_float() const
Definition: SampleCount.h:45

References sampleCount::as_float(), ResampleBuf::bPitch, ResampleBuf::buf, ResampleBuf::end, WaveChannel::GetBestBlockSize(), WaveChannel::GetFloats(), ResampleBuf::iface, ResampleBuf::leftBuffer, ResampleBuf::leftTrack, limitSampleBufferSize(), ResampleBuf::mpException, ResampleBuf::offset, ResampleBuf::processed, ResampleBuf::ratio, ResampleBuf::rightBuffer, and ResampleBuf::rightTrack.

Referenced by SBSMSBase::Process().

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