> >Here's a nice bug..  lame 3.93 (and from the looks of it, every version
> >before it..) identifies files based purely on the friggin suffix of the
> >filename. World-class coding there, guys. (*chuckle*) .... Anyway, I've
> >managed to control my laughter long enough to post a note about it.
>
> There is no fool proof way to identify an mp3 file.

(..*snip* ....bullshit, btw.....*snip*..)


You can identify an MP3 file by calculating frame length ahead of time.
There are a fixed number of possible frame lengths which can occur in a
valid MP3 stream. If the stream fails to conform to any, its not an MP3.

Time to build an indentifier:

Before ANY conversion takes place, the stream should be checked for sanity.

Step 1) Parse the stream for a valid MP3 frame sync. Its simple, really.
Watch the stream and eject everything up until the first frame sync is
discovered.  Were not going to worry about whether or not the frames are
independent or not.  If you find a valid frame sync, go to Step 3.
Otherwise, go to Step 2.

Step 2) Stream is _probably_ not a valid MP3. To be certain about it, you
need to check all the possible permutations that sample rate/padding/bit
rate and layer type can yeild.. Sure, you can't determine what it _is_ (VBR
makes this impossible), but, you _can_ determine what it _isnt_ by using a
simple formula. Supposing you prepend a valid frame header onto the data.
You can then walk the stream for anything unusual:

if (type=L1) then frameLength  = 4*((bitRate*12)/sampleRate+pad)

else

frameLength = 144*((bitRate/sampleRate)+pad)

...So, even though the stream might be deformed, you can at least
distinguish and exclude it from processing by checking for predictable
events that happen every (frameLength) bytes.  Wav files sure as hell dont
have those characteristics. Anyhoo, if frame prediction fails, go to Step 4.
If it succeeds, rebuild the stream with corrected frame headers, rebuild
CRCs (if any), and go to Step 3.

Step 3) Allow the encoding to proceed, allowing for all the normal checks
which occur on the data. Go to step 4.

Step 4) Die.




_______________________________________________
mp3encoder mailing list
[EMAIL PROTECTED]
http://minnie.tuhs.org/mailman/listinfo/mp3encoder

Reply via email to