diff options
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/sf_estim.c')
-rw-r--r-- | media/libstagefright/codecs/aacenc/src/sf_estim.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/sf_estim.c b/media/libstagefright/codecs/aacenc/src/sf_estim.c index d34b365..ffe2e83 100644 --- a/media/libstagefright/codecs/aacenc/src/sf_estim.c +++ b/media/libstagefright/codecs/aacenc/src/sf_estim.c @@ -1,26 +1,26 @@ -/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** Licensed under the Apache License, Version 2.0 (the "License");
- ** you may not use this file except in compliance with the License.
- ** You may obtain a copy of the License at
- **
- ** http://www.apache.org/licenses/LICENSE-2.0
- **
- ** Unless required by applicable law or agreed to in writing, software
- ** distributed under the License is distributed on an "AS IS" BASIS,
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ** See the License for the specific language governing permissions and
- ** limitations under the License.
- */
-/*******************************************************************************
- File: sf_estim.c
-
- Content: Scale factor estimation functions
-
+/* + ** Copyright 2003-2010, VisualOn, Inc. + ** + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + */ +/******************************************************************************* + File: sf_estim.c + + Content: Scale factor estimation functions + *******************************************************************************/ -#include "basic_op.h"
+#include "basic_op.h" #include "oper_32b.h" #include "sf_estim.h" #include "quantize.h" @@ -45,12 +45,12 @@ constants reference in comments #define FF_SQRT_BITS 7 #define FF_SQRT_TABLE_SIZE (1<<FF_SQRT_BITS - 1<<(FF_SQRT_BITS-2)) -#define COEF08_31 0x66666666 /* 0.8*(1 << 31) */
-#define PE_C1_8 24 /* PE_C1*8 */
-#define PE_C2_16 21 /* PE_C2*8/PE_C3 */
-#define PE_SCALE 0x059a /* 0.7 * (1 << (15 - 1 - 3))*/
-
-#define SCALE_ESTIMATE_COEF 0x5555 /* (8.8585/(4*log2(10))) * (1 << 15)*/
+#define COEF08_31 0x66666666 /* 0.8*(1 << 31) */ +#define PE_C1_8 24 /* PE_C1*8 */ +#define PE_C2_16 21 /* PE_C2*8/PE_C3 */ +#define PE_SCALE 0x059a /* 0.7 * (1 << (15 - 1 - 3))*/ + +#define SCALE_ESTIMATE_COEF 0x5555 /* (8.8585/(4*log2(10))) * (1 << 15)*/ /********************************************************************************* * @@ -69,17 +69,17 @@ __inline Word32 formfac_sqrt(Word32 x) postshift = preshift >> 1; preshift = postshift << 1; postshift = postshift + 8; /* sqrt/256 */ - if(preshift >= 0)
- y = x << preshift; /* now 1/4 <= y < 1 */
- else
- y = x >> (-preshift);
- y = formfac_sqrttable[y-32];
-
- if(postshift >= 0)
- y = y >> postshift;
- else
- y = y << (-postshift);
-
+ if(preshift >= 0) + y = x << preshift; /* now 1/4 <= y < 1 */ + else + y = x >> (-preshift); + y = formfac_sqrttable[y-32]; + + if(postshift >= 0) + y = y >> postshift; + else + y = y << (-postshift); + return y; } @@ -97,25 +97,25 @@ CalcFormFactorChannel(Word16 *logSfbFormFactor, Word16 *logSfbEnergy, PSY_OUT_CHANNEL *psyOutChan) { - Word32 sfbw, sfbw1;
+ Word32 sfbw, sfbw1; Word32 i, j; Word32 sfbOffs, sfb, shift; -
- sfbw = sfbw1 = 0;
+ + sfbw = sfbw1 = 0; for (sfbOffs=0; sfbOffs<psyOutChan->sfbCnt; sfbOffs+=psyOutChan->sfbPerGroup){ for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) { i = sfbOffs+sfb; if (psyOutChan->sfbEnergy[i] > psyOutChan->sfbThreshold[i]) { - Word32 accu, avgFormFactor,iSfbWidth;
+ Word32 accu, avgFormFactor,iSfbWidth; Word32 *mdctSpec; - sfbw = psyOutChan->sfbOffsets[i+1] - psyOutChan->sfbOffsets[i];
- iSfbWidth = invSBF[(sfbw >> 2) - 1];
+ sfbw = psyOutChan->sfbOffsets[i+1] - psyOutChan->sfbOffsets[i]; + iSfbWidth = invSBF[(sfbw >> 2) - 1]; mdctSpec = psyOutChan->mdctSpectrum + psyOutChan->sfbOffsets[i]; accu = 0; /* calc sum of sqrt(spec) */ - for (j=sfbw; j; j--) {
- accu += formfac_sqrt(L_abs(*mdctSpec)); mdctSpec++;
+ for (j=sfbw; j; j--) { + accu += formfac_sqrt(L_abs(*mdctSpec)); mdctSpec++; } logSfbFormFactor[i] = iLog4(accu); logSfbEnergy[i] = iLog4(psyOutChan->sfbEnergy[i]); @@ -158,8 +158,8 @@ static Word16 improveScf(Word32 *spec, /* calc real distortion */ sfbDist = calcSfbDist(spec, sfbWidth, scf); - *minScfCalculated = scf;
- if(!sfbDist)
+ *minScfCalculated = scf; + if(!sfbDist) return scfBest; if (sfbDist > thresh125) { @@ -194,7 +194,7 @@ static Word16 improveScf(Word32 *spec, } *minScfCalculated = scf; cnt = cnt + 1; - }
+ } *dist = sfbDistBest; } else { @@ -419,7 +419,7 @@ static void assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, prevScfLast[j] = MAX_16; prevScfNext[j] = MAX_16; deltaPeLast[j] = MAX_16; - }
+ } sfbLast = -1; sfbAct = -1; @@ -713,20 +713,20 @@ EstimateScaleFactorsChannel(PSY_OUT_CHANNEL *psyOutChan, for (i=0; i<psyOutChan->sfbCnt; i++) { - Word32 sbfwith, sbfStart;
+ Word32 sbfwith, sbfStart; Word32 *mdctSpec; thresh = psyOutChan->sfbThreshold[i]; energy = psyOutChan->sfbEnergy[i]; -
- sbfStart = psyOutChan->sfbOffsets[i];
- sbfwith = psyOutChan->sfbOffsets[i+1] - sbfStart;
- mdctSpec = psyOutChan->mdctSpectrum+sbfStart;
+ + sbfStart = psyOutChan->sfbOffsets[i]; + sbfwith = psyOutChan->sfbOffsets[i+1] - sbfStart; + mdctSpec = psyOutChan->mdctSpectrum+sbfStart; maxSpec = 0; /* maximum of spectrum */ - for (j=sbfwith; j; j-- ) {
- Word32 absSpec = L_abs(*mdctSpec); mdctSpec++;
- maxSpec |= absSpec;
+ for (j=sbfwith; j; j-- ) { + Word32 absSpec = L_abs(*mdctSpec); mdctSpec++; + maxSpec |= absSpec; } /* scfs without energy or with thresh>energy are marked with MIN_16 */ @@ -737,7 +737,7 @@ EstimateScaleFactorsChannel(PSY_OUT_CHANNEL *psyOutChan, energyPart = logSfbFormFactor[i]; thresholdPart = iLog4(thresh); - /* -20 = 4*log2(6.75) - 32 */
+ /* -20 = 4*log2(6.75) - 32 */ scfInt = ((thresholdPart - energyPart - 20) * SCALE_ESTIMATE_COEF) >> 15; minSfMaxQuant[i] = iLog4(maxSpec) - 68; /* 68 -16/3*log(MAX_QUANT+0.5-logCon)/log(2) + 1 */ @@ -748,9 +748,9 @@ EstimateScaleFactorsChannel(PSY_OUT_CHANNEL *psyOutChan, } /* find better scalefactor with analysis by synthesis */ - scfInt = improveScf(psyOutChan->mdctSpectrum+sbfStart,
- sbfwith,
- thresh, scfInt, minSfMaxQuant[i],
+ scfInt = improveScf(psyOutChan->mdctSpectrum+sbfStart, + sbfwith, + thresh, scfInt, minSfMaxQuant[i], &sfbDist[i], &minScfCalculated[i]); scf[i] = scfInt; |