#include "types.h"
#include "pcmu_l.h"

#define BIAS 0x84   /* define the add-in bias for 16 bit samples */
#define CLIP 32635

int main(){
  int i;
  for(i=0; i < 256; i++){
    printf("%x > %x\n",i,pcmu_to_l16(i));
  } 

}

int16 pcmu_to_l16(unsigned int ulawbyte)
{
 static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
 int sign, exponent, mantissa, sample;

 ulawbyte = ~ ulawbyte;
 sign = ( ulawbyte & 0x80 );
 exponent = ( ulawbyte >> 4 ) & 0x07;
 mantissa = ulawbyte & 0x0F;
 sample = exp_lut[exponent] + ( mantissa << ( exponent + 3 ) );
 if (sign) sample = -sample;

 return sample;
} /* pcmu_to_l16 */
