annotate vad.c @ 6:9cbb19619a9f default tip

README: punctuation fix
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Aug 2024 19:00:23 +0000
parents 9008dbc8ca74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * TITLE: Half-Rate GSM Voice Activity Detector (VAD) Modules
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * REFERENCE: Recommendation GSM 06.42
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 | Include Files |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "typedefs.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "mathhalf.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "mathdp31.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "vad.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 | Local Defines |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /*** Floating point representations of constants pth, plev and margin ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #define M_PTH 26250
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #define E_PTH 18
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #define M_PLEV 17500
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #define E_PLEV 20
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #define M_MARGIN 27343
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #define E_MARGIN 27
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 | Static Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 static Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 pswRvad[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 swNormRvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 swPt_sacf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 swPt_sav0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 swE_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 swM_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 swAdaptCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 swBurstCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 swHangCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 swOldLagCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 swVeryOldLagCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 swOldLag;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 static Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 pL_sacf[27],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 pL_sav0[36],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 L_lastdm;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 * FUNCTION: vad_reset
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 * PURPOSE: Resets VAD static variables to their initial value.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 void vad_reset(void)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 int i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 pswRvad[0] = 24576;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 swNormRvad = 7;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 swPt_sacf = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 swPt_sav0 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 L_lastdm = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 swE_thvad = 21;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 swM_thvad = 21875;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 swAdaptCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 swBurstCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 swHangCount = -1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 swOldLagCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 swVeryOldLagCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 swOldLag = 21;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (i = 1; i < 9; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 pswRvad[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 for (i = 0; i < 27; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 pL_sacf[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 for (i = 0; i < 36; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 pL_sav0[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 * FUNCTION: vad_algorithm
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 * PURPOSE: Returns a decision as to whether the current frame being
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 * processed by the speech encoder contains speech or not.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 * INPUTS: pL_acf[0..8] autocorrelation of input signal frame
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 * swScaleAcf L_acf scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 * pswRc[0..3] speech encoder reflection coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 * swPtch flag to indicate a periodic signal component
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 * OUTPUTS: pswVadFlag vad decision
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 void vad_algorithm(Longword pL_acf[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 Shortword swScaleAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 Shortword pswRc[4],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 Shortword swPtch,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 Shortword *pswVadFlag)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 pL_av0[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 pL_av1[9];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 swM_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 swE_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 pswRav1[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 swNormRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 swM_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 swStat,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 swTone,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 swVvad;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 energy_computation
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 pL_acf, swScaleAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 pswRvad, swNormRvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 &swM_pvad, &swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 &swM_acf0, &swE_acf0
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 average_acf
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 pL_acf, swScaleAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 pL_av0, pL_av1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 predictor_values
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 pL_av1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 pswRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 &swNormRav1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 spectral_comparison
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 pswRav1, swNormRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 pL_av0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 &swStat
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 tone_detection
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 pswRc,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 &swTone
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 threshold_adaptation
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 swStat, swPtch, swTone,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 pswRav1, swNormRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 swM_pvad, swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 swM_acf0, swE_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 pswRvad, &swNormRvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 &swM_thvad, &swE_thvad
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 vad_decision
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 swM_pvad, swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 swM_thvad, swE_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 &swVvad
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 vad_hangover
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 (
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 swVvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 pswVadFlag
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 * FUNCTION: energy_computation
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 * PURPOSE: Computes the input and residual energies of the adaptive
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 * filter in a floating point representation.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 * INPUTS: pL_acf[0..8] autocorrelation of input signal frame
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 * swScaleAcf L_acf scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 * pswRvad[0..8] autocorrelated adaptive filter coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 * swNormRvad rvad scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 * OUTPUTS: pswM_pvad mantissa of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 * pswE_pvad exponent of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 * pswM_acf0 mantissa of signal frame energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 * pswE_acf0 exponent of signal frame energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 void energy_computation(Longword pL_acf[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 Shortword swScaleAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 Shortword pswRvad[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 Shortword swNormRvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 Shortword *pswM_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 Shortword *pswE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 Shortword *pswM_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 Shortword *pswE_acf0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 pswSacf[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 swNormAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 swNormProd,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 swShift;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 /*** Test if acf[0] is zero ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 if (pL_acf[0] == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 *pswE_pvad = -0x8000;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 *pswM_pvad = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 *pswE_acf0 = -0x8000;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 *pswM_acf0 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 /*** Re-normalisation of L_acf[0..8] ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 swNormAcf = norm_l(pL_acf[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 swShift = sub(swNormAcf, 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 pswSacf[i] = extract_h(L_shl(pL_acf[i], swShift));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 /*** Computation of e_acf0 and m_acf0 ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 *pswE_acf0 = add(32, shl(swScaleAcf, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 *pswE_acf0 = sub(*pswE_acf0, swNormAcf);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 *pswM_acf0 = shl(pswSacf[0], 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 /*** Computation of e_pvad and m_pvad ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 *pswE_pvad = add(*pswE_acf0, 14);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 *pswE_pvad = sub(*pswE_pvad, swNormRvad);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 L_temp = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 for (i = 1; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 L_temp = L_mac(L_temp, pswSacf[i], pswRvad[i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 L_temp = L_add(L_temp, L_shr(L_mult(pswSacf[0], pswRvad[0]), 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 if (L_temp <= 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 L_temp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 swNormProd = norm_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 *pswE_pvad = sub(*pswE_pvad, swNormProd);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 *pswM_pvad = extract_h(L_shl(L_temp, swNormProd));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 * FUNCTION: average_acf
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 * PURPOSE: Computes the arrays L_av0 [0..8] and L_av1 [0..8].
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 * INPUTS: pL_acf[0..8] autocorrelation of input signal frame
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 * swScaleAcf L_acf scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 * OUTPUTS: pL_av0[0..8] ACF averaged over last four frames
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 * pL_av1[0..8] ACF averaged over previous four frames
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 void average_acf(Longword pL_acf[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 Shortword swScaleAcf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 Longword pL_av0[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 Longword pL_av1[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 Longword L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 Shortword swScale;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 int i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 /*** computation of the scaleing factor ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 swScale = sub(10, shl(swScaleAcf, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 /*** Computation of the arrays L_av0 and L_av1 ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 L_temp = L_shr(pL_acf[i], swScale);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 pL_av0[i] = L_add(pL_sacf[i], L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 pL_av0[i] = L_add(pL_sacf[i + 9], pL_av0[i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 pL_av0[i] = L_add(pL_sacf[i + 18], pL_av0[i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 pL_sacf[swPt_sacf + i] = L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 pL_av1[i] = pL_sav0[swPt_sav0 + i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 pL_sav0[swPt_sav0 + i] = pL_av0[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 /*** Update the array pointers ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 if (swPt_sacf == 18)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 swPt_sacf = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 swPt_sacf = add(swPt_sacf, 9);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 if (swPt_sav0 == 27)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 swPt_sav0 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 swPt_sav0 = add(swPt_sav0, 9);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 * FUNCTION: predictor_values
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 * PURPOSE: Computes the array rav [0..8] needed for the spectral
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 * comparison and the threshold adaptation.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 * INPUTS: pL_av1 [0..8] ACF averaged over previous four frames
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 * OUTPUTS: pswRav1 [0..8] ACF obtained from L_av1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 * pswNormRav1 r_av1 scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 void predictor_values(Longword pL_av1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 Shortword pswRav1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 Shortword *pswNormRav1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 pswVpar[8],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 pswAav1[9];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 schur_recursion(pL_av1, pswVpar);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 step_up(8, pswVpar, pswAav1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 compute_rav1(pswAav1, pswRav1, pswNormRav1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 * FUNCTION: schur_recursion
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 * PURPOSE: Uses the Schur recursion to compute adaptive filter
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 * reflection coefficients from an autorrelation function.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 * INPUTS: pL_av1[0..8] autocorrelation function
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 * OUTPUTS: pswVpar[0..7] reflection coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 void schur_recursion(Longword pL_av1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463 Shortword pswVpar[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 pswAcf[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474 pswPp[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475 pswKk[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 swTemp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 int i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 k,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 m,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 n;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 /*** Schur recursion with 16-bit arithmetic ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492 if (pL_av1[0] == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494 for (i = 0; i < 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 pswVpar[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 swTemp = norm_l(pL_av1[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 for (k = 0; k <= 8; k++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 pswAcf[k] = extract_h(L_shl(pL_av1[k], swTemp));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505 /*** Initialise array pp[..] and kk[..] for the recursion: ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 for (i = 1; i <= 7; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 pswKk[9 - i] = pswAcf[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
510 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511 pswPp[i] = pswAcf[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514 /*** Compute Parcor coefficients: ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 for (n = 0; n < 8; n++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518 if (pswPp[0] < abs_s(pswPp[1]))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 for (i = n; i < 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521 pswVpar[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524 pswVpar[n] = divide_s(abs_s(pswPp[1]), pswPp[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 if (pswPp[1] > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527 pswVpar[n] = negate(pswVpar[n]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 if (n == 7)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 /*** Schur recursion: ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
534 pswPp[0] = add(pswPp[0], mult_r(pswPp[1], pswVpar[n]));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536 for (m = 1; m <= (7 - n); m++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 pswPp[m] = add(pswPp[1 + m], mult_r(pswKk[9 - m], pswVpar[n]));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539 pswKk[9 - m] = add(pswKk[9 - m], mult_r(pswPp[1 + m], pswVpar[n]));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
544
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 * FUNCTION: step_up
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 * PURPOSE: Computes the transversal filter coefficients from the
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 * reflection coefficients.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554 * INPUTS: swNp filter order (2..8)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555 * pswVpar[0..np-1] reflection coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557 * OUTPUTS: pswAav1[0..np] transversal filter coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561 void step_up(Shortword swNp,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 Shortword pswVpar[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563 Shortword pswAav1[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
566 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
567 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
570 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573 pL_coef[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 pL_work[9];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
575
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
576 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
577 swTemp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
578
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
579 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
580 i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
581 m;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
582
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
583
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
584 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
585 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
586 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
587 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
588 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
589
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
590 /*** Initialisation of the step-up recursion ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
591
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
592 pL_coef[0] = L_shl(0x4000L, 15);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
593 pL_coef[1] = L_shl(L_deposit_l(pswVpar[0]), 14);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
594
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
595
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
596 /*** Loop on the LPC analysis order: ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
597
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
598 for (m = 2; m <= swNp; m++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
599 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
600 for (i = 1; i < m; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
601 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
602 swTemp = extract_h(pL_coef[m - i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
603 pL_work[i] = L_mac(pL_coef[i], pswVpar[m - 1], swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
604 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
605 for (i = 1; i < m; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
606 pL_coef[i] = pL_work[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
607 pL_coef[m] = L_shl(L_deposit_l(pswVpar[m - 1]), 14);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
608 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
609
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
610
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
611 /*** Keep the aav1[0..swNp] in 15 bits for the following subclause ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
612
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
613 for (i = 0; i <= swNp; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
614 pswAav1[i] = extract_h(L_shr(pL_coef[i], 3));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
615
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
616 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
617
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
618 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
619 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
620 * FUNCTION: compute_rav1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
621 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
622 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
623 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
624 * PURPOSE: Computes the autocorrelation function of the adaptive
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
625 * filter coefficients.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
626 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
627 * INPUTS: pswAav1[0..8] adaptive filter coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
628 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
629 * OUTPUTS: pswRav1[0..8] ACF of aav1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
630 * pswNormRav1 r_av1 scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
631 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
632 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
633
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
634 void compute_rav1(Shortword pswAav1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
635 Shortword pswRav1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
636 Shortword *pswNormRav1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
637 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
638
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
639 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
640 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
641 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
642 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
643 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
644
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
645 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
646 pL_work[9];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
647
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
648 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
649 i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
650 k;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
651
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
652
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
653 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
654 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
655 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
656 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
657 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
658
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
659 /*** Computation of the rav1[0..8] ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
660
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
661 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
662 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
663 pL_work[i] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
664
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
665 for (k = 0; k <= 8 - i; k++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
666 pL_work[i] = L_mac(pL_work[i], pswAav1[k], pswAav1[k + i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
667 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
668
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
669 if (pL_work[0] == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
670 *pswNormRav1 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
671 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
672 *pswNormRav1 = norm_l(pL_work[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
673
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
674 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
675 pswRav1[i] = extract_h(L_shl(pL_work[i], *pswNormRav1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
676
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
677 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
678
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
679 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
680 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
681 * FUNCTION: spectral_comparison
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
682 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
683 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
684 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
685 * PURPOSE: Computes the stat flag needed for the threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
686 * adaptation decision.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
687 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
688 * INPUTS: pswRav1[0..8] ACF obtained from L_av1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
689 * swNormRav1 rav1 scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
690 * pL_av0[0..8] ACF averaged over last four frames
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
691 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
692 * OUTPUTS: pswStat flag to indicate spectral stationarity
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
693 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
694 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
695
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
696 void spectral_comparison(Shortword pswRav1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
697 Shortword swNormRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
698 Longword pL_av0[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
699 Shortword *pswStat)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
700 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
701
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
702 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
703 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
704 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
705 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
706 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
707
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
708 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
709 L_dm,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
710 L_sump,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
711 L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
712
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
713 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
714 pswSav0[9],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
715 swShift,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
716 swDivShift,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
717 swTemp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
718
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
719 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
720 i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
721
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
722
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
723 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
724 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
725 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
726 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
727 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
728
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
729 /*** Re-normalise L_av0[0..8] ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
730
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
731 if (pL_av0[0] == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
732 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
733 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
734 pswSav0[i] = 4095;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
735 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
736 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
737 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
738 swShift = sub(norm_l(pL_av0[0]), 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
739 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
740 pswSav0[i] = extract_h(L_shl(pL_av0[i], swShift));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
741 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
742
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
743 /*** compute partial sum of dm ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
744
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
745 L_sump = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
746
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
747 for (i = 1; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
748 L_sump = L_mac(L_sump, pswRav1[i], pswSav0[i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
749
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
750 /*** compute the division of the partial sum by sav0[0] ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
751
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
752 if (L_sump < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
753 L_temp = L_negate(L_sump);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
754 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
755 L_temp = L_sump;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
756
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
757 if (L_temp == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
758 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
759 L_dm = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
760 swShift = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
761 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
762 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
763 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
764 pswSav0[0] = shl(pswSav0[0], 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
765 swShift = norm_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
766 swTemp = extract_h(L_shl(L_temp, swShift));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
767
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
768 if (pswSav0[0] >= swTemp)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
769 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
770 swDivShift = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
771 swTemp = divide_s(swTemp, pswSav0[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
772 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
773 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
774 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
775 swDivShift = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
776 swTemp = sub(swTemp, pswSav0[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
777 swTemp = divide_s(swTemp, pswSav0[0]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
778 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
779
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
780 if (swDivShift == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
781 L_dm = 0x8000L;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
782 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
783 L_dm = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
784
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
785 L_dm = L_shl((L_add(L_dm, L_deposit_l(swTemp))), 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
786
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
787 if (L_sump < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
788 L_dm = L_sub(0L, L_dm);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
789 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
790
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
791
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
792 /*** Re-normalisation and final computation of L_dm ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
793
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
794 L_dm = L_shl(L_dm, 14);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
795 L_dm = L_shr(L_dm, swShift);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
796 L_dm = L_add(L_dm, L_shl(L_deposit_l(pswRav1[0]), 11));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
797 L_dm = L_shr(L_dm, swNormRav1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
798
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
799
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
800 /*** Compute the difference and save L_dm ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
801
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
802 L_temp = L_sub(L_dm, L_lastdm);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
803 L_lastdm = L_dm;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
804
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
805 if (L_temp < 0L)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
806 L_temp = L_negate(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
807
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
808
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
809 /*** Evaluation of the state flag ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
810
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
811 L_temp = L_sub(L_temp, 4456L);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
812
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
813 if (L_temp < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
814 *pswStat = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
815 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
816 *pswStat = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
817
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
818 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
819
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
820 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
821 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
822 * FUNCTION: tone_detection
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
823 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
824 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
825 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
826 * PURPOSE: Computes the tone flag needed for the threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
827 * adaptation decision.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
828 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
829 * INPUTS: pswRc[0..3] reflection coefficients calculated in the
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
830 * speech encoder short term predictor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
831 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
832 * OUTPUTS: pswTone flag to indicate a periodic signal component
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
833 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
834 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
835
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
836 void tone_detection(Shortword pswRc[4],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
837 Shortword *pswTone)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
838 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
839
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
840 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
841 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
842 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
843 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
844 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
845
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
846 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
847 L_num,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
848 L_den,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
849 L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
850
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
851 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
852 swTemp,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
853 swPredErr,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
854 pswA[3];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
855
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
856 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
857 i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
858
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
859 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
860 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
861 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
862 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
863 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
864
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
865 *pswTone = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
866
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
867
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
868 /*** Calculate filter coefficients ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
869
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
870 step_up(2, pswRc, pswA);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
871
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
872
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
873 /*** Calculate ( a[1] * a[1] ) ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
874
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
875 swTemp = shl(pswA[1], 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
876 L_den = L_mult(swTemp, swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
877
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
878
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
879 /*** Calculate ( 4*a[2] - a[1]*a[1] ) ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
880
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
881 L_temp = L_shl(L_deposit_h(pswA[2]), 3);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
882 L_num = L_sub(L_temp, L_den);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
883
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
884
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
885 /*** Check if pole frequency is less than 385 Hz ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
886
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
887 if (L_num <= 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
888 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
889
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
890 if (pswA[1] < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
891 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
892 swTemp = extract_h(L_den);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
893 L_temp = L_msu(L_num, swTemp, 3189);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
894
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
895 if (L_temp < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
896 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
897 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
898
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
899
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
900 /*** Calculate normalised prediction error ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
901
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
902 swPredErr = 0x7fff;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
903
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
904 for (i = 0; i < 4; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
905 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
906 swTemp = mult(pswRc[i], pswRc[i]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
907 swTemp = sub(32767, swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
908 swPredErr = mult(swPredErr, swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
909 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
910
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
911
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
912 /*** Test if prediction error is smaller than threshold ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
913
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
914 swTemp = sub(swPredErr, 1464);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
915
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
916 if (swTemp < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
917 *pswTone = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
918
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
919 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
920
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
921 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
922 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
923 * FUNCTION: threshold_adaptation
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
924 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
925 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
926 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
927 * PURPOSE: Evaluates the secondary VAD decision. If speech is not
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
928 * present then the noise model rvad and adaptive threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
929 * thvad are updated.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
930 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
931 * INPUTS: swStat flag to indicate spectral stationarity
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
932 * swPtch flag to indicate a periodic signal component
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
933 * swTone flag to indicate a tone signal component
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
934 * pswRav1[0..8] ACF obtained from l_av1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
935 * swNormRav1 r_av1 scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
936 * swM_pvad mantissa of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
937 * swE_pvad exponent of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
938 * swM_acf0 mantissa of signal frame energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
939 * swE_acf0 exponent of signal frame energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
940 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
941 * OUTPUTS: pswRvad[0..8] autocorrelated adaptive filter coefficients
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
942 * pswNormRvad rvad scaling factor
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
943 * pswM_thvad mantissa of decision threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
944 * pswE_thvad exponent of decision threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
945 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
946 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
947
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
948 void threshold_adaptation(Shortword swStat,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
949 Shortword swPtch,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
950 Shortword swTone,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
951 Shortword pswRav1[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
952 Shortword swNormRav1,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
953 Shortword swM_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
954 Shortword swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
955 Shortword swM_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
956 Shortword swE_acf0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
957 Shortword pswRvad[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
958 Shortword *pswNormRvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
959 Shortword *pswM_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
960 Shortword *pswE_thvad)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
961 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
962
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
963 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
964 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
965 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
966 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
967 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
968
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
969 Longword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
970 L_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
971
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
972 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
973 swTemp,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
974 swComp,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
975 swComp2,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
976 swM_temp,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
977 swE_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
978
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
979 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
980 i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
981
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
982
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
983 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
984 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
985 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
986 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
987 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
988
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
989 swComp = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
990
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
991 /*** Test if acf0 < pth; if yes set thvad to plev ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
992
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
993 if (swE_acf0 < E_PTH)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
994 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
995 if ((swE_acf0 == E_PTH) && (swM_acf0 < M_PTH))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
996 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
997
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
998 if (swComp == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
999 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1000 *pswE_thvad = E_PLEV;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1001 *pswM_thvad = M_PLEV;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1002
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1003 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1004 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1005
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1006
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1007 /*** Test if an adaption is required ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1008
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1009 if (swPtch == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1010 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1011 if (swStat == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1012 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1013 if (swTone == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1014 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1015
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1016 if (swComp == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1017 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1018 swAdaptCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1019 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1020 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1021
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1022
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1023 /*** Increment adaptcount ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1024
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1025 swAdaptCount = add(swAdaptCount, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1026 if (swAdaptCount <= 8)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1027 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1028
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1029
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1030 /*** computation of thvad-(thvad/dec) ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1031
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1032 *pswM_thvad = sub(*pswM_thvad, shr(*pswM_thvad, 5));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1033
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1034 if (*pswM_thvad < 0x4000)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1035 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1036 *pswM_thvad = shl(*pswM_thvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1037 *pswE_thvad = sub(*pswE_thvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1038 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1039
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1040
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1041 /*** computation of pvad*fac ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1042
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1043 L_temp = L_mult(swM_pvad, 20889);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1044 L_temp = L_shr(L_temp, 15);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1045 swE_temp = add(swE_pvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1046
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1047 if (L_temp > 0x7fffL)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1048 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1049 L_temp = L_shr(L_temp, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1050 swE_temp = add(swE_temp, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1051 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1052 swM_temp = extract_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1053
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1054
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1055 /*** test if thvad < pavd*fac ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1056
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1057 if (*pswE_thvad < swE_temp)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1058 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1059
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1060 if ((*pswE_thvad == swE_temp) && (*pswM_thvad < swM_temp))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1061 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1062
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1063
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1064 /*** compute minimum(thvad+(thvad/inc), pvad*fac) when comp = 1 ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1065
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1066 if (swComp == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1067 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1068
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1069 /*** compute thvad + (thvad/inc) ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1070
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1071 L_temp = L_add(L_deposit_l(*pswM_thvad),L_deposit_l(shr(*pswM_thvad, 4)));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1072
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1073 if (L_temp > 0x7fffL)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1074 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1075 *pswM_thvad = extract_l(L_shr(L_temp, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1076 *pswE_thvad = add(*pswE_thvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1077 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1078 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1079 *pswM_thvad = extract_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1080
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1081 swComp2 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1082
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1083 if (swE_temp < *pswE_thvad)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1084 swComp2 = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1085
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1086 if ((swE_temp == *pswE_thvad) && (swM_temp < *pswM_thvad))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1087 swComp2 = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1088
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1089 if (swComp2 == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1090 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1091 *pswE_thvad = swE_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1092 *pswM_thvad = swM_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1093 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1094 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1095
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1096
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1097 /*** compute pvad + margin ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1098
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1099 if (swE_pvad == E_MARGIN)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1100 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1101 L_temp = L_add(L_deposit_l(swM_pvad), L_deposit_l(M_MARGIN));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1102 swM_temp = extract_l(L_shr(L_temp, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1103 swE_temp = add(swE_pvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1104 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1105 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1106 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1107 if (swE_pvad > E_MARGIN)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1108 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1109 swTemp = sub(swE_pvad, E_MARGIN);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1110 swTemp = shr(M_MARGIN, swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1111 L_temp = L_add(L_deposit_l(swM_pvad), L_deposit_l(swTemp));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1112
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1113 if (L_temp > 0x7fffL)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1114 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1115 swE_temp = add(swE_pvad, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1116 swM_temp = extract_l(L_shr(L_temp, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1117 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1118 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1119 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1120 swE_temp = swE_pvad;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1121 swM_temp = extract_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1122 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1123 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1124 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1125 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1126 swTemp = sub(E_MARGIN, swE_pvad);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1127 swTemp = shr(swM_pvad, swTemp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1128 L_temp = L_add(L_deposit_l(M_MARGIN), L_deposit_l(swTemp));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1129
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1130 if (L_temp > 0x7fffL)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1131 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1132 swE_temp = add(E_MARGIN, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1133 swM_temp = extract_l(L_shr(L_temp, 1));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1134 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1135 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1136 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1137 swE_temp = E_MARGIN;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1138 swM_temp = extract_l(L_temp);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1139 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1140 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1141 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1142
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1143 /*** Test if thvad > pvad + margin ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1144
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1145 swComp = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1146
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1147 if (*pswE_thvad > swE_temp)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1148 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1149
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1150 if ((*pswE_thvad == swE_temp) && (*pswM_thvad > swM_temp))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1151 swComp = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1152
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1153 if (swComp == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1154 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1155 *pswE_thvad = swE_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1156 *pswM_thvad = swM_temp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1157 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1158
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1159 /*** Normalise and retain rvad[0..8] in memory ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1160
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1161 *pswNormRvad = swNormRav1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1162
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1163 for (i = 0; i <= 8; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1164 pswRvad[i] = pswRav1[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1165
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1166 /*** Set adaptcount to adp + 1 ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1167
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1168 swAdaptCount = 9;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1169
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1170 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1171
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1172 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1173 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1174 * FUNCTION: vad_decision
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1175 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1176 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1177 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1178 * PURPOSE: Computes the VAD decision based on the comparison of the
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1179 * floating point representations of pvad and thvad.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1180 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1181 * INPUTS: swM_pvad mantissa of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1182 * swE_pvad exponent of filtered signal energy
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1183 * swM_thvad mantissa of decision threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1184 * swE_thvad exponent of decision threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1185 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1186 * OUTPUTS: pswVvad vad decision before hangover is added
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1187 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1188 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1189
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1190 void vad_decision(Shortword swM_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1191 Shortword swE_pvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1192 Shortword swM_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1193 Shortword swE_thvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1194 Shortword *pswVvad)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1195 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1196
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1197 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1198 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1199 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1200 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1201 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1202
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1203 *pswVvad = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1204
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1205 if (swE_pvad > swE_thvad)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1206 *pswVvad = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1207 if ((swE_pvad == swE_thvad) && (swM_pvad > swM_thvad))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1208 *pswVvad = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1209
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1210 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1211
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1212 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1213 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1214 * FUNCTION: vad_hangover
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1215 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1216 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1217 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1218 * PURPOSE: Computes the final VAD decision for the current frame
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1219 * being processed.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1220 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1221 * INPUTS: swVvad vad decision before hangover is added
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1222 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1223 * OUTPUTS: pswVadFlag vad decision after hangover is added
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1224 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1225 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1226
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1227 void vad_hangover(Shortword swVvad,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1228 Shortword *pswVadFlag)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1229 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1230
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1231 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1232 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1233 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1234 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1235 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1236
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1237 if (swVvad == 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1238 swBurstCount = add(swBurstCount, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1239 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1240 swBurstCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1241
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1242 if (swBurstCount >= 3)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1243 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1244 swHangCount = 5;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1245 swBurstCount = 3;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1246 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1247
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1248 *pswVadFlag = swVvad;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1249
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1250 if (swHangCount >= 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1251 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1252 *pswVadFlag = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1253 swHangCount = sub(swHangCount, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1254 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1255
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1256 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1257
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1258 /****************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1259 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1260 * FUNCTION: periodicity_update
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1261 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1262 * VERSION: 1.2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1263 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1264 * PURPOSE: Computes the ptch flag needed for the threshold
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1265 * adaptation decision for the next frame.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1266 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1267 * INPUTS: pswLags[0..3] speech encoder long term predictor lags
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1268 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1269 * OUTPUTS: pswPtch Boolean voiced / unvoiced decision
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1270 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1271 ***************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1272
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1273 void periodicity_update(Shortword pswLags[4],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1274 Shortword *pswPtch)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1275 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1276
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1277 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1278 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1279 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1280 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1281 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1282
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1283 Shortword
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1284 swMinLag,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1285 swMaxLag,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1286 swSmallLag,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1287 swLagCount,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1288 swTemp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1289
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1290 int
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1291 i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1292 j;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1293
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1294 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1295 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1296 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1297 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1298 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1299
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1300 /*** Run loop for No. of sub-segments in the frame ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1301
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1302 swLagCount = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1303
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1304 for (i = 0; i <= 3; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1305 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1306 /*** Search the maximum and minimum of consecutive lags ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1307
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1308 if (swOldLag > pswLags[i])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1309 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1310 swMinLag = pswLags[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1311 swMaxLag = swOldLag;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1312 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1313 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1314 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1315 swMinLag = swOldLag;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1316 swMaxLag = pswLags[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1317 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1318
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1319
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1320 /*** Compute smallag (modulo operation not defined) ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1321
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1322 swSmallLag = swMaxLag;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1323
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1324 for (j = 0; j <= 2; j++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1325 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1326 if (swSmallLag >= swMinLag)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1327 swSmallLag = sub(swSmallLag, swMinLag);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1328 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1329
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1330
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1331 /*** Minimum of smallag and minlag - smallag ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1332
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1333 swTemp = sub(swMinLag, swSmallLag);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1334
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1335 if (swTemp < swSmallLag)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1336 swSmallLag = swTemp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1337
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1338 if (swSmallLag < 2)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1339 swLagCount = add(swLagCount, 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1340
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1341
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1342 /*** Save the current LTP lag ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1343
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1344 swOldLag = pswLags[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1345 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1346
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1347
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1348 /*** Update the veryoldlagcount and oldlagcount ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1349
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1350 swVeryOldLagCount = swOldLagCount;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1351 swOldLagCount = swLagCount;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1352
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1353
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1354 /*** Make ptch decision ready for next frame ***/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1355
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1356 swTemp = add(swOldLagCount, swVeryOldLagCount);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1357
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1358 if (swTemp >= 7)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1359 *pswPtch = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1360 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1361 *pswPtch = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1362
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1363 }