[mad-dev] Rewinding with the high-level API

Joe Drew hoserhead@woot.net
20 Sep 2001 21:25:41 -0400


On Thu, 2001-09-20 at 20:16, Andy Lo-A-Foe wrote:
> On Thu, Sep 20, 2001 at 07:39:39PM -0400, Joe Drew wrote:
> > At this point, I've implemented an array of pointers to each of the
> > frame boundaries (which I calculate, since the high-level API doesn't
> > give me this information), and I know very easily how to fast-forward
> > through an mp3 (that is, just skip frames.)
> 
> Do you have a formula that does this accurately? For example for a 128
> Kbit stream a frame is sometimes 417 and other times 418 bytes long
> (padding?). For my application I need to jump to to the exact frame number, 
> preferable without walking through the headers of each file (to build
> up the frame index).

I don't know if it's accurate - I haven't been able to test it yet - but
my algorithm is this:

frame(n) = frame (n-1) + (header->bitrate / 100)
        * mad_timer_count(&header->duration, MAD_UNITS_CENTISECONDS);

You might try changing that to /1000 and MAD_UNITS_MILLISECONDS, but I
don't know how that will affect it. As I said, I haven't been able to
test this yet - it remains to be seen how well it will work. 

I build up the frame index during playtime, when the header_func is
called.

-- 
Joe Drew <hoserhead@woot.net> <drew@debian.org>

Please encrypt email sent to me.