Hi all
        spent a little bit of time fiddling around with quantize().  [I really
should be marking papers :/  ]
        Sped the quantize routine up by about 15% on my p166/mmx. Just a fiddle
with pointers. Not sure if this will be a speedup across different cpus. Still
takes up far too much time though.  The lame quantize routine takes more time
than the whole xing encoder. :(
        Also, another speedup related to this one, but I'm out of programing
time:  in count_bits().  Simply move the check for ix[i]>(8191+14) into the
quantize() routine. Save a bunch of seconds :)  (see comment in code below)
   
The project is hurtling along!!
later
mike


-------------------
drop in quantize replacement 
---------------------
void quantize( double xr[576], int ix[576], gr_info *cod_info )
{
    register int b;
    int j;
    int i;

    int *ixp;
    double *xrp;

    double quantizerStepSize; /* double step */
    double istep_l,istep[3],temp;
    static int init=0;
#define LUTABSIZE 10000
    static int lutab[LUTABSIZE];
    if (init==0) {
      init++;
      for (i=0;i<LUTABSIZE;i++) {
        lutab[i]=nint(pow((double)i/10.0,0.75)-0.0946);
      }
      for (i=1;i<LUTABSIZE;i++) 
        if ((lutab[i]-lutab[i-1])==1) {  /* we have a change over this interval
*/
          lutab[i-1]=-1;
        }
    }
    quantizerStepSize = cod_info->quantizerStepSize;
    /* if subblock gain is used (short blocks), this should be: */
    /* step = pow( 2.0, (quantizerStepSize - 8.0 * (double)
cod_info->subblock_gain[b]) * -0.25 ); */
    /* step = pow( 2.0, quantizerStepSize * -0.25) * 
       pow( 2.0, 2*(double) cod_info->subblock_gain[b]) */
    if ( quantizerStepSize == 0.0 )
        istep_l = 1.0;
    else
        istep_l = pow ( 2.0, quantizerStepSize * -0.25 );
    for (b=0;b<3;b++) {
      if ((cod_info->block_type==2))
        istep[b] = istep_l * pow(2.0,2* (double) cod_info->subblock_gain[b]);
      else istep[b] = istep_l;
    }

    ixp = ix;
    xrp = xr;
    for (j=0;j<192;j++) 
      for (b=0;b<3;b++) {
        temp=istep[b]*fabs(*xrp++); /* step always positive -> temp always
postive */
        *ixp = 0;
        if (temp<0.499996)
          *ixp++;
        else {
          (*ixp)++;
          if (temp<1.862955)
            *ixp++;
          else {
            (*ixp)++;
            if (temp<3.565282)
              *ixp++;
            else {
              (*ixp)++;
              if (temp<5.506396)
                *ixp++;
              else {
                (*ixp)++;
                if (temp<7.638304)
                  *ixp++;
                else {
                  (*ixp)++;
                  if (temp<9.931741)
                    *ixp++;
                  else
                    if (temp<1000.0) {
                      *ixp = lutab[(int)(temp*10.0)];
                      if (*ixp < 0.0) /* too close to an interface, calculate
exact value */  
                        *ixp++ = (int)( sqrt(sqrt(temp)*temp) + 0.4054);
                      else
                        *ixp++;
                    }
                    else
                      *ixp++ = (int)( sqrt(sqrt(temp)*temp) + 0.4054); 
                        /* 
                                Here is where you could put in the check for
                                ix[i]>8191+14 . (or temp > 139000)
                                and remove it from countbits.  As soon as 
                                this value was found, terminate quantize and
                                choose a new stepsize and start again. Which
                                is basically what the first part of countbits
                                does anyway */
                }
              }
            }
          }
        }
      }
}
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to