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

Problems reading from compressed WAV files

Jun 26, 2014 at 3:16 PM
Edited Jun 26, 2014 at 3:31 PM
I'm trying to write a converter from a compressed WAV (format is unknown at ingest) to output a PCM 44.1-16 stereo WAV. I've tried using Mp3FileReader, but when I write the file back it has no data, only the RIFF and fmt headers. Trying to read it via WaveFileReader and AudioFileReader and they throw a NoDriver calling acmFormatSuggest exception. Opening the source file in Windows Media Player causes it to play, so I do have a good codec on my machine.

Mp3FileReader method:
//sourceFile is the input to the next section
string originalFile = chunk._SourceFN;
                    sourceFile = Environment.ExpandEnvironmentVariables("%TEMP%") + @"\resampled.wav";
                    WaveFormat outFormat = new WaveFormat(44100, 16, 2);

using (var reader = new Mp3FileReader(originalFile))
                        WaveFileWriter.CreateWaveFile(@"c:\temp.wav", reader);
                        using (var resampler = new MediaFoundationResampler(reader, outFormat))
                            resampler.ResamplerQuality = 60;
                                WaveFileWriter.CreateWaveFile(sourceFile, resampler);
                                conversion.Add("Converted " + originalFile);
                            catch (Exception e)
                                sourceFile = "";
                                DeleteLog.Add("Could not convert " + originalFile + " to 44.1 16bit stereo wave");
                                DeleteLog.Add("Error " + e.ToString());

using (var reader = new AudioFileReader(originalFile))
                        var resampler = new WdlResamplingSampleProvider(reader, 44100);
                        WaveFileWriter.CreateWaveFile16(sourceFile, resampler);
Jun 30, 2014 at 5:34 PM
Jun 30, 2014 at 6:37 PM
you have to know what the format of the incoming file is to be able to do anything with it. If it's a WAV file, the compression type will be indicated in it's WAVEFORMAT structure. Open it with WaveFileReader and examine the WaveFormat to see what you have. You can only decompress if you have the right codec installed.