utility.cpp (1022B)
1 2 #include "filters/utility.hpp" 3 #include <cstdlib> 4 5 using namespace bogaudio::dsp; 6 7 float DCBlocker::next(float sample) { 8 const float r = 0.999f; 9 _lastOut = sample - _lastIn + r * _lastOut; 10 _lastIn = sample; 11 return _lastOut; 12 } 13 14 15 float AverageRectifiedValue::next(float sample) { 16 return RunningAverage::next(fabsf(sample)); 17 } 18 19 20 float FastRootMeanSquare::next(float sample) { 21 return AverageRectifiedValue::next(_dcBlocker.next(sample)); 22 } 23 24 25 float PureRootMeanSquare::next(float sample) { 26 float a = RunningAverage::next(sample * sample); 27 if (_sum <= 0.0) { 28 return 0.0f; 29 } 30 return sqrtf(a); 31 } 32 33 34 void PucketteEnvelopeFollower::setParams(float sampleRate, float sensitivity) { 35 const float maxCutoff = 10000.0f; 36 const float minCutoff = 100.0f; 37 assert(sensitivity >= 0.0f && sensitivity <= 1.0f); 38 float cutoff = minCutoff + sensitivity * (maxCutoff - minCutoff); 39 _filter.setParams(sampleRate, cutoff); 40 } 41 42 float PucketteEnvelopeFollower::next(float sample) { 43 return _filter.next(fabsf(_dcBlocker.next(sample))); 44 }