views:

614

answers:

2

What is the easiest way to programatically convert a compressed wav file (MPEG codec for example, but could be any installed codec) to an uncompressed wav file (16 bit PCM)?

I've heard that using direct show and writing the code in native C++ would do it, but I've not had much experience with direct show.

Is there an easier way to do this? C# that would be ideal, but C++ would also be fine too.

+2  A: 

DirectShow is probably the best way to do the decoding, assuming we're talking about Windows. DirectShow is a COM API, so you could write native C++ COM code, you could use one of the available DirectShow .Net wrappers or you could use C++/CLI. Which one you choose depends on the rest of your application architecture - if you need to use .Net then C++/CLI is definitely the easiest route. You really need to be a bit more specific about what you're trying to achieve - for example, MPEG itself is not a codec - they just define standards.

Stu Mackellar
+2  A: 

You can decompress WAV files in C# using any ACM codec installed on your PC using NAudio. Here's some sample code:

using (WaveFileReader reader = new WaveFileReader(inputFileName))
{
    using (WaveStream convertedStream = 
        WaveFormatConversionStream.CreatePcmStream(reader))
    {
        WaveFileWriter.CreateWaveFile(outputFileName, convertedStream);
    }
}
Mark Heath