annotate libtwamr/c1035pf.c @ 458:e26b974f7ba3

doc/AMR-study-utils: update for the current situation
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 10 May 2024 18:45:36 +0000
parents 6fd6c5fc1aa4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
318
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : c1035pf.c
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Searches a 35 bit algebraic codebook containing
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * : 10 pulses in a frame of 40 samples.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "c1035pf.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * INCLUDE FILES
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include "typedef.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "basic_op.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "no_count.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "cnst.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #include "inv_sqrt.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include "set_sign.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #include "cor_h.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include "s10_8pf.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "graytab.h"
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * LOCAL VARIABLES AND TABLES
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #define NB_PULSE 10
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * LOCAL PROGRAM CODE
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 static void q_p (
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 Word16 *ind, /* Pulse position */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 n /* Pulse number */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 )
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 Word16 tmp;
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 tmp = *ind; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 test ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (sub (n, 5) < 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *ind = (tmp & 0x8) | gray[tmp & 0x7]; logic16 (); logic16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 logic16 (); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *ind = gray[tmp & 0x7]; logic16 (); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 /*************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 * FUNCTION: build_code()
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 * PURPOSE: Builds the codeword, the filtered codeword and index of the
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 * codevector, based on the signs and positions of 10 pulses.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *************************************************************************/
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 static void build_code (
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Word16 codvec[], /* (i) : position of pulses */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 Word16 sign[], /* (i) : sign of d[n] */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 Word16 cod[], /* (o) : innovative code vector */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 Word16 h[], /* (i) : impulse response of weighted synthesis filter*/
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 y[], /* (o) : filtered innovative code */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Word16 indx[] /* (o) : index of 10 pulses (sign+position) */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 )
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Word16 i, j, k, track, index, _sign[NB_PULSE];
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 Word16 *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 Word32 s;
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (i = 0; i < L_CODE; i++)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 cod[i] = 0; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 for (i = 0; i < NB_TRACK; i++)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 indx[i] = -1; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 for (k = 0; k < NB_PULSE; k++)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* read pulse position */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 i = codvec[k]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 /* read sign */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 j = sign[i]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 index = mult (i, 6554); /* index = pos/5 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /* track = pos%5 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 track = sub (i, extract_l (L_shr (L_mult (index, 5), 1)));
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 test ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (j > 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 cod[i] = add (cod[i], 4096); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 _sign[k] = 8192; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 cod[i] = sub (cod[i], 4096); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 _sign[k] = -8192; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 index = add (index, 8);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 test (); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (indx[track] < 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 indx[track] = index; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 test (); logic16 (); logic16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (((index ^ indx[track]) & 8) == 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 /* sign of 1st pulse == sign of 2nd pulse */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 test ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if (sub (indx[track], index) <= 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 indx[track + 5] = index; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 indx[track + 5] = indx[track];
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 indx[track] = index; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 /* sign of 1st pulse != sign of 2nd pulse */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 test (); logic16 (); logic16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 if (sub ((indx[track] & 7), (index & 7)) <= 0)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 indx[track + 5] = indx[track];
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 indx[track] = index; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 else
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 indx[track + 5] = index; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 p0 = h - codvec[0]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 p1 = h - codvec[1]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 p2 = h - codvec[2]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 p3 = h - codvec[3]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 p4 = h - codvec[4]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 p5 = h - codvec[5]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 p6 = h - codvec[6]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 p7 = h - codvec[7]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 p8 = h - codvec[8]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 p9 = h - codvec[9]; move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 for (i = 0; i < L_CODE; i++)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 s = 0; move32 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 s = L_mac (s, *p0++, _sign[0]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 s = L_mac (s, *p1++, _sign[1]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 s = L_mac (s, *p2++, _sign[2]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 s = L_mac (s, *p3++, _sign[3]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 s = L_mac (s, *p4++, _sign[4]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 s = L_mac (s, *p5++, _sign[5]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 s = L_mac (s, *p6++, _sign[6]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 s = L_mac (s, *p7++, _sign[7]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 s = L_mac (s, *p8++, _sign[8]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 s = L_mac (s, *p9++, _sign[9]);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 y[i] = round (s); move16 ();
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 /*
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 * PUBLIC PROGRAM CODE
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 ********************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 /*************************************************************************
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 * FUNCTION: code_10i40_35bits()
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 * PURPOSE: Searches a 35 bit algebraic codebook containing 10 pulses
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 * in a frame of 40 samples.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 * DESCRIPTION:
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 * The code contains 10 nonzero pulses: i0...i9.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 * All pulses can have two possible amplitudes: +1 or -1.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 * The 40 positions in a subframe are divided into 5 tracks of
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 * interleaved positions. Each track contains two pulses.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 * The pulses can have the following possible positions:
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 * i0, i5 : 0, 5, 10, 15, 20, 25, 30, 35.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 * i1, i6 : 1, 6, 11, 16, 21, 26, 31, 36.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 * i2, i7 : 2, 7, 12, 17, 22, 27, 32, 37.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 * i3, i8 : 3, 8, 13, 18, 23, 28, 33, 38.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 * i4, i9 : 4, 9, 14, 19, 24, 29, 34, 39.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 * Each pair of pulses require 1 bit for their signs and 6 bits for their
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 * positions (3 bits + 3 bits). This results in a 35 bit codebook.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 * The function determines the optimal pulse signs and positions, builds
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 * the codevector, and computes the filtered codevector.
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 *
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 *************************************************************************/
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 void code_10i40_35bits (
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 Word16 x[], /* (i) : target vector */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 Word16 cn[], /* (i) : residual after long term prediction */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 Word16 h[], /* (i) : impulse response of weighted synthesis filter
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 h[-L_subfr..-1] must be set to zero */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 Word16 y[], /* (o) : filtered fixed codebook excitation */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 Word16 indx[] /* (o) : index of 10 pulses (sign + position) */
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 )
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 Word16 ipos[NB_PULSE], pos_max[NB_TRACK], codvec[NB_PULSE];
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 Word16 dn[L_CODE], sign[L_CODE];
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 Word16 rr[L_CODE][L_CODE], i;
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 cor_h_x (h, x, dn, 2);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 set_sign12k2 (dn, cn, sign, pos_max, NB_TRACK, ipos, STEP);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 cor_h (h, sign, rr);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 search_10and8i40 (NB_PULSE, STEP, NB_TRACK,
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 dn, rr, ipos, pos_max, codvec);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 build_code (codvec, sign, cod, h, y, indx);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 for (i = 0; i < 10; i++)
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 {
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 q_p (&indx[i], i);
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 return;
6fd6c5fc1aa4 libtwamr: integrate c1035pf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 }