Search code examples
c++signal-processingaudio-processingequalizer

Audio equalization


I'm developing audio player using FFmpeg and I want to add audio equaliqer to my app. I use FFmpeg to get audio samples and compute FFT, but when I try to apply one of IIR filters, I'm geting very noisy audio signal. This is my code:

double Q = 1.0;
double omega = 2.0 * PI * 1000.0 / 44100.0;
double sine = sin(omega);
double alpha = sine / ( 2.0 * Q);
double cosine = cos(omega);

double b0 = (1 + cosine)/2;
double b1 = (-1) * (1 + cosine);
double b2 = (1 + cosine)/2;
double a0 = 1 + alpha;
double a1 = (-2) * cosine;
double a2 = 1 - alpha;

for( int n = 2; n < fftSize; n++ )
{
   leftChannel2[n].re = ((b0/a0)*leftChannel[n].re + (b1/a0)*leftChannel[n-1].re + (b2/a0)*leftChannel[n-2].re -
                         (a1/a0)*leftChannel2[n-1].re - (a2/a0)*leftChannel2[n-2].re);
   rightChannel2[n].re = ((b0/a0)*rightChannel[n].re + (b1/a0)*rightChannel[n-1].re + (b2/a0)*rightChannel[n-2].re -
                          (a1/a0)*rightChannel2[n-1].re - (a2/a0)*rightChannel2[n-2].re);                    
   leftChannel2[n].im = leftChannel[n].im;
   rightChannel2[n].im = rightChannel[n].im;
}

Can anybody told me what is wrong with this code?


Solution

  • Does this filter perform correctly in Excel or Matlab? At first look, i don't see here syntax or semantic errors. By the way, this filter (difference equation) computes frequency response in time domain. What about the imaginary part of the signal? If it is non-zero, you have to filter it in the same way.