📄 libst.c
字号:
/* libst.c - portable sound tools library*/#include "libst.h"#ifndef FAST_ULAW_CONVERSION/*** This routine converts from linear to ulaw.**** Craig Reese: IDA/Supercomputing Research Center** Joe Campbell: Department of Defense** 29 September 1989**** References:** 1) CCITT Recommendation G.711 (very difficult to follow)** 2) "A New Digital Technique for Implementation of Any** Continuous PCM Companding Law," Villeret, Michel,** et al. 1973 IEEE Int. Conf. on Communications, Vol 1,** 1973, pg. 11.12-11.17** 3) MIL-STD-188-113,"Interoperability and Performance Standards** for Analog-to_Digital Conversion Techniques,"** 17 February 1987**** Input: Signed 16 bit linear sample** Output: 8 bit ulaw sample*/#undef ZEROTRAP /* turn off the trap as per the MIL-STD */#define uBIAS 0x84 /* define the add-in bias for 16 bit samples */#define uCLIP 32635#define ACLIP 31744unsigned charst_linear_to_ulaw( sample )int sample; { static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}; int sign, exponent, mantissa; unsigned char ulawbyte; /* Get the sample into sign-magnitude. */ sign = (sample >> 8) & 0x80; /* set aside the sign */ if ( sign != 0 ) sample = -sample; /* get magnitude */ if ( sample > uCLIP ) sample = uCLIP; /* clip the magnitude */ /* Convert from 16 bit linear to ulaw. */ sample = sample + uBIAS; exponent = exp_lut[( sample >> 7 ) & 0xFF]; mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F; ulawbyte = ~ ( sign | ( exponent << 4 ) | mantissa );#ifdef ZEROTRAP if ( ulawbyte == 0 ) ulawbyte = 0x02; /* optional CCITT trap */#endif return ulawbyte; }/*** This routine converts from ulaw to 16 bit linear.**** Craig Reese: IDA/Supercomputing Research Center** 29 September 1989**** References:** 1) CCITT Recommendation G.711 (very difficult to follow)** 2) MIL-STD-188-113,"Interoperability and Performance Standards** for Analog-to_Digital Conversion Techniques,"** 17 February 1987**** Input: 8 bit ulaw sample** Output: signed 16 bit linear sample*/intst_ulaw_to_linear( ulawbyte )unsigned char 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 != 0 ) sample = -sample; return sample; }#elseunsigned char ulaw_comp_table[16384] = { 0xff,0xfe,0xfe,0xfd,0xfd,0xfc,0xfc,0xfb, 0xfb,0xfa,0xfa,0xf9,0xf9,0xf8,0xf8,0xf7, 0xf7,0xf6,0xf6,0xf5,0xf5,0xf4,0xf4,0xf3, 0xf3,0xf2,0xf2,0xf1,0xf1,0xf0,0xf0,0xef, 0xef,0xef,0xef,0xee,0xee,0xee,0xee,0xed, 0xed,0xed,0xed,0xec,0xec,0xec,0xec,0xeb, 0xeb,0xeb,0xeb,0xea,0xea,0xea,0xea,0xe9, 0xe9,0xe9,0xe9,0xe8,0xe8,0xe8,0xe8,0xe7, 0xe7,0xe7,0xe7,0xe6,0xe6,0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,0xae,0xae,0xae,0xae,0xae, 0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae, 0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xae, 0xae,0xae,0xae,0xae,0xae,0xae,0xae,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xad, 0xad,0xad,0xad,0xad,0xad,0xad,0xad,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xac, 0xac,0xac,0xac,0xac,0xac,0xac,0xac,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xab, 0xab,0xab,0xab,0xab,0xab,0xab,0xab,0xaa, 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, 0xaa,0xaa,0xaa,0xaa,0xaa,0xa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