Created
March 21, 2015 17:29
-
-
Save jakubfiala/66cbbd29f1affa4273b4 to your computer and use it in GitHub Desktop.
Formant filter
This file contains 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
double maxiFilter::formant(double input, double centerFreq, double q, double gain) { | |
cutoff = centerFreq; | |
//offset gain | |
gain += 1; | |
//gain *= 4; | |
//calculate poles and coeffs | |
w0 = TWOPI * cutoff / 44100; | |
alpha = sin(w0)/(20*q); | |
b0 = alpha*gain; | |
b1 = 0; | |
b2 = -alpha*gain; | |
a0 = 1 + alpha/gain; | |
a1 = -2*cos(w0); | |
a2 = 1 - alpha/gain; | |
//apply filter | |
output = (b0/a0)*input + (b1/a0)*in1 + (b2/a0)*in2 - (a1/a0)*out1 - (a2/a0)*out2; | |
//update memory | |
out2 = out1; | |
out1 = output; | |
in2 = in1; | |
in1 = input; | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment