>>>Iterative deepening, doubling the backup each time would seem in
>>>order.  That way you're guaranteed that >50% of the time you spend in
>>>backup isn't `wasted'.
>> 
>> This kind of guesswork shouldn't be necessary.  The size of the 'bit
>> reservoir' (a back-pointer into previous frames) is given exactly by the
>> "main_data_begin" field that appears in the "side info" structure that
>> immediately follows the 4-byte MPEG audio header.
>
>It doesn't help. For the first frame this number is 0, then for all
>subsequent frames the number of greater than 0. That doesn't help to
>find the point to break the stream.

Robert,

I may have misunderstood what you're wanting to do, but I *thought* you
were wanting to know how far back to go from the start of a given frame, in
order to allow for the MP3 decoder's internal 'bit reservior'.   It turns
out that the "main_data_begin" field gives you this information.

If this is what you're wanting to do, then the following pseudo code
calculates how many frames back from the current frame you need to go, to
ensure that the bit reservoir will have enough data for the current frame
to be decoded:

int reservoirSize = currentFrame->side_info.main_data_begin;
frame = currentFrame;
while (reservoirSize > 0) {
        frame = previousFrame(frame); // go back one frame
        unsigned encodedDataInFrame = frameSize(frame)
                - 4 /*MPEG header size*/
                - 2*(isCRCpresent(frame))
                - sideInfoSize(frame);
        disableFrame(frame);
        reservoirSize -= encodedDataInFrame;
}
start decoding from 'frame';

Note:
sideInfoSize() is
        - 32 bytes for MPEG 1 stereo
        - 17 bytes for MPEG 1 mono, or for MPEG 2 stereo
        - 9 bytes for MPEG 2 mono

The tricky part is the "disableFrame()" operation.  This modifies the 'side
info' structure of each previous frame, so that the MP3 decoder will not
attempt to play *it*.  This operation can be implemented by:
- setting the frame's "main_data_begin" to zero, and
- setting all of the frame's "part2_3_length" and "big_values" fields to zero

(Note that you do this only for the *previous* frames - the ones that get
used to fill the bit reservoir of the current frame.)

        Ross.

Reply via email to