FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/p_ol_wgh.c @ 515:bb36ef735f25
hrutil: starting with gsmhr-cod-parse
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 08:05:07 +0000 |
parents | 48c7f8e8c9af |
children |
rev | line source |
---|---|
416
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : p_ol_wgh.c |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Compute the open loop pitch lag with weighting |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 *************************************************************************/ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 /* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 ******************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 * MODULE INCLUDE FILE AND VERSION ID |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "namespace.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "p_ol_wgh.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 /* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * INCLUDE FILES |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include "typedef.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "basic_op.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "oper_32b.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "no_count.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "cnst.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "corrwght.tab" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "gmed_n.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "inv_sqrt.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "vad.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "calc_cor.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "hp_max.h" |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * LOCAL VARIABLES AND TABLES |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 /************************************************************************* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * FUNCTION: Lag_max |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * PURPOSE: Find the lag that has maximum correlation of scal_sig[] in a |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * given delay range. |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * DESCRIPTION: |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * The correlation is given by |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 * The functions outputs the maximum correlation after normalization |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * and the corresponding lag. |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 *************************************************************************/ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 static Word16 Lag_max ( /* o : lag found */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 vadState *vadSt, /* i/o : VAD state struct */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 Word32 corr[], /* i : correlation vector. */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 Word16 scal_sig[], /* i : scaled signal. */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 Word16 L_frame, /* i : length of frame to compute pitch */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 Word16 lag_max, /* i : maximum lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Word16 lag_min, /* i : minimum lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Word16 old_lag, /* i : old open-loop lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 Word16 *cor_max, /* o : normalized correlation of selected lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 Word16 wght_flg, /* i : is weighting function used */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 Word16 *gain_flg, /* o : open-loop flag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 Flag dtx /* i : dtx flag; use dtx=1, do not use dtx=0 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 Word16 i, j; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 Word16 *p, *p1; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 Word32 max, t0; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 Word16 t0_h, t0_l; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 Word16 p_max; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 const Word16 *ww, *we; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 Word32 t1; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ww = &corrweight[250]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 we = &corrweight[123 + lag_max - old_lag]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 max = MIN_32; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 p_max = lag_max; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 for (i = lag_max; i >= lag_min; i--) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 t0 = corr[-i]; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 /* Weighting of the correlation function. */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 L_Extract (corr[-i], &t0_h, &t0_l); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 t0 = Mpy_32_16 (t0_h, t0_l, *ww); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 ww--; move16(); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 test (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (wght_flg > 0) { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 /* Weight the neighbourhood of the old lag. */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 L_Extract (t0, &t0_h, &t0_l); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 t0 = Mpy_32_16 (t0_h, t0_l, *we); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 we--; move16(); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 test (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (L_sub (t0, max) >= 0) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 max = t0; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 p_max = i; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 p = &scal_sig[0]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 p1 = &scal_sig[-p_max]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 t0 = 0; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 t1 = 0; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 for (j = 0; j < L_frame; j++, p++, p1++) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 t0 = L_mac (t0, *p, *p1); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 t1 = L_mac (t1, *p1, *p1); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 if (dtx) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 { /* no test() call since this if is only in simulation env */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (vadSt->use_vad2) { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 /* Save max correlation */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 vadSt->u.v2.L_Rmax = L_add(vadSt->u.v2.L_Rmax, t0); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 /* Save max energy */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 vadSt->u.v2.L_R0 = L_add(vadSt->u.v2.L_R0, t1); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } else { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 /* update and detect tone */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 vad_tone_detection_update (&vadSt->u.v1, 0); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 vad_tone_detection (&vadSt->u.v1, t0, t1); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 /* gain flag is set according to the open_loop gain */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 /* is t2/t1 > 0.4 ? */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 *gain_flg = round(L_msu(t0, round(t1), 13107)); move16(); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 *cor_max = 0; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 return (p_max); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 /* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 * PUBLIC PROGRAM CODE |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 ***************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 /************************************************************************* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 * Function: p_ol_wgh_reset |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 * Purpose: Initializes state memory to zero |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 ************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 void p_ol_wgh_reset (pitchOLWghtState *st) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 /* Reset pitch search states */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 st->old_T0_med = 40; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 st->ada_w = 0; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 st->wght_flg = 0; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 /************************************************************************* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 * Function: p_ol_wgh |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 * Purpose: open-loop pitch search with weighting |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 ************************************************************************** |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 Word16 Pitch_ol_wgh ( /* o : open loop pitch lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 pitchOLWghtState *st, /* i/o : State struct */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 vadState *vadSt, /* i/o : VAD state struct */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 Word16 signal[], /* i : signal used to compute the open loop pitch */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 /* signal[-pit_max] to signal[-1] should be known */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 Word16 pit_min, /* i : minimum pitch lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 Word16 pit_max, /* i : maximum pitch lag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 Word16 L_frame, /* i : length of frame to compute pitch */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 Word16 old_lags[], /* i : history with old stored Cl lags */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 Word16 ol_gain_flg[], /* i : OL gain flag */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 Word16 idx, /* i : index */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 Flag dtx /* i : dtx flag; use dtx=1, do not use dtx=0 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 ) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 Word16 i; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 Word16 max1; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 Word16 p_max1; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 Word32 t0; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 Word16 corr_hp_max; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 Word32 corr[PIT_MAX+1], *corr_ptr; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 /* Scaled signal */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 Word16 scaled_signal[PIT_MAX + L_FRAME]; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 Word16 *scal_sig; |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 scal_sig = &scaled_signal[pit_max]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 t0 = 0L; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 for (i = -pit_max; i < L_frame; i++) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 t0 = L_mac (t0, signal[i], signal[i]); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 /*--------------------------------------------------------* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 * Scaling of input signal. * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 * * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 * if Overflow -> scal_sig[i] = signal[i]>>2 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 * else if t0 < 1^22 -> scal_sig[i] = signal[i]<<2 * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 * else -> scal_sig[i] = signal[i] * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 *--------------------------------------------------------*/ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 /*--------------------------------------------------------* |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 * Verification for risk of overflow. * |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 *--------------------------------------------------------*/ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 test (); test (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 if (L_sub (t0, MAX_32) == 0L) /* Test for overflow */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 for (i = -pit_max; i < L_frame; i++) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 scal_sig[i] = shr (signal[i], 3); move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 else if (L_sub (t0, (Word32) 1048576L) < (Word32) 0) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 for (i = -pit_max; i < L_frame; i++) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 scal_sig[i] = shl (signal[i], 3); move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 else |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 for (i = -pit_max; i < L_frame; i++) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 scal_sig[i] = signal[i]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 /* calculate all coreelations of scal_sig, from pit_min to pit_max */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 corr_ptr = &corr[pit_max]; move32 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 comp_corr (scal_sig, L_frame, pit_max, pit_min, corr_ptr); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 p_max1 = Lag_max (vadSt, corr_ptr, scal_sig, L_frame, pit_max, pit_min, |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 st->old_T0_med, &max1, st->wght_flg, &ol_gain_flg[idx], |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 dtx); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 test (); move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 if (ol_gain_flg[idx] > 0) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 /* Calculate 5-point median of previous lags */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 for (i = 4; i > 0; i--) /* Shift buffer */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 old_lags[i] = old_lags[i-1]; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 old_lags[0] = p_max1; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 st->old_T0_med = gmed_n (old_lags, 5); move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 st->ada_w = 32767; move16 (); /* Q15 = 1.0 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 else |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 st->old_T0_med = p_max1; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 st->ada_w = mult(st->ada_w, 29491); /* = ada_w = ada_w * 0.9 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 test (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (sub(st->ada_w, 9830) < 0) /* ada_w - 0.3 */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 st->wght_flg = 0; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 else |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 st->wght_flg = 1; move16 (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 if (dtx && !vadSt->use_vad2) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 { /* no test() call since this if is only in simulation env */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 test (); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 if (sub(idx, 1) == 0) |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 { |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 /* calculate max high-passed filtered correlation of all lags */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 hp_max (corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 /* update complex background detector */ |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 vad_complex_detection_update(&vadSt->u.v1, corr_hp_max); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 } |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 return (p_max1); |
48c7f8e8c9af
libtwamr: integrate p_ol_wgh.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 } |