annotate libtwamr/gains_tab.c @ 581:e2d5cad04cbf

libgsmhr1 RxFE: store CN R0+LPC separately from speech In the original GSM 06.06 code the ECU for speech mode is entirely separate from the CN generator, maintaining separate state. (The main intertie between them is the speech vs CN state variable, distinguishing between speech and CN BFIs, in addition to the CN-specific function of distinguishing between initial and update SIDs.) In the present RxFE implementation I initially thought that we could use the same saved_frame buffer for both ECU and CN, overwriting just the first 4 params (R0 and LPC) when a valid SID comes in. However, I now realize it was a bad idea: the original code has a corner case (long sequence of speech-mode BFIs to put the ECU in state 6, then SID and CN-mode BFIs, then a good speech frame) that would be broken by that buffer reuse approach. We could eliminate this corner case by resetting the ECU state when passing through a CN insertion period, but doing so would needlessly increase the behavioral diffs between GSM 06.06 and our version. Solution: use a separate CN-specific buffer for CN R0+LPC parameters, and match the behavior of GSM 06.06 code in this regard.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Feb 2025 10:02:45 +0000
parents 5db2c920fc23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
338
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : gains.tab
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Scalar quantization tables of the pitch gain and
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * : the codebook gain.
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * $Id $
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 ********************************************************************************
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 */
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "namespace.h"
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "typedef.h"
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "gains_tab.h"
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 const Word16 qua_gain_pitch[NB_QUA_PITCH] =
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 0, 3277, 6556, 8192, 9830, 11469, 12288, 13107,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 13926, 14746, 15565, 16384, 17203, 18022, 18842, 19661
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 };
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 const Word16 qua_gain_code[NB_QUA_CODE*3] =
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 /* gain factor (g_fac) and quantized energy error (qua_ener_MR122, qua_ener)
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * are stored:
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * qua_ener_MR122 = log2(g_fac) (not the rounded floating point value, but
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * the value the original EFR algorithm
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * calculates from g_fac [using Log2])
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 * qua_ener = 20*log10(g_fac); (rounded floating point value)
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * g_fac (Q11), qua_ener_MR122 (Q10), qua_ener (Q10)
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 */
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 159, -3776, -22731,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 206, -3394, -20428,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 268, -3005, -18088,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 349, -2615, -15739,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 419, -2345, -14113,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 482, -2138, -12867,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 554, -1932, -11629,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 637, -1726, -10387,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 733, -1518, -9139,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 842, -1314, -7906,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 969, -1106, -6656,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 1114, -900, -5416,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 1281, -694, -4173,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 1473, -487, -2931,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 1694, -281, -1688,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 1948, -75, -445,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 2241, 133, 801,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 2577, 339, 2044,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 2963, 545, 3285,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 3408, 752, 4530,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 3919, 958, 5772,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 4507, 1165, 7016,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 5183, 1371, 8259,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 5960, 1577, 9501,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 6855, 1784, 10745,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 7883, 1991, 11988,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 9065, 2197, 13231,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 10425, 2404, 14474,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 12510, 2673, 16096,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 16263, 3060, 18429,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 21142, 3448, 20763,
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 27485, 3836, 23097
5db2c920fc23 libtwamr: gains.tab integrated
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 };