comparison dev/u2s-regen.c @ 230:20750ffb1c3e

dev: new program u2s-regen
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 May 2023 17:41:51 +0000
parents dev/a2s-regen.c@ba737a0203e2
children
comparison
equal deleted inserted replaced
229:f00bf3687286 230:20750ffb1c3e
1 /*
2 * This program generates a G.711 mu-law decoding table of the same form
3 * as the u2s[] table in the toast_ulaw.c module in libgsm/toast; the intent
4 * is to replace that incorrect table with a corrected one. The "engine"
5 * function that does the computation is based on ulaw_expand() from ITU-T
6 * G.191 STL.
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 static unsigned
13 ulaw_expand (input)
14 unsigned input;
15 {
16 short segment; /* segment (Table 2/G711, column 1) */
17 short mantissa; /* low nibble of log companded sample */
18 short exponent; /* high nibble of log companded sample */
19 short sign; /* sign of output sample */
20 short step;
21 short output;
22
23 sign = input < (0x0080) /* sign-bit = 1 for positiv values */
24 ? -1 : 1;
25 mantissa = ~input; /* 1's complement of input value */
26 exponent = (mantissa >> 4) & (0x0007); /* extract exponent */
27 segment = exponent + 1; /* compute segment number */
28 mantissa = mantissa & (0x000F); /* extract mantissa */
29
30 /* Compute Quantized Sample (14 bit left justified!) */
31 step = (4) << segment; /* position of the LSB */
32 /* = 1 quantization step) */
33 output = sign * /* sign */
34 (((0x0080) << exponent) /* '1', preceding the mantissa */
35 +step * mantissa /* left shift of mantissa */
36 + step / 2 /* 1/2 quantization step */
37 - 4 * 33);
38 return output & 0xFFFF;
39 }
40
41 main(argc, argv)
42 char **argv;
43 {
44 unsigned input, output;
45
46 for (input = 0; input < 256; input++) {
47 output = ulaw_expand(input);
48 printf("%6u,", output);
49 if ((input & 7) == 7)
50 putchar('\n');
51 }
52 exit(0);
53 }