hi!
first of all, consider that i'm no mp3-format guru.
just some things i have "stored in my memory at some time or the other".
so consider when reading this...
@all:
i'd suggest counting samples.
somehow one has to adjust for long/short frames.
or am i mistaken?
think not.
one could count short and long frames with 2 distinct counters,
or just count samples.
@Peter Piksa:
there are multiple frames!
only the paragraph
frame()
{
header()
error_check()
audio_data()
ancillary_data()
}describes only ONE frame.
they are simply smashed together to form the mp3-stream.
simple as that.
in the frame-header the length of the frame is encoded.
normally parsing an mp3 looks like...
1) look for the first frame-header-candidate (= look for 11x"1" bit-sequence, byte-aligned)
2) try to decode the frame - if it does not work out (i.e. if there are any severe errors, goto 1)
(if you are only interested in bitrate, bit-allocation or whatever then of course you don't need to
decode all the sample-values)
3) take the frame-size, and jump to the first byte after the current frame
4) goto 1
whenever you get "behind EOF" your done.
if you rely on too much things like the next frame starting immediately after the current one, or
that the bitrate encoded in the frame-header does not change or whatever,
you'll get poor compatibility with "broken" mp3s.
for a player you might want to account for "broken" frames (or anything you cannot decode) by repeating the last frame, substituting silence, or decoding an "average frame" between the last good and the next goot frame.
whatever.
-------------------
there are several things i don't exactly know:
* is the length encoded in the file somewhere?
* is there a time-code for seeking?
* if not, WHY not ? :'( (ok, just joking)
bye,
have a nice day,
--hustbaer