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