均衡原始PCM文件给了我很多噪音

时间:2015-12-02 13:42:47

标签: c++ matlab equalizer

我有一个16位单声道PCM文件,采样率为44100 Hz。当我在Matlab中读取这个PCM文件时,我得到一个介于-32k和+ 32k之间的大数列。在C ++中,我想在这个PCM文件上执行均衡器。在均衡之后,我确实得到了其他价值观。然而,在播放新的均衡PCM文件后,再次在MATLAB中,我得到了很多噪音。为什么?

这是我用于均衡的系数:

void bassCoefficients(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2)
{
    double frequency = 330;
    double qFactor = 0.5;
    double gain = intensity;
    double sampleRate = 44100;
    double pi=4.0*atan(1);

    double a=pow(10.0, gain/40);
    double w0=2*pi*frequency/sampleRate;
    double alpha=sin(w0)/(2.0*qFactor);
    double a0=(a+1)+(a-1)*cos(w0)+2.0*sqrt(a)*alpha;   

    *a1=-(-2.0*((a-1)+(a+1)*cos(w0)))/a0;
    *a2=-((a+1)+(a-1)*cos(w0)-2.0*sqrt(a)*alpha)/a0;
    *b0=(a*((a+1)-(a-1)*cos(w0)+2.0*sqrt(a)*alpha))/a0;
    *b1=(2*a*((a-1)-(a+1)*cos(w0)))/a0;
    *b2=(a*((a+1)-(a-1)*cos(w0)-2.0*sqrt(a)*alpha))/a0;
} 

void trebleCoefficients(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2)
{
    double frequency = 3300;
    double qFactor = 0.5;
    double gain = intensity;
    double sampleRate = 44100;
    double pi=4.0*atan(1);

    double a=pow(10.0, gain/40);
    double w0=2*pi*frequency/sampleRate;
    double alpha=sin(w0)/(2.0*qFactor);

    double a0=(a+1)-(a-1)*cos(w0)+2.0*sqrt(a)*alpha;   

    *a1=-(2.0*((a-1)-(a+1)*cos(w0)))/a0;
    *a2=-((a+1)-(a-1)*cos(w0)-2.0*sqrt(a)*alpha)/a0;
    *b0=(a*((a+1)+(a-1)*cos(w0)+2.0*sqrt(a)*alpha))/a0;
    *b1=(-2.0*a*((a-1)+(a+1)*cos(w0)))/a0;
    *b2=(a*((a+1)+(a-1)*cos(w0)-2.0*sqrt(a)*alpha))/a0;
}

这是我使用的公式:

y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] + a1*y[n-1] + a2*y[n-2]

0 个答案:

没有答案