>Hi Juha,
>
>> By changing the binary_search algorithm used in bin_search_StepSize
>> a major speed up can be achieved.
>>
>
>How about a patch for LAME?
He're is a quickie, eh. But; it might be wise to drop the whole
inner_loop
and replace it with the binary_search version. Might get an other 10-20%
off.
The original binary_search gives always odd numbered results and uses 8
iterations. This one takes on most cases 4 and gives precise results.
It shouldnt affect on quality thougth, because it's used as a start for
iteration later.. If I've got it right - you just might want to use the
binary_search version for the inner_loop too, which would give some
extra
speed-up, like 10 - 20 % of total time.
Here's the timing results from quantify with applode.wav:
(the times are much slower than without quantify)
With my PII350 and VC6.0 optimized encoding was like 1.6x the original.
Original Lame 3.10
.Root. 4017634.99 usec 100.00%
outer_loop 2356395.31 usec 58.65%
bin_search_StepSize 611351.57 usec 15.22%
JHL_BINSEARCH:
.Root. 3689127.73 usec 100.00%
outer_loop 2015472.84 usec 54.63%
bin_search_StepSize 270171.73 usec 7.32%
Total speed up is something like 10%... But it's *not* 100% ISO
complient
change, even thought my guess the changes are almost none.
#ifdef JHL_BINSEARCH
static int OldValue = -30; /* guess it or so.
typedef enum {
BINSEARCH_NONE,
BINSEARCH_UP,
BINSEARCH_DOWN
} binsearchDirection_t;
/*----------------------------------------------------------------------
------*/
int
bin_search_StepSize(int desired_rate,
double start,
int bot,
int *ix,
double xrs[576],
double xrspow[576],
gr_info *cod_info)
/*----------------------------------------------------------------------
------*/
{
int flag_GoneOver = 0;
int CurrentStep = 4;
int nBits, Counter = 0;
int StepSize = OldValue;
binsearchDirection_t Direction = BINSEARCH_NONE;
do
{
cod_info->quantizerStepSize = StepSize;
if (xrpow_flag)
{
quantize_xrpow(xrspow, ix, cod_info);
}
else
{
quantize(xrs, ix, cod_info);
}
nBits = count_bits(ix, cod_info);
if (CurrentStep == 1 || Counter > 50)
/* the 50 is for ''lock-up'' - havent found any.
*/
{
break; /* nothing to adjust anymore */
}
if (flag_GoneOver)
{
CurrentStep /= 2;
}
if (nBits > desired_rate) /* increase Quantize_StepSize */
{
if (Direction == BINSEARCH_DOWN && !flag_GoneOver)
{
flag_GoneOver = 1;
CurrentStep /= 2; /* late adjust */
}
Direction = BINSEARCH_UP;
StepSize += CurrentStep;
}
else if (nBits < desired_rate)
{
if (Direction == BINSEARCH_UP && !flag_GoneOver)
{
flag_GoneOver = 1;
CurrentStep /= 2; /* late adjust */
}
Direction = BINSEARCH_DOWN;
StepSize -= CurrentStep;
}
else break; /* nBits == desired_rate;; most unlikely to happen.
*/
} while (1); /* For-ever, break is adjusted. */
OldValue = StepSize;
return nBits;
}
#else
int bin_search_StepSize(int desired_rate, double start, int bot, int
*ix,
double xrs[576], double xrspow[576], gr_info * cod_info)
{
int top,next,last;
int bit;
top = start;
next = start;
do
{
last = next;
next = (top+bot)/2.0;
cod_info->quantizerStepSize = next;
if (xrpow_flag) {
quantize_xrpow(xrspow,ix,cod_info);
} else {
quantize(xrs,ix,cod_info);
}
bit = count_bits(ix,cod_info);
if (bit>desired_rate) top = next;
else bot = next;
// printf("\n%f %f %f %f %d %d",start,next, top,bot,bit,desired_rate);
}
while ((bit != desired_rate) && abs(last - next) > 1);
//printf("\n done %f %d %d",next,bit,desired_rate);
return bit;
}
#endif
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )