FreeCalypso > hg > gsm-codec-lib
comparison dev/xmaxc-tables.c @ 247:56d3fbacd115
dev: new program xmaxc-tables
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 May 2023 02:04:42 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
246:a55fcc8b6daf | 247:56d3fbacd115 |
---|---|
1 /* | |
2 * For libgsmfrp: if we are going to initiate comfort noise generation | |
3 * upon receiving an invalid SID, and if we are going to harvest the | |
4 * needed LARc and Xmaxc parameters from the last speech frame, we'll | |
5 * need a way to compute a single mean Xmaxc from the 4 subframe Xmaxc | |
6 * parameters of that last speech frame. | |
7 * | |
8 * This program generates Xmaxc dequantization and requantization tables | |
9 * that are specifically optimized for performing this mean manipulation. | |
10 */ | |
11 | |
12 #include <stdio.h> | |
13 #include <stdint.h> | |
14 #include <stdlib.h> | |
15 | |
16 static uint16_t dequant_table[64]; | |
17 static uint8_t requant_table[1024]; | |
18 | |
19 static void | |
20 compute_dequant() | |
21 { | |
22 unsigned xmaxc, dequant, step; | |
23 | |
24 dequant = 0; | |
25 step = 1; | |
26 for (xmaxc = 0; xmaxc < 64; xmaxc++) { | |
27 dequant_table[xmaxc] = dequant; | |
28 dequant += step; | |
29 if ((xmaxc & 7) == 7 && xmaxc != 7) | |
30 step <<= 1; | |
31 } | |
32 } | |
33 | |
34 static void | |
35 compute_requant() | |
36 { | |
37 unsigned x, c; | |
38 | |
39 for (x = 0; x < 1024; x++) { | |
40 for (c = 0; c < 63; c++) { | |
41 if (x < dequant_table[c+1]) | |
42 break; | |
43 } | |
44 requant_table[x] = c; | |
45 } | |
46 } | |
47 | |
48 static void | |
49 print_dequant() | |
50 { | |
51 unsigned c, r; | |
52 | |
53 puts("const uint16_t dequant_table[64] = {"); | |
54 for (c = 0; c < 64; c++) { | |
55 r = c & 7; | |
56 if (!r) | |
57 putchar('\t'); | |
58 printf("%3u,", dequant_table[c]); | |
59 if (r == 7) | |
60 putchar('\n'); | |
61 else | |
62 putchar(' '); | |
63 } | |
64 fputs("};\n\n", stdout); | |
65 } | |
66 | |
67 static void | |
68 print_requant() | |
69 { | |
70 unsigned x, r; | |
71 | |
72 puts("const uint8_t requant_table[1024] = {"); | |
73 for (x = 0; x < 1024; x++) { | |
74 r = x & 15; | |
75 if (!r) | |
76 putchar('\t'); | |
77 printf("%2u,", requant_table[x]); | |
78 if (r == 15) | |
79 putchar('\n'); | |
80 else | |
81 putchar(' '); | |
82 } | |
83 fputs("};\n", stdout); | |
84 } | |
85 | |
86 main(argc, argv) | |
87 char **argv; | |
88 { | |
89 compute_dequant(); | |
90 compute_requant(); | |
91 print_dequant(); | |
92 print_requant(); | |
93 exit(0); | |
94 } |