annotate alaw.c @ 865:83919c1b9924

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