FormatException: Not a recognised MP3 block

Feb 8, 2009 at 9:37 PM
Hello,

i'm using NAudio SVN version, and i must say that this is an excellent .NET Audio library and that ih has a lot of potential.
So, thank you Mark for doing all this!

In view of my experience, i'm not sure when this should be Vista (+) specific, or not, but i noticed some glitches where i must use sepparated code for XP.
(CoreAudioApi.MMDevice -> WaveLibMixer @http://www.codeproject.com/KB/audio-video/AudioLib.aspx)
I know, XP is going off from the market, but there are still lot's of users using it.

Okay, now something about the problem:
In most cases the library is working fine, but on some MP3's there is an exception: "Not a recognised MP3 block" (NAudio.Wave.Mp3Frame.Mp3Frame).
I don't know if this is a bug or not, but i do know that FMOD and BASS24 solved that problem (and that kind of MP3 can be played well on Winamp, Windows Media Player etc.).

P.S.:Of course, i could use BASS24 (or FMOD) for my application as they offer using the library for non-commercial use, but in that case they also obligate user to watch the splash screen (bass24) for a second - and this is why i like your library - open source. :)
Coordinator
Feb 9, 2009 at 11:24 AM
hi there,

the MP3 frame parsing code was knocked up pretty quickly and I'm not surprised it doesn't cover everything. If perhaps you could upload a sample MP3 file somewhere (preferably not something copyrighted) I will see if I can investigate what the unrecognised data is.

Mark
Feb 9, 2009 at 12:07 PM
I uploaded 2 songs.

The first is copyrighted and will be removed within 24 hours.
The second one shouldn't be copyrighted but will be removed too.

The links are:
for: acm not possible calling acm streamconvert mp3 (one fresh 'bug'): http://www.4shared.com/file/85223049/e82a9642/acmnotpossiblecallingacmstreamconvert.html

Thanks
Coordinator
Feb 11, 2009 at 9:31 PM
thanks, I've downloaded them. I'll use them to test next time I get the time to work on the MP3 frame reader
Jun 11, 2009 at 6:17 PM

I had the same problem, mp3 can wrap a RIFF file, so the header block is 'RIFF', if one just skips to the data it is a valid mp3 block and can be played out. To fix this I add the following code to Mp3Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<font size="2">

 

</font>

 

 

public Mp3Frame(Stream input)

{<font size="2">

 

</font>

 

BinaryReader reader = new BinaryReader(input);<font size="2">

 

</font>

 

// try for a header

<font size="2">

 

</font>

 

 

long headerStartPosition = input.Position;<font size="2">

 

</font>

 

byte[] headerBytes = reader.ReadBytes(4);<font size="2">

 

</font>

 

// Added -jam to play wrapped mp3 files via RIFF

<font size="2">

 

</font>

 

 

if ((headerBytes[0] == 'R') &&<font size="2">

(headerBytes[1] ==

</font>

'I') &&<font size="2">

(headerBytes[2] ==

</font>

'F') &&<font size="2">

(headerBytes[3] ==

</font>

'F'))

{

<font size="2">

 

</font>

// Backup 4 bytes

input.Position -= 4;

<font size="2">

 

</font>

 

 

// Now start parsing WAVE file

<font size="2">

 

</font>

 

 

WaveFormat format;<font size="2">

 

</font>

 

long dataChunkPosition;<font size="2">

 

</font>

 

int dataChunkLenght;<font size="2">

 

</font>

 

var chunks = new List<RiffChunk>();<font size="2">

 

</font>

 

WaveFileReader.ReadWaveHeader(input, out format, out dataChunkPosition, out dataChunkLenght, chunks);

 

<font size="2">

 

</font>

 

// Now read the actual mp3 header

input.Position = dataChunkPosition;

headerBytes = reader.ReadBytes(4);

}

 

.... continue with code

Jun 11, 2009 at 6:18 PM

Sorry, didn't realize html didn't work

        public Mp3Frame(Stream input)
        {
            BinaryReader reader = new BinaryReader(input);
            // try for a header
            long headerStartPosition = input.Position;
            byte[] headerBytes = reader.ReadBytes(4);

            // Added -jam to play wrapped mp3 files via RIFF
            if ((headerBytes[0] == 'R') &&
                (headerBytes[1] == 'I') &&
                (headerBytes[2] == 'F') &&
                (headerBytes[3] == 'F'))
            {
                // Backup 4 bytes
                input.Position -= 4;

                // Now start parsing
                WaveFormat format;
                long dataChunkPosition;
                int dataChunkLenght;
                var chunks = new List<RiffChunk>();

                WaveFileReader.ReadWaveHeader(input, out format, out dataChunkPosition, out dataChunkLenght, chunks);
               
                // Now read the actual mp3 header
                input.Position = dataChunkPosition;
                headerBytes = reader.ReadBytes(4);
            }

Coordinator
Jul 2, 2009 at 7:23 PM

thanks for this. your fix will go into a version of NAudio soon

Mark

Oct 17, 2009 at 12:06 AM

Hi all,

Just wanted to mention that (upper) problems are still present, so anybody who are willing to help are welcome!

Test song (for the second, "acm" problem) can be downloaded here: http://www.4shared.com/file/141403711/3d44bb7/testmp3_banshee_dummy_song.html

Cheers

Sep 19, 2010 at 8:02 AM

The problems are still present. Noboby has worked on it ?