-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCompressor.cpp
45 lines (39 loc) · 994 Bytes
/
Compressor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Compressor.cpp
// DSPLibrary
//
// Created by Mayank on 9/11/12.
// Copyright (c) 2012 Mayank Sanganeria. All rights reserved.
//
#include "Compressor.h"
Compressor::Compressor(float wthreshold,float wratio, int srate)
{
threshold = wthreshold;
ratio = wratio;
raisedTo = 1/(ratio-1);
levelEstimator.setTau(0.05, srate);
logThreshold = dB(threshold);
}
void Compressor::setupCompressor(float wthreshold,float wratio, int srate)
{
threshold = wthreshold;
ratio = wratio;
raisedTo = 1/(ratio-1);
levelEstimator.setTau(0.05, srate);
logThreshold = dB(threshold);
}
void Compressor::process(float input, float&output)
{
float levelEstimate,gain;
levelEstimator.process(input, levelEstimate);
float logLevel = dB(levelEstimate);
if (logLevel < logThreshold)
{
output = input;
}
else
{
float dbGain = (logLevel - logThreshold) / (1/ratio -1);
output = input * dB2lin(dbGain);
}
}