25 #ifndef SDRBASE_AUDIO_AUDIOCOMPRESSORSND_H_ 26 #define SDRBASE_AUDIO_AUDIOCOMPRESSORSND_H_ 28 #define _USE_MATH_DEFINES 32 #define AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY 1024 36 #define AUDIOCOMPRESSORSND_SF_COMPRESSOR_SPU 32 39 #define AUDIOCOMPRESSORSND_SF_COMPRESSOR_SPACINGDB 5.0f 42 #define AUDIOCOMPRESSORSND_SF_COMPRESSOR_CHUNKSIZE 128 56 m_threshold = -24.000f;
62 m_releasezone1 = 0.090f;
63 m_releasezone2 = 0.160f;
64 m_releasezone3 = 0.420f;
65 m_releasezone4 = 0.980f;
83 m_threshold = threshold;
89 m_releasezone1 = 0.090f;
90 m_releasezone2 = 0.160f;
91 m_releasezone3 = 0.420f;
92 m_releasezone4 = 0.980f;
99 float compress(
float sample);
118 return powf(10.0f, 0.05f * db);
122 return 20.0f * log10f(lin);
127 static inline float kneecurve(
float x,
float k,
float linearthreshold){
128 return linearthreshold + (1.0f - expf(-k * (x - linearthreshold))) / k;
131 static inline float kneeslope(
float x,
float k,
float linearthreshold){
132 return k * x / ((k * linearthreshold + 1.0f) * expf(k * (x - linearthreshold)) - 1);
135 static inline float compcurve(
float x,
float k,
float slope,
float linearthreshold,
136 float linearthresholdknee,
float threshold,
float knee,
float kneedboffset){
137 if (x < linearthreshold)
140 return db2lin(threshold + slope * (lin2db(x) - threshold));
141 if (x < linearthresholdknee)
142 return kneecurve(x, k, linearthreshold);
143 return db2lin(kneedboffset + slope * (lin2db(x) - threshold - knee));
151 return a * x2 * x + b * x2 + c * x + d;
155 return v < min ? min : (v > max ?
max : v);
158 static inline float absf(
float v){
159 return v < 0.0f ? -v : v;
162 static inline float fixf(
float v,
float def){
164 if (isnan(v) || isinf(v))
207 int rate,
float pregain,
float threshold,
float knee,
float ratio,
float attack,
float release,
219 static void sf_compressor_process(
CompressorState *state,
int size,
float *input,
float *output);
230 #endif // SDRBASE_AUDIO_AUDIOCOMPRESSORSND_H_
#define AUDIOCOMPRESSORSND_SF_COMPRESSOR_MAXDELAY
static float kneecurve(float x, float k, float linearthreshold)
#define AUDIOCOMPRESSORSND_SF_COMPRESSOR_CHUNKSIZE
void initSimple(int rate, float pregain, float threshold, float knee, float ratio, float attack, float release)
CompressorState m_compressorState
static float absf(float v)
float satreleasesamplesinv
static float fixf(float v, float def)
static float adaptivereleasecurve(float x, float a, float b, float c, float d)
static float compcurve(float x, float k, float slope, float linearthreshold, float linearthresholdknee, float threshold, float knee, float kneedboffset)
static float lin2db(float lin)
static float kneeslope(float x, float k, float linearthreshold)
static float clampf(float v, float min, float max)
float linearthresholdknee
static float db2lin(float db)
void initDefault(int rate)
T max(const T &x, const T &y)
T min(const T &x, const T &y)