blob: 57c8fce81510e5f8b2b79a50a544c80f1bd99204 [file] [log] [blame]
Nanang Izzuddin57b88572009-04-01 12:05:34 +00001/******************************************************************************
2**
3** ITU-T G.722.1 (2005-05) - Fixed point implementation for main body and Annex C
4** > Software Release 2.1 (2008-06)
5** (Simple repackaging; no change from 2005-05 Release 2.0 code)
6**
7** © 2004 Polycom, Inc.
8**
9** All rights reserved.
10**
11******************************************************************************/
12
13/******************************************************************************
14* Filename: samples_to_rmlt_coefs.c
15*
16* Purpose: Convert Samples to Reversed MLT (Modulated Lapped Transform)
17* Coefficients
18*
19* The "Reversed MLT" is an overlapped block transform which uses
20* even symmetry * on the left, odd symmetry on the right and a
21* Type IV DCT as the block transform. * It is thus similar to a
22* MLT which uses odd symmetry on the left, even symmetry * on the
23* right and a Type IV DST as the block transform. In fact, it is
24* equivalent * to reversing the order of the samples, performing
25* an MLT and then negating all * the even-numbered coefficients.
26*
27******************************************************************************/
28
29/***************************************************************************
30 Include files
31***************************************************************************/
32#include "defs.h"
33#include "tables.h"
34#include "count.h"
35
36/***************************************************************************
37 Function: samples_to_rmlt_coefs
38
39 Syntax: Word16 samples_to_rmlt_coefs(new_samples,
40 old_samples,
41 coefs,
42 dct_length)
43 Word16 *new_samples;
44 Word16 *old_samples;
45 Word16 *coefs;
46 Word16 dct_length;
47
48 Description: Convert samples to MLT coefficients
49
50 Design Notes:
51
52 WMOPS: 7kHz | 24kbit | 32kbit
53 -------|--------------|----------------
54 AVG | 1.40 | 1.40
55 -------|--------------|----------------
56 MAX | 1.40 | 1.40
57 -------|--------------|----------------
58
59 14kHz | 24kbit | 32kbit | 48kbit
60 -------|--------------|----------------|----------------
61 AVG | 3.07 | 3.07 | 3.07
62 -------|--------------|----------------|----------------
63 MAX | 3.10 | 3.10 | 3.10
64 -------|--------------|----------------|----------------
65
66***************************************************************************/
67
68Word16 samples_to_rmlt_coefs(Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length)
69{
70
71 Word16 index, vals_left,mag_shift,n;
72 Word16 windowed_data[MAX_DCT_LENGTH];
73 Word16 *new_ptr, *old_ptr, *sam_low, *sam_high;
74 Word16 *win_low, *win_high;
75 Word16 *dst_ptr;
76 Word16 neg_win_low;
77 Word16 samp_high;
78 Word16 half_dct_size;
79
80 Word32 acca;
81 Word32 accb;
82 Word16 temp;
83 Word16 temp1;
84 Word16 temp2;
85 Word16 temp5;
86
87 half_dct_size = shr(dct_length,1);
88
89 /*++++++++++++++++++++++++++++++++++++++++++++*/
90 /* Get the first half of the windowed samples */
91 /*++++++++++++++++++++++++++++++++++++++++++++*/
92
93 dst_ptr = windowed_data;
94 move16();
95
96 /* address arithmetic */
97 test();
98 if (dct_length==DCT_LENGTH)
99 {
100 win_high = samples_to_rmlt_window + half_dct_size;
101 }
102 else
103 {
104 win_high = max_samples_to_rmlt_window + half_dct_size;
105 }
106
107 win_low = win_high;
108 move16();
109
110 /* address arithmetic */
111 sam_high = old_samples + half_dct_size;
112
113 sam_low = sam_high;
114 move16();
115
116 for (vals_left = half_dct_size;vals_left > 0;vals_left--)
117 {
118 acca = 0L;
119 move32();
120
121 acca = L_mac(acca,*--win_low, *--sam_low);
122 acca = L_mac(acca,*win_high++, *sam_high++);
Nanang Izzuddin56e380a2009-04-15 14:45:41 +0000123 temp = itu_round(acca);
Nanang Izzuddin57b88572009-04-01 12:05:34 +0000124
125 *dst_ptr++ = temp;
126 move16();
127 }
128
129 /*+++++++++++++++++++++++++++++++++++++++++++++*/
130 /* Get the second half of the windowed samples */
131 /*+++++++++++++++++++++++++++++++++++++++++++++*/
132
133 sam_low = new_samples;
134 move16();
135
136 /* address arithmetic */
137 sam_high = new_samples + dct_length;
138
139 for (vals_left = half_dct_size; vals_left > 0; vals_left--)
140 {
141 acca = 0L;
142 move32();
143
144 acca = L_mac(acca,*--win_high, *sam_low++);
145 neg_win_low = negate(*win_low++);
146 samp_high = *--sam_high;
147 acca = L_mac(acca, neg_win_low, samp_high);
Nanang Izzuddin56e380a2009-04-15 14:45:41 +0000148 temp = itu_round(acca);
Nanang Izzuddin57b88572009-04-01 12:05:34 +0000149
150 *dst_ptr++=temp;
151 move16();
152 }
153
154 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
155 /* Save the new samples for next time, when they will be the old samples */
156 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
157
158 new_ptr = new_samples;
159 move16();
160
161 old_ptr = old_samples;
162 move16();
163
164 for (vals_left = dct_length;vals_left > 0;vals_left--)
165 {
166 *old_ptr++ = *new_ptr++;
167 move16();
168 }
169
170 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
171 /* Calculate how many bits to shift up the input to the DCT. */
172 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
173
174 temp1=0;
175 move16();
176
177 for(index=0;index<dct_length;index++)
178 {
179 temp2 = abs_s(windowed_data[index]);
180 temp = sub(temp2,temp1);
181 test();
182 if(temp > 0)
183 {
184 move16();
185 temp1 = temp2;
186 }
187 }
188
189 mag_shift=0;
190 move16();
191
192 temp = sub(temp1,14000);
193 test();
194 if (temp >= 0)
195 {
196 mag_shift = 0;
197 move16();
198 }
199 else
200 {
201 temp = sub(temp1,438);
202 test();
203 if(temp < 0)
204 temp = add(temp1,1);
205 else
206 {
207 temp = temp1;
208 move16();
209 }
210 accb = L_mult(temp,9587);
211 acca = L_shr(accb,20);
212 temp5 = extract_l(acca);
213 temp = norm_s(temp5);
214 test();
215 if (temp == 0)
216 {
217 mag_shift = 9;
218 move16();
219 }
220 else
221 mag_shift = sub(temp,6);
222
223 }
224
225 acca = 0L;
226 move32();
227 for(index=0; index<dct_length; index++)
228 {
229 temp = abs_s( windowed_data[index]);
230 acca = L_add(acca,temp);
231 }
232
233 acca = L_shr(acca,7);
234
235 test();
236 if (temp1 < acca)
237 {
238 mag_shift = sub(mag_shift,1);
239 }
240
241 test();
242 if (mag_shift > 0)
243 {
244 for(index=0;index<dct_length;index++)
245 {
246 windowed_data[index] = shl(windowed_data[index],mag_shift);
247 }
248 }
249 else
250 {
251 test();
252 if (mag_shift < 0)
253 {
254 n = negate(mag_shift);
255 for(index=0;index<dct_length;index++)
256 {
257 windowed_data[index] = shr(windowed_data[index],n);
258 move16();
259 }
260 }
261 }
262
263 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
264 /* Perform a Type IV DCT on the windowed data to get the coefficients */
265 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
266
267 dct_type_iv_a(windowed_data, coefs, dct_length);
268
269 return(mag_shift);
270}