This project has moved and is read-only. For the latest updates, please go here.

Convolution

Mar 21, 2015 at 2:25 PM
Edited Mar 22, 2015 at 11:42 PM
Are there any examples for convolution in NAudio? How to use the class ImpulseResponseConvolution?

EDIT:
Do I have to create two AudioFileReaders (sound and impulse reaction), read them both into float array buffers and pass them into the Convolve function to get the convolved float array back?
Mar 23, 2015 at 7:48 PM
Ok. I've got convolution to "work". It's really slow through / unusable for samples longer than few seconds because of that. Or maybe its because of AudioFileReader reading the whole file into memory.

I've used 2x AudioFileReader for the sound and the impulse response.

Then I've made two float arrays for those with a fixed size of 88200 (first 2 seconds of the sound) and 44100 (the size of the impulse response).

I wrote the convolution to another float array (convolution result) and then
writer.WriteSamples(convolutionResult, 0, 88200);
out to a file.

The sample is weird through. Sounds amplified its 4 seconds in length instead of 2 (88200). Something wrong with the float array sizes?
Apr 13, 2015 at 4:48 PM
The ImpulseResponseConvolution is one of the oldest bits in NAudio, and to be honest, it should probably be removed from the library. It doesn't really handle the issues around mono / stereo impulses and inputs. And I have a feeling that most commerical software that does convolution does it all in the frequency domain (FFT first, convolve, then inverse FFT).