1
/******************************************************************************
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)
7
** � 2004 Polycom, Inc.
9
** All rights reserved.
11
******************************************************************************/
13
/******************************************************************************
14
* Filename: samples_to_rmlt_coefs.c
16
* Purpose: Convert Samples to Reversed MLT (Modulated Lapped Transform)
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.
27
******************************************************************************/
29
/***************************************************************************
31
***************************************************************************/
36
/***************************************************************************
37
Function: samples_to_rmlt_coefs
39
Syntax: Word16 samples_to_rmlt_coefs(new_samples,
48
Description: Convert samples to MLT coefficients
52
WMOPS: 7kHz | 24kbit | 32kbit
53
-------|--------------|----------------
55
-------|--------------|----------------
57
-------|--------------|----------------
59
14kHz | 24kbit | 32kbit | 48kbit
60
-------|--------------|----------------|----------------
61
AVG | 3.07 | 3.07 | 3.07
62
-------|--------------|----------------|----------------
63
MAX | 3.10 | 3.10 | 3.10
64
-------|--------------|----------------|----------------
66
***************************************************************************/
68
Word16 samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *old_samples,Word16 *coefs,Word16 dct_length)
71
Word16 index, vals_left,mag_shift,n;
72
Word16 windowed_data[MAX_DCT_LENGTH];
74
const Word16 *new_ptr, *sam_low, *sam_high;
75
Word16 *win_low, *win_high;
88
half_dct_size = shr_nocheck(dct_length,1);
90
/*++++++++++++++++++++++++++++++++++++++++++++*/
91
/* Get the first half of the windowed samples */
92
/*++++++++++++++++++++++++++++++++++++++++++++*/
94
dst_ptr = windowed_data;
97
/* address arithmetic */
99
if (dct_length==DCT_LENGTH)
101
win_high = samples_to_rmlt_window + half_dct_size;
105
win_high = max_samples_to_rmlt_window + half_dct_size;
111
/* address arithmetic */
112
sam_high = old_samples + half_dct_size;
117
for (vals_left = half_dct_size;vals_left > 0;vals_left--)
122
acca = L_mac(acca,*--win_low, *--sam_low);
123
acca = L_mac(acca,*win_high++, *sam_high++);
124
temp = itu_round(acca);
130
/*+++++++++++++++++++++++++++++++++++++++++++++*/
131
/* Get the second half of the windowed samples */
132
/*+++++++++++++++++++++++++++++++++++++++++++++*/
134
sam_low = new_samples;
137
/* address arithmetic */
138
sam_high = new_samples + dct_length;
140
for (vals_left = half_dct_size; vals_left > 0; vals_left--)
145
acca = L_mac(acca,*--win_high, *sam_low++);
146
neg_win_low = negate(*win_low++);
147
samp_high = *--sam_high;
148
acca = L_mac(acca, neg_win_low, samp_high);
149
temp = itu_round(acca);
155
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
156
/* Save the new samples for next time, when they will be the old samples */
157
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
159
new_ptr = new_samples;
162
old_ptr = old_samples;
165
for (vals_left = dct_length;vals_left > 0;vals_left--)
167
*old_ptr++ = *new_ptr++;
171
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
172
/* Calculate how many bits to shift up the input to the DCT. */
173
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
178
for(index=0;index<dct_length;index++)
180
temp2 = abs_s(windowed_data[index]);
181
temp = sub(temp2,temp1);
193
temp = sub(temp1,14000);
202
temp = sub(temp1,438);
211
accb = L_mult(temp,9587);
212
acca = L_shr_nocheck(accb,20);
213
temp5 = extract_l(acca);
214
temp = norm_s(temp5);
222
mag_shift = sub(temp,6);
228
for(index=0; index<dct_length; index++)
230
temp = abs_s( windowed_data[index]);
231
acca = L_add(acca,temp);
234
acca = L_shr_nocheck(acca,7);
239
mag_shift = sub(mag_shift,1);
245
for(index=0;index<dct_length;index++)
247
windowed_data[index] = shl_nocheck(windowed_data[index],mag_shift);
255
n = negate(mag_shift);
256
for(index=0;index<dct_length;index++)
258
windowed_data[index] = shr_nocheck(windowed_data[index],n);
264
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
265
/* Perform a Type IV DCT on the windowed data to get the coefficients */
266
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
268
dct_type_iv_a(windowed_data, coefs, dct_length);