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

Convert X to Y

Feb 4, 2014 at 7:43 PM
Edited Feb 4, 2014 at 10:37 PM
I would like to convert any (supported ofcourse) audio format I can throw at NAudio to any (supported ofcourse) audio format NAudio can write. So I might throw a wavefile, mp3 or aiff file at it, specify the output filename and some parameters (samplerate, bit depth, channels) and have NAudio do the heavy lifting / figure out what to do exactly.

There is an AudioFileReader which is supposed to read all supported filetypes but there is no AudioFileWriter, is there?

I guess I need to read the input, convert it to "raw audio" at the input's samplerate/bits/channels and then output it thru some writer? I assume I would need the WaveFormatConversionStream for this?

Because my input and desired output are specified by the user I don't want to have all kinds of ConvertXXXToYYY() methods but one method that handles the conversion. I was hoping something along the lines of:
public function Convert(string inFile, string outFile, Format waveFormat) {
    using (var reader = new AudioFileReader(inFile))
    using (var resampler = new WaveFormatConversionStream(waveFormat, reader))
        AudioFileWriter.CreateFile(outFile, resampler);
(This is just a mockup). Is it possible to achieve this without writing lots of code?
Feb 7, 2014 at 3:33 PM
Have a look at the MediaFoundationEncoder class and where it is used in the sample apps in the NAudio source.