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;
SampleRate getSampleRate() const
Definition: SampleRateBasedClock.h:128
RateLimiter(uint32 iRateLimitInSamples=0)
Definition: SampleRateBasedClock.h:52
uint32 getSampleCountFor(uint32 iMillis) const
Definition: SampleRateBasedClock.h:82
Definition: SampleRateBasedClock.h:49
SampleRateBasedClock(SampleRate iSampleRate)
Definition: SampleRateBasedClock.h:76
uint32 fSampleCount
Definition: SampleRateBasedClock.h:72
bool shouldUpdate(uint32 numSamples)
Definition: SampleRateBasedClock.h:59
void setSampleRate(SampleRate iSampleRate)
Definition: SampleRateBasedClock.h:134
uint32 getTimeForSampleCount(uint32 iSampleCount) const
Definition: SampleRateBasedClock.h:99
RateLimiter getRateLimiter(uint32 iMillis) const
Definition: SampleRateBasedClock.h:140
TSamples getNextBarSampleCount(TSamples iCurrentSampleCount, double iTempo, int32 iTimeSigNumerator=4, int32 iTimeSigDenominator=4) const
Definition: SampleRateBasedClock.h:115
uint32 getSampleCountFor1Bar(double iTempo, int32 iTimeSigNumerator=4, int32 iTimeSigDenominator=4) const
Definition: SampleRateBasedClock.h:88
Definition: SampleRateBasedClock.h:34
SampleRate fSampleRate
Definition: SampleRateBasedClock.h:146
uint32 fRateLimitInSamples
Definition: SampleRateBasedClock.h:71