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

Convert RAW to (WAV to) MP3?

Sep 17, 2014 at 1:02 AM
Hello dear guys,
I am sitting here for 4 hours now and can't figure out how to solve this.
I have a RAW (PCM) audio stream and already got it working to convert it to wav format with the following code:

private FileStream rawstream= .....
rawstream.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[rawstream.Length];
rawstream.Read(buffer, 0, buffer.Length);

using (WaveFileWriter writer2 = new WaveFileWriter(pFile + ".wav", mWaveFormat))
 writer2.Write(buffer, 0, buffer.Length);

I have also read most of the following article:

There is mentioned that some conversion from PCM to MP3 is possible:
using(var reader = MediaFoundationReader("somefile.mp3"))
MediaFoundationEncoder.EncodeToWma(reader, "encoded.wma", 192000);

But when I try to create a MediaFoundationReader the class can't be found.
Furthermore I don't know if it takes a normal Stream as input anyway.

Something like this exists:
MediaFoundationEncoder.EncodeToMP3(reader, "encodedmp3", 192000);

But I also can't convert my "normal pcm stream" to a type that the EncodeToMP3 method would accept it.

Could you please help me and give me a small tip where my failure is?
Or am I totally wrong and can't convert PCM to MP3 with NAudio?

Thank you very much.
Sep 18, 2014 at 11:45 AM
I sadly still didn't get further. Does nobody have an idea?