comparison dev/a2s-regen.c @ 224:b502321000aa

dev: new program a2s-regen
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Apr 2023 04:34:09 +0000
parents dev/s2a-regen.c@3afbc6c64172
children ba737a0203e2
comparison
equal deleted inserted replaced
223:3afbc6c64172 224:b502321000aa
1 /*
2 * This program regenerates a G.711 A-law decoding table equivalent to the
3 * a2s[] table in the toast_alaw.c module in libgsm/toast; the intent is
4 * to check that table for correctness. The "engine" function that does
5 * the computation is based on alaw_expand() from ITU-T G.191 STL.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 static unsigned
12 alaw_expand (input)
13 unsigned input;
14 {
15 short ix, mant, iexp;
16
17 ix = input ^ (0x0055); /* re-toggle toggled bits */
18
19 ix &= (0x007F); /* remove sign bit */
20 iexp = ix >> 4; /* extract exponent */
21 mant = ix & (0x000F); /* now get mantissa */
22 if (iexp > 0)
23 mant = mant + 16; /* add leading '1', if exponent > 0 */
24
25 mant = (mant << 4) + (0x0008); /* now mantissa left justified and */
26 /* 1/2 quantization step added */
27 if (iexp > 1) /* now left shift according exponent */
28 mant = mant << (iexp - 1);
29
30 if (input & 0x80) /* invert, if negative sample */
31 return mant;
32 else
33 return mant + 0x8000;
34 }
35
36 main(argc, argv)
37 char **argv;
38 {
39 unsigned input, output;
40
41 for (input = 0; input < 256; input++) {
42 output = alaw_expand(input);
43 printf("%6u,", output);
44 if ((input & 7) == 7)
45 putchar('\n');
46 }
47 exit(0);
48 }