1
|
1 // code from xanim sources...
|
|
2 // (I hope that not hurt copyright :o)
|
|
3
|
|
4 #define xaLONG long
|
|
5 #define xaULONG unsigned long
|
|
6 #define xaBYTE char
|
|
7 #define xaUBYTE unsigned char
|
|
8
|
756
|
9 //xaULONG long xa_alaw_2_sign[256];
|
|
10 xaULONG xa_alaw_2_sign[256];
|
|
11 xaULONG xa_ulaw_2_sign[256];
|
|
12
|
|
13 /*
|
|
14 ** This routine converts from ulaw to 16 bit linear.
|
|
15 **
|
|
16 ** Craig Reese: IDA/Supercomputing Research Center
|
|
17 ** 29 September 1989
|
|
18 **
|
|
19 ** References:
|
|
20 ** 1) CCITT Recommendation G.711 (very difficult to follow)
|
|
21 ** 2) MIL-STD-188-113,"Interoperability and Performance Standards
|
|
22 ** for Analog-to_Digital Conversion Techniques,"
|
|
23 ** 17 February 1987
|
|
24 **
|
|
25 ** Input: 8 bit ulaw sample
|
|
26 ** Output: signed 16 bit linear sample
|
|
27 */
|
|
28
|
|
29 xaLONG XA_uLaw_to_Signed( ulawbyte )
|
|
30 xaUBYTE ulawbyte;
|
|
31 {
|
|
32 static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
|
|
33 int sign, exponent, mantissa, sample;
|
|
34
|
|
35 ulawbyte = ~ ulawbyte;
|
|
36 sign = ( ulawbyte & 0x80 );
|
|
37 exponent = ( ulawbyte >> 4 ) & 0x07;
|
|
38 mantissa = ulawbyte & 0x0F;
|
|
39 sample = exp_lut[exponent] + ( mantissa << ( exponent + 3 ) );
|
|
40 if ( sign != 0 ) sample = -sample;
|
|
41
|
|
42 return sample;
|
|
43 }
|
|
44
|
|
45 void Gen_uLaw_2_Signed()
|
|
46 { xaULONG i;
|
|
47 for(i=0;i<256;i++)
|
|
48 { xaUBYTE data = (xaUBYTE)(i);
|
|
49 xaLONG d = XA_uLaw_to_Signed( data );
|
|
50 xa_ulaw_2_sign[i] = (xaULONG)((xaULONG)(d) & 0xffff);
|
|
51 }
|
|
52 }
|
|
53
|
|
54
|
1
|
55
|
|
56 void Gen_aLaw_2_Signed()
|
|
57 { xaULONG i;
|
|
58 for(i=0;i<256;i++)
|
|
59 { xaUBYTE data = (xaUBYTE)(i);
|
|
60 xaLONG d, t, seg;
|
|
61
|
|
62 data ^= 0x55;
|
|
63
|
|
64 t = (data & 0xf) << 4;
|
|
65 seg = (data & 0x70) >> 4;
|
|
66 if (seg == 0) t += 8;
|
|
67 else if (seg == 1) t += 0x108;
|
|
68 else { t += 108; t <<= seg - 1; }
|
|
69
|
|
70 d = (data & 0x80)?(t):(-t);
|
|
71 xa_alaw_2_sign[i] = (xaULONG)((xaULONG)(d) & 0xffff);
|
|
72 }
|
|
73 }
|
|
74
|