/src/aac/libAACdec/src/channelinfo.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 - 2018 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: individual channel stream info |
100 | | |
101 | | *******************************************************************************/ |
102 | | |
103 | | #include "channelinfo.h" |
104 | | #include "aac_rom.h" |
105 | | #include "aac_ram.h" |
106 | | #include "FDK_bitstream.h" |
107 | | |
108 | | AAC_DECODER_ERROR IcsReadMaxSfb(HANDLE_FDK_BITSTREAM bs, CIcsInfo *pIcsInfo, |
109 | 0 | const SamplingRateInfo *pSamplingRateInfo) { |
110 | 0 | AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; |
111 | 0 | int nbits; |
112 | |
|
113 | 0 | if (IsLongBlock(pIcsInfo)) { |
114 | 0 | nbits = 6; |
115 | 0 | pIcsInfo->TotalSfBands = pSamplingRateInfo->NumberOfScaleFactorBands_Long; |
116 | 0 | } else { |
117 | 0 | nbits = 4; |
118 | 0 | pIcsInfo->TotalSfBands = pSamplingRateInfo->NumberOfScaleFactorBands_Short; |
119 | 0 | } |
120 | 0 | pIcsInfo->MaxSfBands = (UCHAR)FDKreadBits(bs, nbits); |
121 | |
|
122 | 0 | if (pIcsInfo->MaxSfBands > pIcsInfo->TotalSfBands) { |
123 | 0 | ErrorStatus = AAC_DEC_PARSE_ERROR; |
124 | 0 | } |
125 | |
|
126 | 0 | return ErrorStatus; |
127 | 0 | } |
128 | | |
129 | | AAC_DECODER_ERROR IcsRead(HANDLE_FDK_BITSTREAM bs, CIcsInfo *pIcsInfo, |
130 | | const SamplingRateInfo *pSamplingRateInfo, |
131 | 0 | const UINT flags) { |
132 | 0 | AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; |
133 | |
|
134 | 0 | pIcsInfo->Valid = 0; |
135 | |
|
136 | 0 | if (flags & AC_ELD) { |
137 | 0 | pIcsInfo->WindowSequence = BLOCK_LONG; |
138 | 0 | pIcsInfo->WindowShape = 0; |
139 | 0 | } else { |
140 | 0 | if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { |
141 | 0 | FDKreadBits(bs, 1); |
142 | 0 | } |
143 | 0 | pIcsInfo->WindowSequence = (BLOCK_TYPE)FDKreadBits(bs, 2); |
144 | 0 | pIcsInfo->WindowShape = (UCHAR)FDKreadBits(bs, 1); |
145 | 0 | if (flags & AC_LD) { |
146 | 0 | if (pIcsInfo->WindowShape) { |
147 | 0 | pIcsInfo->WindowShape = 2; /* select low overlap instead of KBD */ |
148 | 0 | } |
149 | 0 | } |
150 | 0 | } |
151 | | |
152 | | /* Sanity check */ |
153 | 0 | if ((flags & (AC_ELD | AC_LD)) && pIcsInfo->WindowSequence != BLOCK_LONG) { |
154 | 0 | pIcsInfo->WindowSequence = BLOCK_LONG; |
155 | 0 | ErrorStatus = AAC_DEC_PARSE_ERROR; |
156 | 0 | goto bail; |
157 | 0 | } |
158 | | |
159 | 0 | ErrorStatus = IcsReadMaxSfb(bs, pIcsInfo, pSamplingRateInfo); |
160 | 0 | if (ErrorStatus != AAC_DEC_OK) { |
161 | 0 | goto bail; |
162 | 0 | } |
163 | | |
164 | 0 | if (IsLongBlock(pIcsInfo)) { |
165 | 0 | if (!(flags & (AC_ELD | AC_SCALABLE | AC_BSAC | AC_USAC | AC_RSVD50 | |
166 | 0 | AC_RSV603DA))) /* If not ELD nor Scalable nor BSAC nor USAC |
167 | | syntax then ... */ |
168 | 0 | { |
169 | 0 | if ((UCHAR)FDKreadBits(bs, 1) != 0) /* UCHAR PredictorDataPresent */ |
170 | 0 | { |
171 | 0 | ErrorStatus = AAC_DEC_UNSUPPORTED_PREDICTION; |
172 | 0 | goto bail; |
173 | 0 | } |
174 | 0 | } |
175 | | |
176 | 0 | pIcsInfo->WindowGroups = 1; |
177 | 0 | pIcsInfo->WindowGroupLength[0] = 1; |
178 | 0 | } else { |
179 | 0 | INT i; |
180 | 0 | UINT mask; |
181 | |
|
182 | 0 | pIcsInfo->ScaleFactorGrouping = (UCHAR)FDKreadBits(bs, 7); |
183 | |
|
184 | 0 | pIcsInfo->WindowGroups = 0; |
185 | |
|
186 | 0 | for (i = 0; i < (8 - 1); i++) { |
187 | 0 | mask = 1 << (6 - i); |
188 | 0 | pIcsInfo->WindowGroupLength[i] = 1; |
189 | |
|
190 | 0 | if (pIcsInfo->ScaleFactorGrouping & mask) { |
191 | 0 | pIcsInfo->WindowGroupLength[pIcsInfo->WindowGroups]++; |
192 | 0 | } else { |
193 | 0 | pIcsInfo->WindowGroups++; |
194 | 0 | } |
195 | 0 | } |
196 | | |
197 | | /* loop runs to i < 7 only */ |
198 | 0 | pIcsInfo->WindowGroupLength[8 - 1] = 1; |
199 | 0 | pIcsInfo->WindowGroups++; |
200 | 0 | } |
201 | | |
202 | 0 | bail: |
203 | 0 | if (ErrorStatus == AAC_DEC_OK) pIcsInfo->Valid = 1; |
204 | |
|
205 | 0 | return ErrorStatus; |
206 | 0 | } |
207 | | |
208 | | /* |
209 | | interleave codebooks the following way |
210 | | |
211 | | 9 (84w) | 1 (51w) |
212 | | 10 (82w) | 2 (39w) |
213 | | SCL (65w) | 4 (38w) |
214 | | 3 (39w) | 5 (41w) |
215 | | | 6 (40w) |
216 | | | 7 (31w) |
217 | | | 8 (31w) |
218 | | (270w) (271w) |
219 | | */ |
220 | | |
221 | | /* |
222 | | Table entries are sorted as following: |
223 | | | num_swb_long_window | sfbands_long | num_swb_short_window | sfbands_short | |
224 | | */ |
225 | | AAC_DECODER_ERROR getSamplingRateInfo(SamplingRateInfo *t, UINT samplesPerFrame, |
226 | | UINT samplingRateIndex, |
227 | 0 | UINT samplingRate) { |
228 | 0 | int index = 0; |
229 | | |
230 | | /* Search closest samplerate according to ISO/IEC 13818-7:2005(E) 8.2.4 (Table |
231 | | * 38): */ |
232 | 0 | if ((samplingRateIndex >= 15) || (samplesPerFrame == 768)) { |
233 | 0 | const UINT borders[] = {(UINT)-1, 92017, 75132, 55426, 46009, 37566, |
234 | 0 | 27713, 23004, 18783, 13856, 11502, 9391}; |
235 | 0 | UINT i, samplingRateSearch = samplingRate; |
236 | |
|
237 | 0 | if (samplesPerFrame == 768) { |
238 | 0 | samplingRateSearch = (samplingRate * 4) / 3; |
239 | 0 | } |
240 | |
|
241 | 0 | for (i = 0; i < 11; i++) { |
242 | 0 | if (borders[i] > samplingRateSearch && |
243 | 0 | samplingRateSearch >= borders[i + 1]) { |
244 | 0 | break; |
245 | 0 | } |
246 | 0 | } |
247 | 0 | samplingRateIndex = i; |
248 | 0 | } |
249 | |
|
250 | 0 | t->samplingRateIndex = samplingRateIndex; |
251 | 0 | t->samplingRate = samplingRate; |
252 | |
|
253 | 0 | switch (samplesPerFrame) { |
254 | 0 | case 1024: |
255 | 0 | index = 0; |
256 | 0 | break; |
257 | 0 | case 960: |
258 | 0 | index = 1; |
259 | 0 | break; |
260 | 0 | case 768: |
261 | 0 | index = 2; |
262 | 0 | break; |
263 | 0 | case 512: |
264 | 0 | index = 3; |
265 | 0 | break; |
266 | 0 | case 480: |
267 | 0 | index = 4; |
268 | 0 | break; |
269 | | |
270 | 0 | default: |
271 | 0 | return AAC_DEC_UNSUPPORTED_FORMAT; |
272 | 0 | } |
273 | | |
274 | 0 | t->ScaleFactorBands_Long = |
275 | 0 | sfbOffsetTables[index][samplingRateIndex].sfbOffsetLong; |
276 | 0 | t->ScaleFactorBands_Short = |
277 | 0 | sfbOffsetTables[index][samplingRateIndex].sfbOffsetShort; |
278 | 0 | t->NumberOfScaleFactorBands_Long = |
279 | 0 | sfbOffsetTables[index][samplingRateIndex].numberOfSfbLong; |
280 | 0 | t->NumberOfScaleFactorBands_Short = |
281 | 0 | sfbOffsetTables[index][samplingRateIndex].numberOfSfbShort; |
282 | |
|
283 | 0 | if (t->ScaleFactorBands_Long == NULL || |
284 | 0 | t->NumberOfScaleFactorBands_Long == 0) { |
285 | 0 | t->samplingRate = 0; |
286 | 0 | return AAC_DEC_UNSUPPORTED_FORMAT; |
287 | 0 | } |
288 | | |
289 | 0 | FDK_ASSERT((UINT)t->ScaleFactorBands_Long[t->NumberOfScaleFactorBands_Long] == |
290 | 0 | samplesPerFrame); |
291 | 0 | FDK_ASSERT( |
292 | 0 | t->ScaleFactorBands_Short == NULL || |
293 | 0 | (UINT)t->ScaleFactorBands_Short[t->NumberOfScaleFactorBands_Short] * 8 == |
294 | 0 | samplesPerFrame); |
295 | | |
296 | 0 | return AAC_DEC_OK; |
297 | 0 | } |