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