FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/cl_ltp.c @ 459:b094bc07051a
doc/Codec-utils: document twamr-* addition
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 10 May 2024 19:50:29 +0000 |
parents | 85e9768d497f |
children |
rev | line source |
---|---|
406
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : cl_ltp.c |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 /* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * MODULE INCLUDE FILE AND VERSION ID |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "namespace.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "cl_ltp.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * INCLUDE FILES |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include <stddef.h> |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "typedef.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "basic_op.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "no_count.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "oper_32b.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "cnst.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "convolve.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "g_pitch.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "pred_lt.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "pitch_fr.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #include "enc_lag3.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 #include "enc_lag6.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #include "q_gain_p.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #include "ton_stab.h" |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 /* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * LOCAL VARIABLES AND TABLES |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 /* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * PUBLIC PROGRAM CODE |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ***************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 /************************************************************************* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 * Function: cl_ltp_reset |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 * Purpose: Initializes state memory to zero |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 ************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 void cl_ltp_reset (clLtpState *state) |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 /* Reset pitch search states */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Pitch_fr_reset (&state->pitchSt); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 /************************************************************************* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 * Function: cl_ltp |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 * Purpose: closed-loop fractional pitch search |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 ************************************************************************** |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 int cl_ltp ( |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 clLtpState *clSt, /* i/o : State struct */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 tonStabState *tonSt, /* i/o : State struct */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 enum Mode mode, /* i : coder mode */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 Word16 frameOffset, /* i : Offset to subframe */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 Word16 T_op[], /* i : Open loop pitch lags */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 Word16 *h1, /* i : Impulse response vector Q12 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 Word16 *exc, /* i/o : Excitation vector Q0 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 Word16 res2[], /* i/o : Long term prediction residual Q0 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 Word16 xn[], /* i : Target vector for pitch search Q0 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 Word16 lsp_flag, /* i : LSP resonance flag */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 Word16 xn2[], /* o : Target vector for codebook search Q0 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 Word16 y1[], /* o : Filtered adaptive excitation Q0 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 Word16 *T0, /* o : Pitch delay (integer part) */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 Word16 *T0_frac, /* o : Pitch delay (fractional part) */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 Word16 *gain_pit, /* o : Pitch gain Q14 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 Word16 g_coeff[], /* o : Correlations between xn, y1, & y2 */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 Word16 **anap, /* o : Analysis parameters */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 Word16 *gp_limit /* o : pitch gain limit */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 ) |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 Word16 i; |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 Word16 index; |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 Word32 L_temp; /* temporarily variable */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 Word16 resu3; /* flag for upsample resolution */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 Word16 gpc_flag; |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 /*----------------------------------------------------------------------* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 * Closed-loop fractional pitch search * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 *----------------------------------------------------------------------*/ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 *T0 = Pitch_fr(&clSt->pitchSt, |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 mode, T_op, exc, xn, h1, |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 L_SUBFR, frameOffset, |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 T0_frac, &resu3, &index); move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 *(*anap)++ = index; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 /*-----------------------------------------------------------------* |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 * - find unity gain pitch excitation (adapitve codebook entry) * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 * with fractional interpolation. * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 * - compute pitch gain and limit between 0 and 1.2 * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 * - update target vector for codebook search * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 * - find LTP residual. * |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 *-----------------------------------------------------------------*/ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 Pred_lt_3or6(exc, *T0, *T0_frac, L_SUBFR, resu3); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 Convolve(exc, h1, y1, L_SUBFR); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 /* gain_pit is Q14 for all modes */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 *gain_pit = G_pitch(mode, xn, y1, g_coeff, L_SUBFR); move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 /* check if the pitch gain should be limit due to resonance in LPC filter */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 gpc_flag = 0; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 *gp_limit = MAX_16; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 test (); test (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if ((lsp_flag != 0) && |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 (sub(*gain_pit, GP_CLIP) > 0)) |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 gpc_flag = check_gp_clipping(tonSt, *gain_pit); move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 /* special for the MR475, MR515 mode; limit the gain to 0.85 to */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 /* cope with bit errors in the decoder in a better way. */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 test (); test (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0)) { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 test (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if ( sub (*gain_pit, 13926) > 0) { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 *gain_pit = 13926; /* 0.85 in Q14 */ move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 test (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 if (gpc_flag != 0) { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 *gp_limit = GP_CLIP; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 else |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 test (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 if (gpc_flag != 0) |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 *gp_limit = GP_CLIP; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 *gain_pit = GP_CLIP; move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 /* For MR122, gain_pit is quantized here and not in gainQuant */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 if (test (), sub(mode, MR122)==0) |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 *(*anap)++ = q_gain_pitch(MR122, *gp_limit, gain_pit, |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 NULL, NULL); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 /* update target vector und evaluate LTP residual */ |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 for (i = 0; i < L_SUBFR; i++) { |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 L_temp = L_mult(y1[i], *gain_pit); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 L_temp = L_shl(L_temp, 1); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 xn2[i] = sub(xn[i], extract_h(L_temp)); move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 L_temp = L_mult(exc[i], *gain_pit); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 L_temp = L_shl(L_temp, 1); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 res2[i] = sub(res2[i], extract_h(L_temp)); move16 (); |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 return 0; |
85e9768d497f
libtwamr: integrate cl_ltp.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |