Source file: /~heha/basteln/Haus/Telefon/Mithören-ISDN/Firmware.zip/alaw_expand.cpp

// Original ITU-T:
#if 0
void            alaw_expand(lseg, logbuf, linbuf)
  long            lseg;
  short          *linbuf;
  short          *logbuf;
{
  short           ix, mant, iexp;
  long            n;

  for (n = 0; n < lseg; n++)
  {
    ix = logbuf[n] ^ (0x0055);	/* re-toggle toggled bits */

    ix &= (0x007F);		/* remove sign bit */
    iexp = ix >> 4;		/* extract exponent */
    mant = ix & (0x000F);	/* now get mantissa */
    if (iexp > 0)
      mant = mant + 16;		/* add leading '1', if exponent > 0 */

    mant = (mant << 4) + (0x0008);	/* now mantissa left justified and */
    /* 1/2 quantization step added */
    if (iexp > 1)		/* now left shift according exponent */
      mant = mant << (iexp - 1);

    linbuf[n] = logbuf[n] > 127	/* invert, if negative sample */
      ? mant
      : -mant;
  }
}
#endif
struct alaw{
  short table[256];
  alaw() {
    byte b=0;
    do{
      byte ix = (b^0x55) & 0x7F;
      byte iexp = ix>>4;		// exponent 0..7
      short mant = byte(ix<<4)|8;	// mantissa
      if (iexp) mant+=256;	// führende 1
      if (iexp) mant<<=iexp-1;
      table[b] = b&0x80 ? mant : -mant;
    }while (++b);
  }
  short expand(byte b) {return table[b];}
  void expand(short*s,const byte*b,size_t l) {if(l)do*s++=expand(*b++);while(--l);}
};
Detected encoding: UTF-80