blob: 8519b175ac36f9d405dbc648122b5420334f35e7 [file] [log] [blame]
Andreas Huberdacaa732009-12-07 09:56:32 -08001/* ------------------------------------------------------------------
James Donga2e29962011-03-13 12:41:43 -07002 * Copyright (C) 1998-2010 PacketVideo
Andreas Huberdacaa732009-12-07 09:56:32 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/*
19
20 Filename: sbr_dec.c
21
22------------------------------------------------------------------------------
23 REVISION HISTORY
24
25
26 Who: Date: MM/DD/YYYY
27 Description:
28
29------------------------------------------------------------------------------
30 INPUT AND OUTPUT DEFINITIONS
31
32
33
34------------------------------------------------------------------------------
35 FUNCTION DESCRIPTION
36
37 sbr decoder core function
38
39------------------------------------------------------------------------------
40 REQUIREMENTS
41
42
43------------------------------------------------------------------------------
44 REFERENCES
45
46SC 29 Software Copyright Licencing Disclaimer:
47
48This software module was originally developed by
49 Coding Technologies
50
51and edited by
52 -
53
54in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
55standards for reference purposes and its performance may not have been
56optimized. This software module is an implementation of one or more tools as
57specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
58ISO/IEC gives users free license to this software module or modifications
59thereof for use in products claiming conformance to audiovisual and
60image-coding related ITU Recommendations and/or ISO/IEC International
61Standards. ISO/IEC gives users the same free license to this software module or
62modifications thereof for research purposes and further ISO/IEC standardisation.
63Those intending to use this software module in products are advised that its
64use may infringe existing patents. ISO/IEC have no liability for use of this
65software module or modifications thereof. Copyright is not released for
66products that do not conform to audiovisual and image-coding related ITU
67Recommendations and/or ISO/IEC International Standards.
68The original developer retains full right to modify and use the code for its
69own purpose, assign or donate the code to a third party and to inhibit third
70parties from using the code for products that do not conform to audiovisual and
71image-coding related ITU Recommendations and/or ISO/IEC International Standards.
72This copyright notice must be included in all copies or derivative works.
73Copyright (c) ISO/IEC 2002.
74
75------------------------------------------------------------------------------
76 PSEUDO-CODE
77
78------------------------------------------------------------------------------
79*/
80
81
82/*----------------------------------------------------------------------------
83; INCLUDES
84----------------------------------------------------------------------------*/
85#ifdef AAC_PLUS
86
87
88#include "s_sbr_frame_data.h"
89#include "calc_sbr_synfilterbank.h"
90#include "calc_sbr_anafilterbank.h"
91#include "calc_sbr_envelope.h"
92#include "sbr_generate_high_freq.h"
93#include "sbr_dec.h"
94#include "decode_noise_floorlevels.h"
95#include "aac_mem_funcs.h"
96#include "fxp_mul32.h"
97
98/*----------------------------------------------------------------------------
99; MACROS
100; Define module specific macros here
101----------------------------------------------------------------------------*/
102
103
104/*----------------------------------------------------------------------------
105; DEFINES
106; Include all pre-processor statements here. Include conditional
107; compile variables also.
108----------------------------------------------------------------------------*/
109
110/*----------------------------------------------------------------------------
111; LOCAL FUNCTION DEFINITIONS
112; Function Prototype declaration
113----------------------------------------------------------------------------*/
114/*----------------------------------------------------------------------------
115; LOCAL STORE/BUFFER/POINTER DEFINITIONS
116; Variable declaration - defined here and used outside this module
117----------------------------------------------------------------------------*/
118
119
120/*----------------------------------------------------------------------------
121; EXTERNAL FUNCTION REFERENCES
122; Declare functions defined elsewhere and referenced in this module
123----------------------------------------------------------------------------*/
124#include "pv_audio_type_defs.h"
125
126#ifdef PARAMETRICSTEREO
127
128#include "ps_applied.h"
129#include "ps_init_stereo_mixing.h"
130
131#endif
132
133/*----------------------------------------------------------------------------
134; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
135; Declare variables used in this module but defined elsewhere
136----------------------------------------------------------------------------*/
137
138/*----------------------------------------------------------------------------
139; FUNCTION CODE
140----------------------------------------------------------------------------*/
141
142void sbr_dec(Int16 *inPcmData,
143 Int16 *ftimeOutPtr,
144 SBR_FRAME_DATA * hFrameData,
145 int32_t applyProcessing,
146 SBR_DEC *sbrDec,
147#ifdef HQ_SBR
148#ifdef PARAMETRICSTEREO
149 Int16 * ftimeOutPtrPS,
150 HANDLE_PS_DEC hParametricStereoDec,
151#endif
152#endif
153 tDec_Int_File *pVars)
154{
155 int32_t i;
156 int32_t j;
157 int32_t m;
158
159 int32_t *frameInfo = hFrameData->frameInfo;
160 Int num_qmf_bands;
161
162#ifdef HQ_SBR
163#ifdef PARAMETRICSTEREO
164
165 int32_t env;
166
167 int32_t *qmf_PS_generated_Real;
168 int32_t *qmf_PS_generated_Imag;
169
170 int32_t *Sr_x;
171 int32_t *Si_x;
172
173
174#endif
175#endif
176
177 int32_t(*scratch_mem)[64];
178 Int16 *circular_buffer_s;
179
180 int32_t k;
181 int32_t *Sr;
182 int32_t *Si;
183 int32_t *ptr_tmp1;
184 int32_t *ptr_tmp2;
185 scratch_mem = pVars->scratch.scratch_mem;
186
187
188 if (applyProcessing)
189 {
190 num_qmf_bands = sbrDec->lowSubband;
191 }
192 else
193 {
194 num_qmf_bands = 32; /* becomes a resampler by 2 */
195 }
196
197 /* -------------------------------------------------- */
198 /*
199 * Re-Load Buffers
200 */
201 pv_memmove(&hFrameData->sbrQmfBufferReal[0],
202 &hFrameData->HistsbrQmfBufferReal[0],
203 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
204#ifdef HQ_SBR
205
206
207 if (sbrDec->LC_aacP_DecoderFlag == OFF)
208 {
209 pv_memmove(&hFrameData->sbrQmfBufferImag[0],
210 &hFrameData->HistsbrQmfBufferImag[0],
211 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
212 }
213#endif
214 /* -------------------------------------------------- */
215
216
217 /*
218 * low band codec signal subband filtering
219 */
220
221 for (i = 0; i < 32; i++)
222 {
223
224 if (sbrDec->LC_aacP_DecoderFlag == ON)
225 {
226
227 calc_sbr_anafilterbank_LC(hFrameData->codecQmfBufferReal[sbrDec->bufWriteOffs + i],
228 &inPcmData[319] + (i << 5),
229 scratch_mem,
230 num_qmf_bands);
231
232 }
233#ifdef HQ_SBR
234 else
235 {
236
237 calc_sbr_anafilterbank(hFrameData->codecQmfBufferReal[sbrDec->bufWriteOffs + i],
238 hFrameData->codecQmfBufferImag[sbrDec->bufWriteOffs + i],
239 &inPcmData[319] + (i << 5),
240 scratch_mem,
241 num_qmf_bands);
242 }
243#endif
244
245 }
246
247 if (pVars->ltp_buffer_state)
248 {
249 pv_memcpy(&inPcmData[-1024-288], &inPcmData[1024], 288*sizeof(*inPcmData));
250 }
251 else
252 {
253 pv_memcpy(&inPcmData[1024 + 288], &inPcmData[1024], 288*sizeof(*inPcmData));
254 }
255
256
257 if (applyProcessing)
258 {
259
260 /*
261 * Inverse filtering of lowband + HF generation
262 */
263
264 if (sbrDec->LC_aacP_DecoderFlag == ON)
265 {
266
267 sbr_generate_high_freq((int32_t(*)[32])(hFrameData->codecQmfBufferReal + sbrDec->bufReadOffs),
268 NULL,
269 (int32_t *)(hFrameData->sbrQmfBufferReal),
270 NULL,
271 hFrameData->sbr_invf_mode,
272 hFrameData->sbr_invf_mode_prev,
273 &(sbrDec->FreqBandTableNoise[1]),
274 sbrDec->NoNoiseBands,
275 sbrDec->lowSubband,
276 sbrDec->V_k_master,
277 sbrDec->Num_Master,
278 sbrDec->outSampleRate,
279 frameInfo,
280 hFrameData->degreeAlias,
281 scratch_mem,
282 hFrameData->BwVector,/* */
283 hFrameData->BwVectorOld,
284 &(sbrDec->Patch),
285 sbrDec->LC_aacP_DecoderFlag,
286 &(sbrDec->highSubband));
287
288
289 /*
290 * Adjust envelope of current frame.
291 */
292
293 calc_sbr_envelope(hFrameData,
294 (int32_t *)(hFrameData->sbrQmfBufferReal),
295 NULL,
296 sbrDec->FreqBandTable,
297 sbrDec->NSfb,
298 sbrDec->FreqBandTableNoise,
299 sbrDec->NoNoiseBands,
300 hFrameData->reset_flag,
301 hFrameData->degreeAlias,
302 &(hFrameData->harm_index),
303 &(hFrameData->phase_index),
304 hFrameData->hFp,
305 &(hFrameData->sUp),
306 sbrDec->limSbc,
307 sbrDec->gateMode,
308#ifdef HQ_SBR
309 NULL,
310 NULL,
311 NULL,
312 NULL,
313#endif
314 scratch_mem,
315 sbrDec->Patch,
316 sbrDec->sqrt_cache,
317 sbrDec->LC_aacP_DecoderFlag);
318 }
319#ifdef HQ_SBR
320 else
321 {
322
323 sbr_generate_high_freq((int32_t(*)[32])(hFrameData->codecQmfBufferReal + sbrDec->bufReadOffs),
324 (int32_t(*)[32])(hFrameData->codecQmfBufferImag + sbrDec->bufReadOffs),
325 (int32_t *)(hFrameData->sbrQmfBufferReal),
326 (int32_t *)(hFrameData->sbrQmfBufferImag),
327 hFrameData->sbr_invf_mode,
328 hFrameData->sbr_invf_mode_prev,
329 &(sbrDec->FreqBandTableNoise[1]),
330 sbrDec->NoNoiseBands,
331 sbrDec->lowSubband,
332 sbrDec->V_k_master,
333 sbrDec->Num_Master,
334 sbrDec->outSampleRate,
335 frameInfo,
336 NULL,
337 scratch_mem,
338 hFrameData->BwVector,
339 hFrameData->BwVectorOld,
340 &(sbrDec->Patch),
341 sbrDec->LC_aacP_DecoderFlag,
342 &(sbrDec->highSubband));
343
344 /*
345 * Adjust envelope of current frame.
346 */
347
348 calc_sbr_envelope(hFrameData,
349 (int32_t *)(hFrameData->sbrQmfBufferReal),
350 (int32_t *)(hFrameData->sbrQmfBufferImag),
351 sbrDec->FreqBandTable,
352 sbrDec->NSfb,
353 sbrDec->FreqBandTableNoise,
354 sbrDec->NoNoiseBands,
355 hFrameData->reset_flag,
356 NULL,
357 &(hFrameData->harm_index),
358 &(hFrameData->phase_index),
359 hFrameData->hFp,
360 &(hFrameData->sUp),
361 sbrDec->limSbc,
362 sbrDec->gateMode,
363 hFrameData->fBuf_man,
364 hFrameData->fBuf_exp,
365 hFrameData->fBufN_man,
366 hFrameData->fBufN_exp,
367 scratch_mem,
368 sbrDec->Patch,
369 sbrDec->sqrt_cache,
370 sbrDec->LC_aacP_DecoderFlag);
371
372 }
373#endif
374
375
376 }
377 else /* else for applyProcessing */
378 {
379 /* no sbr, set high band buffers to zero */
380
381 for (i = 0; i < SBR_NUM_COLUMNS; i++)
382 {
383 pv_memset((void *)&hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS],
384 0,
385 SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
386
387#ifdef HQ_SBR
388 pv_memset((void *)&hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS],
389 0,
390 SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
391
392#endif
393 }
394
395 }
396
397
398 /*
399 * Synthesis subband filtering.
400 */
401
402#ifdef HQ_SBR
403
404#ifdef PARAMETRICSTEREO
405
406
407 /*
408 * psPresentFlag set implies hParametricStereoDec !=NULL, second condition is
409 * is just here to prevent CodeSonar warnings.
410 */
411 if ((pVars->mc_info.psPresentFlag) && (applyProcessing) &&
412 (hParametricStereoDec != NULL))
413 {
414
415 /*
416 * qmfBufferReal uses the rigth aac channel ( perChan[1] is not used)
417 * followed by the buffer fxpCoef[2][2048] which makes a total of
418 * 2349 + 2048*2 = 6445
419 * These 2 matrices (qmfBufferReal & qmfBufferImag) are
420 * [2][38][64] == 4864 int32_t
421 */
422
423
424 tDec_Int_Chan *tmpx = &pVars->perChan[1];
425 /*
426 * dereferencing type-punned pointer avoid
427 * breaking strict-aliasing rules
428 */
429 int32_t *tmp = (int32_t *)tmpx;
430 hParametricStereoDec->qmfBufferReal = (int32_t(*)[64]) tmp;
431
432 tmp = (int32_t *) & hParametricStereoDec->qmfBufferReal[38][0];
433 hParametricStereoDec->qmfBufferImag = (int32_t(*)[64]) tmp;
434
435 for (i = 0; i < 32; i++)
436 {
437 Int xoverBand;
438
439 if (i < ((hFrameData->frameInfo[1]) << 1))
440 {
441 xoverBand = sbrDec->prevLowSubband;
442 }
443 else
444 {
445 xoverBand = sbrDec->lowSubband;
446 }
447
448 if (xoverBand > sbrDec->highSubband)
449 {
James Donga2e29962011-03-13 12:41:43 -0700450 /*
451 * error condition, default to upsampling mode
452 * and make sure that the number of bands for xover does
453 * not exceed the number of high freq bands.
454 */
455 xoverBand = (sbrDec->highSubband > 32)? 32: sbrDec->highSubband;
Andreas Huberdacaa732009-12-07 09:56:32 -0800456 }
457
458 m = sbrDec->bufReadOffs + i; /* 2 + i */
459
460 Sr_x = hParametricStereoDec->qmfBufferReal[i];
461 Si_x = hParametricStereoDec->qmfBufferImag[i];
462
463
464
465 for (int32_t j = 0; j < xoverBand; j++)
466 {
467 Sr_x[j] = shft_lft_1(hFrameData->codecQmfBufferReal[m][j]);
468 Si_x[j] = shft_lft_1(hFrameData->codecQmfBufferImag[m][j]);
469 }
470
471
472
473
474 pv_memcpy(&Sr_x[xoverBand],
475 &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS],
476 (sbrDec->highSubband - xoverBand)*sizeof(*Sr_x));
477
478 pv_memcpy(&Si_x[xoverBand],
479 &hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS],
480 (sbrDec->highSubband - xoverBand)*sizeof(*Si_x));
481
482 pv_memset((void *)&Sr_x[sbrDec->highSubband],
483 0,
484 (64 - sbrDec->highSubband)*sizeof(*Sr_x));
485
486 pv_memset((void *)&Si_x[sbrDec->highSubband],
487 0,
488 (64 - sbrDec->highSubband)*sizeof(*Si_x));
489
490
491 }
492
493 for (i = 32; i < 32 + 6; i++)
494 {
495 m = sbrDec->bufReadOffs + i; /* 2 + i */
496
497 for (int32_t j = 0; j < 5; j++)
498 {
499 hParametricStereoDec->qmfBufferReal[i][j] = shft_lft_1(hFrameData->codecQmfBufferReal[m][j]);
500 hParametricStereoDec->qmfBufferImag[i][j] = shft_lft_1(hFrameData->codecQmfBufferImag[m][j]);
501 }
502
503 }
504
505
506 /*
507 * Update Buffers
508 */
509 for (i = 0; i < sbrDec->bufWriteOffs; i++) /* sbrDec->bufWriteOffs set to 8 and unchanged */
510 {
511 j = sbrDec->noCols + i; /* sbrDec->noCols set to 32 and unchanged */
512
513 pv_memmove(hFrameData->codecQmfBufferReal[i], /* to */
514 hFrameData->codecQmfBufferReal[j], /* from */
515 sizeof(*hFrameData->codecQmfBufferReal[i]) << 5);
516
517 pv_memmove(hFrameData->codecQmfBufferImag[i],
518 hFrameData->codecQmfBufferImag[j],
519 sizeof(*hFrameData->codecQmfBufferImag[i]) << 5);
520 }
521
522
523 pv_memmove(&hFrameData->HistsbrQmfBufferReal[0],
524 &hFrameData->sbrQmfBufferReal[32*SBR_NUM_BANDS],
525 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
526
527 pv_memmove(&hFrameData->HistsbrQmfBufferImag[0],
528 &hFrameData->sbrQmfBufferImag[32*SBR_NUM_BANDS],
529 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
530
531
532 /*
533 * Needs whole QMF matrix formed before applying
534 * Parametric stereo processing.
535 */
536
537 qmf_PS_generated_Real = scratch_mem[0];
538 qmf_PS_generated_Imag = scratch_mem[1];
539 env = 0;
540
541 /*
542 * Set circular buffer for Left channel
543 */
544
545 circular_buffer_s = (Int16 *)scratch_mem[7];
546
547
548 if (pVars->mc_info.bDownSampledSbr)
549 {
550 pv_memmove(&circular_buffer_s[2048],
551 hFrameData->V,
552 640*sizeof(*circular_buffer_s));
553 }
554 else
555 {
556 pv_memmove(&circular_buffer_s[4096],
557 hFrameData->V,
558 1152*sizeof(*circular_buffer_s));
559
560 }
561
562
563 /*
564 * Set Circular buffer for PS hybrid analysis
565 */
James Donga2e29962011-03-13 12:41:43 -0700566
567 int32_t *pt_temp = &scratch_mem[2][32];
568
Andreas Huberdacaa732009-12-07 09:56:32 -0800569 for (i = 0, j = 0; i < 3; i++)
570 {
571
James Donga2e29962011-03-13 12:41:43 -0700572 pv_memmove(&pt_temp[ j],
Andreas Huberdacaa732009-12-07 09:56:32 -0800573 hParametricStereoDec->hHybrid->mQmfBufferReal[i],
574 HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferReal));
James Donga2e29962011-03-13 12:41:43 -0700575 pv_memmove(&pt_temp[ j + 44],
Andreas Huberdacaa732009-12-07 09:56:32 -0800576 hParametricStereoDec->hHybrid->mQmfBufferImag[i],
577 HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferImag));
578 j += 88;
579 }
580
James Donga2e29962011-03-13 12:41:43 -0700581
Andreas Huberdacaa732009-12-07 09:56:32 -0800582 pv_memset((void *)&qmf_PS_generated_Real[hParametricStereoDec->usb],
583 0,
584 (64 - hParametricStereoDec->usb)*sizeof(*qmf_PS_generated_Real));
585
586 pv_memset((void *)&qmf_PS_generated_Imag[hParametricStereoDec->usb],
587 0,
588 (64 - hParametricStereoDec->usb)*sizeof(*qmf_PS_generated_Imag));
589
590
591 for (i = 0; i < 32; i++)
592 {
593 if (i == (Int)hParametricStereoDec-> aEnvStartStop[env])
594 {
595 ps_init_stereo_mixing(hParametricStereoDec, env, sbrDec->highSubband);
596 env++;
597 }
598
599
600 ps_applied(hParametricStereoDec,
601 &hParametricStereoDec->qmfBufferReal[i],
602 &hParametricStereoDec->qmfBufferImag[i],
603 qmf_PS_generated_Real,
604 qmf_PS_generated_Imag,
605 scratch_mem[2],
606 i);
607
608 /* Create time samples for regular mono channel */
609
610 if (pVars->mc_info.bDownSampledSbr)
611 {
612 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i], /* realSamples */
613 hParametricStereoDec->qmfBufferImag[i], /* imagSamples */
614 ftimeOutPtr + (i << 6),
615 &circular_buffer_s[1984 - (i<<6)],
616 pVars->mc_info.bDownSampledSbr);
617 }
618 else
619 {
620 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i], /* realSamples */
621 hParametricStereoDec->qmfBufferImag[i], /* imagSamples */
622 ftimeOutPtr + (i << 7),
623 &circular_buffer_s[3968 - (i<<7)],
624 pVars->mc_info.bDownSampledSbr);
625
626 }
627
628 pv_memmove(hParametricStereoDec->qmfBufferReal[i], qmf_PS_generated_Real, 64*sizeof(*qmf_PS_generated_Real));
629 pv_memmove(hParametricStereoDec->qmfBufferImag[i], qmf_PS_generated_Imag, 64*sizeof(*qmf_PS_generated_Real));
630
631 }
632
633
634 /*
635 * Save Circular buffer history used on PS hybrid analysis
636 */
637
James Donga2e29962011-03-13 12:41:43 -0700638
639 pt_temp = &scratch_mem[2][64];
640
Andreas Huberdacaa732009-12-07 09:56:32 -0800641 for (i = 0, j = 0; i < 3; i++)
642 {
643 pv_memmove(hParametricStereoDec->hHybrid->mQmfBufferReal[i],
James Donga2e29962011-03-13 12:41:43 -0700644 &pt_temp[ j],
Andreas Huberdacaa732009-12-07 09:56:32 -0800645 HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferReal));
646
647 pv_memmove(hParametricStereoDec->hHybrid->mQmfBufferImag[i],
James Donga2e29962011-03-13 12:41:43 -0700648 &pt_temp[ j + 44],
Andreas Huberdacaa732009-12-07 09:56:32 -0800649 HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferImag));
650
651 j += 88;
652 }
653
James Donga2e29962011-03-13 12:41:43 -0700654
Andreas Huberdacaa732009-12-07 09:56:32 -0800655 pv_memmove(hFrameData->V, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
656
657 /*
658 * Set circular buffer for Right channel
659 */
660
661 circular_buffer_s = (Int16 *)scratch_mem[5];
662
663 if (pVars->mc_info.bDownSampledSbr)
664 {
665 pv_memmove(&circular_buffer_s[2048],
666 (int32_t *)hParametricStereoDec->R_ch_qmf_filter_history,
667 640*sizeof(*circular_buffer_s));
668 }
669 else
670 {
671 pv_memmove(&circular_buffer_s[4096],
672 (int32_t *)hParametricStereoDec->R_ch_qmf_filter_history,
673 1152*sizeof(*circular_buffer_s));
674
675 }
676
677
678 for (i = 0; i < 32; i++)
679 {
680 if (pVars->mc_info.bDownSampledSbr)
681 {
682
683 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i], /* realSamples */
684 hParametricStereoDec->qmfBufferImag[i], /* imagSamples */
685 ftimeOutPtrPS + (i << 6),
686 &circular_buffer_s[1984 - (i<<6)],
687 pVars->mc_info.bDownSampledSbr);
688 }
689 else
690 {
691 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i], /* realSamples */
692 hParametricStereoDec->qmfBufferImag[i], /* imagSamples */
693 ftimeOutPtrPS + (i << 7),
694 &circular_buffer_s[3968 - (i<<7)],
695 pVars->mc_info.bDownSampledSbr);
696 }
697
698 }
699
700 if (pVars->mc_info.bDownSampledSbr)
701 {
702 pv_memmove((int32_t *)hParametricStereoDec->R_ch_qmf_filter_history, &circular_buffer_s[0], 640*sizeof(*circular_buffer_s));
703 }
704 else
705 {
706 pv_memmove((int32_t *)hParametricStereoDec->R_ch_qmf_filter_history, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
707 }
708
709
710
711
712
713 }
714 else /* else -- sbrEnablePS */
715 {
716
717#endif /* PARAMETRICSTEREO */
718#endif /* HQ_SBR */
719
720 /*
721 * Use shared aac memory as continuous buffer
722 */
723
724
725 Sr = scratch_mem[0];
726 Si = scratch_mem[1];
727
728 circular_buffer_s = (Int16*)scratch_mem[2];
729
730 if (pVars->mc_info.bDownSampledSbr)
731 {
732
733 pv_memmove(&circular_buffer_s[2048],
734 hFrameData->V,
735 640*sizeof(*circular_buffer_s));
736 }
737 else
738 {
739 pv_memmove(&circular_buffer_s[4096],
740 hFrameData->V,
741 1152*sizeof(*circular_buffer_s));
742 }
743
744 for (i = 0; i < 32; i++)
745 {
746 Int xoverBand;
747
748 if (applyProcessing)
749 {
750 if (i < ((hFrameData->frameInfo[1]) << 1))
751 {
752 xoverBand = sbrDec->prevLowSubband;
753
754 }
755 else
756 {
757 xoverBand = sbrDec->lowSubband;
758 }
759
760 if (xoverBand > sbrDec->highSubband)
761 {
James Donga2e29962011-03-13 12:41:43 -0700762 /*
763 * error condition, default to upsampling mode
764 * and make sure that the number of bands for xover does
765 * not exceed the number of high freq bands.
766 */
767 xoverBand = (sbrDec->highSubband > 32)? 32: sbrDec->highSubband;
Andreas Huberdacaa732009-12-07 09:56:32 -0800768 }
769 }
770 else
771 {
772 xoverBand = 32;
773 sbrDec->highSubband = 32;
774 }
775
776
777 m = sbrDec->bufReadOffs + i; /* sbrDec->bufReadOffs == 2 */
778
779
780 ptr_tmp1 = (hFrameData->codecQmfBufferReal[m]);
781 ptr_tmp2 = Sr;
782
783 if (sbrDec->LC_aacP_DecoderFlag == ON)
784 {
785
786 for (k = (xoverBand >> 1); k != 0; k--)
787 {
788 *(ptr_tmp2++) = (*(ptr_tmp1++)) >> 9;
789 *(ptr_tmp2++) = (*(ptr_tmp1++)) >> 9;
790 }
791 if (xoverBand & 1)
792 {
793 *(ptr_tmp2++) = (*(ptr_tmp1)) >> 9;
794 }
795
796 ptr_tmp1 = &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS];
797
798
799 for (k = xoverBand; k < sbrDec->highSubband; k++)
800 {
801 *(ptr_tmp2++) = (*(ptr_tmp1++)) << 1;
802 }
803
804 pv_memset((void *)ptr_tmp2,
805 0,
806 (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
807
808
809 if (pVars->mc_info.bDownSampledSbr)
810 {
811 calc_sbr_synfilterbank_LC(Sr, /* realSamples */
812 ftimeOutPtr + (i << 6),
813 &circular_buffer_s[1984 - (i<<6)],
814 pVars->mc_info.bDownSampledSbr);
815 }
816 else
817 {
818 calc_sbr_synfilterbank_LC(Sr, /* realSamples */
819 ftimeOutPtr + (i << 7),
820 &circular_buffer_s[3968 - (i<<7)],
821 pVars->mc_info.bDownSampledSbr);
822 }
823 }
824#ifdef HQ_SBR
825 else
826 {
827
828 for (k = xoverBand; k != 0; k--)
829 {
830 *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
831 }
832
833 ptr_tmp1 = &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS];
834 ptr_tmp2 = &Sr[xoverBand];
835
836
837 for (k = xoverBand; k < sbrDec->highSubband; k++)
838 {
839 *(ptr_tmp2++) = (*(ptr_tmp1++));
840 }
841
842 pv_memset((void *)ptr_tmp2,
843 0,
844 (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
845
846
847 ptr_tmp1 = (hFrameData->codecQmfBufferImag[m]);
848 ptr_tmp2 = Si;
849
850 for (k = (xoverBand >> 1); k != 0; k--)
851 {
852 *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
853 *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
854 }
855 if (xoverBand & 1)
856 {
857 *(ptr_tmp2) = shft_lft_1(*(ptr_tmp1));
858 }
859
860 ptr_tmp1 = &hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS];
861 ptr_tmp2 = &Si[xoverBand];
862
863 for (k = xoverBand; k < sbrDec->highSubband; k++)
864 {
865 *(ptr_tmp2++) = (*(ptr_tmp1++));
866 }
867
868 pv_memset((void *)ptr_tmp2,
869 0,
870 (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
871
872
873 if (pVars->mc_info.bDownSampledSbr)
874 {
875 calc_sbr_synfilterbank(Sr, /* realSamples */
876 Si, /* imagSamples */
877 ftimeOutPtr + (i << 6),
878 &circular_buffer_s[1984 - (i<<6)],
879 pVars->mc_info.bDownSampledSbr);
880 }
881 else
882 {
883 calc_sbr_synfilterbank(Sr, /* realSamples */
884 Si, /* imagSamples */
885 ftimeOutPtr + (i << 7),
886 &circular_buffer_s[3968 - (i<<7)],
887 pVars->mc_info.bDownSampledSbr);
888 }
889 }
890#endif
891
892 }
893
894 if (pVars->mc_info.bDownSampledSbr)
895 {
896 pv_memmove(hFrameData->V, &circular_buffer_s[0], 640*sizeof(*circular_buffer_s));
897 }
898 else
899 {
900 pv_memmove(hFrameData->V, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
901 }
902
903
904
905
906 /*
907 * Update Buffers
908 */
909 for (i = 0; i < sbrDec->bufWriteOffs; i++) /* sbrDec->bufWriteOffs set to 8 and unchanged */
910 {
911 j = sbrDec->noCols + i; /* sbrDec->noCols set to 32 and unchanged */
912
913 pv_memmove(hFrameData->codecQmfBufferReal[i], /* to */
914 hFrameData->codecQmfBufferReal[j], /* from */
915 sizeof(*hFrameData->codecQmfBufferReal[i]) << 5);
916 }
917
918
919 pv_memmove(&hFrameData->HistsbrQmfBufferReal[0],
920 &hFrameData->sbrQmfBufferReal[32*SBR_NUM_BANDS],
921 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
922
923#ifdef HQ_SBR
924 if (sbrDec->LC_aacP_DecoderFlag == OFF)
925 {
926 for (i = 0; i < sbrDec->bufWriteOffs; i++) /* sbrDec->bufWriteOffs set to 6 and unchanged */
927 {
928 j = sbrDec->noCols + i; /* sbrDec->noCols set to 32 and unchanged */
929
930
931 pv_memmove(hFrameData->codecQmfBufferImag[i],
932 hFrameData->codecQmfBufferImag[j],
933 sizeof(*hFrameData->codecQmfBufferImag[i]) << 5);
934
935 }
936
937 pv_memmove(&hFrameData->HistsbrQmfBufferImag[0],
938 &hFrameData->sbrQmfBufferImag[32*SBR_NUM_BANDS],
939 6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
940 }
941#endif
942
943
944#ifdef HQ_SBR
945#ifdef PARAMETRICSTEREO
946 }
947#endif
948#endif
949
950
951 hFrameData->reset_flag = 0;
952 if (applyProcessing)
953 {
954 sbrDec->prevLowSubband = sbrDec->lowSubband;
955 }
956
957}
958
959
960#endif /* AAC_PLUS */