NAudio低通滤波器

时间:2017-03-08 22:59:42

标签: wpf audio naudio

我编写了捕获麦克风音频的代码,然后通过扬声器播放音频。我想在e.Buffer byte []上实现一个低通滤波器,以减少来自麦克风的噪声。

一些背景知识:我打算使用此代码创建VOIP程序。客户端将过滤后的e.Buffer数组发送到另一个客户端,然后播放音频。

class Program
{
    public static int inputdevicenumber;
    public static WaveFormat waveformat = new WaveFormat(44100, 16, 1);
    static BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(waveformat);
    static WaveOutEvent waveOut = new WaveOutEvent();

    static void Main(string[] args)
    {
        WaveInEvent waveIn = new WaveInEvent();

        int waveInDevices = WaveIn.DeviceCount;
        for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++)
        {
            WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
            Console.WriteLine("Device {0}: {1}, {2} channels", waveInDevice, deviceInfo.ProductName, deviceInfo.Channels);
        }

        string Reply = Console.ReadLine();
        inputdevicenumber = Convert.ToInt32(Reply);

        NAUDIO_Capture();
        NAudio_Play();

        Console.ReadKey();

    }

    static void NAUDIO_Capture()
    {
        WaveInEvent waveIn = new WaveInEvent();

        waveIn.BufferMilliseconds = 20;
        waveIn.DeviceNumber = inputdevicenumber;
        waveIn.WaveFormat = waveformat;
        waveIn.DataAvailable += new EventHandler<WaveInEventArgs>(waveIn_DataAvailable);
        waveIn.StartRecording();
    }

    static void NAudio_Play()
    {
        bufferedWaveProvider.DiscardOnBufferOverflow = true;
        waveOut.Init(bufferedWaveProvider);
        waveOut.Play();
    }

    static void waveIn_DataAvailable(object sender, WaveInEventArgs e)
    {
        bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
    }
}

1 个答案:

答案 0 :(得分:0)

查看NAudio WPF演示中的Equalizer类,了解如何使用Date dateObject = new Date(yourTimeInMilliseconds);类来应用过滤器。