2017-03-08 251 views
0

我編寫了捕獲麥克風音頻的代碼,然後通過揚聲器播放音頻。我想在e.Buffer byte []上實現一個低通濾波器來減少麥克風的噪音。NAudio低通濾波器

一些背景:我打算用這個代碼來創建一個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); 
    } 
} 

回答

0

看看在n音訊WPF演示的Equalizer類就看你怎麼可以使用BiQuadFilter類應用過濾器。