FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/set_sign.c @ 536:a3300483ae74
doc/FR1-library-API: document return value from gsmfr_tfo_xfrm_*
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 21 Sep 2024 20:48:58 +0000 |
parents | 15c354f75110 |
children |
rev | line source |
---|---|
314
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : set_sign.c |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Builds sign vector according to "dn[]" and "cn[]". |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 /* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * MODULE INCLUDE FILE AND VERSION ID |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "namespace.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "set_sign.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 /* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * INCLUDE FILES |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include "typedef.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "basic_op.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "no_count.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "inv_sqrt.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "cnst.h" |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 /* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * PUBLIC PROGRAM CODE |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 ******************************************************************************** |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /************************************************************************* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * FUNCTION set_sign() |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 * PURPOSE: Builds sign[] vector according to "dn[]" and "cn[]". |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * Also finds the position of maximum of correlation in each track |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * and the starting position for each pulse. |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 *************************************************************************/ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 void set_sign(Word16 dn[], /* i/o : correlation between target and h[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 Word16 sign[], /* o : sign of dn[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 Word16 dn2[], /* o : maximum of correlation in each track. */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 Word16 n /* i : # of maximum correlations in dn2[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 Word16 i, j, k; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 Word16 val, min; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 Word16 pos = 0; /* initialization only needed to keep gcc silent */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* set sign according to dn[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 for (i = 0; i < L_CODE; i++) { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 val = dn[i]; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (val >= 0) { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 sign[i] = 32767; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } else { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 sign[i] = -32767; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 val = negate(val); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 dn[i] = val; move16 (); /* modify dn[] according to the fixed sign */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 dn2[i] = val; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 /* keep 8-n maximum positions/8 of each track and store it in dn2[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 for (i = 0; i < NB_TRACK; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 for (k = 0; k < (8-n); k++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 min = 0x7fff; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 for (j = i; j < L_CODE; j += STEP) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 test (); move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (dn2[j] >= 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 val = sub(dn2[j], min); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (val < 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 min = dn2[j]; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 pos = j; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 dn2[pos] = -1; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 return; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 /************************************************************************* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 * FUNCTION set_sign12k2() |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 * PURPOSE: Builds sign[] vector according to "dn[]" and "cn[]", and modifies |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 * dn[] to include the sign information (dn[i]=sign[i]*dn[i]). |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 * Also finds the position of maximum of correlation in each track |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 * and the starting position for each pulse. |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 *************************************************************************/ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 void set_sign12k2 ( |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 Word16 dn[], /* i/o : correlation between target and h[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 Word16 cn[], /* i : residual after long term prediction */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 Word16 sign[], /* o : sign of d[n] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 Word16 pos_max[], /* o : position of maximum correlation */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 Word16 nb_track, /* i : number of tracks tracks */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 Word16 ipos[], /* o : starting position for each pulse */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 Word16 step /* i : the step size in the tracks */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 ) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 Word16 i, j; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 Word16 val, cor, k_cn, k_dn, max, max_of_all; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 Word16 pos = 0; /* initialization only needed to keep gcc silent */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 Word16 en[L_CODE]; /* correlation vector */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 Word32 s; |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 /* calculate energy for normalization of cn[] and dn[] */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 s = 256; move32 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 for (i = 0; i < L_CODE; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 s = L_mac (s, cn[i], cn[i]); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 s = Inv_sqrt (s); move32 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 k_cn = extract_h (L_shl (s, 5)); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 s = 256; move32 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 for (i = 0; i < L_CODE; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 s = L_mac (s, dn[i], dn[i]); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 s = Inv_sqrt (s); move32 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 k_dn = extract_h (L_shl (s, 5)); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 for (i = 0; i < L_CODE; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 val = dn[i]; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 cor = round (L_shl (L_mac (L_mult (k_cn, cn[i]), k_dn, val), 10)); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (cor >= 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 sign[i] = 32767; move16 (); /* sign = +1 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 else |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 sign[i] = -32767; move16 (); /* sign = -1 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 cor = negate (cor); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 val = negate (val); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 /* modify dn[] according to the fixed sign */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 dn[i] = val; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 en[i] = cor; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 max_of_all = -1; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 for (i = 0; i < nb_track; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 max = -1; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 for (j = i; j < L_CODE; j += step) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 cor = en[j]; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 val = sub (cor, max); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 if (val > 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 max = cor; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 pos = j; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 /* store maximum correlation position */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 pos_max[i] = pos; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 val = sub (max, max_of_all); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (val > 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 max_of_all = max; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 /* starting position for i0 */ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 ipos[0] = i; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 /*----------------------------------------------------------------* |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 * Set starting position of each pulse. * |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 *----------------------------------------------------------------*/ |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 pos = ipos[0]; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 ipos[nb_track] = pos; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 for (i = 1; i < nb_track; i++) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 pos = add (pos, 1); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 test (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 if (sub (pos, nb_track) >= 0) |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 { |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 pos = 0; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 ipos[i] = pos; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 ipos[add(i, nb_track)] = pos; move16 (); |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |
15c354f75110
libtwamr: integrate set_sign.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 } |