Audacity 3.2.0
Classes | Enumerations | Functions
SBSMSEffect.cpp File Reference
#include "SBSMSEffect.h"
#include <math.h>
#include "../LabelTrack.h"
#include "../SyncLock.h"
#include "../WaveClip.h"
#include "../WaveTrack.h"
#include "TimeWarper.h"
Include dependency graph for SBSMSEffect.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 SBSMSEffect.cpp.

27 {
29};
@ SBSMSOutBlockSize
Definition: SBSMSEffect.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 169 of file SBSMSEffect.cpp.

171{
172 std::unique_ptr<TimeWarper> warper;
173 if (rateStart == rateEnd || rateSlideType == SlideConstant) {
174 warper = std::make_unique<LinearTimeWarper>(t0, t0, t1, t0+duration);
175 } else if(rateSlideType == SlideLinearInputRate) {
176 warper = std::make_unique<LinearInputRateTimeWarper>(t0, t1, rateStart, rateEnd);
177 } else if(rateSlideType == SlideLinearOutputRate) {
178 warper = std::make_unique<LinearOutputRateTimeWarper>(t0, t1, rateStart, rateEnd);
179 } else if(rateSlideType == SlideLinearInputStretch) {
180 warper = std::make_unique<LinearInputStretchTimeWarper>(t0, t1, rateStart, rateEnd);
181 } else if(rateSlideType == SlideLinearOutputStretch) {
182 warper = std::make_unique<LinearOutputStretchTimeWarper>(t0, t1, rateStart, rateEnd);
183 } else if(rateSlideType == SlideGeometricInput) {
184 warper = std::make_unique<GeometricInputTimeWarper>(t0, t1, rateStart, rateEnd);
185 } else if(rateSlideType == SlideGeometricOutput) {
186 warper = std::make_unique<GeometricOutputTimeWarper>(t0, t1, rateStart, rateEnd);
187 }
188 return warper;
189}

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

Here is the caller graph for this function:

◆ postResampleCB()

long postResampleCB ( void *  cb_data,
SBSMSFrame *  data 
)

Definition at line 137 of file SBSMSEffect.cpp.

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

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

Referenced by EffectSBSMS::Process().

Here is the caller graph for this function:

◆ resampleCB()

long resampleCB ( void *  cb_data,
SBSMSFrame *  data 
)

Definition at line 89 of file SBSMSEffect.cpp.

90{
91 ResampleBuf *r = (ResampleBuf*) cb_data;
92
93 auto blockSize = limitSampleBufferSize(
95 r->end - r->offset
96 );
97
98 // Get the samples from the tracks and put them in the buffers.
99 // I don't know if we can safely propagate errors through sbsms, and it
100 // does not seem to let us report error codes, so use this roundabout to
101 // stop the effect early.
102 try {
104 (r->leftBuffer.get()), r->offset, blockSize);
106 (r->rightBuffer.get()), r->offset, blockSize);
107 }
108 catch ( ... ) {
109 // Save the exception object for re-throw when out of the library
110 r->mpException = std::current_exception();
111 data->size = 0;
112 return 0;
113 }
114
115 // convert to sbsms audio format
116 for(decltype(blockSize) i=0; i<blockSize; i++) {
117 r->buf[i][0] = r->leftBuffer[i];
118 r->buf[i][1] = r->rightBuffer[i];
119 }
120
121 data->buf = r->buf.get();
122 data->size = blockSize;
123 if(r->bPitch) {
124 float t0 = r->processed.as_float() / r->iface->getSamplesToInput();
125 float t1 = (r->processed + blockSize).as_float() / r->iface->getSamplesToInput();
126 data->ratio0 = r->iface->getStretch(t0);
127 data->ratio1 = r->iface->getStretch(t1);
128 } else {
129 data->ratio0 = r->ratio;
130 data->ratio1 = r->ratio;
131 }
132 r->processed += blockSize;
133 r->offset += blockSize;
134 return blockSize;
135}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
sampleCount offset
Definition: SBSMSEffect.cpp:49
ArrayOf< audio > buf
Definition: SBSMSEffect.cpp:44
WaveTrack * rightTrack
Definition: SBSMSEffect.cpp:54
ArrayOf< float > leftBuffer
Definition: SBSMSEffect.cpp:51
sampleCount processed
Definition: SBSMSEffect.cpp:46
std::exception_ptr mpException
Definition: SBSMSEffect.cpp:65
ArrayOf< float > rightBuffer
Definition: SBSMSEffect.cpp:52
sampleCount end
Definition: SBSMSEffect.cpp:50
WaveTrack * leftTrack
Definition: SBSMSEffect.cpp:53
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:65
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1788
float as_float() const
Definition: SampleCount.h:44

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

Referenced by EffectSBSMS::Process().

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