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

Resample frequency rate when doing MP3->WAV?

Mar 13, 2011 at 12:44 AM

Wow, this library has been incredibly handy in converting MP3's to WAV's.

When I convert from MP3 to WAV, however, is there a way to set the sampling frequency (e.g 48khz or 44.1khz)?

Mar 14, 2011 at 11:59 AM

You would have to do additional sample rate conversion after converting to WAV. You can use either the WaveFormatConversionStream (for ACM) or the DmoResamplerStream (if available on your OS).

Mark

Mar 19, 2011 at 8:41 PM

Hmmm...sounds simple enough...so I tried:

 

using (Mp3FileReader reader = new Mp3FileReader(cuePath))
{
   WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader);
   if (pcmStream.WaveFormat.SampleRate != 48000)
   {
      var format = new WaveFormat(48000, 16, pcmStream.WaveFormat.Channels);
      pcmStream = new WaveFormatConversionStream(format, pcmStream);
   }
   WaveFileWriter.CreateWaveFile(exportPath + "\\" + fileName, pcmStream);
}

But I get the error:

"A runtime error has occurred...

Line 694

Error: InvalidParameter calling acmStreamConvert"

 

It all seemed so simple...maybe I'm missing a step!

 

Thanks in advance for any help you can lend!

Mar 19, 2011 at 8:58 PM

And I also tried this:

Mp3FileReader reader = new Mp3FileReader(cuePath))
var format = new WaveFormat(48000, 16);
WaveStream pcmStream = new WaveFormatConversionStream(format, reader);
WaveFileWriter.CreateWaveFile(exportPath + "\\" + fileName, pcmStream);

 

But then it reports "AcmNotPossible calling acmStreamOpen"

Mar 21, 2011 at 6:11 PM

you have to convert in two stages - first to PCM, then to the sample rate you want.

Also, get the latest code from the source code tab as Mp3FileReader now returns data already in PCM so only one additional stage is required