This project has moved. For the latest updates, please go here.

Using a low-pass filter...

Apr 30, 2013 at 5:23 PM
Edited Apr 30, 2013 at 5:24 PM
Using NAudio I am capturing microphone samples in order to play them back on a remote machine. In some cases I'd like to apply a low-pass filter. How can this done with NAudio?

Ideally I would like to apply the filter based on end user input on the playback machine (maybe via a "enable/disable low-pass filter" button).

It appears as though I need to use...
var myFilter = BiQuadFilter.LowPassFilter (x, y, z);
myFilter.Transform (inBuffer, outBuffer);
However, it isn't clear how/where I insert this transformation prior to playback.
May 1, 2013 at 3:27 AM
This is more or less a guess, I'm sure there is a better way but this is what I would start with.
If you just need a stream of bytes to apply your filter to, you can capture them with WaveIn eventhandler to a MemoryStream then send it to myFilter.Transform as the inBuffer.

YourWaveIn.DataAvailable += WaveIn_DataAvailable;

MemoryStream ms = new MemoryStream();
 private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
//use WaveInEventArgs to write buffer to ms
//then send ms to some function that converts to float[]
//then send float[] to myFilter
May 3, 2013 at 3:15 PM
You'd need to pass the audio through a low pass filter. The route I would take is a BufferedWaveProvider, converted to a SampleProvider (i.e. go 32 bit), then through the BiQuad filter. I'm hoping that a future NAudio will make this a bit more straightforward to setup. but if you understand audio pipelines, you should be able to do this.