Resampling MP3

Jan 29, 2011 at 6:43 PM

Hello,

i want to open mp3 files, change the sample rate and finally read all the (wave) sample data into a byte array.

I tried the ResamplerDmoStream and the WaveFormatConversionStream.

None of them worked.

 

First Attempt with a WaveFormatConversionStream; It just gives me zeros in the resulting byte array:


WaveFormat outputFormat = new WaveFormat(44100, 16, 2); using (var mp3 = new Mp3FileReader("test.mp3")) using (var pcm = new WaveFormatConversionStream(outputFormat, mp3)) { byte[] bytes = new byte[pcm.Length]; pcm.Read(bytes, 0, (int)pcm.Length); }


The second attempt gives me a StackOverflowException:

WaveFormat outputFormat = new WaveFormat(44100, 16, 2);
using (var mp3 = new Mp3FileReader("test.mp3"))
using (var pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
using (var resampler = new ResamplerDmoStream(pcm, outputFormat))
{
                byte[] bytes = new byte[resampler.Length];
                resampler.Read(bytes, 0, (int)resampler.Length);
}

How would you solve this?

 

Regards

Jochen

Jan 31, 2011 at 3:18 PM

Got it working with attempt number 1. I didn't change code, my test mp3 had a little too much silence in the beginning.

 

What's the performance of the WaveFormatConversionStream, is it maybe slower than ResamplerDmoStream?

 

Regards

Coordinator
Feb 1, 2011 at 9:01 AM

I don't know what the performance difference is. I would expect them to be roughly similar. WaveFormatConversionStream uses the ACM codec, and ResamplerDmoStream uses the DMO object.

Mark