annotate libtwamr/pitch_ol.c @ 483:4f13db3a7086

doc/Utils-overview: document new utilities
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 May 2024 01:26:12 +0000
parents 01c4becb9fda
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
415
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : pitch_ol.c
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Compute the open loop pitch lag.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * MODULE INCLUDE FILE AND VERSION ID
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "namespace.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "pitch_ol.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * INCLUDE FILES
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include "typedef.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "basic_op.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "oper_32b.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "no_count.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "cnst.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "inv_sqrt.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "vad.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "calc_cor.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "hp_max.h"
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * LOCAL VARIABLES AND TABLES
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 #define THRESHOLD 27853
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * LOCAL PROGRAM CODE
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 /*************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * FUNCTION: Lag_max
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * PURPOSE: Find the lag that has maximum correlation of scal_sig[] in a
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * given delay range.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 * DESCRIPTION:
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 * The correlation is given by
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 * cor[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 * The functions outputs the maximum correlation after normalization
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 * and the corresponding lag.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *************************************************************************/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 static Word16 Lag_max ( /* o : lag found */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 vadState *vadSt, /* i/o : VAD state struct */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word32 corr[], /* i : correlation vector. */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 scal_sig[], /* i : scaled signal. */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word16 scal_fac, /* i : scaled signal factor. */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 Word16 scal_flag, /* i : if 1 use EFR compatible scaling */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 Word16 L_frame, /* i : length of frame to compute pitch */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Word16 lag_max, /* i : maximum lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 Word16 lag_min, /* i : minimum lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 *cor_max, /* o : normalized correlation of selected lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Word32 *rmax, /* o : max(<s[i]*s[j]>) */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word32 *r0, /* o : residual energy */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 Flag dtx /* i : dtx flag; use dtx=1, do not use dtx=0 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 )
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 Word16 i, j;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 Word16 *p;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 Word32 max, t0;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 Word16 max_h, max_l, ener_h, ener_l;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Word16 p_max = 0; /* initialization only needed to keep gcc silent */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 max = MIN_32; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 p_max = lag_max; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 for (i = lag_max, j = (PIT_MAX-lag_max-1); i >= lag_min; i--, j--)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (L_sub (corr[-i], max) >= 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 max = corr[-i]; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 p_max = i; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /* compute energy */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 t0 = 0; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 p = &scal_sig[-p_max]; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 for (i = 0; i < L_frame; i++, p++)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 t0 = L_mac (t0, *p, *p);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* 1/sqrt(energy) */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (dtx)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 { /* no test() call since this if is only in simulation env */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 *rmax = max; move32();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 *r0 = t0; move32();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /* check tone */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (!vadSt->use_vad2)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 vad_tone_detection (&vadSt->u.v1, max, t0);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 t0 = Inv_sqrt (t0); move32 (); /* function result */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 test();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (scal_flag)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 t0 = L_shl (t0, 1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 /* max = max/sqrt(energy) */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 L_Extract (max, &max_h, &max_l);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 L_Extract (t0, &ener_h, &ener_l);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 t0 = Mpy_32 (max_h, max_l, ener_h, ener_l);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 test();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (scal_flag)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 t0 = L_shr (t0, scal_fac);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 *cor_max = extract_h (L_shl (t0, 15)); /* divide by 2 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 else
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 *cor_max = extract_l(t0);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 return (p_max);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 * PUBLIC PROGRAM CODE
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 ********************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 /*************************************************************************
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 * FUNCTION: Pitch_ol
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 * PURPOSE: Compute the open loop pitch lag.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 * DESCRIPTION:
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * The open-loop pitch lag is determined based on the perceptually
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 * weighted speech signal. This is done in the following steps:
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * - find three maxima of the correlation <sw[n],sw[n-T]>,
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * dividing the search range into three parts:
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 * pit_min ... 2*pit_min-1
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 * 2*pit_min ... 4*pit_min-1
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 * 4*pit_min ... pit_max
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 * - divide each maximum by <sw[n-t], sw[n-t]> where t is the delay at
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 * that maximum correlation.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 * - select the delay of maximum normalized correlation (among the
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 * three candidates) while favoring the lower delay ranges.
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 *************************************************************************/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 Word16 Pitch_ol ( /* o : open loop pitch lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 vadState *vadSt, /* i/o : VAD state struct */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 enum Mode mode, /* i : coder mode */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 Word16 signal[], /* i : signal used to compute the open loop pitch */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 /* signal[-pit_max] to signal[-1] should be known */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 Word16 pit_min, /* i : minimum pitch lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 Word16 pit_max, /* i : maximum pitch lag */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 Word16 L_frame, /* i : length of frame to compute pitch */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 Word16 idx, /* i : frame index */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 Flag dtx /* i : dtx flag; use dtx=1, do not use dtx=0 */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 )
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 Word16 i, j;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 Word16 max1, max2, max3;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 Word16 p_max1, p_max2, p_max3;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 Word16 scal_flag = 0;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word32 t0;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word32 r01, r02, r03;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word32 rmax1, rmax2, rmax3;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 corr_hp_max;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 Word32 corr[PIT_MAX+1], *corr_ptr;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 /* Scaled signal */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 Word16 scaled_signal[L_FRAME + PIT_MAX];
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 Word16 *scal_sig, scal_fac;
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 if (dtx && !vadSt->use_vad2)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 { /* no test() call since this if is only in simulation env */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 /* update tone detection */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 test(); test();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 if ((sub(mode, MR475) == 0) || (sub(mode, MR515) == 0))
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 vad_tone_detection_update (&vadSt->u.v1, 1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 else
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 vad_tone_detection_update (&vadSt->u.v1, 0);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 scal_sig = &scaled_signal[pit_max]; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 t0 = 0L; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 for (i = -pit_max; i < L_frame; i++)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 t0 = L_mac (t0, signal[i], signal[i]);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 /*--------------------------------------------------------*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 * Scaling of input signal. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 * *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 * if Overflow -> scal_sig[i] = signal[i]>>3 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 * else if t0 < 1^20 -> scal_sig[i] = signal[i]<<3 *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 * else -> scal_sig[i] = signal[i] *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 *--------------------------------------------------------*/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 /*--------------------------------------------------------*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 * Verification for risk of overflow. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 *--------------------------------------------------------*/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 if (L_sub (t0, MAX_32) == 0L) /* Test for overflow */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 for (i = -pit_max; i < L_frame; i++)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 scal_sig[i] = shr (signal[i], 3); move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 scal_fac = 3; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 else if (L_sub (t0, (Word32) 1048576L) < (Word32) 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 /* if (t0 < 2^20) */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 for (i = -pit_max; i < L_frame; i++)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 scal_sig[i] = shl (signal[i], 3); move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 scal_fac = -3; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 else
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 for (i = -pit_max; i < L_frame; i++)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 scal_sig[i] = signal[i]; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 scal_fac = 0; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 /* calculate all coreelations of scal_sig, from pit_min to pit_max */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 corr_ptr = &corr[pit_max]; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 comp_corr (scal_sig, L_frame, pit_max, pit_min, corr_ptr);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 /*--------------------------------------------------------------------*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 * The pitch lag search is divided in three sections. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 * Each section cannot have a pitch multiple. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 * We find a maximum for each section. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 * We compare the maximum of each section by favoring small lags. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 * *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 * First section: lag delay = pit_max downto 4*pit_min *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 * Second section: lag delay = 4*pit_min-1 downto 2*pit_min *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 * Third section: lag delay = 2*pit_min-1 downto pit_min *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 *--------------------------------------------------------------------*/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 /* mode dependent scaling in Lag_max */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 if (sub(mode, MR122) == 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 scal_flag = 1; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 else
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 scal_flag = 0; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 j = shl (pit_min, 2);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 p_max1 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 pit_max, j, &max1, &rmax1, &r01, dtx);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 i = sub (j, 1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 j = shl (pit_min, 1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 p_max2 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 i, j, &max2, &rmax2, &r02, dtx);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 i = sub (j, 1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 p_max3 = Lag_max (vadSt, corr_ptr, scal_sig, scal_fac, scal_flag, L_frame,
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 i, pit_min, &max3, &rmax3, &r03, dtx);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 if (dtx && !vadSt->use_vad2)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 { /* no test() call since this if is only in simulation env */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 if (sub(idx, 1) == 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 /* calculate max high-passed filtered correlation of all lags */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 hp_max (corr_ptr, scal_sig, L_frame, pit_max, pit_min, &corr_hp_max);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 /* update complex background detector */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 vad_complex_detection_update(&vadSt->u.v1, corr_hp_max);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 /*--------------------------------------------------------------------*
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 * Compare the 3 sections maximum, and favor small lag. *
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 *--------------------------------------------------------------------*/
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 if (sub (mult (max1, THRESHOLD), max2) < 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 max1 = max2; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 p_max1 = p_max2; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 if (dtx)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 rmax1 = rmax2; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 r01 = r02; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 test ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 if (sub (mult (max1, THRESHOLD), max3) < 0)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 p_max1 = p_max3; move16 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 if (dtx)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 rmax1 = rmax3; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 r01 = r03; move32 ();
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 if (dtx && vadSt->use_vad2)
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 {
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 /* Save max correlation */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 vadSt->u.v2.L_Rmax = L_add(vadSt->u.v2.L_Rmax, rmax1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 /* Save max energy */
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 vadSt->u.v2.L_R0 = L_add(vadSt->u.v2.L_R0, r01);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 }
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 return (p_max1);
01c4becb9fda libtwamr: integrate pitch_ol.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 }