diff options
Diffstat (limited to 'apps/codecs/libfaad/sbr_dec.c')
-rw-r--r-- | apps/codecs/libfaad/sbr_dec.c | 177 |
1 files changed, 66 insertions, 111 deletions
diff --git a/apps/codecs/libfaad/sbr_dec.c b/apps/codecs/libfaad/sbr_dec.c index c460be0c02..7f6a9bbffe 100644 --- a/apps/codecs/libfaad/sbr_dec.c +++ b/apps/codecs/libfaad/sbr_dec.c | |||
@@ -41,34 +41,63 @@ | |||
41 | #include "sbr_hfgen.h" | 41 | #include "sbr_hfgen.h" |
42 | #include "sbr_hfadj.h" | 42 | #include "sbr_hfadj.h" |
43 | 43 | ||
44 | 44 | /* type definitons */ | |
45 | /* globals */ | 45 | typedef struct { |
46 | #if (defined(PS_DEC) || defined(DRM_PS)) | 46 | #if (defined(PS_DEC) || defined(DRM_PS)) |
47 | /* In case of PS_DEC or DRM_PS we need larger buffer data when calling | 47 | /* In case of PS_DEC or DRM_PS we need larger buffer data when calling |
48 | * ps_decode() or drm_ps_decode(). */ | 48 | * ps_decode() or drm_ps_decode(). */ |
49 | static qmf_t X_left [MAX_NTSRPS][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR; | 49 | qmf_t X_L[MAX_NTSRPS][64]; |
50 | static qmf_t X_right[MAX_NTSRPS][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR; | 50 | qmf_t X_R[MAX_NTSRPS][64]; |
51 | #else | 51 | #else |
52 | /* No PS functions called. Keep using MAX_NTSR as array size. */ | 52 | /* No PS functions called. Keep using MAX_NTSR as array size. */ |
53 | static qmf_t X_left [MAX_NTSR][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR; | 53 | qmf_t X_L[MAX_NTSR][64]; |
54 | static qmf_t X_right[MAX_NTSR][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR; | 54 | qmf_t X_R[MAX_NTSR][64]; |
55 | #endif | 55 | #endif |
56 | } XLR_t; | ||
56 | 57 | ||
58 | /* static variables */ | ||
59 | static XLR_t *p_XLR = NULL; | ||
60 | #if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM) | ||
61 | static XLR_t s_XLR IBSS_ATTR MEM_ALIGN_ATTR; | ||
62 | #endif | ||
63 | #if defined(FAAD_STATIC_ALLOC) | ||
64 | static sbr_info s_sbr[MAX_SYNTAX_ELEMENTS]; | ||
65 | #endif | ||
66 | #ifdef SBR_LOW_POWER | ||
67 | static real_t deg[64] MEM_ALIGN_ATTR; | ||
68 | #endif | ||
57 | 69 | ||
58 | /* static function declarations */ | 70 | /* static function declarations */ |
59 | static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch); | 71 | static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch); |
60 | static void sbr_save_matrix(sbr_info *sbr, uint8_t ch); | 72 | static void sbr_save_matrix(sbr_info *sbr, uint8_t ch); |
61 | 73 | ||
62 | 74 | ||
63 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, | 75 | sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele, |
64 | uint32_t sample_rate, uint8_t downSampledSBR | 76 | uint32_t sample_rate, uint8_t downSampledSBR |
65 | #ifdef DRM | 77 | #ifdef DRM |
66 | , uint8_t IsDRM | 78 | , uint8_t IsDRM |
67 | #endif | 79 | #endif |
68 | ) | 80 | ) |
69 | { | 81 | { |
70 | sbr_info *sbr = faad_malloc(sizeof(sbr_info)); | 82 | (void)downSampledSBR; |
83 | |||
84 | /* Allocate sbr_info. */ | ||
85 | #if defined(FAAD_STATIC_ALLOC) | ||
86 | sbr_info *sbr = &s_sbr[id_ele]; | ||
87 | #else | ||
88 | (void)id_ele; | ||
89 | sbr_info *sbr =(sbr_info*)faad_malloc(sizeof(sbr_info)); | ||
90 | #endif | ||
71 | memset(sbr, 0, sizeof(sbr_info)); | 91 | memset(sbr, 0, sizeof(sbr_info)); |
92 | |||
93 | /* Allocate XLR temporary variable. Use static allocation if either | ||
94 | * FAAD_STATIC_ALLOC is set or XLR fits to IRAM. */ | ||
95 | #if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM) | ||
96 | p_XLR = &s_XLR; | ||
97 | #else | ||
98 | p_XLR =(XLR_t*)faad_malloc(sizeof(XLR_t)); | ||
99 | #endif | ||
100 | memset(p_XLR, 0, sizeof(XLR_t)); | ||
72 | 101 | ||
73 | /* save id of the parent element */ | 102 | /* save id of the parent element */ |
74 | sbr->id_aac = id_aac; | 103 | sbr->id_aac = id_aac; |
@@ -115,80 +144,15 @@ sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, | |||
115 | sbr->GQ_ringbuf_index[0] = 0; | 144 | sbr->GQ_ringbuf_index[0] = 0; |
116 | sbr->GQ_ringbuf_index[1] = 0; | 145 | sbr->GQ_ringbuf_index[1] = 0; |
117 | 146 | ||
118 | if (id_aac == ID_CPE) | 147 | memset(sbr->qmfa, 0, 2*sizeof(qmfa_info)); |
119 | { | 148 | memset(sbr->qmfs, 0, 2*sizeof(qmfs_info)); |
120 | /* stereo */ | ||
121 | uint8_t j; | ||
122 | sbr->qmfa[0] = qmfa_init(32); | ||
123 | sbr->qmfa[1] = qmfa_init(32); | ||
124 | sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64); | ||
125 | sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64); | ||
126 | |||
127 | for (j = 0; j < 5; j++) | ||
128 | { | ||
129 | sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t)); | ||
130 | sbr->G_temp_prev[1][j] = faad_malloc(64*sizeof(real_t)); | ||
131 | sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t)); | ||
132 | sbr->Q_temp_prev[1][j] = faad_malloc(64*sizeof(real_t)); | ||
133 | } | ||
134 | 149 | ||
135 | memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t)); | 150 | memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t)); |
136 | memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t)); | 151 | memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t)); |
137 | } else { | ||
138 | /* mono */ | ||
139 | uint8_t j; | ||
140 | sbr->qmfa[0] = qmfa_init(32); | ||
141 | sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64); | ||
142 | sbr->qmfs[1] = NULL; | ||
143 | |||
144 | for (j = 0; j < 5; j++) | ||
145 | { | ||
146 | sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t)); | ||
147 | sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t)); | ||
148 | } | ||
149 | |||
150 | memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t)); | ||
151 | } | ||
152 | 152 | ||
153 | return sbr; | 153 | return sbr; |
154 | } | 154 | } |
155 | 155 | ||
156 | void sbrDecodeEnd(sbr_info *sbr) | ||
157 | { | ||
158 | uint8_t j; | ||
159 | |||
160 | if (sbr) | ||
161 | { | ||
162 | qmfa_end(sbr->qmfa[0]); | ||
163 | qmfs_end(sbr->qmfs[0]); | ||
164 | if (sbr->qmfs[1] != NULL) | ||
165 | { | ||
166 | qmfa_end(sbr->qmfa[1]); | ||
167 | qmfs_end(sbr->qmfs[1]); | ||
168 | } | ||
169 | |||
170 | for (j = 0; j < 5; j++) | ||
171 | { | ||
172 | if (sbr->G_temp_prev[0][j]) faad_free(sbr->G_temp_prev[0][j]); | ||
173 | if (sbr->Q_temp_prev[0][j]) faad_free(sbr->Q_temp_prev[0][j]); | ||
174 | if (sbr->G_temp_prev[1][j]) faad_free(sbr->G_temp_prev[1][j]); | ||
175 | if (sbr->Q_temp_prev[1][j]) faad_free(sbr->Q_temp_prev[1][j]); | ||
176 | } | ||
177 | |||
178 | #ifdef PS_DEC | ||
179 | if (sbr->ps != NULL) | ||
180 | ps_free(sbr->ps); | ||
181 | #endif | ||
182 | |||
183 | #ifdef DRM_PS | ||
184 | if (sbr->drm_ps != NULL) | ||
185 | drm_ps_free(sbr->drm_ps); | ||
186 | #endif | ||
187 | |||
188 | faad_free(sbr); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch) | 156 | static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch) |
193 | { | 157 | { |
194 | uint8_t i; | 158 | uint8_t i; |
@@ -239,10 +203,6 @@ static void sbr_save_matrix(sbr_info *sbr, uint8_t ch) | |||
239 | } | 203 | } |
240 | } | 204 | } |
241 | 205 | ||
242 | #ifdef SBR_LOW_POWER | ||
243 | real_t deg[64] MEM_ALIGN_ATTR; | ||
244 | #endif | ||
245 | |||
246 | static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64], | 206 | static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64], |
247 | uint8_t ch, uint8_t dont_process, | 207 | uint8_t ch, uint8_t dont_process, |
248 | const uint8_t downSampledSBR) | 208 | const uint8_t downSampledSBR) |
@@ -276,9 +236,9 @@ static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_ | |||
276 | 236 | ||
277 | /* subband analysis */ | 237 | /* subband analysis */ |
278 | if (dont_process) | 238 | if (dont_process) |
279 | sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32); | 239 | sbr_qmf_analysis_32(sbr, &sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32); |
280 | else | 240 | else |
281 | sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx); | 241 | sbr_qmf_analysis_32(sbr, &sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx); |
282 | 242 | ||
283 | if (!dont_process) | 243 | if (!dont_process) |
284 | { | 244 | { |
@@ -413,22 +373,22 @@ uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_cha | |||
413 | sbr->just_seeked = 0; | 373 | sbr->just_seeked = 0; |
414 | } | 374 | } |
415 | 375 | ||
416 | sbr_process_channel(sbr, left_chan, X_left, 0, dont_process, downSampledSBR); | 376 | sbr_process_channel(sbr, left_chan, p_XLR->X_L, 0, dont_process, downSampledSBR); |
417 | /* subband synthesis */ | 377 | /* subband synthesis */ |
418 | if (downSampledSBR) | 378 | if (downSampledSBR) |
419 | { | 379 | { |
420 | sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_chan); | 380 | sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, left_chan); |
421 | } else { | 381 | } else { |
422 | sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_chan); | 382 | sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, left_chan); |
423 | } | 383 | } |
424 | 384 | ||
425 | sbr_process_channel(sbr, right_chan, X_right, 1, dont_process, downSampledSBR); | 385 | sbr_process_channel(sbr, right_chan, p_XLR->X_R, 1, dont_process, downSampledSBR); |
426 | /* subband synthesis */ | 386 | /* subband synthesis */ |
427 | if (downSampledSBR) | 387 | if (downSampledSBR) |
428 | { | 388 | { |
429 | sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_chan); | 389 | sbr_qmf_synthesis_32(sbr, &sbr->qmfs[1], p_XLR->X_R, right_chan); |
430 | } else { | 390 | } else { |
431 | sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_chan); | 391 | sbr_qmf_synthesis_64(sbr, &sbr->qmfs[1], p_XLR->X_R, right_chan); |
432 | } | 392 | } |
433 | 393 | ||
434 | if (sbr->bs_header_flag) | 394 | if (sbr->bs_header_flag) |
@@ -495,13 +455,13 @@ uint8_t sbrDecodeSingleFrame(sbr_info *sbr, real_t *channel, | |||
495 | sbr->just_seeked = 0; | 455 | sbr->just_seeked = 0; |
496 | } | 456 | } |
497 | 457 | ||
498 | sbr_process_channel(sbr, channel, X_left, 0, dont_process, downSampledSBR); | 458 | sbr_process_channel(sbr, channel, p_XLR->X_L, 0, dont_process, downSampledSBR); |
499 | /* subband synthesis */ | 459 | /* subband synthesis */ |
500 | if (downSampledSBR) | 460 | if (downSampledSBR) |
501 | { | 461 | { |
502 | sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, channel); | 462 | sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, channel); |
503 | } else { | 463 | } else { |
504 | sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, channel); | 464 | sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, channel); |
505 | } | 465 | } |
506 | 466 | ||
507 | if (sbr->bs_header_flag) | 467 | if (sbr->bs_header_flag) |
@@ -540,8 +500,8 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ | |||
540 | uint8_t dont_process = 0; | 500 | uint8_t dont_process = 0; |
541 | uint8_t ret = 0; | 501 | uint8_t ret = 0; |
542 | 502 | ||
543 | memset(X_left,0,sizeof(X_left)); | 503 | memset(p_XLR->X_L, 0, sizeof(*p_XLR->X_L)); |
544 | memset(X_right,0,sizeof(X_right)); | 504 | memset(p_XLR->X_R, 0, sizeof(*p_XLR->X_R)); |
545 | if (sbr == NULL) | 505 | if (sbr == NULL) |
546 | return 20; | 506 | return 20; |
547 | 507 | ||
@@ -566,20 +526,15 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ | |||
566 | sbr->just_seeked = 0; | 526 | sbr->just_seeked = 0; |
567 | } | 527 | } |
568 | 528 | ||
569 | if (sbr->qmfs[1] == NULL) | 529 | sbr_process_channel(sbr, left_channel, p_XLR->X_L, 0, dont_process, downSampledSBR); |
570 | { | ||
571 | sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64); | ||
572 | } | ||
573 | |||
574 | sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR); | ||
575 | 530 | ||
576 | /* copy some extra data for PS */ | 531 | /* copy some extra data for PS */ |
577 | for (l = 32; l < 38; l++) | 532 | for (l = 32; l < 38; l++) |
578 | { | 533 | { |
579 | for (k = 0; k < 5; k++) | 534 | for (k = 0; k < 5; k++) |
580 | { | 535 | { |
581 | QMF_RE(X_left[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]); | 536 | QMF_RE(p_XLR->X_L[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]); |
582 | QMF_IM(X_left[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]); | 537 | QMF_IM(p_XLR->X_L[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]); |
583 | } | 538 | } |
584 | } | 539 | } |
585 | 540 | ||
@@ -587,11 +542,11 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ | |||
587 | #ifdef DRM_PS | 542 | #ifdef DRM_PS |
588 | if (sbr->Is_DRM_SBR) | 543 | if (sbr->Is_DRM_SBR) |
589 | { | 544 | { |
590 | drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), sbr->sample_rate, X_left, X_right); | 545 | drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), sbr->sample_rate, p_XLR->X_L, p_XLR->X_R); |
591 | } else { | 546 | } else { |
592 | #endif | 547 | #endif |
593 | #ifdef PS_DEC | 548 | #ifdef PS_DEC |
594 | ps_decode(sbr->ps, X_left, X_right); | 549 | ps_decode(sbr->ps, p_XLR->X_L, p_XLR->X_R); |
595 | #endif | 550 | #endif |
596 | #ifdef DRM_PS | 551 | #ifdef DRM_PS |
597 | } | 552 | } |
@@ -600,11 +555,11 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ | |||
600 | /* subband synthesis */ | 555 | /* subband synthesis */ |
601 | if (downSampledSBR) | 556 | if (downSampledSBR) |
602 | { | 557 | { |
603 | sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_channel); | 558 | sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, left_channel); |
604 | sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_channel); | 559 | sbr_qmf_synthesis_32(sbr, &sbr->qmfs[1], p_XLR->X_R, right_channel); |
605 | } else { | 560 | } else { |
606 | sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_channel); | 561 | sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, left_channel); |
607 | sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_channel); | 562 | sbr_qmf_synthesis_64(sbr, &sbr->qmfs[1], p_XLR->X_R, right_channel); |
608 | } | 563 | } |
609 | 564 | ||
610 | if (sbr->bs_header_flag) | 565 | if (sbr->bs_header_flag) |