MP3 detection in SDL_Mixer (was Appending resources to .exe)

But since Andre said he’s using on-the-fly decompression using bzip2, I
assumed that he ends up with one memory block for each logical file, and
creates one SDL_RWops structure for each of them, with the correct start
and ending. If not, that’s how it should be done.

Actually it’s really on-the-fly, I don’t decompress a “logical file” to a memory block and then setup a memory RWops to read it; decompression is made as bytes are read from the RWops. I took a look at music.c from SDL_Mixer and the test for MP3 files relies on the file extension or to the two first bytes of the file:

if ( (ext && MIX_string_equals(ext, "MPG")) ||
     (ext && MIX_string_equals(ext, "MP3")) ||
     (ext && MIX_string_equals(ext, "MPEG")) ||
     (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) ) {

I took a look at some MP3 files I have and all of them start with the same eight characters: ID3\3\0\0\0\0

It is straight forward to add this test to music.c, but does anyone know if this is correct and how many characters should be tested (i.e. eight or just the first three…)?

Cheers,

Andre

Andre de Leiradella escreveu:

I took a look at some MP3 files I have and all of them start with the same eight characters: ID3\3\0\0\0\0

It is straight forward to add this test to music.c, but does anyone know if this is correct and how many characters should be tested (i.e. eight or just the first three…)?

On my system, `file’ identifies MP3 files with:—

MP3, M1A

0 beshort&0xFFFE 0xFFFA MPEG ADTS, layer III, v1

and


MP3, M2A

0 beshort&0xFFFE 0xFFF2 MPEG ADTS, layer III, v2

and


MP3, M25A

0 beshort&0xFFFE 0xFFE2 MPEG ADTS, layer III, v2.5

and


ID3 version 2 tags

0 string ID3 MP3 file with ID3 version 2.

For those file-magic-impaired:
“0” means the offset being tested.
“beshort” means to test 2 bytes, interpreting as a big-endian value
"&0xhhhh" means to mask the value with 0xhhhh
The value in the third column is the value that needs to be matched.

So if you want to support MP3 files without ID3 tags, you need to do
more tests.


Daniel K. O.

On my system, `file’ identifies MP3 files with:


MP3, M1A

0 beshort&0xFFFE 0xFFFA MPEG ADTS, layer III, v1

and


MP3, M2A

0 beshort&0xFFFE 0xFFF2 MPEG ADTS, layer III, v2

and


MP3, M25A

0 beshort&0xFFFE 0xFFE2 MPEG ADTS, layer III, v2.5

and


ID3 version 2 tags

0 string ID3 MP3 file with ID3 version 2.

For those file-magic-impaired:
“0” means the offset being tested.
“beshort” means to test 2 bytes, interpreting as a big-endian value
"&0xhhhh" means to mask the value with 0xhhhh
The value in the third column is the value that needs to be matched.

So if you want to support MP3 files without ID3 tags, you need to do
more tests.

The first two cases, 0xFFFA and 0xFFF2 are already handled by SDL_Mixer,
notice the last comparison in the code inside music.c:

if ( (ext && MIX_string_equals(ext, "MPG")) ||
     (ext && MIX_string_equals(ext, "MP3")) ||
     (ext && MIX_string_equals(ext, "MPEG")) ||
     (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) ) {

The third case, 0xFFE2, can be easily added, and also the fourth case,
“ID3”.

I’ll grab the latest magic file from ftp://ftp.astron.com/pub/file/ when
I get some spare time and update the MP3 file detection code of SDL_Mixer.

Cheers,

Andre