2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
84 /******************************** MPEG Audio Encoder **************************
86 Initial author: M.Werner
87 contents/description: Psychoaccoustic configuration
89 ******************************************************************************/
91 #include "psy_configuration.h"
93 #include "aacEnc_rom.h"
95 #include "genericStds.h"
97 #include "FDK_trigFcts.h"
101 const SFB_PARAM_LONG
*paramLong
;
102 const SFB_PARAM_SHORT
*paramShort
;
106 static const SFB_INFO_TAB sfbInfoTab
[] = {
107 {8000, &p_FDKaacEnc_8000_long_1024
, &p_FDKaacEnc_8000_short_128
},
108 {11025, &p_FDKaacEnc_11025_long_1024
, &p_FDKaacEnc_11025_short_128
},
109 {12000, &p_FDKaacEnc_12000_long_1024
, &p_FDKaacEnc_12000_short_128
},
110 {16000, &p_FDKaacEnc_16000_long_1024
, &p_FDKaacEnc_16000_short_128
},
111 {22050, &p_FDKaacEnc_22050_long_1024
, &p_FDKaacEnc_22050_short_128
},
112 {24000, &p_FDKaacEnc_24000_long_1024
, &p_FDKaacEnc_24000_short_128
},
113 {32000, &p_FDKaacEnc_32000_long_1024
, &p_FDKaacEnc_32000_short_128
},
114 {44100, &p_FDKaacEnc_44100_long_1024
, &p_FDKaacEnc_44100_short_128
},
115 {48000, &p_FDKaacEnc_48000_long_1024
, &p_FDKaacEnc_48000_short_128
},
116 {64000, &p_FDKaacEnc_64000_long_1024
, &p_FDKaacEnc_64000_short_128
},
117 {88200, &p_FDKaacEnc_88200_long_1024
, &p_FDKaacEnc_88200_short_128
},
118 {96000, &p_FDKaacEnc_96000_long_1024
, &p_FDKaacEnc_96000_short_128
}
122 /* 22050 and 24000 Hz */
123 static const SFB_PARAM_LONG p_22050_long_512
= {
125 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
126 4, 8, 8, 8, 12, 12, 12, 16, 20, 24,
127 28, 32, 32, 32, 32, 32, 32, 32, 32, 32,
132 static const SFB_PARAM_LONG p_32000_long_512
= {
134 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
135 4, 4, 4, 4, 8, 8, 8, 8, 8, 12,
136 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
137 32, 32, 32, 32, 32, 32, 32}
141 static const SFB_PARAM_LONG p_44100_long_512
= {
143 {4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
144 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
145 12, 12, 12, 12, 16, 20, 24, 28, 32, 32,
146 32, 32, 32, 32, 32, 52}
149 static const SFB_INFO_TAB sfbInfoTabLD512
[] = {
150 { 8000, &p_22050_long_512
, NULL
},
151 {11025, &p_22050_long_512
, NULL
},
152 {12000, &p_22050_long_512
, NULL
},
153 {16000, &p_22050_long_512
, NULL
},
154 {22050, &p_22050_long_512
, NULL
},
155 {24000, &p_22050_long_512
, NULL
},
156 {32000, &p_32000_long_512
, NULL
},
157 {44100, &p_44100_long_512
, NULL
},
158 {48000, &p_44100_long_512
, NULL
},
159 {64000, &p_44100_long_512
, NULL
},
160 {88200, &p_44100_long_512
, NULL
},
161 {96000, &p_44100_long_512
, NULL
},
166 /* 22050 and 24000 Hz */
167 static const SFB_PARAM_LONG p_22050_long_480
= {
169 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
170 4, 8, 8, 8, 12, 12, 12, 16, 20, 24,
171 28, 32, 32, 32, 32, 32, 32, 32, 32, 32}
175 static const SFB_PARAM_LONG p_32000_long_480
= {
177 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
178 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
179 8, 8, 12, 12, 12, 16, 16, 20, 24, 32,
180 32, 32, 32, 32, 32, 32, 32}
184 static const SFB_PARAM_LONG p_44100_long_480
= {
186 { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
187 4, 4, 4, 4, 8, 8, 8, 8, 8, 12,
188 12, 12, 12, 12, 16, 16, 24, 28, 32, 32,
192 static const SFB_INFO_TAB sfbInfoTabLD480
[] = {
193 { 8000, &p_22050_long_480
, NULL
},
194 {11025, &p_22050_long_480
, NULL
},
195 {12000, &p_22050_long_480
, NULL
},
196 {16000, &p_22050_long_480
, NULL
},
197 {22050, &p_22050_long_480
, NULL
},
198 {24000, &p_22050_long_480
, NULL
},
199 {32000, &p_32000_long_480
, NULL
},
200 {44100, &p_44100_long_480
, NULL
},
201 {48000, &p_44100_long_480
, NULL
},
202 {64000, &p_44100_long_480
, NULL
},
203 {88200, &p_44100_long_480
, NULL
},
204 {96000, &p_44100_long_480
, NULL
},
208 /* Fixed point precision definitions */
209 #define Q_BARCVAL (25)
211 static AAC_ENCODER_ERROR
FDKaacEnc_initSfbTable(LONG sampleRate
, INT blockType
, INT granuleLength
, INT
*sfbOffset
, INT
*sfbCnt
)
213 INT i
, specStartOffset
= 0;
214 const UCHAR
* sfbWidth
= NULL
;
215 const SFB_INFO_TAB
*sfbInfo
= NULL
;
221 switch(granuleLength
) {
224 sfbInfo
= sfbInfoTab
;
225 size
= (INT
)(sizeof(sfbInfoTab
)/sizeof(SFB_INFO_TAB
));
228 sfbInfo
= sfbInfoTabLD512
;
229 size
= sizeof(sfbInfoTabLD512
);
232 sfbInfo
= sfbInfoTabLD480
;
233 size
= sizeof(sfbInfoTabLD480
);
236 return AAC_ENC_INVALID_FRAME_LENGTH
;
239 for(i
= 0; i
< size
; i
++){
240 if(sfbInfo
[i
].sampleRate
== sampleRate
){
245 sfbWidth
= sfbInfo
[i
].paramLong
->sfbWidth
;
246 *sfbCnt
= sfbInfo
[i
].paramLong
->sfbCnt
;
249 sfbWidth
= sfbInfo
[i
].paramShort
->sfbWidth
;
250 *sfbCnt
= sfbInfo
[i
].paramShort
->sfbCnt
;
251 granuleLength
/= TRANS_FAC
;
258 return AAC_ENC_UNSUPPORTED_SAMPLINGRATE
;
264 for(i
= 0; i
< *sfbCnt
; i
++){
265 sfbOffset
[i
] = specStartOffset
;
266 specStartOffset
+= sfbWidth
[i
];
267 if (specStartOffset
>= granuleLength
) {
272 *sfbCnt
= fixMin(i
,*sfbCnt
);
273 sfbOffset
[*sfbCnt
] = fixMin(specStartOffset
,granuleLength
);
279 /*****************************************************************************
281 functionname: FDKaacEnc_BarcLineValue
282 description: Calculates barc value for one frequency line
283 returns: barc value of line
284 input: number of lines in transform, index of line to check, Fs
287 *****************************************************************************/
288 static FIXP_DBL
FDKaacEnc_BarcLineValue(INT noOfLines
, INT fftLine
, LONG samplingFreq
)
291 FIXP_DBL FOURBY3EM4
= (FIXP_DBL
)0x45e7b273; /* 4.0/3 * 0.0001 in q43 */
292 FIXP_DBL PZZZ76
= (FIXP_DBL
)0x639d5e4a; /* 0.00076 in q41 */
293 FIXP_DBL ONE3P3
= (FIXP_DBL
)0x35333333; /* 13.3 in q26 */
294 FIXP_DBL THREEP5
= (FIXP_DBL
)0x1c000000; /* 3.5 in q27 */
295 FIXP_DBL INV480
= (FIXP_DBL
)0x44444444; // 1/480 in q39
297 FIXP_DBL center_freq
, x1
, x2
;
298 FIXP_DBL bvalFFTLine
, atan1
, atan2
;
300 /* Theoritical maximum of center_freq (samp_freq*0.5) is 96khz * 0.5 = 48000 */
301 /* Theoritical maximum of x1 is 1.3333333e-4f * center_freq = 6.4, can keep in q28 */
302 /* Theoritical maximum of x2 is 0.00076f * center_freq = 36.48, can keep in q25 */
304 center_freq
= fftLine
* samplingFreq
; /* q11 or q8 */
308 center_freq
= center_freq
<< 2; /* q13 */
311 center_freq
= center_freq
<< 5; /* q13 */
314 center_freq
= (fftLine
* samplingFreq
) << 3; // q13
317 center_freq
= fMult(center_freq
, INV480
) << 4; // q13
320 center_freq
= (FIXP_DBL
)0;
323 x1
= fMult(center_freq
, FOURBY3EM4
); /* q13 * q43 - (DFRACT_BITS-1) = q25 */
324 x2
= fMult(center_freq
, PZZZ76
) << 2; /* q13 * q41 - (DFRACT_BITS-1) + 2 = q25 */
326 atan1
= fixp_atan(x1
);
327 atan2
= fixp_atan(x2
);
329 /* q25 (q26 * q30 - (DFRACT_BITS-1)) + q25 (q27 * q30 * q30) */
330 bvalFFTLine
= fMult(ONE3P3
, atan2
) + fMult(THREEP5
, fMult(atan1
, atan1
));
336 do not consider energies below a certain input signal level,
337 i.e. of -96dB or 1 bit at 16 bit PCM resolution,
338 might need to be configurable to e.g. 24 bit PCM Input or a lower
339 resolution for low bit rates
341 static void FDKaacEnc_InitMinPCMResolution(int numPb
,
343 FIXP_DBL
*sfbPCMquantThreshold
)
345 /* PCM_QUANT_NOISE = FDKpow(10.0f, - 20.f / 10.0f) * ABS_LOW * NORM_PCM_ENERGY * FDKpow(2,PCM_QUANT_THR_SCALE) */
346 #define PCM_QUANT_NOISE ((FIXP_DBL)0x00547062)
348 for( int i
= 0; i
< numPb
; i
++ ) {
349 sfbPCMquantThreshold
[i
] = (pbOffset
[i
+1] - pbOffset
[i
]) * PCM_QUANT_NOISE
;
353 static FIXP_DBL
getMaskFactor(
354 const FIXP_DBL dbVal_fix
,
356 const FIXP_DBL ten_fix
,
361 FIXP_DBL mask_factor
;
363 mask_factor
= fPow(ten_fix
, DFRACT_BITS
-1-ten_e
, -dbVal_fix
, DFRACT_BITS
-1-dbVal_e
, &q_msk
);
364 q_msk
= fixMin(DFRACT_BITS
-1,fixMax(-(DFRACT_BITS
-1),q_msk
));
366 if ( (q_msk
>0) && (mask_factor
>(FIXP_DBL
)MAXVAL_DBL
>>q_msk
) ) {
367 mask_factor
= (FIXP_DBL
)MAXVAL_DBL
;
370 mask_factor
= scaleValue(mask_factor
, q_msk
);
373 return (mask_factor
);
376 static void FDKaacEnc_initSpreading(INT numPb
,
377 FIXP_DBL
*pbBarcValue
,
378 FIXP_DBL
*pbMaskLoFactor
,
379 FIXP_DBL
*pbMaskHiFactor
,
380 FIXP_DBL
*pbMaskLoFactorSprEn
,
381 FIXP_DBL
*pbMaskHiFactorSprEn
,
387 FIXP_DBL MASKLOWSPREN
, MASKHIGHSPREN
;
389 FIXP_DBL MASKHIGH
= (FIXP_DBL
)0x30000000; /* 1.5 in q29 */
390 FIXP_DBL MASKLOW
= (FIXP_DBL
)0x60000000; /* 3.0 in q29 */
391 FIXP_DBL MASKLOWSPRENLONG
= (FIXP_DBL
)0x60000000; /* 3.0 in q29 */
392 FIXP_DBL MASKHIGHSPRENLONG
= (FIXP_DBL
)0x40000000; /* 2.0 in q29 */
393 FIXP_DBL MASKHIGHSPRENLONGLOWBR
= (FIXP_DBL
)0x30000000; /* 1.5 in q29 */
394 FIXP_DBL MASKLOWSPRENSHORT
= (FIXP_DBL
)0x40000000; /* 2.0 in q29 */
395 FIXP_DBL MASKHIGHSPRENSHORT
= (FIXP_DBL
)0x30000000; /* 1.5 in q29 */
396 FIXP_DBL TEN
= (FIXP_DBL
)0x50000000; /* 10.0 in q27 */
398 if (blockType
!= SHORT_WINDOW
)
400 MASKLOWSPREN
= MASKLOWSPRENLONG
;
401 MASKHIGHSPREN
= (bitrate
>20000)?MASKHIGHSPRENLONG
:MASKHIGHSPRENLONGLOWBR
;
405 MASKLOWSPREN
= MASKLOWSPRENSHORT
;
406 MASKHIGHSPREN
= MASKHIGHSPRENSHORT
;
409 for(i
=0; i
<numPb
; i
++)
413 pbMaskHiFactor
[i
] = getMaskFactor(
414 fMult(MASKHIGH
, (pbBarcValue
[i
] - pbBarcValue
[i
-1])), 23,
417 pbMaskLoFactor
[i
-1] = getMaskFactor(
418 fMult(MASKLOW
, (pbBarcValue
[i
] - pbBarcValue
[i
-1])), 23,
421 pbMaskHiFactorSprEn
[i
] = getMaskFactor(
422 fMult(MASKHIGHSPREN
, (pbBarcValue
[i
] - pbBarcValue
[i
-1])), 23,
425 pbMaskLoFactorSprEn
[i
-1] = getMaskFactor(
426 fMult(MASKLOWSPREN
, (pbBarcValue
[i
] - pbBarcValue
[i
-1])), 23,
431 pbMaskHiFactor
[i
] = (FIXP_DBL
)0;
432 pbMaskLoFactor
[numPb
-1] = (FIXP_DBL
)0;
433 pbMaskHiFactorSprEn
[i
] = (FIXP_DBL
)0;
434 pbMaskLoFactorSprEn
[numPb
-1] = (FIXP_DBL
)0;
439 static void FDKaacEnc_initBarcValues(INT numPb
,
442 INT samplingFrequency
,
446 FIXP_DBL MAX_BARC
= (FIXP_DBL
)0x30000000; /* 24.0 in q25 */
448 for(i
=0; i
<numPb
; i
++)
450 FIXP_DBL v1
, v2
, cur_bark
;
451 v1
= FDKaacEnc_BarcLineValue(numLines
, pbOffset
[i
], samplingFrequency
);
452 v2
= FDKaacEnc_BarcLineValue(numLines
, pbOffset
[i
+1], samplingFrequency
);
453 cur_bark
= (v1
>> 1) + (v2
>> 1);
454 pbBval
[i
] = fixMin(cur_bark
, MAX_BARC
);
458 static void FDKaacEnc_initMinSnr(const LONG bitrate
,
459 const LONG samplerate
,
461 const INT
*sfbOffset
,
464 FIXP_DBL
*sfbMinSnrLdData
)
468 /* Fix conversion variables */
469 INT qbfac
, qperwin
, qdiv
, qpeprt_const
, qpeprt
;
470 INT qtmp
, qsnr
, sfbWidth
;
472 FIXP_DBL MAX_BARC
= (FIXP_DBL
)0x30000000; /* 24.0 in q25 */
473 FIXP_DBL MAX_BARCP1
= (FIXP_DBL
)0x32000000; /* 25.0 in q25 */
474 FIXP_DBL BITS2PEFAC
= (FIXP_DBL
)0x4b851eb8; /* 1.18 in q30 */
475 FIXP_DBL PERS2P4
= (FIXP_DBL
)0x624dd2f2; /* 0.024 in q36 */
476 FIXP_DBL ONEP5
= (FIXP_DBL
)0x60000000; /* 1.5 in q30 */
477 FIXP_DBL MAX_SNR
= (FIXP_DBL
)0x33333333; /* 0.8 in q30 */
478 FIXP_DBL MIN_SNR
= (FIXP_DBL
)0x003126e9; /* 0.003 in q30 */
480 FIXP_DBL barcFactor
, pePerWindow
, pePart
, barcWidth
;
481 FIXP_DBL pePart_const
, tmp
, snr
, one_qsnr
, one_point5
;
483 /* relative number of active barks */
484 barcFactor
= fDivNorm(fixMin(FDKaacEnc_BarcLineValue(numLines
, sfbOffset
[sfbActive
], samplerate
), MAX_BARC
),
487 qbfac
= DFRACT_BITS
-1-qbfac
;
489 pePerWindow
= fDivNorm(bitrate
, samplerate
, &qperwin
);
490 qperwin
= DFRACT_BITS
-1-qperwin
;
491 pePerWindow
= fMult(pePerWindow
, BITS2PEFAC
); qperwin
= qperwin
+ 30 - (DFRACT_BITS
-1);
492 pePerWindow
= fMult(pePerWindow
, PERS2P4
); qperwin
= qperwin
+ 36 - (DFRACT_BITS
-1);
496 qperwin
= qperwin
- 10;
499 qperwin
= qperwin
- 7;
502 qperwin
= qperwin
- 9;
505 qperwin
= qperwin
- 9;
506 pePerWindow
= fMult(pePerWindow
, FL2FXCONST_DBL(480.f
/512.f
));
510 /* for short blocks it is assumed that more bits are available */
511 if (blockType
== SHORT_WINDOW
)
513 pePerWindow
= fMult(pePerWindow
, ONEP5
);
514 qperwin
= qperwin
+ 30 - (DFRACT_BITS
-1);
516 pePart_const
= fDivNorm(pePerWindow
, barcFactor
, &qdiv
); qpeprt_const
= qperwin
- qbfac
+ DFRACT_BITS
-1-qdiv
;
518 for (sfb
= 0; sfb
< sfbActive
; sfb
++)
520 barcWidth
= FDKaacEnc_BarcLineValue(numLines
, sfbOffset
[sfb
+1], samplerate
) -
521 FDKaacEnc_BarcLineValue(numLines
, sfbOffset
[sfb
], samplerate
);
523 /* adapt to sfb bands */
524 pePart
= fMult(pePart_const
, barcWidth
); qpeprt
= qpeprt_const
+ 25 - (DFRACT_BITS
-1);
526 /* pe -> snr calculation */
527 sfbWidth
= (sfbOffset
[sfb
+1] - sfbOffset
[sfb
]);
528 pePart
= fDivNorm(pePart
, sfbWidth
, &qdiv
); qpeprt
+= DFRACT_BITS
-1-qdiv
;
530 tmp
= f2Pow(pePart
, DFRACT_BITS
-1-qpeprt
, &qtmp
);
531 qtmp
= DFRACT_BITS
-1-qtmp
;
534 qsnr
= fixMin(qtmp
, 30);
535 tmp
= tmp
>> (qtmp
- qsnr
);
537 if((30+1-qsnr
) > (DFRACT_BITS
-1))
538 one_point5
= (FIXP_DBL
)0;
540 one_point5
= (FIXP_DBL
)(ONEP5
>> (30+1-qsnr
));
542 snr
= (tmp
>>1) - (one_point5
); qsnr
-= 1;
546 one_qsnr
= (FIXP_DBL
)(1 << qsnr
);
548 one_qsnr
= (FIXP_DBL
)0;
550 snr
= fixMax(one_qsnr
, snr
);
553 snr
= fDivNorm(one_qsnr
, snr
, &qsnr
);
554 qsnr
= DFRACT_BITS
-1-qsnr
;
555 snr
= (qsnr
> 30)? (snr
>>(qsnr
-30)):snr
;
557 /* upper limit is -1 dB */
558 snr
= (snr
> MAX_SNR
) ? MAX_SNR
: snr
;
560 /* lower limit is -25 dB */
561 snr
= (snr
< MIN_SNR
) ? MIN_SNR
: snr
;
564 sfbMinSnrLdData
[sfb
] = CalcLdData(snr
);
568 AAC_ENCODER_ERROR
FDKaacEnc_InitPsyConfiguration(INT bitrate
,
574 PSY_CONFIGURATION
*psyConf
,
577 AAC_ENCODER_ERROR ErrorStatus
;
579 FIXP_DBL sfbBarcVal
[MAX_SFB
];
580 const INT frameLengthLong
= granuleLength
;
581 const INT frameLengthShort
= granuleLength
/TRANS_FAC
;
583 FDKmemclear(psyConf
, sizeof(PSY_CONFIGURATION
));
584 psyConf
->granuleLength
= granuleLength
;
585 psyConf
->filterbank
= filterbank
;
587 psyConf
->allowIS
= (useIS
) && ( (bitrate
/bandwidth
) < 5 );
590 ErrorStatus
= FDKaacEnc_initSfbTable(samplerate
,blocktype
,granuleLength
,psyConf
->sfbOffset
,&psyConf
->sfbCnt
);
591 if (ErrorStatus
!= AAC_ENC_OK
)
594 /* calculate barc values for each pb */
595 FDKaacEnc_initBarcValues(psyConf
->sfbCnt
,
597 psyConf
->sfbOffset
[psyConf
->sfbCnt
],
601 FDKaacEnc_InitMinPCMResolution(psyConf
->sfbCnt
,
603 psyConf
->sfbPcmQuantThreshold
);
605 /* calculate spreading function */
606 FDKaacEnc_initSpreading(psyConf
->sfbCnt
,
608 psyConf
->sfbMaskLowFactor
,
609 psyConf
->sfbMaskHighFactor
,
610 psyConf
->sfbMaskLowFactorSprEn
,
611 psyConf
->sfbMaskHighFactorSprEn
,
617 psyConf
->maxAllowedIncreaseFactor
= 2; /* integer */
618 psyConf
->minRemainingThresholdFactor
= (FIXP_SGL
)0x0148; /* FL2FXCONST_SGL(0.01f); */ /* fract */
620 psyConf
->clipEnergy
= (FIXP_DBL
)0x773593ff; /* FL2FXCONST_DBL(1.0e9*NORM_PCM_ENERGY); */
622 if (blocktype
!=SHORT_WINDOW
) {
623 psyConf
->lowpassLine
= (INT
)((2*bandwidth
*frameLengthLong
)/samplerate
);
624 psyConf
->lowpassLineLFE
= LFE_LOWPASS_LINE
;
627 psyConf
->lowpassLine
= (INT
)((2*bandwidth
*frameLengthShort
)/samplerate
);
628 psyConf
->lowpassLineLFE
= 0; /* LFE only in lonf blocks */
629 /* psyConf->clipEnergy /= (TRANS_FAC * TRANS_FAC); */
630 psyConf
->clipEnergy
>>= 6;
633 for (sfb
= 0; sfb
< psyConf
->sfbCnt
; sfb
++){
634 if (psyConf
->sfbOffset
[sfb
] >= psyConf
->lowpassLine
)
637 psyConf
->sfbActive
= sfb
;
639 for (sfb
= 0; sfb
< psyConf
->sfbCnt
; sfb
++){
640 if (psyConf
->sfbOffset
[sfb
] >= psyConf
->lowpassLineLFE
)
643 psyConf
->sfbActiveLFE
= sfb
;
645 /* calculate minSnr */
646 FDKaacEnc_initMinSnr(bitrate
,
648 psyConf
->sfbOffset
[psyConf
->sfbCnt
],
652 psyConf
->sfbMinSnrLdData
);