FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/cod_amr.c @ 449:2af2b5c12268
Library-versions: libtwamr is officially version 1.0.0
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 10 May 2024 01:43:05 +0000 |
parents | 93d6c6960a46 |
children |
rev | line source |
---|---|
418
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : cod_amr.c |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Main encoder routine operating on a frame basis. |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "namespace.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "cod_amr.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 * INCLUDE FILES |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include "typedef.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 #include "basic_op.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #include "no_count.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include "cnst.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "memops.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "qua_gain.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "lpc.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "lsp.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "pre_big.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "ol_ltp.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "p_ol_wgh.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "spreproc.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "cl_ltp.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #include "pred_lt.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 #include "spstproc.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #include "cbsearch.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #include "gain_q.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 #include "convolve.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 #include "ton_stab.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 #include "vad.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 #include "dtx_enc.h" |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * LOCAL VARIABLES AND TABLES |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * PUBLIC VARIABLES AND TABLES |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* Spectral expansion factors */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 static const Word16 gamma1[M] = |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 30802, 28954, 27217, 25584, 24049, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 22606, 21250, 19975, 18777, 17650 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 }; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 /* gamma1 differs for the 12k2 coder */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 static const Word16 gamma1_12k2[M] = |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 29491, 26542, 23888, 21499, 19349, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 17414, 15672, 14105, 12694, 11425 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 }; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 static const Word16 gamma2[M] = |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 19661, 11797, 7078, 4247, 2548, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 1529, 917, 550, 330, 198 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 }; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 * PUBLIC PROGRAM CODE |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 ***************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 /* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 ************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 * Function : cod_amr_reset |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 * Purpose : Resets state memory |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 ************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 void cod_amr_reset (cod_amrState *st, Flag dtx, Flag use_vad2) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 Word16 i; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 /* save DTX flag */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 st->dtx = dtx; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 /*-----------------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 * Initialize pointers to speech vector. * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 *-----------------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 st->new_speech = st->old_speech + L_TOTAL - L_FRAME; /* New speech */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 st->speech = st->new_speech - L_NEXT; /* Present frame */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 st->p_window = st->old_speech + L_TOTAL - L_WINDOW; /* For LPC window */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 st->p_window_12k2 = st->p_window - L_NEXT; /* EFR LPC window: no lookahead */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 /* Initialize static pointers */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 st->wsp = st->old_wsp + PIT_MAX; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 st->exc = st->old_exc + PIT_MAX + L_INTERPOL; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 st->zero = st->ai_zero + MP1; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 st->error = st->mem_err + M; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 st->h1 = &st->hvec[L_SUBFR]; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 /* Static vectors to zero */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 Set_zero(st->old_speech, L_TOTAL); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 Set_zero(st->old_exc, PIT_MAX + L_INTERPOL); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 Set_zero(st->old_wsp, PIT_MAX); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 Set_zero(st->mem_syn, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 Set_zero(st->mem_w, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 Set_zero(st->mem_w0, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 Set_zero(st->mem_err, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 Set_zero(st->zero, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 Set_zero(st->hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 /* OL LTP states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 for (i = 0; i < 5; i++) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 st->old_lags[i] = 40; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 /* Reset lpc states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 lpc_reset(&st->lpcSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 /* Reset lsp states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 lsp_reset(&st->lspSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 /* Reset clLtp states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 cl_ltp_reset(&st->clLtpSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 gainQuant_reset(&st->gainQuantSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 p_ol_wgh_reset(&st->pitchOLWghtSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 ton_stab_reset(&st->tonStabSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 vad_reset(&st->vadSt, use_vad2); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 dtx_enc_reset(&st->dtx_encSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 st->sharp = SHARPMIN; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 /*************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 * FUNCTION: cod_amr_first |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 * PURPOSE: Copes with look-ahead. |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 * INPUTS: |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 * No input argument are passed to this function. However, before |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 * calling this function, 40 new speech data should be copied to the |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 * vector new_speech[]. This is a global pointer which is declared in |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 * this file (it points to the end of speech buffer minus 200). |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 ***************************************************************************/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 int cod_amr_first(cod_amrState *st, /* i/o : State struct */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 Word16 new_speech[]) /* i : speech input (L_FRAME) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 Copy(new_speech,&st->new_speech[-L_NEXT], L_NEXT); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 /* Copy(new_speech,st->new_speech,L_FRAME); */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 return 0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 /*************************************************************************** |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 * FUNCTION: cod_amr |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 * PURPOSE: Main encoder routine. |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 * DESCRIPTION: This function is called every 20 ms speech frame, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 * operating on the newly read 160 speech samples. It performs the |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 * principle encoding functions to produce the set of encoded parameters |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 * which include the LSP, adaptive codebook, and fixed codebook |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 * quantization indices (addresses and gains). |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 * INPUTS: |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 * No input argument are passed to this function. However, before |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 * calling this function, 160 new speech data should be copied to the |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 * vector new_speech[]. This is a global pointer which is declared in |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 * this file (it points to the end of speech buffer minus 160). |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 * OUTPUTS: |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 * ana[]: vector of analysis parameters. |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 * synth[]: Local synthesis speech (for debugging purposes) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 ***************************************************************************/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 int cod_amr( |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 cod_amrState *st, /* i/o : State struct */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 enum Mode mode, /* i : AMR mode */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 Word16 new_speech[], /* i : speech input (L_FRAME) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 Word16 ana[], /* o : Analysis parameters */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 enum Mode *usedMode, /* o : used mode */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 Word16 synth[] /* o : Local synthesis */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 ) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 /* LPC coefficients */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 Word16 A_t[(MP1) * 4]; /* A(z) unquantized for the 4 subframes */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 Word16 Aq_t[(MP1) * 4]; /* A(z) quantized for the 4 subframes */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 Word16 *A, *Aq; /* Pointer on A_t and Aq_t */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 Word16 lsp_new[M]; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 /* Other vectors */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 Word16 xn[L_SUBFR]; /* Target vector for pitch search */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 Word16 code[L_SUBFR]; /* Fixed codebook excitation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 Word16 y2[L_SUBFR]; /* Filtered fixed codebook excitation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 Word16 gCoeff[6]; /* Correlations between xn, y1, & y2: */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 Word16 res[L_SUBFR]; /* Short term (LPC) prediction residual */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 Word16 res2[L_SUBFR]; /* Long term (LTP) prediction residual */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 /* Vector and scalars needed for the MR475 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 Word16 xn_sf0[L_SUBFR]; /* Target vector for pitch search */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 Word16 y2_sf0[L_SUBFR]; /* Filtered codebook innovation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 Word16 code_sf0[L_SUBFR]; /* Fixed codebook excitation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 Word16 h1_sf0[L_SUBFR]; /* The impulse response of sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 Word16 mem_syn_save[M]; /* Filter memory */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 Word16 mem_w0_save[M]; /* Filter memory */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 Word16 mem_err_save[M]; /* Filter memory */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 Word16 sharp_save; /* Sharpening */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 Word16 evenSubfr; /* Even subframe indicator */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 Word16 T0_sf0 = 0; /* Integer pitch lag of sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 Word16 T0_frac_sf0 = 0; /* Fractional pitch lag of sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 Word16 i_subfr_sf0 = 0; /* Position in exc[] for sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 Word16 gain_pit_sf0; /* Quantized pitch gain for sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 Word16 gain_code_sf0; /* Quantized codebook gain for sf0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 /* Scalars */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 Word16 i_subfr, subfrNr; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 Word16 T_op[L_FRAME/L_FRAME_BY2]; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 Word16 T0, T0_frac; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 Word16 gain_pit, gain_code; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 /* Flags */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 Word16 lsp_flag = 0; /* indicates resonance in LPC filter */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 Word16 gp_limit; /* pitch gain limit value */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 Word16 vad_flag; /* VAD decision flag */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 Word16 compute_sid_flag; /* SID analysis flag */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 Copy(new_speech, st->new_speech, L_FRAME); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 *usedMode = mode; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 /* DTX processing */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 if (st->dtx) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 { /* no test() call since this if is only in simulation env */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 /* Find VAD decision */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (st->vadSt.use_vad2) { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 vad_flag = vad2(st->new_speech, &st->vadSt.u.v2); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 vad_flag = vad2(st->new_speech+80, &st->vadSt.u.v2) || vad_flag; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 } else { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 vad_flag = vad1(&st->vadSt.u.v1, st->new_speech); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 /* NB! usedMode may change here */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 compute_sid_flag = tx_dtx_handler(&st->dtx_encSt, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 vad_flag, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 usedMode); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 else |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 compute_sid_flag = 0; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 /*------------------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 * - Perform LPC analysis: * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 * * autocorrelation + lag windowing * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 * * Levinson-durbin algorithm to find a[] * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 * * convert a[] to lsp[] * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 * * quantize and code the LSPs * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 * * find the interpolated LSPs and convert to a[] for all * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 * subframes (both quantized and unquantized) * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 *------------------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 /* LP analysis */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 lpc(&st->lpcSt, mode, st->p_window, st->p_window_12k2, A_t); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 /* From A(z) to lsp. LSP quantization and interpolation */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 lsp(&st->lspSt, mode, *usedMode, A_t, Aq_t, lsp_new, &ana); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 /* Buffer lsp's and energy */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 dtx_buffer(&st->dtx_encSt, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 lsp_new, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 st->new_speech); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 /* Check if in DTX mode */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 test(); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 if (sub(*usedMode, MRDTX) == 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 dtx_enc(&st->dtx_encSt, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 compute_sid_flag, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 &st->lspSt.qSt, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 &st->gainQuantSt.gc_predSt, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 &ana); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 Set_zero(st->old_exc, PIT_MAX + L_INTERPOL); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 Set_zero(st->mem_w0, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 Set_zero(st->mem_err, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 Set_zero(st->zero, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 Set_zero(st->hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 /* Reset lsp states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 lsp_reset(&st->lspSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 Copy(lsp_new, st->lspSt.lsp_old, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 Copy(lsp_new, st->lspSt.lsp_old_q, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 /* Reset clLtp states */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 cl_ltp_reset(&st->clLtpSt); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 st->sharp = SHARPMIN; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 else |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 /* check resonance in the filter */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 lsp_flag = check_lsp(&st->tonStabSt, st->lspSt.lsp_old); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 /*----------------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 * - Find the weighted input speech w_sp[] for the whole speech frame * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 * - Find the open-loop pitch delay for first 2 subframes * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 * - Set the range for searching closed-loop pitch in 1st subframe * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 * - Find the open-loop pitch delay for last 2 subframes * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 *----------------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 if (st->dtx && st->vadSt.use_vad2) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 { /* no test() call since this if is only in simulation env */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 st->vadSt.u.v2.L_Rmax = 0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 st->vadSt.u.v2.L_R0 = 0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 for(subfrNr = 0, i_subfr = 0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 subfrNr < L_FRAME/L_FRAME_BY2; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 subfrNr++, i_subfr += L_FRAME_BY2) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 /* Pre-processing on 80 samples */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 pre_big(mode, gamma1, gamma1_12k2, gamma2, A_t, i_subfr, st->speech, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 st->mem_w, st->wsp); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 test (); test (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 if ((sub(mode, MR475) != 0) && (sub(mode, MR515) != 0)) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 /* Find open loop pitch lag for two subframes */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 ol_ltp(&st->pitchOLWghtSt, &st->vadSt, mode, &st->wsp[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 &T_op[subfrNr], st->old_lags, st->ol_gain_flg, subfrNr, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 st->dtx); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0)) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 /* Find open loop pitch lag for ONE FRAME ONLY */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 /* search on 160 samples */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 ol_ltp(&st->pitchOLWghtSt, &st->vadSt, mode, &st->wsp[0], &T_op[0], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 st->old_lags, st->ol_gain_flg, 1, st->dtx); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 T_op[1] = T_op[0]; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 if (st->dtx && st->vadSt.use_vad2) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 { /* no test() call since this if is only in simulation env */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 LTP_flag_update(&st->vadSt.u.v2, mode); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 /* run VAD pitch detection */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 if (st->dtx && !st->vadSt.use_vad2) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 { /* no test() call since this if is only in simulation env */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 vad_pitch_detection(&st->vadSt.u.v1, T_op); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 if (sub(*usedMode, MRDTX) == 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 goto the_end; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 /*------------------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 * Loop for every subframe in the analysis frame * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 *------------------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 * To find the pitch and innovation parameters. The subframe size is * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 * - find the weighted LPC coefficients * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 * - find the LPC residual signal res[] * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 * - compute the target signal for pitch search * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 * - compute impulse response of weighted synthesis filter (h1[]) * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 * - find the closed-loop pitch parameters * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 * - encode the pitch dealy * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 * - update the impulse response h1[] by including fixed-gain pitch * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 * - find target vector for codebook search * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 * - codebook search * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 * - encode codebook address * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 * - VQ of pitch and codebook gains * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 * - find synthesis speech * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 * - update states of weighting filter * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 *------------------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 A = A_t; /* pointer to interpolated LPC parameters */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 Aq = Aq_t; /* pointer to interpolated quantized LPC parameters */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 evenSubfr = 0; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 subfrNr = -1; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 subfrNr = add(subfrNr, 1); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 evenSubfr = sub(1, evenSubfr); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 /* Save states for the MR475 mode */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 test(); test(); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 if ((evenSubfr != 0) && (sub(*usedMode, MR475) == 0)) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 Copy(st->mem_syn, mem_syn_save, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 Copy(st->mem_w0, mem_w0_save, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 Copy(st->mem_err, mem_err_save, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 sharp_save = st->sharp; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 /*-----------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 * - Preprocessing of subframe * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 *-----------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 if (sub(*usedMode, MR475) != 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 subframePreProc(*usedMode, gamma1, gamma1_12k2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 gamma2, A, Aq, &st->speech[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 st->mem_err, st->mem_w0, st->zero, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 st->ai_zero, &st->exc[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 st->h1, xn, res, st->error); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 else |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 { /* MR475 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 subframePreProc(*usedMode, gamma1, gamma1_12k2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 gamma2, A, Aq, &st->speech[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 st->mem_err, mem_w0_save, st->zero, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 st->ai_zero, &st->exc[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 st->h1, xn, res, st->error); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 /* save impulse response (modified in cbsearch) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 if (evenSubfr != 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 Copy (st->h1, h1_sf0, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 /* copy the LP residual (res2 is modified in the CL LTP search) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 Copy (res, res2, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 /*-----------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 * - Closed-loop LTP search * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 *-----------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 cl_ltp(&st->clLtpSt, &st->tonStabSt, *usedMode, i_subfr, T_op, st->h1, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 &st->exc[i_subfr], res2, xn, lsp_flag, xn2, y1, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 &T0, &T0_frac, &gain_pit, gCoeff, &ana, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 &gp_limit); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 /* update LTP lag history */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 if ((subfrNr == 0) && (st->ol_gain_flg[0] > 0)) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 st->old_lags[1] = T0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 if ((sub(subfrNr, 3) == 0) && (st->ol_gain_flg[1] > 0)) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 st->old_lags[0] = T0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 /*-----------------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 * - Inovative codebook search (find index and gain) * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 *-----------------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 cbsearch(xn2, st->h1, T0, st->sharp, gain_pit, res2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 code, y2, &ana, *usedMode, subfrNr); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 /*------------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 * - Quantization of gains. * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 *------------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 gainQuant(&st->gainQuantSt, *usedMode, res, &st->exc[i_subfr], code, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 xn, xn2, y1, y2, gCoeff, evenSubfr, gp_limit, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 &gain_pit_sf0, &gain_code_sf0, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 &gain_pit, &gain_code, &ana); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
493 /* update gain history */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 update_gp_clipping(&st->tonStabSt, gain_pit); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
495 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 if (sub(*usedMode, MR475) != 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 /* Subframe Post Porcessing */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 st->mem_err, st->mem_w0, st->exc, &st->sharp); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 else |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
505 if (evenSubfr != 0) |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
507 i_subfr_sf0 = i_subfr; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
508 Copy(xn, xn_sf0, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
509 Copy(y2, y2_sf0, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
510 Copy(code, code_sf0, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
511 T0_sf0 = T0; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
512 T0_frac_sf0 = T0_frac; move16 (); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
513 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
514 /* Subframe Post Porcessing */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 gain_code, Aq, synth, xn, code, y1, y2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 mem_syn_save, st->mem_err, mem_w0_save, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
518 st->exc, &st->sharp); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 st->sharp = sharp_save; move16(); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 else |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 { |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
523 /* update both subframes for the MR475 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
524 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
525 /* Restore states for the MR475 mode */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
526 Copy(mem_err_save, st->mem_err, M); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
527 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
528 /* re-build excitation for sf 0 */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
529 Pred_lt_3or6(&st->exc[i_subfr_sf0], T0_sf0, T0_frac_sf0, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
530 L_SUBFR, 1); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
531 Convolve(&st->exc[i_subfr_sf0], h1_sf0, y1, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
532 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
533 Aq -= MP1; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
534 subframePostProc(st->speech, *usedMode, i_subfr_sf0, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
535 gain_pit_sf0, gain_code_sf0, Aq, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
536 synth, xn_sf0, code_sf0, y1, y2_sf0, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
537 st->mem_syn, st->mem_err, st->mem_w0, st->exc, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
538 &sharp_save); /* overwrites sharp_save */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
539 Aq += MP1; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
540 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
541 /* re-run pre-processing to get xn right (needed by postproc) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
542 /* (this also reconstructs the unsharpened h1 for sf 1) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
543 subframePreProc(*usedMode, gamma1, gamma1_12k2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
544 gamma2, A, Aq, &st->speech[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
545 st->mem_err, st->mem_w0, st->zero, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
546 st->ai_zero, &st->exc[i_subfr], |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
547 st->h1, xn, res, st->error); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
548 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
549 /* re-build excitation sf 1 (changed if lag < L_SUBFR) */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
550 Pred_lt_3or6(&st->exc[i_subfr], T0, T0_frac, L_SUBFR, 1); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
551 Convolve(&st->exc[i_subfr], st->h1, y1, L_SUBFR); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
552 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
553 subframePostProc(st->speech, *usedMode, i_subfr, gain_pit, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
554 gain_code, Aq, synth, xn, code, y1, y2, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
555 st->mem_syn, st->mem_err, st->mem_w0, |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
556 st->exc, &st->sharp); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
557 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
558 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
559 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
560 A += MP1; /* interpolated LPC parameters for next subframe */ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
561 Aq += MP1; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
562 } |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
563 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
564 Copy(&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
565 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
566 the_end: |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
567 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
568 /*--------------------------------------------------* |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
569 * Update signal for next frame. * |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
570 *--------------------------------------------------*/ |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
571 Copy(&st->old_wsp[L_FRAME], &st->old_wsp[0], PIT_MAX); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
572 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
573 Copy(&st->old_speech[L_FRAME], &st->old_speech[0], L_TOTAL - L_FRAME); |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
574 |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
575 return 0; |
93d6c6960a46
libtwamr: integrate cod_amr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
576 } |