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