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

does naudio provides more methods to decode mp3?

Apr 18, 2011 at 8:23 AM

how many and which methodes provides naudio the decode mp3. Is there only the "WaveFormatConversionStream.CreatePcmStream(Mp3FileReader)" or are there a few other?

Apr 18, 2011 at 8:36 AM

NAudio also includes a wrapper for the DMO MP3 Decoder (with the latest NAudio code you can see easily how to swap out MP3 frame decoders). Also, I created NLayer here on codeplex, a fully managed MP3 decoder. Sadly it can't be incorporated fully into NAudio due to the licenses being incompatile.

Apr 18, 2011 at 8:50 AM

ok thanks i found another class and changed it to public you may take a look on this:(it is because of the networkstreaming you remember?)

            byte[] buffer = new byte[100]; //The mp3Buffer i recive from the network from the
            byte[] OutPutBuffer = new byte[100]; //The OutputBuffer
            Mp3Frame mp3frame = new Mp3Frame(new MemoryStream(buffer)); //Put the mp3buffer from network in the mp3frame
            AcmMp3FrameDecompressor mp3framedec = new AcmMp3FrameDecompressor(new WaveFormat()); //inzialize a new instance of the decoder
            mp3framedec.DecompressFrame(mp3frame, OutPutBuffer, 0); //decode



could this BASICLY work?

And sorry about my english i am really bad in english... so I may be inpolite or do many mistakes but i am doing my best :D

Apr 18, 2011 at 9:47 AM

Naudio may a wrapper for MPG123 decoding too, that is a much faster and better sound qaulity mp3 decoder
Now they provide the CLR version already for C#

Apr 18, 2011 at 10:26 AM

hmm but i am not searching 4 something ... 1. i want to do something on my on ( its fun :D) and 2. i don t want to have a console open D:

Apr 18, 2011 at 10:28 AM

yes, the basic idea should work, although those buffer sizes will probably need tweaking

Apr 18, 2011 at 11:49 AM
Edited Apr 18, 2011 at 11:50 AM

ok but don t worry the buffersize of 100 is just a sample. In real it is 418(frame.length). But i have 2 more questions: I always get an error on this line:

mp3framedec.DecompressFrame(mp3frame, OutPutBuffer, 0); //decode

The Error:

Couldn't convert the whole MP3 frame

because of this:

sourceBytesConverted != frame.FrameLength

So why?


And 2nd question:

How can i convert the bytes to a waveprovider to use the WaveOut or which class/Interface... what ever should i use to play in the end?

Apr 18, 2011 at 11:55 AM

that's strange. can you play the MP3 file using NAudio demo?

2nd question: use BufferedWaveProvider

Apr 18, 2011 at 4:40 PM

i don t use a mp3file :D its an mp3stream. From network --> it is live radio.

Apr 18, 2011 at 5:08 PM

What are the values of sourceBytesConverted and frame.FrameLength? Are you sure your dest buffer is big enough?


Apr 21, 2011 at 7:21 PM

i ve changed a little part of your libary:


 throw new InvalidOperationException("Couldn't convert the whole MP3 frame" + sourceBytesConverted.ToString() + " / " + frame.FrameLength);


that comes out: Couldn't convert the whole MP3 frame416 / 418

and here is again my whole code for this test:


            const string url = "";

            var response = WebRequest.Create(url).GetResponse();
            using (var stream = response.GetResponseStream())
                byte[] buffer = new byte[418];
                byte[] OutPutBuffer = new byte[416];
                stream.Read(buffer, 0, buffer.Length);
                Mp3Frame mp3frame = new Mp3Frame(new MemoryStream(buffer));
                AcmMp3FrameDecompressor mp3framedec = new AcmMp3FrameDecompressor(new WaveFormat());
                mp3framedec.DecompressFrame(mp3frame, OutPutBuffer, 0);
                WaveOut o = new WaveOut();


Apr 21, 2011 at 7:46 PM

you need a much bigger output buffer. MP3 is a compressed format, PCM is uncompressed. Pass in an output buffer of 4196 bytes

Apr 22, 2011 at 10:30 AM

oh yeah your right sorry what a silly problem of me. i was ill so may my brain was a bit confused :D


but thanks :)
i will try

Apr 25, 2011 at 12:20 PM

ok that was one problem but there is stil the same problem.
Here is a screen of the problem

Apr 25, 2011 at 1:09 PM

ok, not sure why only 416 bytes are converted. It might be you have a different MP3 ACM codec installed. Or maybe NAudio is not correctly calculating the frame length and it is only 416 bytes. What happens if you comment out the exception? Can you play the file to the end?

Apr 25, 2011 at 1:46 PM

i can t test it because i have to finish the algorithm to stream a internet radio. Thats the problem but do you think it might be a problem?

Apr 25, 2011 at 3:49 PM

Stream some of the internet radio into a local file. Save it with an mp3 extension and see if the NAudio demo can play it. (also see it Windows Media Player can)

Apr 25, 2011 at 6:30 PM

ok what I know exactly is that the mp3 files are working(if i save them). I ve written a programm 4 recording the radio some time ago. And the files worked. But I m can t do play that frame 4 frame:


byte[] buffer = new byte[418];
                byte[] OutPutBuffer = new byte[4196];
                BufferedWaveProvider prov = new BufferedWaveProvider(new WaveFormat());
                AcmMp3FrameDecompressor mp3framedec = new AcmMp3FrameDecompressor(new WaveFormat());

                prov.DiscardOnBufferOverflow = true;

                new System.Threading.Thread(delegate(object o)
                    while (true)
                        stream.Read(buffer, 0, buffer.Length);
                        Mp3Frame mp3frame = new Mp3Frame(new MemoryStream(buffer));
                        mp3framedec.DecompressFrame(mp3frame, OutPutBuffer, 0);
                        prov.AddSamples(OutPutBuffer, 0, OutPutBuffer.Length);

                WaveOut wo = new WaveOut(WaveCallbackInfo.NewWindow());




I always get different errors

Apr 26, 2011 at 3:59 PM

Can the NAudioDemo play the MP3 files you saved though? We need to know if the MP3Frame decoding is getting the wrong frame length.

Apr 26, 2011 at 5:48 PM

ok what should i exactly do now? should i save frame 4 frame or just save the file on classic method means saving the responestream getting from network?

Apr 28, 2011 at 4:01 PM

Just save all the bytes that come back from the network into a .mp3 file. Then load NAudioDemo and see if it can play it. This will help narrow down where things are going wrong.