/src/aac/libSBRdec/src/sbrdec_drc.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 | | /**************************** SBR decoder library ****************************** |
96 | | |
97 | | Author(s): Christian Griebel |
98 | | |
99 | | Description: Dynamic range control (DRC) decoder tool for SBR |
100 | | |
101 | | *******************************************************************************/ |
102 | | |
103 | | #include "sbrdec_drc.h" |
104 | | |
105 | | /* DRC - Offset table for QMF interpolation. Shifted by one index position. |
106 | | The table defines the (short) window borders rounded to the nearest QMF |
107 | | timeslot. It has the size 16 because it is accessed with the |
108 | | drcInterpolationScheme that is read from the bitstream with 4 bit. */ |
109 | | static const UCHAR winBorderToColMappingTab[2][16] = { |
110 | | /*-1, 0, 1, 2, 3, 4, 5, 6, 7, 8 */ |
111 | | {0, 0, 4, 8, 12, 16, 20, 24, 28, 32, 32, 32, 32, 32, 32, |
112 | | 32}, /* 1024 framing */ |
113 | | {0, 0, 4, 8, 11, 15, 19, 23, 26, 30, 30, 30, 30, 30, 30, |
114 | | 30} /* 960 framing */ |
115 | | }; |
116 | | |
117 | | /*! |
118 | | \brief Initialize DRC QMF factors |
119 | | |
120 | | \hDrcData Handle to DRC channel data. |
121 | | |
122 | | \return none |
123 | | */ |
124 | 662k | void sbrDecoder_drcInitChannel(HANDLE_SBR_DRC_CHANNEL hDrcData) { |
125 | 662k | int band; |
126 | | |
127 | 662k | if (hDrcData == NULL) { |
128 | 0 | return; |
129 | 0 | } |
130 | | |
131 | 43.0M | for (band = 0; band < (64); band++) { |
132 | 42.4M | hDrcData->prevFact_mag[band] = FL2FXCONST_DBL(0.5f); |
133 | 42.4M | } |
134 | | |
135 | 11.2M | for (band = 0; band < SBRDEC_MAX_DRC_BANDS; band++) { |
136 | 10.6M | hDrcData->currFact_mag[band] = FL2FXCONST_DBL(0.5f); |
137 | 10.6M | hDrcData->nextFact_mag[band] = FL2FXCONST_DBL(0.5f); |
138 | 10.6M | } |
139 | | |
140 | 662k | hDrcData->prevFact_exp = 1; |
141 | 662k | hDrcData->currFact_exp = 1; |
142 | 662k | hDrcData->nextFact_exp = 1; |
143 | | |
144 | 662k | hDrcData->numBandsCurr = 1; |
145 | 662k | hDrcData->numBandsNext = 1; |
146 | | |
147 | 662k | hDrcData->winSequenceCurr = 0; |
148 | 662k | hDrcData->winSequenceNext = 0; |
149 | | |
150 | 662k | hDrcData->drcInterpolationSchemeCurr = 0; |
151 | 662k | hDrcData->drcInterpolationSchemeNext = 0; |
152 | | |
153 | 662k | hDrcData->enable = 0; |
154 | 662k | } |
155 | | |
156 | | /*! |
157 | | \brief Swap DRC QMF scaling factors after they have been applied. |
158 | | |
159 | | \hDrcData Handle to DRC channel data. |
160 | | |
161 | | \return none |
162 | | */ |
163 | 689k | void sbrDecoder_drcUpdateChannel(HANDLE_SBR_DRC_CHANNEL hDrcData) { |
164 | 689k | if (hDrcData == NULL) { |
165 | 0 | return; |
166 | 0 | } |
167 | 689k | if (hDrcData->enable != 1) { |
168 | 644k | return; |
169 | 644k | } |
170 | | |
171 | | /* swap previous data */ |
172 | 44.8k | FDKmemcpy(hDrcData->currFact_mag, hDrcData->nextFact_mag, |
173 | 44.8k | SBRDEC_MAX_DRC_BANDS * sizeof(FIXP_DBL)); |
174 | | |
175 | 44.8k | hDrcData->currFact_exp = hDrcData->nextFact_exp; |
176 | | |
177 | 44.8k | hDrcData->numBandsCurr = hDrcData->numBandsNext; |
178 | | |
179 | 44.8k | FDKmemcpy(hDrcData->bandTopCurr, hDrcData->bandTopNext, |
180 | 44.8k | SBRDEC_MAX_DRC_BANDS * sizeof(USHORT)); |
181 | | |
182 | 44.8k | hDrcData->drcInterpolationSchemeCurr = hDrcData->drcInterpolationSchemeNext; |
183 | | |
184 | 44.8k | hDrcData->winSequenceCurr = hDrcData->winSequenceNext; |
185 | 44.8k | } |
186 | | |
187 | | /*! |
188 | | \brief Apply DRC factors slot based. |
189 | | |
190 | | \hDrcData Handle to DRC channel data. |
191 | | \qmfRealSlot Pointer to real valued QMF data of one time slot. |
192 | | \qmfImagSlot Pointer to the imaginary QMF data of one time slot. |
193 | | \col Number of the time slot. |
194 | | \numQmfSubSamples Total number of time slots for one frame. |
195 | | \scaleFactor Pointer to the out scale factor of the time slot. |
196 | | |
197 | | \return None. |
198 | | */ |
199 | | void sbrDecoder_drcApplySlot(HANDLE_SBR_DRC_CHANNEL hDrcData, |
200 | | FIXP_DBL *qmfRealSlot, FIXP_DBL *qmfImagSlot, |
201 | 1.60M | int col, int numQmfSubSamples, int maxShift) { |
202 | 1.60M | const UCHAR *winBorderToColMap; |
203 | | |
204 | 1.60M | int band, bottomMdct, topMdct, bin, useLP; |
205 | 1.60M | int indx = numQmfSubSamples - (numQmfSubSamples >> 1) - 10; /* l_border */ |
206 | 1.60M | int frameLenFlag = (numQmfSubSamples == 30) ? 1 : 0; |
207 | 1.60M | int frameSize = (frameLenFlag == 1) ? 960 : 1024; |
208 | | |
209 | 1.60M | const FIXP_DBL *fact_mag = NULL; |
210 | 1.60M | INT fact_exp = 0; |
211 | 1.60M | UINT numBands = 0; |
212 | 1.60M | USHORT *bandTop = NULL; |
213 | 1.60M | int shortDrc = 0; |
214 | | |
215 | 1.60M | FIXP_DBL alphaValue = FL2FXCONST_DBL(0.0f); |
216 | | |
217 | 1.60M | if (hDrcData == NULL) { |
218 | 0 | return; |
219 | 0 | } |
220 | 1.60M | if (hDrcData->enable != 1) { |
221 | 165k | return; |
222 | 165k | } |
223 | | |
224 | 1.44M | winBorderToColMap = winBorderToColMappingTab[frameLenFlag]; |
225 | | |
226 | 1.44M | useLP = (qmfImagSlot == NULL) ? 1 : 0; |
227 | | |
228 | 1.44M | col += indx; |
229 | 1.44M | bottomMdct = 0; |
230 | | |
231 | | /* get respective data and calc interpolation factor */ |
232 | 1.44M | if (col < (numQmfSubSamples >> 1)) { /* first half of current frame */ |
233 | 460k | if (hDrcData->winSequenceCurr != 2) { /* long window */ |
234 | 96.9k | int j = col + (numQmfSubSamples >> 1); |
235 | | |
236 | 96.9k | if (j < winBorderToColMap[15]) { |
237 | 96.9k | if (hDrcData->drcInterpolationSchemeCurr == 0) { |
238 | 76.2k | INT k = (frameLenFlag) ? 0x4444445 : 0x4000000; |
239 | | |
240 | 76.2k | alphaValue = (FIXP_DBL)(j * k); |
241 | 76.2k | } else { |
242 | 20.6k | if (j >= |
243 | 20.6k | (int)winBorderToColMap[hDrcData->drcInterpolationSchemeCurr]) { |
244 | 10.3k | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
245 | 10.3k | } |
246 | 20.6k | } |
247 | 96.9k | } else { |
248 | 0 | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
249 | 0 | } |
250 | 363k | } else { /* short windows */ |
251 | 363k | shortDrc = 1; |
252 | 363k | } |
253 | | |
254 | 460k | fact_mag = hDrcData->currFact_mag; |
255 | 460k | fact_exp = hDrcData->currFact_exp; |
256 | 460k | numBands = hDrcData->numBandsCurr; |
257 | 460k | bandTop = hDrcData->bandTopCurr; |
258 | 982k | } else if (col < numQmfSubSamples) { /* second half of current frame */ |
259 | 721k | if (hDrcData->winSequenceNext != 2) { /* next: long window */ |
260 | 115k | int j = col - (numQmfSubSamples >> 1); |
261 | | |
262 | 115k | if (j < winBorderToColMap[15]) { |
263 | 115k | if (hDrcData->drcInterpolationSchemeNext == 0) { |
264 | 76.3k | INT k = (frameLenFlag) ? 0x4444445 : 0x4000000; |
265 | | |
266 | 76.3k | alphaValue = (FIXP_DBL)(j * k); |
267 | 76.3k | } else { |
268 | 39.1k | if (j >= |
269 | 39.1k | (int)winBorderToColMap[hDrcData->drcInterpolationSchemeNext]) { |
270 | 7.85k | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
271 | 7.85k | } |
272 | 39.1k | } |
273 | 115k | } else { |
274 | 0 | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
275 | 0 | } |
276 | | |
277 | 115k | fact_mag = hDrcData->nextFact_mag; |
278 | 115k | fact_exp = hDrcData->nextFact_exp; |
279 | 115k | numBands = hDrcData->numBandsNext; |
280 | 115k | bandTop = hDrcData->bandTopNext; |
281 | 605k | } else { /* next: short windows */ |
282 | 605k | if (hDrcData->winSequenceCurr != 2) { /* current: long window */ |
283 | 91.6k | alphaValue = (FIXP_DBL)0; |
284 | | |
285 | 91.6k | fact_mag = hDrcData->nextFact_mag; |
286 | 91.6k | fact_exp = hDrcData->nextFact_exp; |
287 | 91.6k | numBands = hDrcData->numBandsNext; |
288 | 91.6k | bandTop = hDrcData->bandTopNext; |
289 | 513k | } else { /* current: short windows */ |
290 | 513k | shortDrc = 1; |
291 | | |
292 | 513k | fact_mag = hDrcData->currFact_mag; |
293 | 513k | fact_exp = hDrcData->currFact_exp; |
294 | 513k | numBands = hDrcData->numBandsCurr; |
295 | 513k | bandTop = hDrcData->bandTopCurr; |
296 | 513k | } |
297 | 605k | } |
298 | 721k | } else { /* first half of next frame */ |
299 | 260k | if (hDrcData->winSequenceNext != 2) { /* long window */ |
300 | 40.3k | int j = col - (numQmfSubSamples >> 1); |
301 | | |
302 | 40.3k | if (j < winBorderToColMap[15]) { |
303 | 40.3k | if (hDrcData->drcInterpolationSchemeNext == 0) { |
304 | 27.1k | INT k = (frameLenFlag) ? 0x4444445 : 0x4000000; |
305 | | |
306 | 27.1k | alphaValue = (FIXP_DBL)(j * k); |
307 | 27.1k | } else { |
308 | 13.2k | if (j >= |
309 | 13.2k | (int)winBorderToColMap[hDrcData->drcInterpolationSchemeNext]) { |
310 | 5.29k | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
311 | 5.29k | } |
312 | 13.2k | } |
313 | 40.3k | } else { |
314 | 0 | alphaValue = (FIXP_DBL)MAXVAL_DBL; |
315 | 0 | } |
316 | 220k | } else { /* short windows */ |
317 | 220k | shortDrc = 1; |
318 | 220k | } |
319 | | |
320 | 260k | fact_mag = hDrcData->nextFact_mag; |
321 | 260k | fact_exp = hDrcData->nextFact_exp; |
322 | 260k | numBands = hDrcData->numBandsNext; |
323 | 260k | bandTop = hDrcData->bandTopNext; |
324 | | |
325 | 260k | col -= numQmfSubSamples; |
326 | 260k | } |
327 | | |
328 | | /* process bands */ |
329 | 6.24M | for (band = 0; band < (int)numBands; band++) { |
330 | 4.80M | int bottomQmf, topQmf; |
331 | | |
332 | 4.80M | FIXP_DBL drcFact_mag = (FIXP_DBL)MAXVAL_DBL; |
333 | | |
334 | 4.80M | topMdct = (bandTop[band] + 1) << 2; |
335 | | |
336 | 4.80M | if (!shortDrc) { /* long window */ |
337 | 1.25M | if (frameLenFlag) { |
338 | | /* 960 framing */ |
339 | 708k | bottomQmf = fMultIfloor((FIXP_DBL)0x4444445, bottomMdct); |
340 | 708k | topQmf = fMultIfloor((FIXP_DBL)0x4444445, topMdct); |
341 | | |
342 | 708k | topMdct = 30 * topQmf; |
343 | 708k | } else { |
344 | | /* 1024 framing */ |
345 | 542k | topMdct &= ~0x1f; |
346 | | |
347 | 542k | bottomQmf = bottomMdct >> 5; |
348 | 542k | topQmf = topMdct >> 5; |
349 | 542k | } |
350 | | |
351 | 1.25M | if (band == ((int)numBands - 1)) { |
352 | 344k | topQmf = (64); |
353 | 344k | } |
354 | | |
355 | 26.4M | for (bin = bottomQmf; bin < topQmf; bin++) { |
356 | 25.2M | FIXP_DBL drcFact1_mag = hDrcData->prevFact_mag[bin]; |
357 | 25.2M | FIXP_DBL drcFact2_mag = fact_mag[band]; |
358 | | |
359 | | /* normalize scale factors */ |
360 | 25.2M | if (hDrcData->prevFact_exp < maxShift) { |
361 | 9.49M | drcFact1_mag >>= maxShift - hDrcData->prevFact_exp; |
362 | 9.49M | } |
363 | 25.2M | if (fact_exp < maxShift) { |
364 | 3.62M | drcFact2_mag >>= maxShift - fact_exp; |
365 | 3.62M | } |
366 | | |
367 | | /* interpolate */ |
368 | 25.2M | if (alphaValue == (FIXP_DBL)0) { |
369 | 11.6M | drcFact_mag = drcFact1_mag; |
370 | 13.5M | } else if (alphaValue == (FIXP_DBL)MAXVAL_DBL) { |
371 | 2.19M | drcFact_mag = drcFact2_mag; |
372 | 11.4M | } else { |
373 | 11.4M | drcFact_mag = |
374 | 11.4M | fMult(alphaValue, drcFact2_mag) + |
375 | 11.4M | fMult(((FIXP_DBL)MAXVAL_DBL - alphaValue), drcFact1_mag); |
376 | 11.4M | } |
377 | | |
378 | | /* apply scaling */ |
379 | 25.2M | qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag); |
380 | 25.2M | if (!useLP) { |
381 | 7.58M | qmfImagSlot[bin] = fMult(qmfImagSlot[bin], drcFact_mag); |
382 | 7.58M | } |
383 | | |
384 | | /* save previous factors */ |
385 | 25.2M | if (col == (numQmfSubSamples >> 1) - 1) { |
386 | 676k | hDrcData->prevFact_mag[bin] = fact_mag[band]; |
387 | 676k | } |
388 | 25.2M | } |
389 | 3.54M | } else { /* short windows */ |
390 | 3.54M | unsigned startWinIdx, stopWinIdx; |
391 | 3.54M | int startCol, stopCol; |
392 | 3.54M | FIXP_DBL invFrameSizeDiv8 = |
393 | 3.54M | (frameLenFlag) ? (FIXP_DBL)0x1111112 : (FIXP_DBL)0x1000000; |
394 | | |
395 | | /* limit top at the frame borders */ |
396 | 3.54M | if (topMdct < 0) { |
397 | 0 | topMdct = 0; |
398 | 0 | } |
399 | 3.54M | if (topMdct >= frameSize) { |
400 | 475k | topMdct = frameSize - 1; |
401 | 475k | } |
402 | | |
403 | 3.54M | if (frameLenFlag) { |
404 | | /* 960 framing */ |
405 | 978k | topMdct = fMultIfloor((FIXP_DBL)0x78000000, |
406 | 978k | fMultIfloor((FIXP_DBL)0x22222223, topMdct) << 2); |
407 | | |
408 | 978k | startWinIdx = fMultIfloor(invFrameSizeDiv8, bottomMdct) + |
409 | 978k | 1; /* winBorderToColMap table has offset of 1 */ |
410 | 978k | stopWinIdx = fMultIceil(invFrameSizeDiv8 - (FIXP_DBL)1, topMdct) + 1; |
411 | 2.57M | } else { |
412 | | /* 1024 framing */ |
413 | 2.57M | topMdct &= ~0x03; |
414 | | |
415 | 2.57M | startWinIdx = fMultIfloor(invFrameSizeDiv8, bottomMdct) + 1; |
416 | 2.57M | stopWinIdx = fMultIceil(invFrameSizeDiv8, topMdct) + 1; |
417 | 2.57M | } |
418 | | |
419 | | /* startCol is truncated to the nearest corresponding start subsample in |
420 | | the QMF of the short window bottom is present in:*/ |
421 | 3.54M | startCol = (int)winBorderToColMap[startWinIdx]; |
422 | | |
423 | | /* stopCol is rounded upwards to the nearest corresponding stop subsample |
424 | | in the QMF of the short window top is present in. */ |
425 | 3.54M | stopCol = (int)winBorderToColMap[stopWinIdx]; |
426 | | |
427 | 3.54M | bottomQmf = fMultIfloor(invFrameSizeDiv8, |
428 | 3.54M | ((bottomMdct % (numQmfSubSamples << 2)) << 5)); |
429 | 3.54M | topQmf = fMultIfloor(invFrameSizeDiv8, |
430 | 3.54M | ((topMdct % (numQmfSubSamples << 2)) << 5)); |
431 | | |
432 | | /* extend last band */ |
433 | 3.54M | if (band == ((int)numBands - 1)) { |
434 | 1.09M | topQmf = (64); |
435 | 1.09M | stopCol = numQmfSubSamples; |
436 | 1.09M | stopWinIdx = 10; |
437 | 1.09M | } |
438 | | |
439 | 3.54M | if (topQmf == 0) { |
440 | 139k | if (frameLenFlag) { |
441 | 136k | FIXP_DBL rem = fMult(invFrameSizeDiv8, |
442 | 136k | (FIXP_DBL)(topMdct << (DFRACT_BITS - 12))); |
443 | 136k | if ((LONG)rem & (LONG)0x1F) { |
444 | 131k | stopWinIdx -= 1; |
445 | 131k | stopCol = (int)winBorderToColMap[stopWinIdx]; |
446 | 131k | } |
447 | 136k | } |
448 | 139k | topQmf = (64); |
449 | 139k | } |
450 | | |
451 | | /* save previous factors */ |
452 | 3.54M | if (stopCol == numQmfSubSamples) { |
453 | 1.10M | int tmpBottom = bottomQmf; |
454 | | |
455 | 1.10M | if ((int)winBorderToColMap[8] > startCol) { |
456 | 1.10M | tmpBottom = 0; /* band starts in previous short window */ |
457 | 1.10M | } |
458 | | |
459 | 71.5M | for (bin = tmpBottom; bin < topQmf; bin++) { |
460 | 70.4M | hDrcData->prevFact_mag[bin] = fact_mag[band]; |
461 | 70.4M | } |
462 | 1.10M | } |
463 | | |
464 | | /* apply */ |
465 | 3.54M | if ((col >= startCol) && (col < stopCol)) { |
466 | 1.47M | if (col >= (int)winBorderToColMap[startWinIdx + 1]) { |
467 | 1.08M | bottomQmf = 0; /* band starts in previous short window */ |
468 | 1.08M | } |
469 | 1.47M | if (col < (int)winBorderToColMap[stopWinIdx - 1]) { |
470 | 1.24M | topQmf = (64); /* band ends in next short window */ |
471 | 1.24M | } |
472 | | |
473 | 1.47M | drcFact_mag = fact_mag[band]; |
474 | | |
475 | | /* normalize scale factor */ |
476 | 1.47M | if (fact_exp < maxShift) { |
477 | 86.6k | drcFact_mag >>= maxShift - fact_exp; |
478 | 86.6k | } |
479 | | |
480 | | /* apply scaling */ |
481 | 81.4M | for (bin = bottomQmf; bin < topQmf; bin++) { |
482 | 79.9M | qmfRealSlot[bin] = fMult(qmfRealSlot[bin], drcFact_mag); |
483 | 79.9M | if (!useLP) { |
484 | 749k | qmfImagSlot[bin] = fMult(qmfImagSlot[bin], drcFact_mag); |
485 | 749k | } |
486 | 79.9M | } |
487 | 1.47M | } |
488 | 3.54M | } |
489 | | |
490 | 4.80M | bottomMdct = topMdct; |
491 | 4.80M | } /* end of bands loop */ |
492 | | |
493 | 1.44M | if (col == (numQmfSubSamples >> 1) - 1) { |
494 | 46.1k | hDrcData->prevFact_exp = fact_exp; |
495 | 46.1k | } |
496 | 1.44M | } |
497 | | |
498 | | /*! |
499 | | \brief Apply DRC factors frame based. |
500 | | |
501 | | \hDrcData Handle to DRC channel data. |
502 | | \qmfRealSlot Pointer to real valued QMF data of the whole frame. |
503 | | \qmfImagSlot Pointer to the imaginary QMF data of the whole frame. |
504 | | \numQmfSubSamples Total number of time slots for one frame. |
505 | | \scaleFactor Pointer to the out scale factor of the frame. |
506 | | |
507 | | \return None. |
508 | | */ |
509 | | void sbrDecoder_drcApply(HANDLE_SBR_DRC_CHANNEL hDrcData, |
510 | | FIXP_DBL **QmfBufferReal, FIXP_DBL **QmfBufferImag, |
511 | 542k | int numQmfSubSamples, int *scaleFactor) { |
512 | 542k | int col; |
513 | 542k | int maxShift = 0; |
514 | | |
515 | 542k | if (hDrcData == NULL) { |
516 | 0 | return; |
517 | 0 | } |
518 | 542k | if (hDrcData->enable == 0) { |
519 | 498k | return; /* Avoid changing the scaleFactor even though the processing is |
520 | | disabled. */ |
521 | 498k | } |
522 | | |
523 | | /* get max scale factor */ |
524 | 43.6k | if (hDrcData->prevFact_exp > maxShift) { |
525 | 43.2k | maxShift = hDrcData->prevFact_exp; |
526 | 43.2k | } |
527 | 43.6k | if (hDrcData->currFact_exp > maxShift) { |
528 | 3.46k | maxShift = hDrcData->currFact_exp; |
529 | 3.46k | } |
530 | 43.6k | if (hDrcData->nextFact_exp > maxShift) { |
531 | 4.39k | maxShift = hDrcData->nextFact_exp; |
532 | 4.39k | } |
533 | | |
534 | 1.41M | for (col = 0; col < numQmfSubSamples; col++) { |
535 | 1.36M | FIXP_DBL *qmfSlotReal = QmfBufferReal[col]; |
536 | 1.36M | FIXP_DBL *qmfSlotImag = (QmfBufferImag == NULL) ? NULL : QmfBufferImag[col]; |
537 | | |
538 | 1.36M | sbrDecoder_drcApplySlot(hDrcData, qmfSlotReal, qmfSlotImag, col, |
539 | 1.36M | numQmfSubSamples, maxShift); |
540 | 1.36M | } |
541 | | |
542 | 43.6k | *scaleFactor += maxShift; |
543 | 43.6k | } |