1
2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
4
5 � Copyright 1995 - 2015 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 = fixMin(fMult(*noiseLevel, noiseFloorOffset), (FIXP_DBL)MAXVAL_DBL>>NOISE_FLOOR_OFFSET_SCALING) << NOISE_FLOOR_OFFSET_SCALING;
273 }
274
275 /*
276 * check to see that we don't exceed the maximum allowed level
277 **************************************************************/
278 *noiseLevel = fixMin(*noiseLevel, ana_max_level); /* ana_max_level is scaled with factor 0.25 */
279 }
280
281 /**************************************************************************/
282 /*!
283 \brief Does the noise floor level estiamtion.
284 The function calls the Noisefloor estimation function
285 for the time segments decided based upon the transient
286 information. The block is always divided into one or two segments.
287
288
289 \return none
290
291 */
292 /**************************************************************************/
293 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,UINT numberOfEstimatesPerFrame,int transientFrame,INVF_MODE * pInvFiltLevels,UINT sbrSyntaxFlags)294 FDKsbrEnc_sbrNoiseFloorEstimateQmf(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
295 const SBR_FRAME_INFO *frame_info, /*!< Time frequency grid of the current frame. */
296 FIXP_DBL *noiseLevels, /*!< Pointer to vector to store the noise levels in.*/
297 FIXP_DBL **quotaMatrixOrig, /*!< Matrix holding the quota values of the original. */
298 SCHAR *indexVector, /*!< Index vector to obtain the patched data. */
299 INT missingHarmonicsFlag, /*!< Flag indicating if a strong tonal component will be missing. */
300 INT startIndex, /*!< Start index. */
301 UINT numberOfEstimatesPerFrame, /*!< The number of tonality estimates per frame. */
302 int transientFrame, /*!< A flag indicating if a transient is present. */
303 INVF_MODE* pInvFiltLevels, /*!< Pointer to the vector holding the inverse filtering levels. */
304 UINT sbrSyntaxFlags
305 )
306
307 {
308
309 INT nNoiseEnvelopes, startPos[2], stopPos[2], env, band;
310
311 INT noNoiseBands = h_sbrNoiseFloorEstimate->noNoiseBands;
312 INT *freqBandTable = h_sbrNoiseFloorEstimate->freqBandTableQmf;
313
314 nNoiseEnvelopes = frame_info->nNoiseEnvelopes;
315
316 if (sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) {
317 nNoiseEnvelopes = 1;
318 startPos[0] = startIndex;
319 stopPos[0] = startIndex + min(numberOfEstimatesPerFrame,2);
320 } else
321 if(nNoiseEnvelopes == 1){
322 startPos[0] = startIndex;
323 stopPos[0] = startIndex + 2;
324 }
325 else{
326 startPos[0] = startIndex;
327 stopPos[0] = startIndex + 1;
328 startPos[1] = startIndex + 1;
329 stopPos[1] = startIndex + 2;
330 }
331
332 /*
333 * Estimate the noise floor.
334 **************************************/
335 for(env = 0; env < nNoiseEnvelopes; env++){
336 for(band = 0; band < noNoiseBands; band++){
337 FDK_ASSERT( (band + env*noNoiseBands) < MAX_NUM_NOISE_VALUES);
338 qmfBasedNoiseFloorDetection(&noiseLevels[band + env*noNoiseBands],
339 quotaMatrixOrig,
340 indexVector,
341 startPos[env],
342 stopPos[env],
343 freqBandTable[band],
344 freqBandTable[band+1],
345 h_sbrNoiseFloorEstimate->ana_max_level,
346 h_sbrNoiseFloorEstimate->noiseFloorOffset[band],
347 missingHarmonicsFlag,
348 h_sbrNoiseFloorEstimate->weightFac,
349 h_sbrNoiseFloorEstimate->diffThres,
350 pInvFiltLevels[band]);
351 }
352 }
353
354
355 /*
356 * Smoothing of the values.
357 **************************/
358 smoothingOfNoiseLevels(noiseLevels,
359 nNoiseEnvelopes,
360 h_sbrNoiseFloorEstimate->noNoiseBands,
361 h_sbrNoiseFloorEstimate->prevNoiseLevels,
362 h_sbrNoiseFloorEstimate->smoothFilter,
363 transientFrame);
364
365
366 /* quantisation*/
367 for(env = 0; env < nNoiseEnvelopes; env++){
368 for(band = 0; band < noNoiseBands; band++){
369 FDK_ASSERT( (band + env*noNoiseBands) < MAX_NUM_NOISE_VALUES);
370 noiseLevels[band + env*noNoiseBands] =
371 (FIXP_DBL)NOISE_FLOOR_OFFSET_64 - (FIXP_DBL)CalcLdData(noiseLevels[band + env*noNoiseBands]+(FIXP_DBL)1) + QuantOffset;
372 }
373 }
374 }
375
376 /**************************************************************************/
377 /*!
378 \brief
379
380
381 \return errorCode, noError if successful
382
383 */
384 /**************************************************************************/
385 static INT
downSampleLoRes(INT * v_result,INT num_result,const UCHAR * freqBandTableRef,INT num_Ref)386 downSampleLoRes(INT *v_result, /*!< */
387 INT num_result, /*!< */
388 const UCHAR *freqBandTableRef,/*!< */
389 INT num_Ref) /*!< */
390 {
391 INT step;
392 INT i,j;
393 INT org_length,result_length;
394 INT v_index[MAX_FREQ_COEFFS/2];
395
396 /* init */
397 org_length=num_Ref;
398 result_length=num_result;
399
400 v_index[0]=0; /* Always use left border */
401 i=0;
402 while(org_length > 0) /* Create downsample vector */
403 {
404 i++;
405 step=org_length/result_length; /* floor; */
406 org_length=org_length - step;
407 result_length--;
408 v_index[i]=v_index[i-1]+step;
409 }
410
411 if(i != num_result ) /* Should never happen */
412 return (1);/* error downsampling */
413
414 for(j=0;j<=i;j++) /* Use downsample vector to index LoResolution vector. */
415 {
416 v_result[j]=freqBandTableRef[v_index[j]];
417 }
418
419 return (0);
420 }
421
422 /**************************************************************************/
423 /*!
424 \brief Initialize an instance of the noise floor level estimation module.
425
426
427 \return errorCode, noError if successful
428
429 */
430 /**************************************************************************/
431 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)432 FDKsbrEnc_InitSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
433 INT ana_max_level, /*!< Maximum level of the adaptive noise. */
434 const UCHAR *freqBandTable, /*!< Frequany band table. */
435 INT nSfb, /*!< Number of frequency bands. */
436 INT noiseBands, /*!< Number of noise bands per octave. */
437 INT noiseFloorOffset, /*!< Noise floor offset. */
438 INT timeSlots, /*!< Number of time slots in a frame. */
439 UINT useSpeechConfig /*!< Flag: adapt tuning parameters according to speech */
440 )
441 {
442 INT i, qexp, qtmp;
443 FIXP_DBL tmp, exp;
444
445 FDKmemclear(h_sbrNoiseFloorEstimate,sizeof(SBR_NOISE_FLOOR_ESTIMATE));
446
447 h_sbrNoiseFloorEstimate->smoothFilter = smoothFilter;
448 if (useSpeechConfig) {
449 h_sbrNoiseFloorEstimate->weightFac = (FIXP_DBL)MAXVAL_DBL;
450 h_sbrNoiseFloorEstimate->diffThres = INVF_LOW_LEVEL;
451 }
452 else {
453 h_sbrNoiseFloorEstimate->weightFac = FL2FXCONST_DBL(0.25f);
454 h_sbrNoiseFloorEstimate->diffThres = INVF_MID_LEVEL;
455 }
456
457 h_sbrNoiseFloorEstimate->timeSlots = timeSlots;
458 h_sbrNoiseFloorEstimate->noiseBands = noiseBands;
459
460 /* h_sbrNoiseFloorEstimate->ana_max_level is scaled by 0.25 */
461 switch(ana_max_level)
462 {
463 case 6:
464 h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
465 break;
466 case 3:
467 h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.5);
468 break;
469 case -3:
470 h_sbrNoiseFloorEstimate->ana_max_level = FL2FXCONST_DBL(0.125);
471 break;
472 default:
473 /* Should not enter here */
474 h_sbrNoiseFloorEstimate->ana_max_level = (FIXP_DBL)MAXVAL_DBL;
475 break;
476 }
477
478 /*
479 calculate number of noise bands and allocate
480 */
481 if(FDKsbrEnc_resetSbrNoiseFloorEstimate(h_sbrNoiseFloorEstimate,freqBandTable,nSfb))
482 return(1);
483
484 if(noiseFloorOffset == 0) {
485 tmp = ((FIXP_DBL)MAXVAL_DBL)>>NOISE_FLOOR_OFFSET_SCALING;
486 }
487 else {
488 /* noiseFloorOffset has to be smaller than 12, because
489 the result of the calculation below must be smaller than 1:
490 (2^(noiseFloorOffset/3))*2^4<1 */
491 FDK_ASSERT(noiseFloorOffset<12);
492
493 /* Assumes the noise floor offset in tuning table are in q31 */
494 /* Change the qformat here when non-zero values would be filled */
495 exp = fDivNorm((FIXP_DBL)noiseFloorOffset, 3, &qexp);
496 tmp = fPow(2, DFRACT_BITS-1, exp, qexp, &qtmp);
497 tmp = scaleValue(tmp, qtmp-NOISE_FLOOR_OFFSET_SCALING);
498 }
499
500 for(i=0;i<h_sbrNoiseFloorEstimate->noNoiseBands;i++) {
501 h_sbrNoiseFloorEstimate->noiseFloorOffset[i] = tmp;
502 }
503
504 return (0);
505 }
506
507 /**************************************************************************/
508 /*!
509 \brief Resets the current instance of the noise floor estiamtion
510 module.
511
512
513 \return errorCode, noError if successful
514
515 */
516 /**************************************************************************/
517 INT
FDKsbrEnc_resetSbrNoiseFloorEstimate(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate,const UCHAR * freqBandTable,INT nSfb)518 FDKsbrEnc_resetSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate, /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
519 const UCHAR *freqBandTable, /*!< Frequany band table. */
520 INT nSfb) /*!< Number of bands in the frequency band table. */
521 {
522 INT k2,kx;
523
524 /*
525 * Calculate number of noise bands
526 ***********************************/
527 k2=freqBandTable[nSfb];
528 kx=freqBandTable[0];
529 if(h_sbrNoiseFloorEstimate->noiseBands == 0){
530 h_sbrNoiseFloorEstimate->noNoiseBands = 1;
531 }
532 else{
533 /*
534 * Calculate number of noise bands 1,2 or 3 bands/octave
535 ********************************************************/
536 FIXP_DBL tmp, ratio, lg2;
537 INT ratio_e, qlg2, nNoiseBands;
538
539 ratio = fDivNorm(k2, kx, &ratio_e);
540 lg2 = fLog2(ratio, ratio_e, &qlg2);
541 tmp = fMult((FIXP_DBL)(h_sbrNoiseFloorEstimate->noiseBands<<24), lg2);
542 tmp = scaleValue(tmp, qlg2-23);
543
544 nNoiseBands = (INT)((tmp + (FIXP_DBL)1) >> 1);
545
546
547 if (nNoiseBands > MAX_NUM_NOISE_COEFFS ) {
548 nNoiseBands = MAX_NUM_NOISE_COEFFS;
549 }
550
551 if( nNoiseBands == 0 ) {
552 nNoiseBands = 1;
553 }
554
555 h_sbrNoiseFloorEstimate->noNoiseBands = nNoiseBands;
556
557 }
558
559
560 return(downSampleLoRes(h_sbrNoiseFloorEstimate->freqBandTableQmf,
561 h_sbrNoiseFloorEstimate->noNoiseBands,
562 freqBandTable,nSfb));
563 }
564
565 /**************************************************************************/
566 /*!
567 \brief Deletes the current instancce of the noise floor level
568 estimation module.
569
570
571 \return none
572
573 */
574 /**************************************************************************/
575 void
FDKsbrEnc_deleteSbrNoiseFloorEstimate(HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate)576 FDKsbrEnc_deleteSbrNoiseFloorEstimate (HANDLE_SBR_NOISE_FLOOR_ESTIMATE h_sbrNoiseFloorEstimate) /*!< Handle to SBR_NOISE_FLOOR_ESTIMATE struct */
577 {
578
579 if (h_sbrNoiseFloorEstimate) {
580 /*
581 nothing to do
582 */
583 }
584 }
585