By changing the binary_search algorithm used in bin_search_StepSize
a major speed up can be achieved.

 The current implementation walks through the search space using:

(heavily simplified)

bin_search(desired_bits, top, bottom)
{
    do {
        middle = (top + bottom) / 2;
        bits = calculate_bits(middle);
        if (bits == desired_bits) break;  // most unlikely?
        else if (bits > desired_bits) top = middle;     // -> next try
range is from (bottom, middle)
        else                          bottom = middle;  // -> next try
range is from (middle, top)
    while (abs(top - bottom) > 1);
    return bits; // the true ''return value'' is the calculated quantize
table.
}

Usually, the (top - bottom) range is quite huge, the top value is hard
fixed to 200
and the bottom is approximated with the quantanf_init function.. and
than substracted
some 70 to make the check range even larger, range something between
256, 512 which
makes 9 iterations before final value.

 The point is, that in most cases the calculated value doesnt change so
much... even less
in a short time frame. By changing the algorithm so, that we get a good
guess (like the
middlepoint or so) or the previously calculated value (which seems quite
good) and than
use a directional delta value for the middlepoint. If the new guess goes
over the limit,
half and change the direction... and so.

 I succeeded quite well by using start delta 8 and last calculated value
as the start
point to achieve average iterations between (3 - 4) for music. That
drops the amount of
calculations done in bin_search_StepSize to 1/3... Just print the result
to see how
little it varies and how large the search range really is for it. I did
this but than
got a bit ancious and broke something while trying to implement this on
the inner_loop
and skip the whole initialization part.. 

 Another intresting thing is that what happends after this; the initial
value is calculated
by using the max_bits[ch] as the limit, but than the first inner_loop
gets 
max_bits[ch] - cod_info[ch]->part2_length.. And for that, inner_loop has
a loop for 
makeing the quantizer stepsize larger to makes bit counter less.. urgh.
why not use it for
the first time too?

 The calculated value is defined as a double but used as a interger..
But I'm quite sure
it doesnt affect much for the quality anyway, if any.

 - Juha Laukala
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to