[speex-dev] speex_bits_pack optimizations...

Alfrédo Moreira alfredo.moreira at neolinks.com
Thu Jun 3 04:54:29 PDT 2004



another optimization you can do for packing bits together...

the original one is :
-------------------------------------------------------------------------------------------------------------
void speex_bits_pack(SpeexBits *bits, int data, int nbBits)
{
   int i;
   unsigned int d=data;

   if (bits->bytePtr+((nbBits+bits->bitPtr)>>3) >= bits->buf_size)
   {
       //remain unchanged....
   }

   while(nbBits)
   {
      int bit;
      bit = (d>>(nbBits-1))&1;
      bits->bytes[bits->bytePtr] |= bit<<(7-bits->bitPtr);
      bits->bitPtr++;

      if (bits->bitPtr==8)
      {
         bits->bitPtr=0;
         bits->bytePtr++;
      }
      bits->nbBits++;
      nbBits--;
   }
}

----------------------------------------------------------------------------------------------------------------
you can replace it by....
----------------------------------------------------------------------------------------------------------------

void speex_bits_pack(SpeexBits *bits, int data, int nbBits)
{
   int i;
   unsigned int d=data;

   if (bits->bytePtr+((nbBits+bits->bitPtr)>>3) >= bits->buf_size)
   {
       //remain unchanged....
   }

   *((unsigned long*)(bits->bytes+bits->bytePtr))=
   ((*(unsigned 
long*)(bits->bytes+bits->bytePtr))&((1<<bits->bitPtr)-1))|((d&((1<<nbBits)-1))<<bits->bitPtr);
   bits->bytePtr+= (bits->bitPtr+nbBits) >> 3; //advance the byte ptr
   bits->bitPtr  = (bits->bitPtr+nbBits) & 7;  //advance the bit ptr
}

-----------------------------------------------------------------------------------------------------------------

more optimizations next time....

Frédo

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'speex-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Speex-dev mailing list