Last active
January 27, 2019 14:58
-
-
Save alexliesenfeld/d59b5454d5516b8d18479a707b6336d6 to your computer and use it in GitHub Desktop.
A C++ class to smooth out DSP parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SMOOTHER_H | |
#define SMOOTHER_H | |
#include <math.h> | |
class Smoother { | |
private: | |
double mSampleRate; | |
double mLastOutput{}; | |
double mA{}; | |
double mB{}; | |
public: | |
Smoother(double pInitialSmoothingTimeInMs, double pSampleRate) : mSampleRate(pSampleRate) { | |
setSmoothingTime(pInitialSmoothingTimeInMs); | |
} | |
double process(double pInput) { | |
mLastOutput = (pInput * mB) + (mLastOutput * mA); | |
return mLastOutput; | |
} | |
void setSmoothingTime(double pSmoothingTimeInMs) { | |
mA = exp(-(M_PI * 2) / (pSmoothingTimeInMs * 0.001 * mSampleRate)); | |
mB = 1.0 - mA; | |
} | |
}; | |
#endif // SMOOTHER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment