On Thu, Aug 16, 2007, John Joyce wrote:
> Yeah, I read that already. Seemed simple. Many file descriptions are  
> readable, but the MP3 one is one of many that don't make sense to me.  
> " Numeric types can be specified with &0xnnnn, where the
> >number is ANDed with the magic."
> Makes no sense to me at all. I'm not a C person really.

That's not a C thing, that's just general math.

> >># MPEG 1.0 Layer 3
> >>0       beshort&0xfffe  =0xfffa         \bMP3
> So what does the above mean??
> I see hex numbers. but what is that '=' doing ?

Okay, from left to right:

0: that's the offset.  It means the magic starts at byte 0

beshort&0xfffe: the magic is a big-endian short (2bytes), and you should
take the value you get from the file and AND it with 0xfffe

=0xfffa: this is what you're looking for

\bMP3: this is what file will print if it matches this magic.

> That's cryptic.

Sure, but it's all explained in the man page.

> The other lines after that make sense. They all describe the second  
> byte and that it determines the bitrate.
> so do I care about 0xfffe? or 0xfffa?
> or both?

Yes, that's the magic.

> I'm hoping I'm doing this right.

If your script is correctly identifying MP3 files you're using as a
control, then you're probably doing it just fine :)

One thing to be careful of is that there are multiple definitions of
what an MP3 looks like (at least, there are in my magic file).  For
instance, MP3s with an ID3v2 tag will start with "ID3" instead of the
magic described above.

Make sure you search through your whole magic file for any given type
before you commit to writing code for it.  You might find exceptions or
easier cases.

Cheers,
Ben