FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/vad1.c @ 443:526a7f0e027d
amrtest: implement twamr-encode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 May 2024 21:00:33 +0000 |
parents | 8847c1740e78 |
children |
rev | line source |
---|---|
408
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 **-------------------------------------------------------------------------** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 ** ** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 ** GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 ** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 ** R99 Version 3.3.0 ** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 ** REL-4 Version 4.1.0 ** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ** ** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 **-------------------------------------------------------------------------** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * File : vad1.c |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * Purpose : Voice Activity Detection (VAD) for AMR (option 1) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 * MODULE INCLUDE FILE AND VERSION ID |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "namespace.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include "vad1.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * INCLUDE FILES |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "typedef.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "basic_op.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "no_count.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "oper_32b.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "cnst_vad.h" |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * LOCAL VARIABLES AND TABLES |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 ******************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * PRIVATE PROGRAM CODE |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 ******************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * Function : first_filter_stage |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * Purpose : Scale input down by one bit. Calculate 5th order |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * half-band lowpass/highpass filter pair with |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * decimation. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 static void first_filter_stage(Word16 in[], /* i : input signal */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 Word16 out[], /* o : output values, every other */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* output is low-pass part and */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* other is high-pass part every */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 Word16 data[] /* i/o : filter memory */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 Word16 temp0, temp1, temp2, temp3, i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Word16 data0, data1; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 data0 = data[0]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 data1 = data[1]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (i = 0; i < FRAME_LEN/4; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 temp0 = sub(shr(in[4*i+0], 2), mult(COEFF5_1, data0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 temp1 = add(data0, mult(COEFF5_1, temp0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 temp3 = sub(shr(in[4*i+1], 2), mult(COEFF5_2, data1)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 temp2 = add(data1, mult(COEFF5_2, temp3)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 out[4*i+0] = add(temp1, temp2); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 out[4*i+1] = sub(temp1, temp2); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 data0 = sub(shr(in[4*i+2], 2), mult(COEFF5_1, temp0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 temp1 = add(temp0, mult(COEFF5_1, data0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 data1 = sub(shr(in[4*i+3], 2), mult(COEFF5_2, temp3)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 temp2 = add(temp3, mult(COEFF5_2, data1)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 out[4*i+2] = add(temp1, temp2); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 out[4*i+3] = sub(temp1, temp2); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 data[0] = data0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 data[1] = data1; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 * Function : filter5 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 * Purpose : Fifth-order half-band lowpass/highpass filter pair with |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 * decimation. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 static void filter5(Word16 *in0, /* i/o : input values; output low-pass part */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 Word16 *in1, /* i/o : input values; output high-pass part */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 Word16 data[] /* i/o : updated filter memory */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 Word16 temp0, temp1, temp2; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 temp0 = sub(*in0, mult(COEFF5_1, data[0])); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 temp1 = add(data[0], mult(COEFF5_1, temp0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 data[0] = temp0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 temp0 = sub(*in1, mult(COEFF5_2, data[1])); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 temp2 = add(data[1], mult(COEFF5_2, temp0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 data[1] = temp0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 *in0 = shr(add(temp1, temp2), 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 *in1 = shr(sub(temp1, temp2), 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 * Function : filter3 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 * Purpose : Third-order half-band lowpass/highpass filter pair with |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 * decimation. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 * Return value : |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 static void filter3(Word16 *in0, /* i/o : input values; output low-pass part */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 Word16 *in1, /* i/o : input values; output high-pass part */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 Word16 *data /* i/o : updated filter memory */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 Word16 temp1, temp2; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 temp1 = sub(*in1, mult(COEFF3, *data)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 temp2 = add(*data, mult(COEFF3, temp1)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 *data = temp1; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 *in1 = shr(sub(*in0, temp2), 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 *in0 = shr(add(*in0, temp2), 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 * Function : level_calculation |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 * Purpose : Calculate signal level in a sub-band. Level is calculated |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 * by summing absolute values of the input data. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 * Return value : signal level |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 static Word16 level_calculation( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 Word16 data[], /* i : signal buffer */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 Word16 *sub_level, /* i : level calculate at the end of the previous frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 /* o : level of signal calculated from the last */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 /* (count2 - count1) samples */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 Word16 count1, /* i : number of samples to be counted */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 Word16 count2, /* i : number of samples to be counted */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 Word16 ind_m, /* i : step size for the index of the data buffer */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 Word16 ind_a, /* i : starting index of the data buffer */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 Word16 scale /* i : scaling for the level calculation */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 Word32 l_temp1, l_temp2; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 Word16 level, i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 l_temp1 = 0L; move32 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 for (i = count1; i < count2; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 l_temp1 = L_mac(l_temp1, 1, abs_s(data[ind_m*i+ind_a])); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 l_temp2 = L_add(l_temp1, L_shl(*sub_level, sub(16, scale))); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 *sub_level = extract_h(L_shl(l_temp1, scale)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 for (i = 0; i < count1; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 l_temp2 = L_mac(l_temp2, 1, abs_s(data[ind_m*i+ind_a])); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 level = extract_h(L_shl(l_temp2, scale)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 return level; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 * Function : filter_bank |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 * Purpose : Divides input signal into 9-bands and calculas level of |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 * the signal in each band |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 static void filter_bank(vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 Word16 in[], /* i : input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 Word16 level[] /* 0 : signal levels at each band */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 Word16 i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 Word16 tmp_buf[FRAME_LEN]; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 /* calculate the filter bank */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 first_filter_stage(in, tmp_buf, st->a_data5[0]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 for (i = 0; i < FRAME_LEN/4; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 filter5(&tmp_buf[4*i], &tmp_buf[4*i+2], st->a_data5[1]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 filter5(&tmp_buf[4*i+1], &tmp_buf[4*i+3], st->a_data5[2]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 for (i = 0; i < FRAME_LEN/8; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 filter3(&tmp_buf[8*i+0], &tmp_buf[8*i+4], &st->a_data3[0]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 filter3(&tmp_buf[8*i+2], &tmp_buf[8*i+6], &st->a_data3[1]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 filter3(&tmp_buf[8*i+3], &tmp_buf[8*i+7], &st->a_data3[4]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 for (i = 0; i < FRAME_LEN/16; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 filter3(&tmp_buf[16*i+0], &tmp_buf[16*i+8], &st->a_data3[2]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 filter3(&tmp_buf[16*i+4], &tmp_buf[16*i+12], &st->a_data3[3]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 /* calculate levels in each frequency band */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 /* 3000 - 4000 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 level[8] = level_calculation(tmp_buf, &st->sub_level[8], FRAME_LEN/4-8, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 FRAME_LEN/4, 4, 1, 15); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 /* 2500 - 3000 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 level[7] = level_calculation(tmp_buf, &st->sub_level[7], FRAME_LEN/8-4, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 FRAME_LEN/8, 8, 7, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 /* 2000 - 2500 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 level[6] = level_calculation(tmp_buf, &st->sub_level[6], FRAME_LEN/8-4, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 FRAME_LEN/8, 8, 3, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 /* 1500 - 2000 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 level[5] = level_calculation(tmp_buf, &st->sub_level[5], FRAME_LEN/8-4, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 FRAME_LEN/8, 8, 2, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 /* 1000 - 1500 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 level[4] = level_calculation(tmp_buf, &st->sub_level[4], FRAME_LEN/8-4, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 FRAME_LEN/8, 8, 6, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 /* 750 - 1000 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 level[3] = level_calculation(tmp_buf, &st->sub_level[3], FRAME_LEN/16-2, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 FRAME_LEN/16, 16, 4, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 /* 500 - 750 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 level[2] = level_calculation(tmp_buf, &st->sub_level[2], FRAME_LEN/16-2, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 FRAME_LEN/16, 16, 12, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 /* 250 - 500 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 level[1] = level_calculation(tmp_buf, &st->sub_level[1], FRAME_LEN/16-2, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 FRAME_LEN/16, 16, 8, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 /* 0 - 250 Hz*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 level[0] = level_calculation(tmp_buf, &st->sub_level[0], FRAME_LEN/16-2, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 FRAME_LEN/16, 16, 0, 16); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 * Function : update_cntrl |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 * Purpose : Control update of the background noise estimate. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 * Inputs : pitch: flags for pitch detection |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 * stat_count: stationary counter |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 * tone: flags indicating presence of a tone |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 * complex: flags for complex detection |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 * vadreg: intermediate VAD flags |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 * Output : stat_count: stationary counter |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 static void update_cntrl(vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 Word16 level[] /* i : sub-band levels of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 Word16 i, temp, stat_rat, exp; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 Word16 num, denom; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 Word16 alpha; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 /* handle highband complex signal input separately */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 /* if ther has been highband correlation for some time */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 /* make sure that the VAD update speed is low for a while */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 if (st->complex_warning != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 if (sub(st->stat_count, CAD_MIN_STAT_COUNT) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 st->stat_count = CAD_MIN_STAT_COUNT; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 /* NB stat_count is allowed to be decreased by one below again */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 /* deadlock in speech is not possible unless the signal is very */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 /* complex and need a high rate */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 /* if fullband pitch or tone have been detected for a while, initialize stat_count */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 logic16 (); test (); logic16 (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 if ((sub((st->pitch & 0x6000), 0x6000) == 0) || |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 (sub((st->tone & 0x7c00), 0x7c00) == 0)) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 st->stat_count = STAT_COUNT; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 /* if 8 last vad-decisions have been "0", reinitialize stat_count */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 logic16 (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 if ((st->vadreg & 0x7f80) == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 st->stat_count = STAT_COUNT; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 stat_rat = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 if (sub(level[i], st->ave_level[i]) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 num = level[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 denom = st->ave_level[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 num = st->ave_level[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 denom = level[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 /* Limit nimimum value of num and denom to STAT_THR_LEVEL */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 if (sub(num, STAT_THR_LEVEL) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 num = STAT_THR_LEVEL; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 if (sub(denom, STAT_THR_LEVEL) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 denom = STAT_THR_LEVEL; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 exp = norm_s(denom); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 denom = shl(denom, exp); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 /* stat_rat = num/denom * 64 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 temp = div_s(shr(num, 1), denom); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 stat_rat = add(stat_rat, shr(temp, sub(8, exp))); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 /* compare stat_rat with a threshold and update stat_count */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 if (sub(stat_rat, STAT_THR) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 st->stat_count = STAT_COUNT; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 logic16 ();test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 if ((st->vadreg & 0x4000) != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 if (st->stat_count != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 st->stat_count = sub(st->stat_count, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 /* Update average amplitude estimate for stationarity estimation */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 alpha = ALPHA4; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 if (sub(st->stat_count, STAT_COUNT) == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 alpha = 32767; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 else if ((st->vadreg & 0x4000) == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 logic16 (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 alpha = ALPHA5; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 st->ave_level[i] = add(st->ave_level[i], |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 mult_r(alpha, sub(level[i], st->ave_level[i]))); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 * Function : hangover_addition |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 * Purpose : Add hangover for complex signal or after speech bursts |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 * Inputs : burst_count: counter for the length of speech bursts |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 * hang_count: hangover counter |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 * vadreg: intermediate VAD decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 * Outputs : burst_count: counter for the length of speech bursts |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 * hang_count: hangover counter |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 * Return value : VAD_flag indicating final VAD decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 static Word16 hangover_addition( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 Word16 noise_level, /* i : average level of the noise */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 /* estimates */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 Word16 low_power /* i : flag power of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 Word16 hang_len, burst_len; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 Calculate burst_len and hang_len |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 burst_len: number of consecutive intermediate vad flags with "1"-decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 required for hangover addition |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 hang_len: length of the hangover |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 if (sub(noise_level, HANG_NOISE_THR) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 burst_len = BURST_LEN_HIGH_NOISE; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 hang_len = HANG_LEN_HIGH_NOISE; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 burst_len = BURST_LEN_LOW_NOISE; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 hang_len = HANG_LEN_LOW_NOISE; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 /* if the input power (pow_sum) is lower than a threshold, clear |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 counters and set VAD_flag to "0" "fast exit" */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 if (low_power != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 st->burst_count = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 st->hang_count = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 st->complex_hang_count = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 st->complex_hang_timer = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 return 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 if (sub(st->complex_hang_timer, CVAD_HANG_LIMIT) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 if (sub(st->complex_hang_count, CVAD_HANG_LENGTH) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 st->complex_hang_count = CVAD_HANG_LENGTH; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 /* long time very complex signal override VAD output function */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 if (st->complex_hang_count != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 st->burst_count = BURST_LEN_HIGH_NOISE; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 st->complex_hang_count = sub(st->complex_hang_count, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 return 1; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 /* let hp_corr work in from a noise_period indicated by the VAD */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 test (); test (); logic16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 if (((st->vadreg & 0x3ff0) == 0) && |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 (sub(st->corr_hp_fast, CVAD_THRESH_IN_NOISE) > 0)) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 return 1; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 /* update the counters (hang_count, burst_count) */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 logic16 (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 if ((st->vadreg & 0x4000) != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 st->burst_count = add(st->burst_count, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 if (sub(st->burst_count, burst_len) >= 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 st->hang_count = hang_len; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 return 1; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 st->burst_count = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 if (st->hang_count > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 st->hang_count = sub(st->hang_count, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 return 1; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
493 return 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
495 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 * Function : noise_estimate_update |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 * Purpose : Update of background noise estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 * Inputs : bckr_est: background noise estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 * pitch: flags for pitch detection |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 * stat_count: stationary counter |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 * Outputs : bckr_est: background noise estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
505 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 static void noise_estimate_update( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
507 vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
508 Word16 level[] /* i : sub-band levels of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
509 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
510 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
511 Word16 i, alpha_up, alpha_down, bckr_add; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
512 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
513 /* Control update of bckr_est[] */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
514 update_cntrl(st, level); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 /* Choose update speed */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 bckr_add = 2; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
518 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 logic16 (); test (); logic16 (); test (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 if (((0x7800 & st->vadreg) == 0) && |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 ((st->pitch & 0x7800) == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 && (st->complex_hang_count == 0)) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
523 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
524 alpha_up = ALPHA_UP1; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
525 alpha_down = ALPHA_DOWN1; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
526 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
527 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
528 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
529 test (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
530 if ((st->stat_count == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
531 && (st->complex_hang_count == 0)) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
532 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
533 alpha_up = ALPHA_UP2; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
534 alpha_down = ALPHA_DOWN2; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
535 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
536 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
537 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
538 alpha_up = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
539 alpha_down = ALPHA3; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
540 bckr_add = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
541 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
542 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
543 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
544 /* Update noise estimate (bckr_est) */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
545 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
546 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
547 Word16 temp; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
548 temp = sub(st->old_level[i], st->bckr_est[i]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
549 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
550 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
551 if (temp < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
552 { /* update downwards*/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
553 st->bckr_est[i] = add(-2, add(st->bckr_est[i], mult_r(alpha_down, temp))); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
554 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
555 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
556 /* limit minimum value of the noise estimate to NOISE_MIN */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
557 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
558 if (sub(st->bckr_est[i], NOISE_MIN) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
559 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
560 st->bckr_est[i] = NOISE_MIN; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
561 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
562 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
563 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
564 { /* update upwards */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
565 st->bckr_est[i] = add(bckr_add, add(st->bckr_est[i], mult_r(alpha_up, temp))); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
566 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
567 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
568 /* limit maximum value of the noise estimate to NOISE_MAX */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
569 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
570 if (sub(st->bckr_est[i], NOISE_MAX) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
571 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
572 st->bckr_est[i] = NOISE_MAX; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
573 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
574 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
575 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
576 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
577 /* Update signal levels of the previous frame (old_level) */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
578 for(i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
579 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
580 st->old_level[i] = level[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
581 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
582 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
583 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
584 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
585 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
586 * Function : complex_estimate_adapt |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
587 * Purpose : Update/adapt of complex signal estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
588 * Inputs : low_power: low signal power flag |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
589 * Outputs : st->corr_hp_fast: long term complex signal estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
590 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
591 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
592 static void complex_estimate_adapt( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
593 vadState1 *st, /* i/o : VAD state struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
594 Word16 low_power /* i : very low level flag of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
595 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
596 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
597 Word16 alpha; /* Q15 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
598 Word32 L_tmp; /* Q31 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
599 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
600 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
601 /* adapt speed on own state */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
602 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
603 if (sub(st->best_corr_hp, st->corr_hp_fast) < 0) /* decrease */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
604 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
605 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
606 if (sub(st->corr_hp_fast, CVAD_THRESH_ADAPT_HIGH) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
607 { /* low state */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
608 alpha = CVAD_ADAPT_FAST; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
609 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
610 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
611 { /* high state */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
612 alpha = CVAD_ADAPT_REALLY_FAST; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
613 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
614 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
615 else /* increase */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
616 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
617 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
618 if (sub(st->corr_hp_fast, CVAD_THRESH_ADAPT_HIGH) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
619 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
620 alpha = CVAD_ADAPT_FAST; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
621 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
622 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
623 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
624 alpha = CVAD_ADAPT_SLOW; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
625 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
626 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
627 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
628 L_tmp = L_deposit_h(st->corr_hp_fast); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
629 L_tmp = L_msu(L_tmp, alpha, st->corr_hp_fast); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
630 L_tmp = L_mac(L_tmp, alpha, st->best_corr_hp); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
631 st->corr_hp_fast = round(L_tmp); /* Q15 */ move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
632 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
633 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
634 if (sub(st->corr_hp_fast, CVAD_MIN_CORR) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
635 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
636 st->corr_hp_fast = CVAD_MIN_CORR; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
637 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
638 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
639 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
640 if (low_power != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
641 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
642 st->corr_hp_fast = CVAD_MIN_CORR; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
643 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
644 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
645 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
646 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
647 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
648 * Function : complex_vad |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
649 * Purpose : complex background decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
650 * Return value : the complex background decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
651 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
652 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
653 static Word16 complex_vad(vadState1 *st, /* i/o : VAD state struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
654 Word16 low_power /* i : flag power of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
655 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
656 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
657 st->complex_high = shr(st->complex_high, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
658 st->complex_low = shr(st->complex_low, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
659 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
660 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
661 if (low_power == 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
662 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
663 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
664 if (sub(st->corr_hp_fast, CVAD_THRESH_ADAPT_HIGH) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
665 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
666 st->complex_high = st->complex_high | 0x4000; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
667 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
668 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
669 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
670 if (sub(st->corr_hp_fast, CVAD_THRESH_ADAPT_LOW) > 0 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
671 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
672 st->complex_low = st->complex_low | 0x4000; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
673 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
674 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
675 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
676 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
677 if (sub(st->corr_hp_fast, CVAD_THRESH_HANG) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
678 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
679 st->complex_hang_timer = add(st->complex_hang_timer, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
680 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
681 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
682 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
683 st->complex_hang_timer = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
684 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
685 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
686 test (); logic16 (); test (); logic16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
687 return ((sub((st->complex_high & 0x7f80), 0x7f80) == 0) || |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
688 (sub((st->complex_low & 0x7fff), 0x7fff) == 0)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
689 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
690 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
691 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
692 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
693 * Function : vad_decision |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
694 * Purpose : Calculates VAD_flag |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
695 * Inputs : bckr_est: background noise estimate |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
696 * vadreg: intermediate VAD flags |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
697 * Outputs : noise_level: average level of the noise estimates |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
698 * vadreg: intermediate VAD flags |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
699 * Return value : VAD_flag |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
700 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
701 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
702 static Word16 vad_decision( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
703 vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
704 Word16 level[COMPLEN], /* i : sub-band levels of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
705 Word32 pow_sum /* i : power of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
706 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
707 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
708 Word16 i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
709 Word16 snr_sum; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
710 Word32 L_temp; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
711 Word16 vad_thr, temp, noise_level; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
712 Word16 low_power_flag; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
713 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
714 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
715 Calculate squared sum of the input levels (level) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
716 divided by the background noise components (bckr_est). |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
717 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
718 L_temp = 0; move32(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
719 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
720 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
721 Word16 exp; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
722 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
723 exp = norm_s(st->bckr_est[i]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
724 temp = shl(st->bckr_est[i], exp); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
725 temp = div_s(shr(level[i], 1), temp); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
726 temp = shl(temp, sub(exp, UNIRSHFT-1)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
727 L_temp = L_mac(L_temp, temp, temp); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
728 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
729 snr_sum = extract_h(L_shl(L_temp, 6)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
730 snr_sum = mult(snr_sum, INV_COMPLEN); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
731 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
732 /* Calculate average level of estimated background noise */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
733 L_temp = 0; move32(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
734 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
735 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
736 L_temp = L_add(L_temp, st->bckr_est[i]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
737 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
738 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
739 noise_level = extract_h(L_shl(L_temp, 13)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
740 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
741 /* Calculate VAD threshold */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
742 vad_thr = add(mult(VAD_SLOPE, sub(noise_level, VAD_P1)), VAD_THR_HIGH); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
743 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
744 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
745 if (sub(vad_thr, VAD_THR_LOW) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
746 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
747 vad_thr = VAD_THR_LOW; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
748 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
749 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
750 /* Shift VAD decision register */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
751 st->vadreg = shr(st->vadreg, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
752 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
753 /* Make intermediate VAD decision */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
754 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
755 if (sub(snr_sum, vad_thr) > 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
756 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
757 st->vadreg = st->vadreg | 0x4000; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
758 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
759 /* primary vad decsion made */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
760 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
761 /* check if the input power (pow_sum) is lower than a threshold" */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
762 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
763 if (L_sub(pow_sum, VAD_POW_LOW) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
764 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
765 low_power_flag = 1; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
766 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
767 else |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
768 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
769 low_power_flag = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
770 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
771 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
772 /* update complex signal estimate st->corr_hp_fast and hangover reset timer using */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
773 /* low_power_flag and corr_hp_fast and various adaptation speeds */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
774 complex_estimate_adapt(st, low_power_flag); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
775 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
776 /* check multiple thresholds of the st->corr_hp_fast value */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
777 st->complex_warning = complex_vad(st, low_power_flag); move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
778 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
779 /* Update speech subband vad background noise estimates */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
780 noise_estimate_update(st, level); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
781 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
782 /* Add speech and complex hangover and return speech VAD_flag */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
783 /* long term complex hangover may be added */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
784 st->speech_vad_decision = hangover_addition(st, noise_level, low_power_flag); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
785 move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
786 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
787 return (st->speech_vad_decision); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
788 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
789 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
790 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
791 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
792 * PUBLIC PROGRAM CODE |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
793 ***************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
794 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
795 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
796 /************************************************************************* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
797 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
798 * Function: vad1_reset |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
799 * Purpose: Initializes state memory to zero |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
800 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
801 ************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
802 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
803 void vad1_reset (vadState1 *state) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
804 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
805 Word16 i, j; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
806 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
807 /* Initialize pitch detection variables */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
808 state->oldlag_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
809 state->oldlag = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
810 state->pitch = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
811 state->tone = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
812 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
813 state->complex_high = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
814 state->complex_low = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
815 state->complex_hang_timer = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
816 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
817 state->vadreg = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
818 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
819 state->stat_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
820 state->burst_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
821 state->hang_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
822 state->complex_hang_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
823 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
824 /* initialize memory used by the filter bank */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
825 for (i = 0; i < 3; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
826 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
827 for (j = 0; j < 2; j++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
828 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
829 state->a_data5[i][j] = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
830 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
831 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
832 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
833 for (i = 0; i < 5; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
834 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
835 state->a_data3[i] = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
836 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
837 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
838 /* initialize the rest of the memory */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
839 for (i = 0; i < COMPLEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
840 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
841 state->bckr_est[i] = NOISE_INIT; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
842 state->old_level[i] = NOISE_INIT; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
843 state->ave_level[i] = NOISE_INIT; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
844 state->sub_level[i] = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
845 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
846 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
847 state->best_corr_hp = CVAD_LOWPOW_RESET; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
848 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
849 state->speech_vad_decision = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
850 state->complex_warning = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
851 state->sp_burst_count = 0; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
852 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
853 state->corr_hp_fast = CVAD_LOWPOW_RESET; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
854 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
855 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
856 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
857 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
858 * Function : vad_complex_detection_update |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
859 * Purpose : update vad->bestCorr_hp complex signal feature state |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
860 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
861 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
862 void vad_complex_detection_update (vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
863 Word16 best_corr_hp /* i : best Corr */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
864 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
865 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
866 st->best_corr_hp = best_corr_hp; move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
867 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
868 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
869 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
870 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
871 * Function : vad_tone_detection |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
872 * Purpose : Set tone flag if pitch gain is high. This is used to detect |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
873 * signaling tones and other signals with high pitch gain. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
874 * Inputs : tone: flags indicating presence of a tone |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
875 * Outputs : tone: flags indicating presence of a tone |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
876 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
877 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
878 void vad_tone_detection (vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
879 Word32 t0, /* i : autocorrelation maxima */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
880 Word32 t1 /* i : energy */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
881 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
882 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
883 Word16 temp; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
884 /* |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
885 if (t0 > TONE_THR * t1) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
886 set tone flag |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
887 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
888 temp = round(t1); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
889 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
890 test (); test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
891 if ((temp > 0) && (L_msu(t0, temp, TONE_THR) > 0)) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
892 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
893 st->tone = st->tone | 0x4000; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
894 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
895 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
896 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
897 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
898 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
899 * Function : vad_tone_detection_update |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
900 * Purpose : Update the tone flag register. Tone flags are shifted right |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
901 * by one bit. This function should be called from the speech |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
902 * encoder before call to Vad_tone_detection() function. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
903 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
904 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
905 void vad_tone_detection_update ( |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
906 vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
907 Word16 one_lag_per_frame /* i : 1 if one open-loop lag is |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
908 calculated per each frame, |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
909 otherwise 0 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
910 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
911 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
912 /* Shift tone flags right by one bit */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
913 st->tone = shr(st->tone, 1); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
914 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
915 /* If open-loop lag is calculated only once in each frame, do extra update |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
916 and assume that the other tone flag of the frame is one. */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
917 if (one_lag_per_frame != 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
918 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
919 st->tone = shr(st->tone, 1); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
920 st->tone = st->tone | 0x2000; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
921 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
922 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
923 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
924 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
925 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
926 * Function : vad_pitch_detection |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
927 * Purpose : Test whether signal contains pitch or other periodic |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
928 * component. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
929 * Return value : Boolean voiced / unvoiced decision in state variable |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
930 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
931 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
932 void vad_pitch_detection (vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
933 Word16 T_op[] /* i : speech encoder open loop lags */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
934 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
935 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
936 Word16 lagcount, i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
937 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
938 lagcount = 0; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
939 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
940 for (i = 0; i < 2; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
941 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
942 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
943 if (sub (abs_s (sub (st->oldlag, T_op[i])), LTHRESH) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
944 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
945 lagcount = add (lagcount, 1); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
946 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
947 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
948 /* Save the current LTP lag */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
949 st->oldlag = T_op[i]; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
950 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
951 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
952 /* Make pitch decision. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
953 Save flag of the pitch detection to the variable pitch. |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
954 */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
955 st->pitch = shr(st->pitch, 1); move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
956 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
957 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
958 if (sub ( add (st->oldlag_count, lagcount), NTHRESH) >= 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
959 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
960 st->pitch = st->pitch | 0x4000; logic16(); move16(); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
961 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
962 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
963 /* Update oldlagcount */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
964 st->oldlag_count = lagcount; move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
965 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
966 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
967 /**************************************************************************** |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
968 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
969 * Function : vad |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
970 * Purpose : Main program for Voice Activity Detection (VAD) for AMR |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
971 * Return value : VAD Decision, 1 = speech, 0 = noise |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
972 * |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
973 ***************************************************************************/ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
974 Word16 vad1(vadState1 *st, /* i/o : State struct */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
975 Word16 in_buf[] /* i : samples of the input frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
976 ) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
977 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
978 Word16 level[COMPLEN]; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
979 Word32 pow_sum; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
980 Word16 i; |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
981 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
982 /* Calculate power of the input frame. */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
983 pow_sum = 0L; move32 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
984 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
985 for (i = 0; i < FRAME_LEN; i++) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
986 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
987 pow_sum = L_mac(pow_sum, in_buf[i-LOOKAHEAD], in_buf[i-LOOKAHEAD]); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
988 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
989 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
990 /* If input power is very low, clear pitch flag of the current frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
991 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
992 if (L_sub(pow_sum, POW_PITCH_THR) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
993 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
994 st->pitch = st->pitch & 0x3fff; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
995 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
996 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
997 /* If input power is very low, clear complex flag of the "current" frame */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
998 test (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
999 if (L_sub(pow_sum, POW_COMPLEX_THR) < 0) |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1000 { |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1001 st->complex_low = st->complex_low & 0x3fff; logic16 (); move16 (); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1002 } |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1003 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1004 /* Run the filter bank which calculates signal levels at each band */ |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1005 filter_bank(st, in_buf, level); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1006 |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1007 return (vad_decision(st, level, pow_sum)); |
8847c1740e78
libtwamr: integrate VAD1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1008 } |