不需要的音频强度降低

时间:2015-02-23 15:09:04

标签: c# winforms naudio

我有一个c#windows表单项目,其中包含以下c#代码,它使用BiQuadFilter类的NAudio库来实现低通滤波器。我面临的问题是声音的强度也随着频率而下降,从而使音量几乎听不见。我该如何解决这个问题?

我的代码:

    private ISampleProvider sourceProvider;
    private BiQuadFilter[] filters;
    private int channels,cutOffFreq;

    //Constructor
    public MyFilter(ISampleProvider sourceProvider,int cutOffFreq)
    {
        this.sourceProvider = sourceProvider;
        this.cutOffFreq = cutOffFreq;

        channels = sourceProvider.WaveFormat.Channels;
        filters = new BiQuadFilter[channels];
        CreateFilters();
    }

    private void CreateFilters()
    {
        for (int n = 0; n < channels; n++)
            if (filters[n] == null)
                filters[n] = BiQuadFilter.LowPassFilter(44100, cutOffFreq, 1);
            else
                filters[n].SetLowPassFilter(44100, cutOffFreq, 1);
    }

    public WaveFormat WaveFormat { get { return sourceProvider.WaveFormat; } }

    public int Read(float[] buffer, int offset, int count)
    {
        int samplesRead = sourceProvider.Read(buffer, offset, count);

        for (int i = 0; i < samplesRead; i++)
            buffer[offset + i] = filters[(i % channels)].Transform(buffer[offset + i]);

        return samplesRead;
    }

这就是我使用它的方式:

    waveOut.Init(new MyFilter(new AudioFileReader(path + "\\Audio_Tracks\\" + topic + "\\" + currentTrack + ".wav"), 750));

    waveOut.Play();

1 个答案:

答案 0 :(得分:0)

嗯,我不知道你的源材料是什么,但截止频率仅为750Hz的低通滤波器可能会从原始信号中减少很多。一般来说,过滤器会让事情变得更安静。之后放大声音(例如,在变换后将每个样本乘以增益因子)。