FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/pitch_fr.c @ 391:be8edf9e6bc1
libtwamr: integrate pitch_fr.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 May 2024 18:30:00 +0000 |
parents | |
children |
rev | line source |
---|---|
391
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : pitch_fr.c |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Find the pitch period with 1/3 or 1/6 subsample |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * : resolution (closed loop). |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "pitch_fr.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * INCLUDE FILES |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "typedef.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "basic_op.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "oper_32b.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "no_count.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "cnst.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "enc_lag3.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "enc_lag6.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "inter_36.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "inv_sqrt.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "convolve.h" |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * LOCAL VARIABLES AND TABLES |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * mode dependent parameters used in Pitch_fr() |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * Note: order of MRxx in 'enum Mode' is important! |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 static const struct { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 Word16 max_frac_lag; /* lag up to which fractional lags are used */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 Word16 flag3; /* enable 1/3 instead of 1/6 fract. resolution */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 Word16 first_frac; /* first fractional to check */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 Word16 last_frac; /* last fractional to check */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 Word16 delta_int_low; /* integer lag below TO to start search from */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 Word16 delta_int_range; /* integer range around T0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 Word16 delta_frc_low; /* fractional below T0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 Word16 delta_frc_range; /* fractional range around T0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 Word16 pit_min; /* minimum pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } mode_dep_parm[8] = { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 /* MR475 */ { 84, 1, -2, 2, 5, 10, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 /* MR515 */ { 84, 1, -2, 2, 5, 10, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 /* MR59 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /* MR67 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 /* MR74 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 /* MR795 */ { 84, 1, -2, 2, 3, 6, 10, 19, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 /* MR102 */ { 84, 1, -2, 2, 3, 6, 5, 9, PIT_MIN }, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 /* MR122 */ { 94, 0, -3, 3, 3, 6, 5, 9, PIT_MIN_MR122 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 }; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * LOCAL PROGRAM CODE |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 /************************************************************************* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 * FUNCTION: Norm_Corr() |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 * PURPOSE: Find the normalized correlation between the target vector |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 * and the filtered past excitation. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 * DESCRIPTION: |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 * The normalized correlation is given by the correlation between the |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 * target and filtered past excitation divided by the square root of |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 * the energy of filtered excitation. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 * corr[k] = <x[], y_k[]>/sqrt(y_k[],y_k[]) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 * where x[] is the target vector and y_k[] is the filtered past |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 * excitation at delay k. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *************************************************************************/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 static void Norm_Corr (Word16 exc[], Word16 xn[], Word16 h[], Word16 L_subfr, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 Word16 t_min, Word16 t_max, Word16 corr_norm[]) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 Word16 i, j, k; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 Word16 corr_h, corr_l, norm_h, norm_l; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 Word32 s; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 /* Usally dynamic allocation of (L_subfr) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 Word16 excf[L_SUBFR]; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 Word16 scaling, h_fac, *s_excf, scaled_excf[L_SUBFR]; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 k = -t_min; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 /* compute the filtered excitation for the first delay t_min */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 Convolve (&exc[k], h, excf, L_subfr); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 /* scale "excf[]" to avoid overflow */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 for (j = 0; j < L_subfr; j++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 scaled_excf[j] = shr (excf[j], 2); move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 /* Compute 1/sqrt(energy of excf[]) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 s = 0; move32 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 for (j = 0; j < L_subfr; j++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 s = L_mac (s, excf[j], excf[j]); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 if (L_sub (s, 67108864L) <= 0) { /* if (s <= 2^26) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 s_excf = excf; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 h_fac = 15 - 12; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 scaling = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 /* "excf[]" is divided by 2 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 s_excf = scaled_excf; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 h_fac = 15 - 12 - 2; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 scaling = 2; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 /* loop for every possible period */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 for (i = t_min; i <= t_max; i++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 /* Compute 1/sqrt(energy of excf[]) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 s = 0; move32 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 for (j = 0; j < L_subfr; j++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 s = L_mac (s, s_excf[j], s_excf[j]); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 s = Inv_sqrt (s); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 L_Extract (s, &norm_h, &norm_l); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 /* Compute correlation between xn[] and excf[] */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 s = 0; move32 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 for (j = 0; j < L_subfr; j++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 s = L_mac (s, xn[j], s_excf[j]); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 L_Extract (s, &corr_h, &corr_l); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 /* Normalize correlation = correlation * (1/sqrt(energy)) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 s = Mpy_32 (corr_h, corr_l, norm_h, norm_l); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 corr_norm[i] = extract_h (L_shl (s, 16)); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 /* modify the filtered excitation excf[] for the next iteration */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 if (sub (i, t_max) != 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 k--; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 for (j = L_subfr - 1; j > 0; j--) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 s = L_mult (exc[k], h[j]); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 s = L_shl (s, h_fac); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 s_excf[j] = add (extract_h (s), s_excf[j - 1]); move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 s_excf[0] = shr (exc[k], scaling); move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 return; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 /************************************************************************* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 * FUNCTION: searchFrac() |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 * PURPOSE: Find fractional pitch |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 * DESCRIPTION: |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 * The function interpolates the normalized correlation at the |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 * fractional positions around lag T0. The position at which the |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 * interpolation function reaches its maximum is the fractional pitch. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 * Starting point of the search is frac, end point is last_frac. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 * frac is overwritten with the fractional pitch. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 *************************************************************************/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 static void searchFrac ( |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 Word16 *lag, /* i/o : integer pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 Word16 *frac, /* i/o : start point of search - |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 fractional pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 Word16 last_frac, /* i : endpoint of search */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 Word16 corr[], /* i : normalized correlation */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 Word16 flag3 /* i : subsample resolution |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 (3: =1 / 6: =0) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 ) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 Word16 i; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 Word16 max; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 Word16 corr_int; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 /* Test the fractions around T0 and choose the one which maximizes */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 /* the interpolated normalized correlation. */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 max = Interpol_3or6 (&corr[*lag], *frac, flag3); move16 (); /* function result */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 for (i = add (*frac, 1); i <= last_frac; i++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 corr_int = Interpol_3or6 (&corr[*lag], i, flag3); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 if (sub (corr_int, max) > 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 max = corr_int; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 *frac = i; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 test(); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 if (flag3 == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 /* Limit the fraction value in the interval [-2,-1,0,1,2,3] */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 if (sub (*frac, -3) == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 *frac = 3; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 *lag = sub (*lag, 1); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 /* limit the fraction value between -1 and 1 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 if (sub (*frac, -2) == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 *frac = 1; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 *lag = sub (*lag, 1); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 if (sub (*frac, 2) == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 *frac = -1; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 *lag = add (*lag, 1); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 /************************************************************************* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 * FUNCTION: getRange() |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 * PURPOSE: Sets range around open-loop pitch or integer pitch of last subframe |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 * DESCRIPTION: |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 * Takes integer pitch T0 and calculates a range around it with |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 * t0_min = T0-delta_low and t0_max = (T0-delta_low) + delta_range |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 * t0_min and t0_max are bounded by pitmin and pitmax |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 *************************************************************************/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 static void getRange ( |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 Word16 T0, /* i : integer pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 Word16 delta_low, /* i : search start offset */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 Word16 delta_range, /* i : search range */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 Word16 pitmin, /* i : minimum pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 Word16 pitmax, /* i : maximum pitch */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 Word16 *t0_min, /* o : search range minimum */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 Word16 *t0_max) /* o : search range maximum */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 *t0_min = sub(T0, delta_low); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 if (sub(*t0_min, pitmin) < 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 *t0_min = pitmin; move16(); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 *t0_max = add(*t0_min, delta_range); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 if (sub(*t0_max, pitmax) > 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 *t0_max = pitmax; move16(); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 *t0_min = sub(*t0_max, delta_range); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 /* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 * PUBLIC PROGRAM CODE |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 ******************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 /************************************************************************* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 * Function: Pitch_fr_reset |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 * Purpose: Initializes state memory to zero |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 ************************************************************************** |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 void Pitch_fr_reset (Pitch_frState *state) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 state->T0_prev_subframe = 0; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 /************************************************************************* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 * FUNCTION: Pitch_fr() |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 * PURPOSE: Find the pitch period with 1/3 or 1/6 subsample resolution |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 * (closed loop). |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 * DESCRIPTION: |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 * - find the normalized correlation between the target and filtered |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 * past excitation in the search range. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 * - select the delay with maximum normalized correlation. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 * - interpolate the normalized correlation at fractions -3/6 to 3/6 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 * with step 1/6 around the chosen delay. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 * - The fraction which gives the maximum interpolated value is chosen. |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 *************************************************************************/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 Word16 Pitch_fr ( /* o : pitch period (integer) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 Pitch_frState *st, /* i/o : State struct */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 enum Mode mode, /* i : codec mode */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 Word16 T_op[], /* i : open loop pitch lags */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 Word16 exc[], /* i : excitation buffer Q0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 Word16 xn[], /* i : target vector Q0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 Word16 h[], /* i : impulse response of synthesis and |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 weighting filters Q12 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 Word16 L_subfr, /* i : Length of subframe */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 Word16 i_subfr, /* i : subframe offset */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 Word16 *pit_frac, /* o : pitch period (fractional) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 Word16 *resu3, /* o : subsample resolution 1/3 (=1) or 1/6 (=0) */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 Word16 *ana_index /* o : index of encoding */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 ) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 Word16 i; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 Word16 t_min, t_max; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 Word16 t0_min, t0_max; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 Word16 max, lag, frac; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 Word16 tmp_lag; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 Word16 *corr; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 Word16 corr_v[40]; /* Total length = t0_max-t0_min+1+2*L_INTER_SRCH */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 Word16 max_frac_lag; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 Word16 flag3, flag4; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 Word16 last_frac; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 Word16 delta_int_low, delta_int_range; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 Word16 delta_frc_low, delta_frc_range; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 Word16 pit_min; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 Word16 frame_offset; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 Word16 delta_search; |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 * set mode specific variables * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 max_frac_lag = mode_dep_parm[mode].max_frac_lag; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 flag3 = mode_dep_parm[mode].flag3; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 frac = mode_dep_parm[mode].first_frac; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 last_frac = mode_dep_parm[mode].last_frac; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 delta_int_low = mode_dep_parm[mode].delta_int_low; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 delta_int_range = mode_dep_parm[mode].delta_int_range; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 delta_frc_low = mode_dep_parm[mode].delta_frc_low; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 delta_frc_range = mode_dep_parm[mode].delta_frc_range; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 pit_min = mode_dep_parm[mode].pit_min; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 * decide upon full or differential search * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 delta_search = 1; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 if ((i_subfr == 0) || (sub(i_subfr,L_FRAME_BY2) == 0)) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 /* Subframe 1 and 3 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 test (); test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 if (((sub(mode, MR475) != 0) && (sub(mode, MR515) != 0)) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 (sub(i_subfr,L_FRAME_BY2) != 0)) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 /* set t0_min, t0_max for full search */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 /* this is *not* done for mode MR475, MR515 in subframe 3 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 delta_search = 0; /* no differential search */ move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 /* calculate index into T_op which contains the open-loop */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 /* pitch estimations for the 2 big subframes */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 frame_offset = 1; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 if (i_subfr == 0) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 frame_offset = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 /* get T_op from the corresponding half frame and */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 /* set t0_min, t0_max */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 getRange (T_op[frame_offset], delta_int_low, delta_int_range, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 pit_min, PIT_MAX, &t0_min, &t0_max); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 /* mode MR475, MR515 and 3. Subframe: delta search as well */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 pit_min, PIT_MAX, &t0_min, &t0_max); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 /* for Subframe 2 and 4 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 /* get range around T0 of previous subframe for delta search */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 pit_min, PIT_MAX, &t0_min, &t0_max); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 * Find interval to compute normalized correlation * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 t_min = sub (t0_min, L_INTER_SRCH); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 t_max = add (t0_max, L_INTER_SRCH); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 corr = &corr_v[-t_min]; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 * Compute normalized correlation between target and filtered excitation * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 Norm_Corr (exc, xn, h, L_subfr, t_min, t_max, corr); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 * Find integer pitch * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 max = corr[t0_min]; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 lag = t0_min; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 for (i = t0_min + 1; i <= t0_max; i++) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 if (sub (corr[i], max) >= 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 max = corr[i]; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 lag = i; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 * Find fractional pitch * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 if ((delta_search == 0) && (sub (lag, max_frac_lag) > 0)) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 /* full search and integer pitch greater than max_frac_lag */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 /* fractional search is not needed, set fractional to zero */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 frac = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 /* if differential search AND mode MR475 OR MR515 OR MR59 OR MR67 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 /* then search fractional with 4 bits resolution */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 test (); test (); test (); test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 if ((delta_search != 0) && |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 ((sub (mode, MR475) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 (sub (mode, MR515) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 (sub (mode, MR59) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 (sub (mode, MR67) == 0))) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 /* modify frac or last_frac according to position of last */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 /* integer pitch: either search around integer pitch, */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 /* or only on left or right side */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 tmp_lag = st->T0_prev_subframe; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 if ( sub( sub(tmp_lag, t0_min), 5) > 0) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 tmp_lag = add (t0_min, 5); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 if ( sub( sub(t0_max, tmp_lag), 4) > 0) |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 tmp_lag = sub (t0_max, 4); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 if ((sub (lag, tmp_lag) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 (sub (lag, sub(tmp_lag, 1)) == 0)) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 /* normal search in fractions around T0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 searchFrac (&lag, &frac, last_frac, corr, flag3); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 else if (sub (lag, sub (tmp_lag, 2)) == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 /* limit search around T0 to the right side */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 frac = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 searchFrac (&lag, &frac, last_frac, corr, flag3); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 else if (sub (lag, add(tmp_lag, 1)) == 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
493 /* limit search around T0 to the left side */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 last_frac = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
495 searchFrac (&lag, &frac, last_frac, corr, flag3); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 else { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 /* no fractional search */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 frac = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 else |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 /* test the fractions around T0 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
505 searchFrac (&lag, &frac, last_frac, corr, flag3); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
507 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
508 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
509 * encode pitch * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
510 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
511 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
512 test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
513 if (flag3 != 0) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
514 /* flag4 indicates encoding with 4 bit resolution; */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 /* this is needed for mode MR475, MR515 and MR59 */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 flag4 = 0; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
518 test (); test (); test (); test (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 if ( (sub (mode, MR475) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 (sub (mode, MR515) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 (sub (mode, MR59) == 0) || |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 (sub (mode, MR67) == 0) ) { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
523 flag4 = 1; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
524 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
525 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
526 /* encode with 1/3 subsample resolution */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
527 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
528 *ana_index = Enc_lag3(lag, frac, st->T0_prev_subframe, |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
529 t0_min, t0_max, delta_search, flag4); move16 (); /* function result */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
530 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
531 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
532 else |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
533 { |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
534 /* encode with 1/6 subsample resolution */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
535 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
536 *ana_index = Enc_lag6(lag, frac, t0_min, delta_search); move16 (); /* function result */ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
537 } |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
538 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
539 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
540 * update state variables * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
541 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
542 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
543 st->T0_prev_subframe = lag; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
544 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
545 /*-----------------------------------------------------------------------* |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
546 * update output variables * |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
547 *-----------------------------------------------------------------------*/ |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
548 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
549 *resu3 = flag3; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
550 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
551 *pit_frac = frac; move16 (); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
552 |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
553 return (lag); |
be8edf9e6bc1
libtwamr: integrate pitch_fr.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
554 } |