/src/aac/libAACdec/src/channel.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* ----------------------------------------------------------------------------- |
2 | | Software License for The Fraunhofer FDK AAC Codec Library for Android |
3 | | |
4 | | © Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten |
5 | | Forschung e.V. All rights reserved. |
6 | | |
7 | | 1. INTRODUCTION |
8 | | The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software |
9 | | that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding |
10 | | scheme for digital audio. This FDK AAC Codec software is intended to be used on |
11 | | a wide variety of Android devices. |
12 | | |
13 | | AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient |
14 | | general perceptual audio codecs. AAC-ELD is considered the best-performing |
15 | | full-bandwidth communications codec by independent studies and is widely |
16 | | deployed. AAC has been standardized by ISO and IEC as part of the MPEG |
17 | | specifications. |
18 | | |
19 | | Patent licenses for necessary patent claims for the FDK AAC Codec (including |
20 | | those of Fraunhofer) may be obtained through Via Licensing |
21 | | (www.vialicensing.com) or through the respective patent owners individually for |
22 | | the purpose of encoding or decoding bit streams in products that are compliant |
23 | | with the ISO/IEC MPEG audio standards. Please note that most manufacturers of |
24 | | Android devices already license these patent claims through Via Licensing or |
25 | | directly from the patent owners, and therefore FDK AAC Codec software may |
26 | | already be covered under those patent licenses when it is used for those |
27 | | licensed purposes only. |
28 | | |
29 | | Commercially-licensed AAC software libraries, including floating-point versions |
30 | | with enhanced sound quality, are also available from Fraunhofer. Users are |
31 | | encouraged to check the Fraunhofer website for additional applications |
32 | | information and documentation. |
33 | | |
34 | | 2. COPYRIGHT LICENSE |
35 | | |
36 | | Redistribution and use in source and binary forms, with or without modification, |
37 | | are permitted without payment of copyright license fees provided that you |
38 | | satisfy the following conditions: |
39 | | |
40 | | You must retain the complete text of this software license in redistributions of |
41 | | the FDK AAC Codec or your modifications thereto in source code form. |
42 | | |
43 | | You must retain the complete text of this software license in the documentation |
44 | | and/or other materials provided with redistributions of the FDK AAC Codec or |
45 | | your modifications thereto in binary form. You must make available free of |
46 | | charge copies of the complete source code of the FDK AAC Codec and your |
47 | | modifications thereto to recipients of copies in binary form. |
48 | | |
49 | | The name of Fraunhofer may not be used to endorse or promote products derived |
50 | | from this library without prior written permission. |
51 | | |
52 | | You may not charge copyright license fees for anyone to use, copy or distribute |
53 | | the FDK AAC Codec software or your modifications thereto. |
54 | | |
55 | | Your modified versions of the FDK AAC Codec must carry prominent notices stating |
56 | | that you changed the software and the date of any change. For modified versions |
57 | | of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android" |
58 | | must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK |
59 | | AAC Codec Library for Android." |
60 | | |
61 | | 3. NO PATENT LICENSE |
62 | | |
63 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without |
64 | | limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE. |
65 | | Fraunhofer provides no warranty of patent non-infringement with respect to this |
66 | | software. |
67 | | |
68 | | You may use this FDK AAC Codec software or modifications thereto only for |
69 | | purposes that are authorized by appropriate patent licenses. |
70 | | |
71 | | 4. DISCLAIMER |
72 | | |
73 | | This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright |
74 | | holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, |
75 | | including but not limited to the implied warranties of merchantability and |
76 | | fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
77 | | CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, |
78 | | or consequential damages, including but not limited to procurement of substitute |
79 | | goods or services; loss of use, data, or profits, or business interruption, |
80 | | however caused and on any theory of liability, whether in contract, strict |
81 | | liability, or tort (including negligence), arising in any way out of the use of |
82 | | this software, even if advised of the possibility of such damage. |
83 | | |
84 | | 5. CONTACT INFORMATION |
85 | | |
86 | | Fraunhofer Institute for Integrated Circuits IIS |
87 | | Attention: Audio and Multimedia Departments - FDK AAC LL |
88 | | Am Wolfsmantel 33 |
89 | | 91058 Erlangen, Germany |
90 | | |
91 | | www.iis.fraunhofer.de/amm |
92 | | amm-info@iis.fraunhofer.de |
93 | | ----------------------------------------------------------------------------- */ |
94 | | |
95 | | /**************************** AAC decoder library ****************************** |
96 | | |
97 | | Author(s): Josef Hoepfl |
98 | | |
99 | | Description: |
100 | | |
101 | | *******************************************************************************/ |
102 | | |
103 | | #include "channel.h" |
104 | | #include "aacdecoder.h" |
105 | | #include "block.h" |
106 | | #include "aacdec_tns.h" |
107 | | #include "FDK_bitstream.h" |
108 | | |
109 | | #include "conceal.h" |
110 | | |
111 | | #include "rvlc.h" |
112 | | |
113 | | #include "aacdec_hcr.h" |
114 | | |
115 | | #include "usacdec_lpd.h" |
116 | | #include "usacdec_fac.h" |
117 | | |
118 | | static void MapMidSideMaskToPnsCorrelation( |
119 | 13.7k | CAacDecoderChannelInfo *pAacDecoderChannelInfo[2]) { |
120 | 13.7k | int group; |
121 | | |
122 | 70.2k | for (group = 0; group < pAacDecoderChannelInfo[L]->icsInfo.WindowGroups; |
123 | 56.5k | group++) { |
124 | 56.5k | UCHAR groupMask = 1 << group; |
125 | | |
126 | 238k | for (UCHAR band = 0; band < pAacDecoderChannelInfo[L]->icsInfo.MaxSfBands; |
127 | 181k | band++) { |
128 | 181k | if (pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] & |
129 | 181k | groupMask) { /* channels are correlated */ |
130 | 18.4k | CPns_SetCorrelation(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, |
131 | 18.4k | band, 0); |
132 | | |
133 | 18.4k | if (CPns_IsPnsUsed(&pAacDecoderChannelInfo[L]->data.aac.PnsData, group, |
134 | 18.4k | band) && |
135 | 18.4k | CPns_IsPnsUsed(&pAacDecoderChannelInfo[R]->data.aac.PnsData, group, |
136 | 4.63k | band)) |
137 | 2.05k | pAacDecoderChannelInfo[L]->pComData->jointStereoData.MsUsed[band] ^= |
138 | 2.05k | groupMask; /* clear the groupMask-bit */ |
139 | 18.4k | } |
140 | 181k | } |
141 | 56.5k | } |
142 | 13.7k | } |
143 | | |
144 | | static void Clean_Complex_Prediction_coefficients( |
145 | | CJointStereoPersistentData *pJointStereoPersistentData, int windowGroups, |
146 | 0 | const int low_limit, const int high_limit) { |
147 | 0 | for (int group = 0; group < windowGroups; group++) { |
148 | 0 | for (int sfb = low_limit; sfb < high_limit; sfb++) { |
149 | 0 | pJointStereoPersistentData->alpha_q_re_prev[group][sfb] = 0; |
150 | 0 | pJointStereoPersistentData->alpha_q_im_prev[group][sfb] = 0; |
151 | 0 | } |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | | /*! |
156 | | \brief Decode channel pair element |
157 | | |
158 | | The function decodes a channel pair element. |
159 | | |
160 | | \return none |
161 | | */ |
162 | | void CChannelElement_Decode( |
163 | | CAacDecoderChannelInfo |
164 | | *pAacDecoderChannelInfo[2], /*!< pointer to aac decoder channel info */ |
165 | | CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[2], |
166 | | SamplingRateInfo *pSamplingRateInfo, UINT flags, UINT elFlags, |
167 | 561k | int el_channels) { |
168 | 561k | int ch = 0; |
169 | | |
170 | 561k | int maxSfBandsL = 0, maxSfBandsR = 0; |
171 | 561k | int maybe_jstereo = (el_channels > 1); |
172 | | |
173 | 561k | if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && el_channels == 2) { |
174 | 90.2k | if (pAacDecoderChannelInfo[L]->data.usac.core_mode || |
175 | 90.2k | pAacDecoderChannelInfo[R]->data.usac.core_mode) { |
176 | 12.3k | maybe_jstereo = 0; |
177 | 12.3k | } |
178 | 90.2k | } |
179 | | |
180 | 561k | if (maybe_jstereo) { |
181 | 208k | maxSfBandsL = |
182 | 208k | GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo); |
183 | 208k | maxSfBandsR = |
184 | 208k | GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[R]->icsInfo); |
185 | | |
186 | | /* apply ms */ |
187 | 208k | if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { |
188 | 183k | if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { |
189 | 126k | if (pAacDecoderChannelInfo[L]->data.aac.PnsData.PnsActive || |
190 | 126k | pAacDecoderChannelInfo[R]->data.aac.PnsData.PnsActive) { |
191 | 13.7k | MapMidSideMaskToPnsCorrelation(pAacDecoderChannelInfo); |
192 | 13.7k | } |
193 | 126k | } |
194 | | /* if tns_on_lr == 1 run MS */ /* && |
195 | | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active |
196 | | == 1) */ |
197 | 183k | if (((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && |
198 | 183k | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == |
199 | 56.5k | 1)) || |
200 | 183k | ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) == 0)) { |
201 | 163k | int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); |
202 | | |
203 | 163k | CJointStereo_ApplyMS( |
204 | 163k | pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, |
205 | 163k | pAacDecoderChannelInfo[L]->pSpectralCoefficient, |
206 | 163k | pAacDecoderChannelInfo[R]->pSpectralCoefficient, |
207 | 163k | pAacDecoderChannelInfo[L]->pDynData->aSfbScale, |
208 | 163k | pAacDecoderChannelInfo[R]->pDynData->aSfbScale, |
209 | 163k | pAacDecoderChannelInfo[L]->specScale, |
210 | 163k | pAacDecoderChannelInfo[R]->specScale, |
211 | 163k | GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, |
212 | 163k | pSamplingRateInfo), |
213 | 163k | GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), |
214 | 163k | GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, |
215 | 163k | maxSfBandsL, maxSfBandsR, |
216 | 163k | pAacDecoderChannelInfo[L] |
217 | 163k | ->pComData->jointStereoData.store_dmx_re_prev, |
218 | 163k | &(pAacDecoderChannelInfo[L] |
219 | 163k | ->pComData->jointStereoData.store_dmx_re_prev_e), |
220 | 163k | 1); |
221 | | |
222 | 163k | } /* if ( ((elFlags & AC_EL_USAC_CP_POSSIBLE).... */ |
223 | 183k | } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow)*/ |
224 | | |
225 | | /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb |
226 | | */ |
227 | 208k | if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { |
228 | 130k | if ((pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == |
229 | 130k | 1) && |
230 | 130k | (el_channels == 2)) { |
231 | 126k | CJointStereo_ApplyIS( |
232 | 126k | pAacDecoderChannelInfo, |
233 | 126k | GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, |
234 | 126k | pSamplingRateInfo), |
235 | 126k | GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), |
236 | 126k | GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), |
237 | 126k | GetScaleFactorBandsTransmitted( |
238 | 126k | &pAacDecoderChannelInfo[L]->icsInfo)); |
239 | 126k | } |
240 | 130k | } |
241 | 208k | } /* maybe_stereo */ |
242 | | |
243 | 1.34M | for (ch = 0; ch < el_channels; ch++) { |
244 | 782k | if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { |
245 | | /* Decode LPD data */ |
246 | 47.7k | CLpdChannelStream_Decode(pAacDecoderChannelInfo[ch], |
247 | 47.7k | pAacDecoderStaticChannelInfo[ch], flags); |
248 | 734k | } else { |
249 | 734k | UCHAR noSfbs = |
250 | 734k | GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[ch]->icsInfo); |
251 | | /* For USAC common window: max_sfb of both channels may differ |
252 | | * (common_max_sfb == 0). */ |
253 | 734k | if ((maybe_jstereo == 1) && |
254 | 734k | (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == |
255 | 416k | 1)) { |
256 | 366k | noSfbs = fMax(maxSfBandsL, maxSfBandsR); |
257 | 366k | } |
258 | 734k | int CP_active = 0; |
259 | 734k | if (elFlags & AC_EL_USAC_CP_POSSIBLE) { |
260 | 114k | CP_active = pAacDecoderChannelInfo[ch] |
261 | 114k | ->pComData->jointStereoData.cplx_pred_flag; |
262 | 114k | } |
263 | | |
264 | | /* Omit writing of pAacDecoderChannelInfo[ch]->specScale for complex |
265 | | stereo prediction since scaling has already been carried out. */ |
266 | 734k | int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); |
267 | | |
268 | 734k | if (!(CP_active && (max_sfb_ste == noSfbs)) || |
269 | 734k | !(CP_active && |
270 | 90.6k | !(pAacDecoderChannelInfo[ch]->pDynData->TnsData.Active)) || |
271 | 734k | ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && |
272 | 21.1k | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == |
273 | 722k | 0))) { |
274 | 722k | CBlock_ScaleSpectralData(pAacDecoderChannelInfo[ch], noSfbs, |
275 | 722k | pSamplingRateInfo); |
276 | | |
277 | | /*Active for the case of TNS applied before MS/CP*/ |
278 | 722k | if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && |
279 | 722k | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == |
280 | 322k | 0)) { |
281 | 218k | if (IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo)) { |
282 | 2.00M | for (int i = 0; i < noSfbs; i++) { |
283 | 1.79M | pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i] = |
284 | 1.79M | pAacDecoderChannelInfo[ch]->specScale[0]; |
285 | 1.79M | } |
286 | 207k | } else { |
287 | 102k | for (int i = 0; i < 8; i++) { |
288 | 594k | for (int j = 0; j < noSfbs; j++) { |
289 | 503k | pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i * 16 + j] = |
290 | 503k | pAacDecoderChannelInfo[ch]->specScale[i]; |
291 | 503k | } |
292 | 91.3k | } |
293 | 11.4k | } |
294 | 218k | } |
295 | 722k | } |
296 | 734k | } |
297 | 782k | } /* End "for (ch = 0; ch < el_channels; ch++)" */ |
298 | | |
299 | 561k | if (maybe_jstereo) { |
300 | | /* apply ms */ |
301 | 208k | if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { |
302 | 183k | } /* CommonWindow */ |
303 | 25.0k | else { |
304 | 25.0k | if (elFlags & AC_EL_USAC_CP_POSSIBLE) { |
305 | 3.65k | FDKmemclear( |
306 | 3.65k | pAacDecoderStaticChannelInfo[L] |
307 | 3.65k | ->pCpeStaticData->jointStereoPersistentData.alpha_q_re_prev, |
308 | 3.65k | JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); |
309 | 3.65k | FDKmemclear( |
310 | 3.65k | pAacDecoderStaticChannelInfo[L] |
311 | 3.65k | ->pCpeStaticData->jointStereoPersistentData.alpha_q_im_prev, |
312 | 3.65k | JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); |
313 | 3.65k | } |
314 | 25.0k | } |
315 | | |
316 | 208k | } /* if (maybe_jstereo) */ |
317 | | |
318 | 1.34M | for (ch = 0; ch < el_channels; ch++) { |
319 | 782k | if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { |
320 | 734k | } else { |
321 | 734k | if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { |
322 | | /* Use same seed for coupled channels (CPE) */ |
323 | 399k | int pnsCh = (ch > 0) ? L : ch; |
324 | 399k | CPns_UpdateNoiseState( |
325 | 399k | &pAacDecoderChannelInfo[ch]->data.aac.PnsData, |
326 | 399k | pAacDecoderChannelInfo[pnsCh]->data.aac.PnsData.currentSeed, |
327 | 399k | pAacDecoderChannelInfo[ch]->pComData->pnsRandomSeed); |
328 | 399k | } |
329 | | |
330 | 734k | if ((!(flags & (AC_USAC))) || |
331 | 734k | ((flags & (AC_USAC)) && |
332 | 335k | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active == |
333 | 335k | 1)) || |
334 | 734k | (maybe_jstereo == 0)) { |
335 | 660k | ApplyTools( |
336 | 660k | pAacDecoderChannelInfo, pSamplingRateInfo, flags, elFlags, ch, |
337 | 660k | pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow); |
338 | 660k | } |
339 | 734k | } /* End "} else" */ |
340 | 782k | } /* End "for (ch = 0; ch < el_channels; ch++)" */ |
341 | | |
342 | 561k | if (maybe_jstereo) { |
343 | | /* apply ms */ |
344 | 208k | if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { |
345 | | /* if tns_on_lr == 0 run MS */ |
346 | 183k | if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && |
347 | 183k | (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == |
348 | 56.5k | 0)) { |
349 | 19.3k | int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); |
350 | | |
351 | 19.3k | CJointStereo_ApplyMS( |
352 | 19.3k | pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, |
353 | 19.3k | pAacDecoderChannelInfo[L]->pSpectralCoefficient, |
354 | 19.3k | pAacDecoderChannelInfo[R]->pSpectralCoefficient, |
355 | 19.3k | pAacDecoderChannelInfo[L]->pDynData->aSfbScale, |
356 | 19.3k | pAacDecoderChannelInfo[R]->pDynData->aSfbScale, |
357 | 19.3k | pAacDecoderChannelInfo[L]->specScale, |
358 | 19.3k | pAacDecoderChannelInfo[R]->specScale, |
359 | 19.3k | GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, |
360 | 19.3k | pSamplingRateInfo), |
361 | 19.3k | GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), |
362 | 19.3k | GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, |
363 | 19.3k | maxSfBandsL, maxSfBandsR, |
364 | 19.3k | pAacDecoderChannelInfo[L] |
365 | 19.3k | ->pComData->jointStereoData.store_dmx_re_prev, |
366 | 19.3k | &(pAacDecoderChannelInfo[L] |
367 | 19.3k | ->pComData->jointStereoData.store_dmx_re_prev_e), |
368 | 19.3k | 1); |
369 | 19.3k | } |
370 | | |
371 | 183k | } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) */ |
372 | | |
373 | 208k | } /* if (maybe_jstereo) */ |
374 | | |
375 | 1.34M | for (ch = 0; ch < el_channels; ch++) { |
376 | 782k | if (elFlags & AC_EL_USAC_CP_POSSIBLE) { |
377 | 130k | pAacDecoderStaticChannelInfo[L] |
378 | 130k | ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0; |
379 | 130k | } |
380 | 782k | } |
381 | | |
382 | 561k | CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, |
383 | 561k | flags, el_channels); |
384 | 561k | } |
385 | | |
386 | | void CChannel_CodebookTableInit( |
387 | 337k | CAacDecoderChannelInfo *pAacDecoderChannelInfo) { |
388 | 337k | int b, w, maxBands, maxWindows; |
389 | 337k | int maxSfb = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo); |
390 | 337k | UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; |
391 | | |
392 | 337k | if (IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) { |
393 | 266k | maxBands = 64; |
394 | 266k | maxWindows = 1; |
395 | 266k | } else { |
396 | 70.5k | maxBands = 16; |
397 | 70.5k | maxWindows = 8; |
398 | 70.5k | } |
399 | | |
400 | 1.16M | for (w = 0; w < maxWindows; w++) { |
401 | 3.25M | for (b = 0; b < maxSfb; b++) { |
402 | 2.42M | pCodeBook[b] = ESCBOOK; |
403 | 2.42M | } |
404 | 24.5M | for (; b < maxBands; b++) { |
405 | 23.6M | pCodeBook[b] = ZERO_HCB; |
406 | 23.6M | } |
407 | 831k | pCodeBook += maxBands; |
408 | 831k | } |
409 | 337k | } |
410 | | |
411 | | /* |
412 | | * Arbitrary order bitstream parser |
413 | | */ |
414 | | AAC_DECODER_ERROR CChannelElement_Read( |
415 | | HANDLE_FDK_BITSTREAM hBs, CAacDecoderChannelInfo *pAacDecoderChannelInfo[], |
416 | | CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[], |
417 | | const AUDIO_OBJECT_TYPE aot, SamplingRateInfo *pSamplingRateInfo, |
418 | | const UINT flags, const UINT elFlags, const UINT frame_length, |
419 | | const UCHAR numberOfChannels, const SCHAR epConfig, |
420 | 573k | HANDLE_TRANSPORTDEC pTpDec) { |
421 | 573k | AAC_DECODER_ERROR error = AAC_DEC_OK; |
422 | 573k | const element_list_t *list; |
423 | 573k | int i, ch, decision_bit; |
424 | 573k | int crcReg1 = -1, crcReg2 = -1; |
425 | 573k | int cplxPred; |
426 | 573k | int ind_sw_cce_flag = 0, num_gain_element_lists = 0; |
427 | | |
428 | 573k | FDK_ASSERT((numberOfChannels == 1) || (numberOfChannels == 2)); |
429 | | |
430 | | /* Get channel element sequence table */ |
431 | 573k | list = getBitstreamElementList(aot, epConfig, numberOfChannels, 0, elFlags); |
432 | 573k | if (list == NULL) { |
433 | 0 | error = AAC_DEC_UNSUPPORTED_FORMAT; |
434 | 0 | goto bail; |
435 | 0 | } |
436 | | |
437 | 573k | CTns_Reset(&pAacDecoderChannelInfo[0]->pDynData->TnsData); |
438 | | /* Set common window to 0 by default. If signalized in the bit stream it will |
439 | | * be overwritten later explicitely */ |
440 | 573k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; |
441 | 573k | if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) { |
442 | 296k | pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = 0; |
443 | 296k | pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = 0; |
444 | 296k | } |
445 | 573k | if (numberOfChannels == 2) { |
446 | 225k | CTns_Reset(&pAacDecoderChannelInfo[1]->pDynData->TnsData); |
447 | 225k | pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; |
448 | 225k | } |
449 | | |
450 | 573k | cplxPred = 0; |
451 | 573k | if (pAacDecoderStaticChannelInfo != NULL) { |
452 | 572k | if (elFlags & AC_EL_USAC_CP_POSSIBLE) { |
453 | 65.7k | pAacDecoderChannelInfo[0]->pComData->jointStereoData.cplx_pred_flag = 0; |
454 | 65.7k | cplxPred = 1; |
455 | 65.7k | } |
456 | 572k | } |
457 | | |
458 | 573k | if (0 || (flags & (AC_ELD | AC_SCALABLE))) { |
459 | 252k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 1; |
460 | 252k | if (numberOfChannels == 2) { |
461 | 127k | pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = |
462 | 127k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; |
463 | 127k | } |
464 | 252k | } |
465 | | |
466 | | /* Iterate through sequence table */ |
467 | 573k | i = 0; |
468 | 573k | ch = 0; |
469 | 573k | decision_bit = 0; |
470 | 8.81M | do { |
471 | 8.81M | switch (list->id[i]) { |
472 | 25.2k | case element_instance_tag: |
473 | 25.2k | pAacDecoderChannelInfo[0]->ElementInstanceTag = FDKreadBits(hBs, 4); |
474 | 25.2k | if (numberOfChannels == 2) { |
475 | 6.12k | pAacDecoderChannelInfo[1]->ElementInstanceTag = |
476 | 6.12k | pAacDecoderChannelInfo[0]->ElementInstanceTag; |
477 | 6.12k | } |
478 | 25.2k | break; |
479 | 84.6k | case common_window: |
480 | 84.6k | decision_bit = |
481 | 84.6k | pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow = |
482 | 84.6k | FDKreadBits(hBs, 1); |
483 | 84.6k | if (numberOfChannels == 2) { |
484 | 84.6k | pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = |
485 | 84.6k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; |
486 | 84.6k | } |
487 | 84.6k | break; |
488 | 562k | case ics_info: |
489 | | /* store last window sequence (utilized in complex stereo prediction) |
490 | | * before reading new channel-info */ |
491 | 562k | if (cplxPred) { |
492 | 65.5k | if (pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { |
493 | 49.4k | pAacDecoderStaticChannelInfo[0] |
494 | 49.4k | ->pCpeStaticData->jointStereoPersistentData.winSeqPrev = |
495 | 49.4k | pAacDecoderChannelInfo[0]->icsInfo.WindowSequence; |
496 | 49.4k | pAacDecoderStaticChannelInfo[0] |
497 | 49.4k | ->pCpeStaticData->jointStereoPersistentData.winShapePrev = |
498 | 49.4k | pAacDecoderChannelInfo[0]->icsInfo.WindowShape; |
499 | 49.4k | } |
500 | 65.5k | } |
501 | | /* Read individual channel info */ |
502 | 562k | error = IcsRead(hBs, &pAacDecoderChannelInfo[ch]->icsInfo, |
503 | 562k | pSamplingRateInfo, flags); |
504 | | |
505 | 562k | if (elFlags & AC_EL_LFE && |
506 | 562k | GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) != |
507 | 0 | BLOCK_LONG) { |
508 | 0 | error = AAC_DEC_PARSE_ERROR; |
509 | 0 | break; |
510 | 0 | } |
511 | | |
512 | 562k | if (numberOfChannels == 2 && |
513 | 562k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { |
514 | 186k | pAacDecoderChannelInfo[1]->icsInfo = |
515 | 186k | pAacDecoderChannelInfo[0]->icsInfo; |
516 | 186k | } |
517 | 562k | break; |
518 | | |
519 | 56.8k | case common_max_sfb: |
520 | 56.8k | if (FDKreadBit(hBs) == 0) { |
521 | 26.2k | error = IcsReadMaxSfb(hBs, &pAacDecoderChannelInfo[1]->icsInfo, |
522 | 26.2k | pSamplingRateInfo); |
523 | 26.2k | } |
524 | 56.8k | break; |
525 | | |
526 | 83.2k | case ltp_data_present: |
527 | 83.2k | if (FDKreadBits(hBs, 1) != 0) { |
528 | 57 | error = AAC_DEC_UNSUPPORTED_PREDICTION; |
529 | 57 | } |
530 | 83.2k | break; |
531 | | |
532 | 186k | case ms: |
533 | | |
534 | 186k | INT max_sfb_ste; |
535 | 186k | INT max_sfb_ste_clear; |
536 | | |
537 | 186k | max_sfb_ste = GetScaleMaxFactorBandsTransmitted( |
538 | 186k | &pAacDecoderChannelInfo[0]->icsInfo, |
539 | 186k | &pAacDecoderChannelInfo[1]->icsInfo); |
540 | | |
541 | 186k | max_sfb_ste_clear = 64; |
542 | | |
543 | 186k | pAacDecoderChannelInfo[0]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; |
544 | 186k | pAacDecoderChannelInfo[1]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; |
545 | | |
546 | 186k | if (flags & (AC_USAC | AC_RSV603DA) && |
547 | 186k | pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow == |
548 | 56.8k | 0) { |
549 | 0 | Clean_Complex_Prediction_coefficients( |
550 | 0 | &pAacDecoderStaticChannelInfo[0] |
551 | 0 | ->pCpeStaticData->jointStereoPersistentData, |
552 | 0 | GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), 0, 64); |
553 | 0 | } |
554 | | |
555 | 186k | if (CJointStereo_Read( |
556 | 186k | hBs, &pAacDecoderChannelInfo[0]->pComData->jointStereoData, |
557 | 186k | GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), |
558 | 186k | max_sfb_ste, max_sfb_ste_clear, |
559 | | /* jointStereoPersistentData and cplxPredictionData are only |
560 | | available/allocated if cplxPred is active. */ |
561 | 186k | ((cplxPred == 0) || (pAacDecoderStaticChannelInfo == NULL)) |
562 | 186k | ? NULL |
563 | 186k | : &pAacDecoderStaticChannelInfo[0] |
564 | 49.4k | ->pCpeStaticData->jointStereoPersistentData, |
565 | 186k | ((cplxPred == 0) || (pAacDecoderChannelInfo[0] == NULL)) |
566 | 186k | ? NULL |
567 | 186k | : pAacDecoderChannelInfo[0] |
568 | 49.4k | ->pComStaticData->cplxPredictionData, |
569 | 186k | cplxPred, |
570 | 186k | GetScaleFactorBandsTotal(&pAacDecoderChannelInfo[0]->icsInfo), |
571 | 186k | GetWindowSequence(&pAacDecoderChannelInfo[0]->icsInfo), |
572 | 186k | flags)) { |
573 | 7 | error = AAC_DEC_PARSE_ERROR; |
574 | 7 | } |
575 | | |
576 | 186k | break; |
577 | | |
578 | 748k | case global_gain: |
579 | 748k | pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.GlobalGain = |
580 | 748k | (UCHAR)FDKreadBits(hBs, 8); |
581 | 748k | break; |
582 | | |
583 | 410k | case section_data: |
584 | 410k | error = CBlock_ReadSectionData(hBs, pAacDecoderChannelInfo[ch], |
585 | 410k | pSamplingRateInfo, flags); |
586 | 410k | break; |
587 | | |
588 | 337k | case scale_factor_data_usac: |
589 | 337k | pAacDecoderChannelInfo[ch]->currAliasingSymmetry = 0; |
590 | | /* Set active sfb codebook indexes to HCB_ESC to make them "active" */ |
591 | 337k | CChannel_CodebookTableInit( |
592 | 337k | pAacDecoderChannelInfo[ch]); /* equals ReadSectionData(self, |
593 | | bs) in float soft. block.c |
594 | | line: ~599 */ |
595 | | /* Note: The missing "break" is intentional here, since we need to call |
596 | | * CBlock_ReadScaleFactorData(). */ |
597 | 337k | FDK_FALLTHROUGH; |
598 | | |
599 | 747k | case scale_factor_data: |
600 | 747k | if (flags & AC_ER_RVLC) { |
601 | | /* read RVLC data from bitstream (error sens. cat. 1) */ |
602 | 176k | CRvlc_Read(pAacDecoderChannelInfo[ch], hBs); |
603 | 571k | } else { |
604 | 571k | error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs, |
605 | 571k | flags); |
606 | 571k | } |
607 | 747k | break; |
608 | | |
609 | 31.1k | case pulse: |
610 | 31.1k | if (CPulseData_Read( |
611 | 31.1k | hBs, |
612 | 31.1k | &pAacDecoderChannelInfo[ch]->pDynData->specificTo.aac.PulseData, |
613 | 31.1k | pSamplingRateInfo->ScaleFactorBands_Long, /* pulse data is only |
614 | | allowed to be |
615 | | present in long |
616 | | blocks! */ |
617 | 31.1k | (void *)&pAacDecoderChannelInfo[ch]->icsInfo, |
618 | 31.1k | frame_length) != 0) { |
619 | 34 | error = AAC_DEC_DECODE_FRAME_ERROR; |
620 | 34 | } |
621 | 31.1k | break; |
622 | 591k | case tns_data_present: |
623 | 591k | CTns_ReadDataPresentFlag( |
624 | 591k | hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData); |
625 | 591k | if (elFlags & AC_EL_LFE && |
626 | 591k | pAacDecoderChannelInfo[ch]->pDynData->TnsData.DataPresent) { |
627 | 0 | error = AAC_DEC_PARSE_ERROR; |
628 | 0 | } |
629 | 591k | break; |
630 | 747k | case tns_data: |
631 | | /* tns_data_present is checked inside CTns_Read(). */ |
632 | 747k | error = CTns_Read(hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData, |
633 | 747k | &pAacDecoderChannelInfo[ch]->icsInfo, flags); |
634 | | |
635 | 747k | break; |
636 | | |
637 | 597 | case gain_control_data: |
638 | 597 | break; |
639 | | |
640 | 31.1k | case gain_control_data_present: |
641 | 31.1k | if (FDKreadBits(hBs, 1)) { |
642 | 35 | error = AAC_DEC_UNSUPPORTED_GAIN_CONTROL_DATA; |
643 | 35 | } |
644 | 31.1k | break; |
645 | | |
646 | 280k | case tw_data: |
647 | 280k | break; |
648 | 78.5k | case common_tw: |
649 | 78.5k | break; |
650 | 78.5k | case tns_data_present_usac: |
651 | 78.5k | if (pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active) { |
652 | 40.8k | CTns_ReadDataPresentUsac( |
653 | 40.8k | hBs, &pAacDecoderChannelInfo[0]->pDynData->TnsData, |
654 | 40.8k | &pAacDecoderChannelInfo[1]->pDynData->TnsData, |
655 | 40.8k | &pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr, |
656 | 40.8k | &pAacDecoderChannelInfo[0]->icsInfo, flags, elFlags, |
657 | 40.8k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow); |
658 | 40.8k | } else { |
659 | 37.6k | pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = |
660 | 37.6k | (UCHAR)1; |
661 | 37.6k | } |
662 | 78.5k | break; |
663 | 387k | case core_mode: |
664 | 387k | decision_bit = FDKreadBits(hBs, 1); |
665 | 387k | pAacDecoderChannelInfo[ch]->data.usac.core_mode = decision_bit; |
666 | 387k | if ((ch == 1) && (pAacDecoderChannelInfo[0]->data.usac.core_mode != |
667 | 91.3k | pAacDecoderChannelInfo[1]->data.usac.core_mode)) { |
668 | | /* StereoCoreToolInfo(core_mode[ch] ) */ |
669 | 8.89k | pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; |
670 | 8.89k | pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; |
671 | 8.89k | } |
672 | 387k | break; |
673 | 78.5k | case tns_active: |
674 | 78.5k | pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = |
675 | 78.5k | FDKreadBit(hBs); |
676 | 78.5k | break; |
677 | 337k | case noise: |
678 | 337k | if (elFlags & AC_EL_USAC_NOISE) { |
679 | 14.1k | pAacDecoderChannelInfo[ch] |
680 | 14.1k | ->pDynData->specificTo.usac.fd_noise_level_and_offset = |
681 | 14.1k | FDKreadBits(hBs, 3 + 5); /* Noise level */ |
682 | 14.1k | } |
683 | 337k | break; |
684 | 49.2k | case lpd_channel_stream: |
685 | | |
686 | 49.2k | { |
687 | 49.2k | error = CLpdChannelStream_Read(/* = lpd_channel_stream() */ |
688 | 49.2k | hBs, pAacDecoderChannelInfo[ch], |
689 | 49.2k | pAacDecoderStaticChannelInfo[ch], |
690 | 49.2k | pSamplingRateInfo, flags); |
691 | 49.2k | } |
692 | | |
693 | 49.2k | pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_LPD; |
694 | 49.2k | break; |
695 | 336k | case fac_data: { |
696 | 336k | int fFacDatPresent = FDKreadBit(hBs); |
697 | | |
698 | | /* Wee need a valid fac_data[0] even if no FAC data is present (as |
699 | | * temporal buffer) */ |
700 | 336k | pAacDecoderChannelInfo[ch]->data.usac.fac_data[0] = |
701 | 336k | pAacDecoderChannelInfo[ch]->data.usac.fac_data0; |
702 | | |
703 | 336k | if (fFacDatPresent) { |
704 | 38.9k | if (elFlags & AC_EL_LFE) { |
705 | 0 | error = AAC_DEC_PARSE_ERROR; |
706 | 0 | break; |
707 | 0 | } |
708 | | /* FAC data present, this frame is FD, so the last mode had to be |
709 | | * ACELP. */ |
710 | 38.9k | if (pAacDecoderStaticChannelInfo[ch]->last_core_mode != LPD || |
711 | 38.9k | pAacDecoderStaticChannelInfo[ch]->last_lpd_mode != 0) { |
712 | 31.9k | pAacDecoderChannelInfo[ch]->data.usac.core_mode_last = LPD; |
713 | 31.9k | pAacDecoderChannelInfo[ch]->data.usac.lpd_mode_last = 0; |
714 | | /* We can't change the past! So look to the future and go ahead! */ |
715 | 31.9k | } |
716 | 38.9k | CLpd_FAC_Read(hBs, pAacDecoderChannelInfo[ch]->data.usac.fac_data[0], |
717 | 38.9k | pAacDecoderChannelInfo[ch]->data.usac.fac_data_e, |
718 | 38.9k | CLpd_FAC_getLength( |
719 | 38.9k | IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo), |
720 | 38.9k | pAacDecoderChannelInfo[ch]->granuleLength), |
721 | 38.9k | 1, 0); |
722 | 297k | } else { |
723 | 297k | if (pAacDecoderStaticChannelInfo[ch]->last_core_mode == LPD && |
724 | 297k | pAacDecoderStaticChannelInfo[ch]->last_lpd_mode == 0) { |
725 | | /* ACELP to FD transitons without FAC are possible. That is why we |
726 | | zero it out (i.e FAC will not be considered in the subsequent |
727 | | calculations */ |
728 | 13.2k | FDKmemclear(pAacDecoderChannelInfo[ch]->data.usac.fac_data0, |
729 | 13.2k | LFAC * sizeof(FIXP_DBL)); |
730 | 13.2k | } |
731 | 297k | } |
732 | 336k | } break; |
733 | 374k | case esc2_rvlc: |
734 | 374k | if (flags & AC_ER_RVLC) { |
735 | 176k | CRvlc_Decode(pAacDecoderChannelInfo[ch], |
736 | 176k | pAacDecoderStaticChannelInfo[ch], hBs); |
737 | 176k | } |
738 | 374k | break; |
739 | | |
740 | 381k | case esc1_hcr: |
741 | 381k | if (flags & AC_ER_HCR) { |
742 | 11.9k | CHcr_Read(hBs, pAacDecoderChannelInfo[ch], |
743 | 11.9k | numberOfChannels == 2 ? ID_CPE : ID_SCE); |
744 | 11.9k | } |
745 | 381k | break; |
746 | | |
747 | 409k | case spectral_data: |
748 | 409k | error = CBlock_ReadSpectralData(hBs, pAacDecoderChannelInfo[ch], |
749 | 409k | pSamplingRateInfo, flags); |
750 | 409k | if (flags & AC_ELD) { |
751 | 296k | pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_ELDFB; |
752 | 296k | } else { |
753 | 113k | if (flags & AC_HDAAC) { |
754 | 0 | pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_INTIMDCT; |
755 | 113k | } else { |
756 | 113k | pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; |
757 | 113k | } |
758 | 113k | } |
759 | 409k | break; |
760 | | |
761 | 337k | case ac_spectral_data: |
762 | 337k | error = CBlock_ReadAcSpectralData( |
763 | 337k | hBs, pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], |
764 | 337k | pSamplingRateInfo, frame_length, flags); |
765 | 337k | pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; |
766 | 337k | break; |
767 | | |
768 | 918 | case coupled_elements: { |
769 | 918 | int num_coupled_elements, c; |
770 | | |
771 | 918 | ind_sw_cce_flag = FDKreadBit(hBs); |
772 | 918 | num_coupled_elements = FDKreadBits(hBs, 3); |
773 | | |
774 | 4.80k | for (c = 0; c < (num_coupled_elements + 1); c++) { |
775 | 3.88k | int cc_target_is_cpe; |
776 | | |
777 | 3.88k | num_gain_element_lists++; |
778 | 3.88k | cc_target_is_cpe = FDKreadBit(hBs); /* cc_target_is_cpe[c] */ |
779 | 3.88k | FDKreadBits(hBs, 4); /* cc_target_tag_select[c] */ |
780 | | |
781 | 3.88k | if (cc_target_is_cpe) { |
782 | 1.16k | int cc_l, cc_r; |
783 | | |
784 | 1.16k | cc_l = FDKreadBit(hBs); /* cc_l[c] */ |
785 | 1.16k | cc_r = FDKreadBit(hBs); /* cc_r[c] */ |
786 | | |
787 | 1.16k | if (cc_l && cc_r) { |
788 | 521 | num_gain_element_lists++; |
789 | 521 | } |
790 | 1.16k | } |
791 | 3.88k | } |
792 | 918 | FDKreadBit(hBs); /* cc_domain */ |
793 | 918 | FDKreadBit(hBs); /* gain_element_sign */ |
794 | 918 | FDKreadBits(hBs, 2); /* gain_element_scale */ |
795 | 918 | } break; |
796 | | |
797 | 892 | case gain_element_lists: { |
798 | 892 | const CodeBookDescription *hcb; |
799 | 892 | UCHAR *pCodeBook; |
800 | 892 | int c; |
801 | | |
802 | 892 | hcb = &AACcodeBookDescriptionTable[BOOKSCL]; |
803 | 892 | pCodeBook = pAacDecoderChannelInfo[ch]->pDynData->aCodeBook; |
804 | | |
805 | 4.26k | for (c = 1; c < num_gain_element_lists; c++) { |
806 | 3.37k | int cge; |
807 | 3.37k | if (ind_sw_cce_flag) { |
808 | 1.20k | cge = 1; |
809 | 2.17k | } else { |
810 | 2.17k | cge = FDKreadBits(hBs, 1); /* common_gain_element_present[c] */ |
811 | 2.17k | } |
812 | 3.37k | if (cge) { |
813 | | /* Huffman */ |
814 | 1.56k | CBlock_DecodeHuffmanWord( |
815 | 1.56k | hBs, hcb); /* hcod_sf[common_gain_element[c]] 1..19 */ |
816 | 1.80k | } else { |
817 | 1.80k | int g, sfb; |
818 | 1.80k | for (g = 0; |
819 | 5.69k | g < GetWindowGroups(&pAacDecoderChannelInfo[ch]->icsInfo); |
820 | 3.88k | g++) { |
821 | 10.4k | for (sfb = 0; sfb < GetScaleFactorBandsTransmitted( |
822 | 10.4k | &pAacDecoderChannelInfo[ch]->icsInfo); |
823 | 6.51k | sfb++) { |
824 | 6.51k | if (pCodeBook[sfb] != ZERO_HCB) { |
825 | | /* Huffman */ |
826 | 5.44k | CBlock_DecodeHuffmanWord( |
827 | 5.44k | hBs, |
828 | 5.44k | hcb); /* hcod_sf[dpcm_gain_element[c][g][sfb]] 1..19 */ |
829 | 5.44k | } |
830 | 6.51k | } |
831 | 3.88k | } |
832 | 1.80k | } |
833 | 3.37k | } |
834 | 892 | } break; |
835 | | |
836 | | /* CRC handling */ |
837 | 23.6k | case adtscrc_start_reg1: |
838 | 23.6k | if (pTpDec != NULL) { |
839 | 23.6k | crcReg1 = transportDec_CrcStartReg(pTpDec, 192); |
840 | 23.6k | } |
841 | 23.6k | break; |
842 | 5.02k | case adtscrc_start_reg2: |
843 | 5.02k | if (pTpDec != NULL) { |
844 | 5.02k | crcReg2 = transportDec_CrcStartReg(pTpDec, 128); |
845 | 5.02k | } |
846 | 5.02k | break; |
847 | 23.0k | case adtscrc_end_reg1: |
848 | 23.0k | case drmcrc_end_reg: |
849 | 23.0k | if (pTpDec != NULL) { |
850 | 23.0k | transportDec_CrcEndReg(pTpDec, crcReg1); |
851 | 23.0k | crcReg1 = -1; |
852 | 23.0k | } |
853 | 23.0k | break; |
854 | 5.01k | case adtscrc_end_reg2: |
855 | 5.01k | if (crcReg1 != -1) { |
856 | 0 | error = AAC_DEC_DECODE_FRAME_ERROR; |
857 | 5.01k | } else if (pTpDec != NULL) { |
858 | 5.01k | transportDec_CrcEndReg(pTpDec, crcReg2); |
859 | 5.01k | crcReg2 = -1; |
860 | 5.01k | } |
861 | 5.01k | break; |
862 | 0 | case drmcrc_start_reg: |
863 | 0 | if (pTpDec != NULL) { |
864 | 0 | crcReg1 = transportDec_CrcStartReg(pTpDec, 0); |
865 | 0 | } |
866 | 0 | break; |
867 | | |
868 | | /* Non data cases */ |
869 | 770k | case next_channel: |
870 | 770k | ch = (ch + 1) % numberOfChannels; |
871 | 770k | break; |
872 | 550k | case link_sequence: |
873 | 550k | list = list->next[decision_bit]; |
874 | 550k | i = -1; |
875 | 550k | break; |
876 | | |
877 | 0 | default: |
878 | 0 | error = AAC_DEC_UNSUPPORTED_FORMAT; |
879 | 0 | break; |
880 | 8.81M | } |
881 | | |
882 | 8.81M | if (error != AAC_DEC_OK) { |
883 | 3.34k | goto bail; |
884 | 3.34k | } |
885 | | |
886 | 8.81M | i++; |
887 | | |
888 | 8.81M | } while (list->id[i] != end_of_sequence); |
889 | | |
890 | 1.36M | for (ch = 0; ch < numberOfChannels; ch++) { |
891 | 794k | if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_IMDCT || |
892 | 794k | pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_ELDFB) { |
893 | | /* Shows which bands are empty. */ |
894 | 745k | UCHAR *band_is_noise = |
895 | 745k | pAacDecoderChannelInfo[ch]->pDynData->band_is_noise; |
896 | 745k | FDKmemset(band_is_noise, (UCHAR)1, sizeof(UCHAR) * (8 * 16)); |
897 | | |
898 | 745k | error = CBlock_InverseQuantizeSpectralData( |
899 | 745k | pAacDecoderChannelInfo[ch], pSamplingRateInfo, band_is_noise, 1); |
900 | 745k | if (error != AAC_DEC_OK) { |
901 | 53 | return error; |
902 | 53 | } |
903 | | |
904 | 745k | if (elFlags & AC_EL_USAC_NOISE) { |
905 | 13.8k | CBlock_ApplyNoise(pAacDecoderChannelInfo[ch], pSamplingRateInfo, |
906 | 13.8k | &pAacDecoderStaticChannelInfo[ch]->nfRandomSeed, |
907 | 13.8k | band_is_noise); |
908 | | |
909 | 13.8k | } /* if (elFlags & AC_EL_USAC_NOISE) */ |
910 | 745k | } |
911 | 794k | } |
912 | | |
913 | 573k | bail: |
914 | 573k | if (crcReg1 != -1 || crcReg2 != -1) { |
915 | 0 | if (error == AAC_DEC_OK) { |
916 | 0 | error = AAC_DEC_DECODE_FRAME_ERROR; |
917 | 0 | } |
918 | 0 | if (crcReg1 != -1) { |
919 | 0 | transportDec_CrcEndReg(pTpDec, crcReg1); |
920 | 0 | } |
921 | 0 | if (crcReg2 != -1) { |
922 | 0 | transportDec_CrcEndReg(pTpDec, crcReg2); |
923 | 0 | } |
924 | 0 | } |
925 | 573k | return error; |
926 | 570k | } |