1
2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
4
5 � Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6 All rights reserved.
7
8 1. INTRODUCTION
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.
12
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.
17
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.
24
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.
28
29 2. COPYRIGHT LICENSE
30
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:
33
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.
36
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.
41
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
44
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.
47
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."
52
53 3. NO PATENT LICENSE
54
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.
58
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
61
62 4. DISCLAIMER
63
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.
72
73 5. CONTACT INFORMATION
74
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
77 Am Wolfsmantel 33
78 91058 Erlangen, Germany
79
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
83
84 #include "nf_est.h"
85
86 #include "sbr_misc.h"
87
88 #include "genericStds.h"
89
90 /* smoothFilter[4] = {0.05857864376269f, 0.2f, 0.34142135623731f, 0.4f}; */
91 static const FIXP_DBL smoothFilter[4] = { 0x077f813d, 0x19999995, 0x2bb3b1f5, 0x33333335 };
92
93 /* static const INT smoothFilterLength = 4; */
94
95 static const FIXP_DBL QuantOffset = (INT)0xfc000000; /* ld64(0.25) */
96
97 #ifndef min
98 #define min(a,b) ( a < b ? a:b)
99 #endif
100
101 #ifndef max
102 #define max(a,b) ( a > b ? a:b)
103 #endif
104
105 #define NOISE_FLOOR_OFFSET_SCALING (4)
106
107
108
109 /**************************************************************************/
110 /*!
111 \brief The function applies smoothing to the noise levels.
112
113
114
115 \return none
116
117 */
118 /**************************************************************************/
119 static void
smoothingOfNoiseLevels(FIXP_DBL * NoiseLevels,INT nEnvelopes,INT noNoiseBands,FIXP_DBL prevNoiseLevels[NF_SMOOTHING_LENGTH][MAX_NUM_NOISE_VALUES],const FIXP_DBL * smoothFilter,INT transientFlag)120 smoothingOfNoiseLevels(FIXP_DBL *NoiseLevels, /*!< pointer to noise-floor levels.*/
121 INT nEnvelopes, /*!< Number of noise floor envelopes.*/
122 INT noNoiseBands, /*!< Number of noise bands for every noise floor envelope. */
123 FIXP_DBL prevNoiseLevels[NF_SMOOTHING_LENGTH][MAX_NUM_NOISE_VALUES],/*!< Previous noise floor envelopes. */
124 const FIXP_DBL *smoothFilter, /*!< filter used for smoothing the noise floor levels. */
125 INT transientFlag) /*!< flag indicating if a transient is present*/
126
127 {
128 INT i,band,env;
129 FIXP_DBL accu;
130
131 for(env = 0; env < nEnvelopes; env++){
132 if(transientFlag){
133 for (i = 0; i < NF_SMOOTHING_LENGTH; i++){
134 FDKmemcpy(prevNoiseLevels[i],NoiseLevels+env*noNoiseBands,noNoiseBands*sizeof(FIXP_DBL));
135 }
136 }
137 else {
138 for (i = 1; i < NF_SMOOTHING_LENGTH; i++){
139 FDKmemcpy(prevNoiseLevels[i - 1],prevNoiseLevels[i],noNoiseBands*sizeof(FIXP_DBL));
140 }
141 FDKmemcpy(prevNoiseLevels[NF_SMOOTHING_LENGTH - 1],NoiseLevels+env*noNoiseBands,noNoiseBands*sizeof(FIXP_DBL));
142 }
143
144 for (band = 0; band < noNoiseBands; band++){
145 accu = FL2FXCONST_DBL(0.0f);
146 for (i = 0; i < NF_SMOOTHING_LENGTH; i++){
147 accu += fMultDiv2(smoothFilter[i], prevNoiseLevels[i][band]);
148 }
149 FDK_ASSERT( (band + env*noNoiseBands) < MAX_NUM_NOISE_VALUES);
150 NoiseLevels[band+ env*noNoiseBands] = accu<<1;
151 }
152 }
153 }
154
155 /**************************************************************************/
156 /*!
157 \brief Does the noise floor level estiamtion.
158
159 The noiseLevel samples are scaled by the factor 0.25
160
161 \return none
162
163 */
164 /**************************************************************************/
165 static void
qmfBasedNoiseFloorDetection(FIXP_DBL * noiseLevel,FIXP_DBL ** quotaMatrixOrig,SCHAR * indexVector,INT startIndex,INT stopIndex,INT startChannel,INT stopChannel,FIXP_DBL ana_max_level,FIXP_DBL noiseFloorOffset,INT missingHarmonicFlag,FIXP_DBL weightFac,INVF_MODE diffThres,INVF_MODE inverseFilteringLevel)166 qmfBasedNoiseFloorDetection(FIXP_DBL *noiseLevel, /*!< Pointer to vector to store the noise levels in.*/
167 FIXP_DBL ** quotaMatrixOrig, /*!< Matrix holding the quota values of the original. */
168 SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
169 INT startIndex, /*!< Start index. */
170 INT stopIndex, /*!< Stop index. */
171 INT startChannel, /*!< Start channel of the current noise floor band.*/
172 INT stopChannel, /*!< Stop channel of the current noise floor band. */
173 FIXP_DBL ana_max_level, /*!< Maximum level of the adaptive noise.*/
174 FIXP_DBL noiseFloorOffset, /*!< Noise floor offset. */
175 INT missingHarmonicFlag, /*!< Flag indicating if a strong tonal component is missing.*/
176 FIXP_DBL weightFac, /*!< Weightening factor for the difference between orig and sbr. */
177 INVF_MODE diffThres, /*!< Threshold value to control the inverse filtering decision.*/
178 INVF_MODE inverseFilteringLevel) /*!< Inverse filtering level of the current band.*/
179 {
180 INT scale, l, k;
181 FIXP_DBL meanOrig=FL2FXCONST_DBL(0.0f), meanSbr=FL2FXCONST_DBL(0.0f), diff;
182 FIXP_DBL invIndex = GetInvInt(stopIndex-startIndex);
183 FIXP_DBL invChannel = GetInvInt(stopChannel-startChannel);
184 FIXP_DBL accu;
185
186 /*
187 Calculate the mean value, over the current time segment, for the original, the HFR
188 and the difference, over all channels in the current frequency range.
189 */
190
191 if(missingHarmonicFlag == 1){
192 for(l = startChannel; l < stopChannel;l++){
193 /* tonalityOrig */
194 accu = FL2FXCONST_DBL(0.0f);
195 for(k = startIndex ; k < stopIndex; k++){
196 accu += fMultDiv2(quotaMatrixOrig[k][l], invIndex);
197 }
198 meanOrig = fixMax(meanOrig,(accu<<1));
199
200 /* tonalitySbr */
201 accu = FL2FXCONST_DBL(0.0f);
202 for(k = startIndex ; k < stopIndex; k++){
203 accu += fMultDiv2(quotaMatrixOrig[k][indexVector[l]], invIndex);
204 }
205 meanSbr = fixMax(meanSbr,(accu<<1));
206
207 }
208 }
209 else{
210 for(l = startChannel; l < stopChannel;l++){
211 /* tonalityOrig */
212 accu = FL2FXCONST_DBL(0.0f);
213 for(k = startIndex ; k < stopIndex; k++){
214 accu += fMultDiv2(quotaMatrixOrig[k][l], invIndex);
215 }
216 meanOrig += fMult((accu<<1), invChannel);
217
218 /* tonalitySbr */
219 accu = FL2FXCONST_DBL(0.0f);
220 for(k = startIndex ; k < stopIndex; k++){
221 accu += fMultDiv2(quotaMatrixOrig[k][indexVector[l]], invIndex);
222 }
223 meanSbr += fMult((accu<<1), invChannel);
224 }
225 }
226
227 /* Small fix to avoid noise during silent passages.*/
228 if( meanOrig <= FL2FXCONST_DBL(0.000976562f*RELAXATION_FLOAT) &&
229 meanSbr <= FL2FXCONST_DBL(0.000976562f*RELAXATION_FLOAT) )
230 {
231 meanOrig = FL2FXCONST_DBL(101.5936673f*RELAXATION_FLOAT);
232 meanSbr = FL2FXCONST_DBL(101.5936673f*RELAXATION_FLOAT);
233 }
234
235 meanOrig = fixMax(meanOrig,RELAXATION);
236 meanSbr = fixMax(meanSbr,RELAXATION);
237
238 if (missingHarmonicFlag == 1 ||
239 inverseFilteringLevel == INVF_MID_LEVEL ||
240 inverseFilteringLevel == INVF_LOW_LEVEL ||
241 inverseFilteringLevel == INVF_OFF ||
242 inverseFilteringLevel <= diffThres)
243 {
244 diff = RELAXATION;
245 }
246 else {
247 accu = fDivNorm(meanSbr, meanOrig, &scale);
248
249 diff = fixMax( RELAXATION,
250 fMult(RELAXATION_FRACT,fMult(weightFac,accu)) >>( RELAXATION_SHIFT-scale ) ) ;
251 }
252
253 /*
254 * noise Level is now a positive value, i.e.
255 * the more harmonic the signal is the higher noise level,
256 * this makes no sense so we change the sign.
257 *********************************************************/
258 accu = fDivNorm(diff, meanOrig, &scale);
259 scale -= 2;
260
261 if ( (scale>0) && (accu > ((FIXP_DBL)MAXVAL_DBL)>>scale) ) {
262 *noiseLevel = (FIXP_DBL)MAXVAL_DBL;
263 }
264 else {
265 *noiseLevel = scaleValue(accu, scale);
266 }
267
268 /*
269 * Add a noise floor offset to compensate for bias in the detector
270 *****************************************************************/
271 if(!missingHarmonicFlag)
272 *noiseLevel = fMult(*noiseLevel, noiseFloorOffset)<<(NOISE_FLOOR_OFFSET_SCALING);
273
274 /*
275 * check to see that we don't exceed the maximum allowed level
276 **************************************************************/
277 *noiseLevel = fixMin(*noiseLevel, ana_max_level); /* ana_max_level is scaled with factor 0.25 */
278 }
279
280 /**************************************************************************/
281 /*!
282 \brief Does the noise floor level estiamtion.
283 The function calls the Noisefloor estimation function
284 for the time segments decided based upon the transient
285 information. The block is always divided into one or two segments.
286
287
288 \return none
289
290 */
291 /**************************************************************************/
292 void
FDKsbrEnc_sbrNoiseFloorEstimateQmf(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate,const SBR_FRAME_INFO * frame_info,FIXP_DBL * noiseLevels,FIXP_DBL ** quotaMatrixOrig,SCHAR * indexVector,INT missingHarmonicsFlag,INT startIndex,int numberOfEstimatesPerFrame,int transientFrame,INVF_MODE * pInvFiltLevels,UINT sbrSyntaxFlags)293 FDKsbrEnc_sbrNoiseFloorEstimateQmf(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
294 const SBR_FRAME_INFO *frame_info, /*!< Time frequency grid of the current frame. */
295 FIXP_DBL *noiseLevels, /*!< Pointer to vector to store the noise levels in.*/
296 FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the quota values of the original. */
297 SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
298 INT missingHarmonicsFlag, /*!< Flag indicating if a strong tonal component will be missing. */
299 INT startIndex, /*!< Start index. */
300 int numberOfEstimatesPerFrame, /*!< The number of tonality estimates per frame. */
301 int transientFrame, /*!< A flag indicating if a transient is present. */
302 INVF_MODE* pInvFiltLevels, /*!< Pointer to the vector holding the inverse filtering levels. */
303 UINT sbrSyntaxFlags
304 )
305
306 {
307
308 INT nNoiseEnvelopes, startPos[2], stopPos[2], env, band;
309
310 INT noNoiseBands = h_sbrNoiseFloorEstimate->noNoiseBands;
311 INT *freqBandTable = h_sbrNoiseFloorEstimate->freqBandTableQmf;
312
313 nNoiseEnvelopes = frame_info->nNoiseEnvelopes;
314
315 if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
316 nNoiseEnvelopes = 1;
317 startPos[0] = startIndex;
318 stopPos[0] = startIndex + min(numberOfEstimatesPerFrame,2);
319 } else
320 if(nNoiseEnvelopes == 1){
321 startPos[0] = startIndex;
322 stopPos[0] = startIndex + 2;
323 }
324 else{
325 startPos[0] = startIndex;
326 stopPos[0] = startIndex + 1;
327 startPos[1] = startIndex + 1;
328 stopPos[1] = startIndex + 2;
329 }
330
331 /*
332 * Estimate the noise floor.
333 **************************************/
334 for(env = 0; env < nNoiseEnvelopes; env++){
335 for(band = 0; band < noNoiseBands; band++){
336 FDK_ASSERT( (band + env*noNoiseBands) < MAX_NUM_NOISE_VALUES);
337 qmfBasedNoiseFloorDetection(&noiseLevels[band + env*noNoiseBands],
338 quotaMatrixOrig,
339 indexVector,
340 startPos[env],
341 stopPos[env],
342 freqBandTable[band],
343 freqBandTable[band+1],
344 h_sbrNoiseFloorEstimate->ana_max_level,
345 h_sbrNoiseFloorEstimate->noiseFloorOffset[band],
346 missingHarmonicsFlag,
347 h_sbrNoiseFloorEstimate->weightFac,
348 h_sbrNoiseFloorEstimate->diffThres,
349 pInvFiltLevels[band]);
350 }
351 }
352
353
354 /*
355 * Smoothing of the values.
356 **************************/
357 smoothingOfNoiseLevels(noiseLevels,
358 nNoiseEnvelopes,
359 h_sbrNoiseFloorEstimate->noNoiseBands,
360 h_sbrNoiseFloorEstimate->prevNoiseLevels,
361 h_sbrNoiseFloorEstimate->smoothFilter,
362 transientFrame);
363
364
365 /* quantisation*/
366 for(env = 0; env < nNoiseEnvelopes; env++){
367 for(band = 0; band < noNoiseBands; band++){
368 FDK_ASSERT( (band + env*noNoiseBands) < MAX_NUM_NOISE_VALUES);
369 noiseLevels[band + env*noNoiseBands] =
370 (FIXP_DBL)NOISE_FLOOR_OFFSET_64 - (FIXP_DBL)CalcLdData(noiseLevels[band + env*noNoiseBands]+(FIXP_DBL)1) + QuantOffset;
371 }
372 }
373 }
374
375 /**************************************************************************/
376 /*!
377 \brief
378
379
380 \return errorCode, noError if successful
381
382 */
383 /**************************************************************************/
384 static INT
downSampleLoRes(INT * v_result,INT num_result,const UCHAR * freqBandTableRef,INT num_Ref)385 downSampleLoRes(INT *v_result, /*!< */
386 INT num_result, /*!< */
387 const UCHAR *freqBandTableRef,/*!< */
388 INT num_Ref) /*!< */
389 {
390 INT step;
391 INT i,j;
392 INT org_length,result_length;
393 INT v_index[MAX_FREQ_COEFFS/2];
394
395 /* init */
396 org_length=num_Ref;
397 result_length=num_result;
398
399 v_index[0]=0; /* Always use left border */
400 i=0;
401 while(org_length > 0) /* Create downsample vector */
402 {
403 i++;
404 step=org_length/result_length; /* floor; */
405 org_length=org_length - step;
406 result_length--;
407 v_index[i]=v_index[i-1]+step;
408 }
409
410 if(i != num_result ) /* Should never happen */
411 return (1);/* error downsampling */
412
413 for(j=0;j<=i;j++) /* Use downsample vector to index LoResolution vector. */
414 {
415 v_result[j]=freqBandTableRef[v_index[j]];
416 }
417
418 return (0);
419 }
420
421 /**************************************************************************/
422 /*!
423 \brief Initialize an instance of the noise floor level estimation module.
424
425
426 \return errorCode, noError if successful
427
428 */
429 /**************************************************************************/
430 INT
FDKsbrEnc_InitSbrNoiseFloorEstimate(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate,INT ana_max_level,const UCHAR * freqBandTable,INT nSfb,INT noiseBands,INT noiseFloorOffset,INT timeSlots,UINT useSpeechConfig)431 FDKsbrEnc_InitSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
432 INT ana_max_level, /*!< Maximum level of the adaptive noise. */
433 const UCHAR *freqBandTable, /*!< Frequany band table. */
434 INT nSfb, /*!< Number of frequency bands. */
435 INT noiseBands, /*!< Number of noise bands per octave. */
436 INT noiseFloorOffset, /*!< Noise floor offset. */
437 INT timeSlots, /*!< Number of time slots in a frame. */
438 UINT useSpeechConfig /*!< Flag: adapt tuning parameters according to speech */
439 )
440 {
441 INT i, qexp, qtmp;
442 FIXP_DBL tmp, exp;
443
444 FDKmemclear(h_sbrNoiseFloorEstimate,sizeof(SBR_NOISE_FLOOR_ESTIMATE));
445
446 h_sbrNoiseFloorEstimate->smoothFilter = smoothFilter;
447 if (useSpeechConfig) {
448 h_sbrNoiseFloorEstimate->weightFac = (FIXP_DBL)MAXVAL_DBL;
449 h_sbrNoiseFloorEstimate->diffThres = INVF_LOW_LEVEL;
450 }
451 else {
452 h_sbrNoiseFloorEstimate->weightFac = FL2FXCONST_DBL(0.25f);
453 h_sbrNoiseFloorEstimate->diffThres = INVF_MID_LEVEL;
454 }
455
456 h_sbrNoiseFloorEstimate->timeSlots = timeSlots;
457 h_sbrNoiseFloorEstimate->noiseBands = noiseBands;
458
459 /* h_sbrNoiseFloorEstimate->ana_max_level is scaled by 0.25 */
460 switch(ana_max_level)
461 {
462 case 6:
463 h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
464 break;
465 case 3:
466 h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.5);
467 break;
468 case -3:
469 h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.125);
470 break;
471 default:
472 /* Should not enter here */
473 h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
474 break;
475 }
476
477 /*
478 calculate number of noise bands and allocate
479 */
480 if(FDKsbrEnc_resetSbrNoiseFloorEstimate(h_sbrNoiseFloorEstimate,freqBandTable,nSfb))
481 return(1);
482
483 if(noiseFloorOffset == 0) {
484 tmp = ((FIXP_DBL)MAXVAL_DBL)>>NOISE_FLOOR_OFFSET_SCALING;
485 }
486 else {
487 /* noiseFloorOffset has to be smaller than 12, because
488 the result of the calculation below must be smaller than 1:
489 (2^(noiseFloorOffset/3))*2^4<1 */
490 FDK_ASSERT(noiseFloorOffset<12);
491
492 /* Assumes the noise floor offset in tuning table are in q31 */
493 /* Change the qformat here when non-zero values would be filled */
494 exp = fDivNorm((FIXP_DBL)noiseFloorOffset, 3, &qexp);
495 tmp = fPow(2, DFRACT_BITS-1, exp, qexp, &qtmp);
496 tmp = scaleValue(tmp, qtmp-NOISE_FLOOR_OFFSET_SCALING);
497 }
498
499 for(i=0;i<h_sbrNoiseFloorEstimate->noNoiseBands;i++) {
500 h_sbrNoiseFloorEstimate->noiseFloorOffset[i] = tmp;
501 }
502
503 return (0);
504 }
505
506 /**************************************************************************/
507 /*!
508 \brief Resets the current instance of the noise floor estiamtion
509 module.
510
511
512 \return errorCode, noError if successful
513
514 */
515 /**************************************************************************/
516 INT
FDKsbrEnc_resetSbrNoiseFloorEstimate(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate,const UCHAR * freqBandTable,INT nSfb)517 FDKsbrEnc_resetSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
518 const UCHAR *freqBandTable, /*!< Frequany band table. */
519 INT nSfb) /*!< Number of bands in the frequency band table. */
520 {
521 INT k2,kx;
522
523 /*
524 * Calculate number of noise bands
525 ***********************************/
526 k2=freqBandTable[nSfb];
527 kx=freqBandTable[0];
528 if(h_sbrNoiseFloorEstimate->noiseBands == 0){
529 h_sbrNoiseFloorEstimate->noNoiseBands = 1;
530 }
531 else{
532 /*
533 * Calculate number of noise bands 1,2 or 3 bands/octave
534 ********************************************************/
535 FIXP_DBL tmp, ratio, lg2;
536 INT ratio_e, qlg2, nNoiseBands;
537
538 ratio = fDivNorm(k2, kx, &ratio_e);
539 lg2 = fLog2(ratio, ratio_e, &qlg2);
540 tmp = fMult((FIXP_DBL)(h_sbrNoiseFloorEstimate->noiseBands<<24), lg2);
541 tmp = scaleValue(tmp, qlg2-23);
542
543 nNoiseBands = (INT)((tmp + (FIXP_DBL)1) >> 1);
544
545
546 if (nNoiseBands > MAX_NUM_NOISE_COEFFS ) {
547 nNoiseBands = MAX_NUM_NOISE_COEFFS;
548 }
549
550 if( nNoiseBands == 0 ) {
551 nNoiseBands = 1;
552 }
553
554 h_sbrNoiseFloorEstimate->noNoiseBands = nNoiseBands;
555
556 }
557
558
559 return(downSampleLoRes(h_sbrNoiseFloorEstimate->freqBandTableQmf,
560 h_sbrNoiseFloorEstimate->noNoiseBands,
561 freqBandTable,nSfb));
562 }
563
564 /**************************************************************************/
565 /*!
566 \brief Deletes the current instancce of the noise floor level
567 estimation module.
568
569
570 \return none
571
572 */
573 /**************************************************************************/
574 void
FDKsbrEnc_deleteSbrNoiseFloorEstimate(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate)575 FDKsbrEnc_deleteSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate) /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
576 {
577
578 if (h_sbrNoiseFloorEstimate) {
579 /*
580 nothing to do
581 */
582 }
583 }
584