20 #include <pluginterfaces/base/ftypes.h> 21 #include <pluginterfaces/vst/vsttypes.h> 28 using namespace Steinberg;
29 using namespace Steinberg::Vst;
52 explicit RateLimiter(uint32 iRateLimitInSamples = 0) : fRateLimitInSamples{iRateLimitInSamples}, fSampleCount{0}
61 fSampleCount += numSamples;
62 if(fSampleCount >= fRateLimitInSamples)
64 fSampleCount -= fRateLimitInSamples;
84 return static_cast<uint32>(ceil(fSampleRate * iMillis / 1000.0));
90 auto oneBarInSeconds = 240.0 / iTempo;
91 if(iTimeSigNumerator != iTimeSigDenominator && iTimeSigDenominator != 0)
93 oneBarInSeconds *= (static_cast<double>(iTimeSigNumerator) / static_cast<double>(iTimeSigDenominator));
95 return static_cast<uint32>(ceil(fSampleRate * oneBarInSeconds));
101 return static_cast<uint32>(ceil(iSampleCount * 1000.0 / fSampleRate));
115 TSamples
getNextBarSampleCount(TSamples iCurrentSampleCount,
double iTempo, int32 iTimeSigNumerator = 4, int32 iTimeSigDenominator = 4)
const 117 auto sampleCountFor1Bar =
118 static_cast<TSamples>(getSampleCountFor1Bar(iTempo, iTimeSigNumerator, iTimeSigDenominator));
119 auto barMultiples = iCurrentSampleCount / sampleCountFor1Bar;
120 auto barBoundary = barMultiples * sampleCountFor1Bar;
121 if(barBoundary == iCurrentSampleCount)
122 return iCurrentSampleCount;
124 return barBoundary + sampleCountFor1Bar;
136 fSampleRate = iSampleRate;
RateLimiter getRateLimiter(uint32 iMillis) const
Definition: SampleRateBasedClock.h:140
SampleRate fSampleRate
Definition: SampleRateBasedClock.h:146
uint32 fSampleCount
Definition: SampleRateBasedClock.h:72
Keeps track of the time in number of samples processed vs sample rate.
Definition: SampleRateBasedClock.h:49
SampleRate getSampleRate() const
Definition: SampleRateBasedClock.h:128
uint32 getTimeForSampleCount(uint32 iSampleCount) const
Definition: SampleRateBasedClock.h:99
uint32 getSampleCountFor(uint32 iMillis) const
Definition: SampleRateBasedClock.h:82
SampleRateBasedClock(SampleRate iSampleRate)
Definition: SampleRateBasedClock.h:76
uint32 getSampleCountFor1Bar(double iTempo, int32 iTimeSigNumerator=4, int32 iTimeSigDenominator=4) const
Definition: SampleRateBasedClock.h:88
bool shouldUpdate(uint32 numSamples)
Calls this method when a new batch of samples is processed and returns true if the limit (in samples)...
Definition: SampleRateBasedClock.h:59
void setSampleRate(SampleRate iSampleRate)
Definition: SampleRateBasedClock.h:134
TSamples getNextBarSampleCount(TSamples iCurrentSampleCount, double iTempo, int32 iTimeSigNumerator=4, int32 iTimeSigDenominator=4) const
Given the current sample count (which can be extracted from ProcessData::processContext->projectTimeS...
Definition: SampleRateBasedClock.h:115
uint32 fRateLimitInSamples
Definition: SampleRateBasedClock.h:71
RateLimiter(uint32 iRateLimitInSamples=0)
Definition: SampleRateBasedClock.h:52
The purpose of this class is to deal with timing based on the sample rate and do the proper conversio...
Definition: SampleRateBasedClock.h:34