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

Andre de Leiradella leiradella at bigfoot.com
Fri Apr 6 21:12:16 PDT 2007


> 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 <waschk at informatik.uni-rostock.de>
> 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


More information about the SDL mailing list