gpt4 book ai didi

wpf - NAudio低通滤波器

转载 作者:行者123 更新时间:2023-12-02 23:06:34 25 4
gpt4 key购买 nike

我编写了捕获麦克风音频,然后通过扬声器播放音频的代码。我想在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);
}
}

最佳答案

看看NAudio WPF演示中的 Equalizer 类,看看如何使用BiQuadFilter类应用过滤器。

关于wpf - NAudio低通滤波器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42683570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com