What is the easiest way to convert a compressed wav file to an uncompressed wav file in C# or C++?

StackOverflow https://stackoverflow.com/questions/461773

Question

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.

Was it helpful?

Solution

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);
    }
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top