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: dct_type_iv_s.c
16
* Purpose: Discrete Cosine Transform, Type IV used for inverse MLT
18
* The basis functions are
20
* cos(PI*(t+0.5)*(k+0.5)/block_length)
22
* for time t and basis function number k. Due to the symmetry of the expression
23
* in t and k, it is clear that the forward and inverse transforms are the same.
25
*********************************************************************************/
27
/***************************************************************************
29
***************************************************************************/
34
/***************************************************************************
35
External variable declarations
36
***************************************************************************/
37
extern Word16 syn_bias_7khz[DCT_LENGTH];
38
extern Word16 dither[DCT_LENGTH];
39
extern Word16 max_dither[MAX_DCT_LENGTH];
41
extern Word16 dct_core_s[DCT_LENGTH_DIV_32][DCT_LENGTH_DIV_32];
42
extern cos_msin_t s_cos_msin_2[DCT_LENGTH_DIV_32];
43
extern cos_msin_t s_cos_msin_4[DCT_LENGTH_DIV_16];
44
extern cos_msin_t s_cos_msin_8[DCT_LENGTH_DIV_8];
45
extern cos_msin_t s_cos_msin_16[DCT_LENGTH_DIV_4];
46
extern cos_msin_t s_cos_msin_32[DCT_LENGTH_DIV_2];
47
extern cos_msin_t s_cos_msin_64[DCT_LENGTH];
48
extern cos_msin_t *s_cos_msin_table[];
50
/********************************************************************************
51
Function: dct_type_iv_s
53
Syntax: void dct_type_iv_s (Word16 *input,Word16 *output,Word16 dct_length)
56
Description: Discrete Cosine Transform, Type IV used for inverse MLT
60
WMOPS: 7kHz | 24kbit | 32kbit
61
-------|--------------|----------------
63
-------|--------------|----------------
65
-------|--------------|----------------
67
14kHz | 24kbit | 32kbit | 48kbit
68
-------|--------------|----------------|----------------
69
AVG | 3.62 | 3.62 | 3.62
70
-------|--------------|----------------|----------------
71
MAX | 3.62 | 3.62 | 3.62
72
-------|--------------|----------------|----------------
74
********************************************************************************/
76
void dct_type_iv_s (Word16 *input,Word16 *output,Word16 dct_length)
78
Word16 buffer_a[MAX_DCT_LENGTH], buffer_b[MAX_DCT_LENGTH], buffer_c[MAX_DCT_LENGTH];
79
Word16 *in_ptr, *in_ptr_low, *in_ptr_high, *next_in_base;
80
Word16 *out_ptr_low, *out_ptr_high, *next_out_base;
81
Word16 *out_buffer, *in_buffer, *buffer_swap;
82
Word16 in_val_low, in_val_high;
83
Word16 out_val_low, out_val_high;
84
Word16 in_low_even, in_low_odd;
85
Word16 in_high_even, in_high_odd;
86
Word16 out_low_even, out_low_odd;
87
Word16 out_high_even, out_high_odd;
89
Word16 cos_even, cos_odd, msin_even, msin_odd;
90
Word16 set_span, set_count, set_count_log, pairs_left, sets_left;
95
cos_msin_t **table_ptr_ptr, *cos_msin_ptr;
100
Word16 dct_length_log;
103
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
104
/* Do the sum/difference butterflies, the first part of */
105
/* converting one N-point transform into 32 - 10 point transforms */
106
/* transforms, where N = 1 << DCT_LENGTH_LOG. */
107
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
109
if (dct_length==DCT_LENGTH)
111
dct_length_log = DCT_LENGTH_LOG;
118
dct_length_log = MAX_DCT_LENGTH_LOG;
120
dither_ptr = max_dither;
126
out_buffer = buffer_a;
135
for (set_count_log = 0; set_count_log <= dct_length_log - 2; set_count_log++)
138
/*===========================================================*/
139
/* Initialization for the loop over sets at the current size */
140
/*===========================================================*/
142
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
143
set_span = shr_nocheck(dct_length,set_count_log);
145
set_count = shl_nocheck(1,set_count_log);
148
next_out_base = out_buffer;
151
/*=====================================*/
152
/* Loop over all the sets of this size */
153
/*=====================================*/
158
for (sets_left = set_count;sets_left > 0;sets_left--)
161
/*||||||||||||||||||||||||||||||||||||||||||||*/
162
/* Set up output pointers for the current set */
163
/*||||||||||||||||||||||||||||||||||||||||||||*/
164
/* pointer arithmetic */
165
out_ptr_low = next_out_base;
167
next_out_base += set_span;
169
out_ptr_high = next_out_base;
172
/*||||||||||||||||||||||||||||||||||||||||||||||||||*/
173
/* Loop over all the butterflies in the current set */
174
/*||||||||||||||||||||||||||||||||||||||||||||||||||*/
178
in_val_low = *in_ptr++;
180
in_val_high = *in_ptr++;
183
/* BEST METHOD OF GETTING RID OF BIAS, BUT COMPUTATIONALLY UNPLEASANT */
184
/* ALTERNATIVE METHOD, SMEARS BIAS OVER THE ENTIRE FRAME, COMPUTATIONALLY SIMPLEST. */
185
/* IF THIS WORKS, IT'S PREFERABLE */
187
dummy = add(in_val_low,dither_ptr[i++]);
188
// blp: addition of two 16bits vars, there's no way
189
// they'll overflow a 32bit var
190
//acca = L_add(dummy,in_val_high);
191
acca = dummy + in_val_high;
192
out_val_low = extract_l(L_shr_nocheck(acca,1));
194
dummy = add(in_val_low,dither_ptr[i++]);
195
// blp: addition of two 16bits vars, there's no way
196
// they'll overflow a 32bit var
197
//acca = L_add(dummy,-in_val_high);
198
acca = dummy - in_val_high;
199
out_val_high = extract_l(L_shr_nocheck(acca,1));
201
*out_ptr_low++ = out_val_low;
203
*--out_ptr_high = out_val_high;
208
/* this involves comparison of pointers */
209
/* pointer arithmetic */
211
} while (out_ptr_low < out_ptr_high);
213
} /* End of loop over sets of the current size */
217
for (sets_left = set_count; sets_left > 0; sets_left--)
219
/*||||||||||||||||||||||||||||||||||||||||||||*/
220
/* Set up output pointers for the current set */
221
/*||||||||||||||||||||||||||||||||||||||||||||*/
223
out_ptr_low = next_out_base;
225
next_out_base += set_span;
227
out_ptr_high = next_out_base;
230
/*||||||||||||||||||||||||||||||||||||||||||||||||||*/
231
/* Loop over all the butterflies in the current set */
232
/*||||||||||||||||||||||||||||||||||||||||||||||||||*/
236
in_val_low = *in_ptr++;
238
in_val_high = *in_ptr++;
241
out_val_low = add(in_val_low,in_val_high);
242
out_val_high = add(in_val_low,negate(in_val_high));
244
*out_ptr_low++ = out_val_low;
246
*--out_ptr_high = out_val_high;
250
} while (out_ptr_low < out_ptr_high);
252
} /* End of loop over sets of the current size */
255
/*============================================================*/
256
/* Decide which buffers to use as input and output next time. */
257
/* Except for the first time (when the input buffer is the */
258
/* subroutine input) we just alternate the local buffers. */
259
/*============================================================*/
261
in_buffer = out_buffer;
265
if (out_buffer == buffer_a)
267
out_buffer = buffer_b;
272
out_buffer = buffer_a;
276
index = add(index,1);
277
} /* End of loop over set sizes */
280
/*++++++++++++++++++++++++++++++++*/
281
/* Do 32 - 10 point transforms */
282
/*++++++++++++++++++++++++++++++++*/
284
pair_ptr = in_buffer;
286
buffer_swap = buffer_c;
289
for (pairs_left = 1 << (dct_length_log - 1); pairs_left > 0; pairs_left--)
291
for ( k=0; k<CORE_SIZE; k++ )
294
/* blp: danger danger! not really compatible but faster */
298
for ( i=0; i<CORE_SIZE; i++ )
300
sum64 += L_mult(pair_ptr[i], dct_core_s[i][k]);
302
sum = L_saturate(sum64);
307
for ( i=0; i<CORE_SIZE; i++ )
309
sum = L_mac(sum, pair_ptr[i],dct_core_s[i][k]);
312
buffer_swap[k] = itu_round(sum);
315
pair_ptr += CORE_SIZE;
317
buffer_swap += CORE_SIZE;
321
for (i=0;i<dct_length;i++)
323
in_buffer[i] = buffer_c[i];
327
table_ptr_ptr = s_cos_msin_table;
330
/*++++++++++++++++++++++++++++++*/
331
/* Perform rotation butterflies */
332
/*++++++++++++++++++++++++++++++*/
336
for (set_count_log = dct_length_log - 2 ; set_count_log >= 0; set_count_log--)
339
/*===========================================================*/
340
/* Initialization for the loop over sets at the current size */
341
/*===========================================================*/
343
/* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */
344
set_span = shr_nocheck(dct_length,set_count_log);
346
set_count = shl_nocheck(1,set_count_log);
347
next_in_base = in_buffer;
350
if (set_count_log == 0)
352
next_out_base = output;
357
next_out_base = out_buffer;
361
/*=====================================*/
362
/* Loop over all the sets of this size */
363
/*=====================================*/
365
for (sets_left = set_count; sets_left > 0; sets_left--)
368
/*|||||||||||||||||||||||||||||||||||||||||*/
369
/* Set up the pointers for the current set */
370
/*|||||||||||||||||||||||||||||||||||||||||*/
372
in_ptr_low = next_in_base;
375
temp = shr_nocheck(set_span,1);
376
in_ptr_high = in_ptr_low + temp;
379
next_in_base += set_span;
382
out_ptr_low = next_out_base;
385
next_out_base += set_span;
387
out_ptr_high = next_out_base;
390
cos_msin_ptr = *table_ptr_ptr;
393
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
394
/* Loop over all the butterfly pairs in the current set */
395
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
399
in_low_even = *in_ptr_low++;
401
in_low_odd = *in_ptr_low++;
403
in_high_even = *in_ptr_high++;
405
in_high_odd = *in_ptr_high++;
407
cos_even = cos_msin_ptr[0].cosine;
409
msin_even = cos_msin_ptr[0].minus_sine;
411
cos_odd = cos_msin_ptr[1].cosine;
413
msin_odd = cos_msin_ptr[1].minus_sine;
420
sum = L_mac(sum,cos_even,in_low_even);
421
sum = L_mac(sum,negate(msin_even),in_high_even);
422
out_low_even = itu_round(L_shl_nocheck(sum,1));
426
sum = L_mac(sum,msin_even,in_low_even);
427
sum = L_mac(sum,cos_even,in_high_even);
428
out_high_even = itu_round(L_shl_nocheck(sum,1));
432
sum = L_mac(sum,cos_odd,in_low_odd);
433
sum = L_mac(sum,msin_odd,in_high_odd);
434
out_low_odd = itu_round(L_shl_nocheck(sum,1));
438
sum = L_mac(sum,msin_odd,in_low_odd);
439
sum = L_mac(sum,negate(cos_odd),in_high_odd);
440
out_high_odd = itu_round(L_shl_nocheck(sum,1));
442
*out_ptr_low++ = out_low_even;
444
*--out_ptr_high = out_high_even;
446
*out_ptr_low++ = out_low_odd;
448
*--out_ptr_high = out_high_odd;
452
} while (out_ptr_low < out_ptr_high);
454
} /* End of loop over sets of the current size */
456
/*=============================================*/
457
/* Swap input and output buffers for next time */
458
/*=============================================*/
460
buffer_swap = in_buffer;
462
in_buffer = out_buffer;
464
out_buffer = buffer_swap;
467
index = add(index,1);
470
/*------------------------------------
472
ADD IN BIAS FOR OUTPUT
474
-----------------------------------*/
475
if (dct_length==DCT_LENGTH)
479
// blp: addition of two 16bits vars, there's no way
480
// they'll overflow a 32bit var
481
//sum = L_add(output[i],syn_bias_7khz[i]);
482
sum = output[i] + syn_bias_7khz[i];
483
acca = L_sub(sum,32767);
490
// blp: addition of two 16bits vars, there's no way
491
// they'll overflow 32bit var
492
//acca = L_add(sum,32768L);
500
output[i] = extract_l(sum);