annotate libtwamr/c2_9pf.c @ 544:bd32bb1e8dab

doc/EFR-library-API: document malloc-alternative provision
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 03 Oct 2024 08:22:41 +0000
parents ee64aabcc7a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
320
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : c2_9pf.c
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Searches a 9 bit algebraic codebook containing
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * 2 pulses in a frame of 40 samples.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 * MODULE INCLUDE FILE AND VERSION ID
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "namespace.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "c2_9pf.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * INCLUDE FILES
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "typedef.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "basic_op.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "no_count.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "inv_sqrt.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "cnst.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "cor_h.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "set_sign.h"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * LOCAL VARIABLES AND TABLES
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #define NB_PULSE 2
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 #include "c2_9pf.tab"
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * DECLARATION OF PROTOTYPES
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 static void search_2i40(
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word16 subNr, /* i : subframe number */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 Word16 dn[], /* i : correlation between target and h[] */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 rr[][L_CODE],/* i : matrix of autocorrelation */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 Word16 codvec[] /* o : algebraic codebook vector */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 );
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 static Word16 build_code(
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Word16 subNr, /* i : subframe number */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 codvec[], /* i : algebraic codebook vector */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 dn_sign[], /* i : sign of dn[] */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 h[], /* i : impulse response of weighted synthesis filter */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Word16 y[], /* o : filtered fixed codebook excitation */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 sign[] /* o : sign of 2 pulses */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 );
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 * PUBLIC PROGRAM CODE
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /*************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 * FUNCTION: code_2i40_9bits()
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 * PURPOSE: Searches a 9 bit algebraic codebook containing 2 pulses
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 * in a frame of 40 samples.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * DESCRIPTION:
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * The code length is 40, containing 2 nonzero pulses: i0...i1.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 * All pulses can have two possible amplitudes: +1 or -1.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * Pulse i0 can have 8 possible positions, pulse i1 can have
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * 8 positions. Also coded is which track pair should be used,
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * i.e. first or second pair. Where each pair contains 2 tracks.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 * First subframe:
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 * first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 * i1 : 2, 7, 12, 17, 22, 27, 32, 37.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 * second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 * i1 : 3, 8, 13, 18, 23, 28, 33, 38.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 * Second subframe:
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 * first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 * i1 : 3, 8, 13, 18, 23, 28, 33, 38.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 * second i0 : 2, 7, 12, 17, 22, 27, 32, 37.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 * i1 : 4, 9, 14, 19, 24, 29, 34, 39.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 * Third subframe:
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * i1 : 2, 7, 12, 17, 22, 27, 32, 37.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 * second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 * i1 : 4, 9, 14, 19, 24, 29, 34, 39.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 * Fourth subframe:
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 * first i0 : 0, 5, 10, 15, 20, 25, 30, 35.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 * i1 : 3, 8, 13, 18, 23, 28, 33, 38.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 * second i0 : 1, 6, 11, 16, 21, 26, 31, 36.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 * i1 : 4, 9, 14, 19, 24, 29, 34, 39.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 *************************************************************************/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 Word16 code_2i40_9bits(
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 Word16 subNr, /* i : subframe number */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 Word16 x[], /* i : target vector */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 Word16 h[], /* i : impulse response of weighted synthesis filter */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 /* h[-L_subfr..-1] must be set to zero. */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 Word16 T0, /* i : Pitch lag */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 Word16 pitch_sharp, /* i : Last quantized pitch gain */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 Word16 code[], /* o : Innovative codebook */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 Word16 y[], /* o : filtered fixed codebook excitation */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 Word16 * sign /* o : Signs of 2 pulses */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 )
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 Word16 codvec[NB_PULSE];
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 Word16 dn[L_CODE], dn2[L_CODE], dn_sign[L_CODE];
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 Word16 rr[L_CODE][L_CODE];
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 Word16 i, index, sharp;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 sharp = shl(pitch_sharp, 1);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 if (sub(T0, L_CODE) < 0)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 for (i = T0; i < L_CODE; i++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 h[i] = add(h[i], mult(h[i - T0], sharp)); move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 cor_h_x(h, x, dn, 1);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 set_sign(dn, dn_sign, dn2, 8); /* dn2[] not used in this codebook search */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 cor_h(h, dn_sign, rr);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 search_2i40(subNr, dn, rr, codvec);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 move16 (); /* function result */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 index = build_code(subNr, codvec, dn_sign, code, h, y, sign);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 /*-----------------------------------------------------------------*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 * Compute innovation vector gain. *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 * Include fixed-gain pitch contribution into code[]. *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 *-----------------------------------------------------------------*/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 if (sub(T0, L_CODE) < 0)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 for (i = T0; i < L_CODE; i++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 code[i] = add(code[i], mult(code[i - T0], sharp)); move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 return index;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 /*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * PRIVATE PROGRAM CODE
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 *****************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 /*************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 * FUNCTION search_2i40()
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 * PURPOSE: Search the best codevector; determine positions of the 2 pulses
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 * in the 40-sample frame.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 *************************************************************************/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 #define _1_2 (Word16)(32768L/2)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 #define _1_4 (Word16)(32768L/4)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 #define _1_8 (Word16)(32768L/8)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 #define _1_16 (Word16)(32768L/16)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 static void search_2i40(
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 Word16 subNr, /* i : subframe number */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 Word16 dn[], /* i : correlation between target and h[] */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 Word16 rr[][L_CODE], /* i : matrix of autocorrelation */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 Word16 codvec[] /* o : algebraic codebook vector */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 )
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 Word16 i0, i1;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 Word16 ix = 0; /* initialization only needed to keep gcc silent */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 Word16 track1, ipos[NB_PULSE];
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 Word16 psk, ps0, ps1, sq, sq1;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 Word16 alpk, alp, alp_16;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 Word32 s, alp0, alp1;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 Word16 i;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 psk = -1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 alpk = 1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 for (i = 0; i < NB_PULSE; i++)
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 codvec[i] = i; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 for (track1 = 0; track1 < 2; track1++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 /* fix starting position */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 ipos[0] = startPos[subNr*2+8*track1]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 ipos[1] = startPos[subNr*2+1+8*track1]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 /*----------------------------------------------------------------*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 * i0 loop: try 8 positions. *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 *----------------------------------------------------------------*/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 move16 (); /* account for ptr. init. (rr[io]) */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 for (i0 = ipos[0]; i0 < L_CODE; i0 += STEP) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 ps0 = dn[i0]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 alp0 = L_mult(rr[i0][i0], _1_4);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 /*----------------------------------------------------------------*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 * i1 loop: 8 positions. *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 *----------------------------------------------------------------*/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 sq = -1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 alp = 1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 ix = ipos[1]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 /*-------------------------------------------------------------------*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 * These index have low complexity address computation because *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 * they are, in fact, pointers with fixed increment. For example, *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 * "rr[i0][i2]" is a pointer initialized to "&rr[i0][ipos[2]]" *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 * and incremented by "STEP". *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 *-------------------------------------------------------------------*/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 move16 (); /* account for ptr. init. (rr[i1]) */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 move16 (); /* account for ptr. init. (dn[i1]) */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 move16 (); /* account for ptr. init. (rr[io]) */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 for (i1 = ipos[1]; i1 < L_CODE; i1 += STEP) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 ps1 = add(ps0, dn[i1]); /* idx increment = STEP */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 /* alp1 = alp0 + rr[i0][i1] + 1/2*rr[i1][i1]; */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 alp1 = L_mac(alp0, rr[i1][i1], _1_4); /* idx incr = STEP */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 alp1 = L_mac(alp1, rr[i0][i1], _1_2); /* idx incr = STEP */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 sq1 = mult(ps1, ps1);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 alp_16 = round(alp1);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 s = L_msu(L_mult(alp, sq1), sq, alp_16);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 if (s > 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 sq = sq1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 alp = alp_16; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 ix = i1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 /*----------------------------------------------------------------*
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 * memorise codevector if this one is better than the last one. *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 *----------------------------------------------------------------*/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 s = L_msu(L_mult(alpk, sq), psk, alp);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 if (s > 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 psk = sq; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 alpk = alp; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 codvec[0] = i0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 codvec[1] = ix; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 return;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 /*************************************************************************
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 * FUNCTION: build_code()
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 * PURPOSE: Builds the codeword, the filtered codeword and index of the
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 * codevector, based on the signs and positions of 2 pulses.
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 *
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 *************************************************************************/
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 static Word16 build_code(
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 Word16 subNr, /* i : subframe number */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 Word16 codvec[], /* i : position of pulses */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 Word16 dn_sign[], /* i : sign of pulses */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 Word16 cod[], /* o : innovative code vector */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 Word16 h[], /* i : impulse response of weighted synthesis filter */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 Word16 y[], /* o : filtered innovative code */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 Word16 sign[] /* o : sign of 2 pulses */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 )
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 Word16 i, j, k, track, first, index, _sign[NB_PULSE], indx, rsign;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 Word16 *p0, *p1, *pt;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 Word32 s;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 static Word16 trackTable[4*5] = {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 0, 1, 0, 1, -1, /* subframe 1; track to code; -1 do not code this position */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 0, -1, 1, 0, 1, /* subframe 2 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 0, 1, 0, -1, 1, /* subframe 3 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 0, 1, -1, 0, 1};/* subframe 4 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 pt = &trackTable[add(subNr, shl(subNr, 2))];
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 for (i = 0; i < L_CODE; i++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 cod[i] = 0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 indx = 0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 rsign = 0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 for (k = 0; k < NB_PULSE; k++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 i = codvec[k]; /* read pulse position */ move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 j = dn_sign[i]; /* read sign */ move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 index = mult(i, 6554); /* index = pos/5 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 /* track = pos%5 */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 track = sub(i, extract_l(L_shr(L_mult(index, 5), 1)));
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 first = pt[track]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 if (first == 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 if (k == 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 track = 0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 } else {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 track = 1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 index = shl(index, 3);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 } else {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 if (k == 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 track = 0; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 index = add(index, 64); /* table bit is MSB */
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 } else {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 track = 1; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 index = shl(index, 3);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 test ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 if (j > 0) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 cod[i] = 8191; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 _sign[k] = 32767; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 rsign = add(rsign, shl(1, track));
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 } else {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 cod[i] = -8192; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 _sign[k] = (Word16) - 32768L; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 indx = add(indx, index);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 *sign = rsign; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 p0 = h - codvec[0]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 p1 = h - codvec[1]; move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 for (i = 0; i < L_CODE; i++) {
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 s = 0; move32 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 s = L_mac(s, *p0++, _sign[0]);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 s = L_mac(s, *p1++, _sign[1]);
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 y[i] = round(s); move16 ();
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 }
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 return indx;
ee64aabcc7a0 libtwamr: integrate c2_9pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 }