annotate dev/a2s-regen.c @ 536:a3300483ae74

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