summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacenc/src/adj_thr.c
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/adj_thr.c')
-rw-r--r--media/libstagefright/codecs/aacenc/src/adj_thr.c364
1 files changed, 182 insertions, 182 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/adj_thr.c b/media/libstagefright/codecs/aacenc/src/adj_thr.c
index 83b43a1..c656f65 100644
--- a/media/libstagefright/codecs/aacenc/src/adj_thr.c
+++ b/media/libstagefright/codecs/aacenc/src/adj_thr.c
@@ -71,7 +71,7 @@ static void calcThreshExp(Word32 thrExp[MAX_CHANNELS][MAX_GROUPED_SFB],
Word32 *pthrExp, *psfbThre;
for (ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
- for(sfbGrp = 0; sfbGrp < psyOutChan->sfbCnt; sfbGrp+= psyOutChan->sfbPerGroup)
+ for(sfbGrp = 0; sfbGrp < psyOutChan->sfbCnt; sfbGrp+= psyOutChan->sfbPerGroup)
pthrExp = &(thrExp[ch][sfbGrp]);
psfbThre = psyOutChan->sfbThreshold + sfbGrp;
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
@@ -96,21 +96,21 @@ static void adaptMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
Word32 nSfb, avgEn;
Word16 log_avgEn = 0;
Word32 startRatio_x_avgEn = 0;
-
+
for (ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL* psyOutChan = &psyOutChannel[ch];
/* calc average energy per scalefactor band */
- avgEn = 0;
- nSfb = 0;
+ avgEn = 0;
+ nSfb = 0;
for (sfbOffs=0; sfbOffs<psyOutChan->sfbCnt; sfbOffs+=psyOutChan->sfbPerGroup) {
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
avgEn = L_add(avgEn, psyOutChan->sfbEnergy[sfbOffs+sfb]);
nSfb = nSfb + 1;
}
}
-
+
if (nSfb > 0) {
avgEn = avgEn / nSfb;
@@ -118,7 +118,7 @@ static void adaptMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
startRatio_x_avgEn = fixmul(msaParam->startRatio, avgEn);
}
-
+
/* reduce minSnr requirement by minSnr^minSnrRed dependent on avgEn/sfbEn */
for (sfbOffs=0; sfbOffs<psyOutChan->sfbCnt; sfbOffs+=psyOutChan->sfbPerGroup) {
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
@@ -126,22 +126,22 @@ static void adaptMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
Word16 dbRatio, minSnrRed;
Word32 snrRed;
Word16 newMinSnr;
-
+
dbRatio = log_avgEn - logSfbEnergy[ch][sfbOffs+sfb];
dbRatio = dbRatio + (dbRatio << 1);
minSnrRed = 110 - ((dbRatio + (dbRatio << 1)) >> 2);
- minSnrRed = max(minSnrRed, 20); /* 110: (0.375(redOffs)+1)*80,
+ minSnrRed = max(minSnrRed, 20); /* 110: (0.375(redOffs)+1)*80,
3: 0.00375(redRatioFac)*80
20: 0.25(maxRed) * 80 */
- snrRed = minSnrRed * iLog4((psyOutChan->sfbMinSnr[sfbOffs+sfb] << 16));
- /*
+ snrRed = minSnrRed * iLog4((psyOutChan->sfbMinSnr[sfbOffs+sfb] << 16));
+ /*
snrRedI si now scaled by 80 (minSnrRed) and 4 (ffr_iLog4)
*/
-
+
newMinSnr = round16(pow2_xy(snrRed,80*4));
-
+
psyOutChan->sfbMinSnr[sfbOffs+sfb] = min(newMinSnr, minSnrLimit);
}
}
@@ -169,7 +169,7 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
for (ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
-
+
if (psyOutChan->windowSequence != SHORT_WINDOW) {
for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
psfbSpreadEn = psyOutChan->sfbSpreadedEnergy + sfbGrp;
@@ -194,7 +194,7 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
if (ahParam->modifyMinSnr) {
for(ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
-
+
if (psyOutChan->windowSequence != SHORT_WINDOW)
threshold = HOLE_THR_LONG;
else
@@ -204,39 +204,39 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
Word16 *psfbMinSnr = psyOutChan->sfbMinSnr + sfbGrp;
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
Word32 sfbEn, sfbEnm1, sfbEnp1, avgEn;
-
+
if (sfb > 0)
sfbEnm1 = psyOutChan->sfbEnergy[sfbGrp+sfb-1];
else
sfbEnm1 = psyOutChan->sfbEnergy[sfbGrp];
-
+
if (sfb < (psyOutChan->maxSfbPerGroup-1))
sfbEnp1 = psyOutChan->sfbEnergy[sfbGrp+sfb+1];
else
sfbEnp1 = psyOutChan->sfbEnergy[sfbGrp+sfb];
avgEn = (sfbEnm1 + sfbEnp1) >> 1;
- sfbEn = psyOutChan->sfbEnergy[sfbGrp+sfb];
-
+ sfbEn = psyOutChan->sfbEnergy[sfbGrp+sfb];
+
if (sfbEn > avgEn && avgEn > 0) {
Word32 tmpMinSnr;
shift = norm_l(sfbEn);
tmpMinSnr = Div_32(L_mpy_ls(avgEn, minSnrLimit) << shift, sfbEn << shift );
- tmpMinSnr = max(tmpMinSnr, HOLE_THR_LONG);
+ tmpMinSnr = max(tmpMinSnr, HOLE_THR_LONG);
tmpMinSnr = max(tmpMinSnr, threshold);
*psfbMinSnr = min(*psfbMinSnr, tmpMinSnr);
}
/* valley ? */
-
+
if ((sfbEn < (avgEn >> 1)) && (sfbEn > 0)) {
Word32 tmpMinSnr;
- Word32 minSnrEn = L_mpy_wx(avgEn, *psfbMinSnr);
-
+ Word32 minSnrEn = L_mpy_wx(avgEn, *psfbMinSnr);
+
if(minSnrEn < sfbEn) {
shift = norm_l(sfbEn);
tmpMinSnr = Div_32( minSnrEn << shift, sfbEn<<shift);
}
else {
- tmpMinSnr = MAX_16;
+ tmpMinSnr = MAX_16;
}
tmpMinSnr = min(minSnrLimit, tmpMinSnr);
@@ -251,7 +251,7 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
/* stereo: adapt the minimum requirements sfbMinSnr of mid and
side channels */
-
+
if (nChannels == 2) {
PSY_OUT_CHANNEL *psyOutChanM = &psyOutChannel[0];
PSY_OUT_CHANNEL *psyOutChanS = &psyOutChannel[1];
@@ -260,30 +260,30 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
Word32 sfbEnM = psyOutChanM->sfbEnergy[sfb];
Word32 sfbEnS = psyOutChanS->sfbEnergy[sfb];
Word32 maxSfbEn = max(sfbEnM, sfbEnS);
- Word32 maxThr = L_mpy_wx(maxSfbEn, psyOutChanM->sfbMinSnr[sfb]) >> 1;
-
+ Word32 maxThr = L_mpy_wx(maxSfbEn, psyOutChanM->sfbMinSnr[sfb]) >> 1;
+
if(maxThr >= sfbEnM) {
- psyOutChanM->sfbMinSnr[sfb] = MAX_16;
+ psyOutChanM->sfbMinSnr[sfb] = MAX_16;
}
else {
- shift = norm_l(sfbEnM);
- psyOutChanM->sfbMinSnr[sfb] = min(max(psyOutChanM->sfbMinSnr[sfb],
+ shift = norm_l(sfbEnM);
+ psyOutChanM->sfbMinSnr[sfb] = min(max(psyOutChanM->sfbMinSnr[sfb],
round16(Div_32(maxThr<<shift, sfbEnM << shift))), minSnrLimit);
}
-
+
if(maxThr >= sfbEnS) {
psyOutChanS->sfbMinSnr[sfb] = MAX_16;
}
else {
shift = norm_l(sfbEnS);
- psyOutChanS->sfbMinSnr[sfb] = min(max(psyOutChanS->sfbMinSnr[sfb],
+ psyOutChanS->sfbMinSnr[sfb] = min(max(psyOutChanS->sfbMinSnr[sfb],
round16(Div_32(maxThr << shift, sfbEnS << shift))), minSnrLimit);
}
-
+
if (sfbEnM > psyOutChanM->sfbSpreadedEnergy[sfb])
psyOutChanS->sfbSpreadedEnergy[sfb] = L_mpy_ls(sfbEnS, MS_THRSPREAD_COEF);
-
+
if (sfbEnS > psyOutChanS->sfbSpreadedEnergy[sfb])
psyOutChanM->sfbSpreadedEnergy[sfb] = L_mpy_ls(sfbEnM, MS_THRSPREAD_COEF);
}
@@ -297,7 +297,7 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
Word16 *pahFlag = ahFlag[ch] + sfbGrp;
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
-
+
if ((psyOutChan->sfbSpreadedEnergy[sfbGrp+sfb] > psyOutChan->sfbEnergy[sfbGrp+sfb]) ||
(psyOutChan->sfbEnergy[sfbGrp+sfb] <= psyOutChan->sfbThreshold[sfbGrp+sfb]) ||
(psyOutChan->sfbMinSnr[sfbGrp+sfb] == MAX_16)) {
@@ -308,7 +308,7 @@ static void initAvoidHoleFlag(Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
}
}
for (sfb=psyOutChan->maxSfbPerGroup; sfb<psyOutChan->sfbPerGroup; sfb++) {
- *pahFlag++ = NO_AH;
+ *pahFlag++ = NO_AH;
}
}
}
@@ -331,15 +331,15 @@ static void calcPeNoAH(Word16 *pe,
Word16 ch, sfb, sfbGrp;
int ipe, iconstPart, inActiveLines;
- ipe = 0;
- iconstPart = 0;
- inActiveLines = 0;
+ ipe = 0;
+ iconstPart = 0;
+ inActiveLines = 0;
for(ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
PE_CHANNEL_DATA *peChanData = &peData->peChannelData[ch];
for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup){
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
-
+
if (ahFlag[ch][sfbGrp+sfb] < AH_ACTIVE) {
ipe = ipe + peChanData->sfbPe[sfbGrp+sfb];
iconstPart = iconstPart + peChanData->sfbConstPart[sfbGrp+sfb];
@@ -349,9 +349,9 @@ static void calcPeNoAH(Word16 *pe,
}
}
- *pe = saturate(ipe);
- *constPart = saturate(iconstPart);
- *nActiveLines = saturate(inActiveLines);
+ *pe = saturate(ipe);
+ *constPart = saturate(iconstPart);
+ *nActiveLines = saturate(inActiveLines);
}
/********************************************************************************
@@ -367,16 +367,16 @@ static void reduceThresholds(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
const Word32 redVal)
{
Word32 sfbThrReduced;
- Word32 *psfbEn, *psfbThr;
+ Word32 *psfbEn, *psfbThr;
Word16 ch, sfb, sfbGrp;
for(ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
for(sfbGrp=0; sfbGrp<psyOutChan->sfbCnt; sfbGrp+=psyOutChan->sfbPerGroup) {
- psfbEn = psyOutChan->sfbEnergy + sfbGrp;
+ psfbEn = psyOutChan->sfbEnergy + sfbGrp;
psfbThr = psyOutChan->sfbThreshold + sfbGrp;
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
-
+
if (*psfbEn > *psfbThr) {
/* threshold reduction formula */
Word32 tmp = thrExp[ch][sfbGrp+sfb] + redVal;
@@ -384,11 +384,11 @@ static void reduceThresholds(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
sfbThrReduced = fixmul(tmp, tmp);
/* avoid holes */
tmp = L_mpy_ls(*psfbEn, psyOutChan->sfbMinSnr[sfbGrp+sfb]);
-
- if ((sfbThrReduced > tmp) &&
+
+ if ((sfbThrReduced > tmp) &&
(ahFlag[ch][sfbGrp+sfb] != NO_AH)){
sfbThrReduced = max(tmp, *psfbThr);
- ahFlag[ch][sfbGrp+sfb] = AH_ACTIVE;
+ ahFlag[ch][sfbGrp+sfb] = AH_ACTIVE;
}
*psfbThr = sfbThrReduced;
}
@@ -426,7 +426,7 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
Word32 sfbThrReduced;
/* for each sfb calc relative factors for pe changes */
- normFactor = 1;
+ normFactor = 1;
for(ch=0; ch<nChannels; ch++) {
psyOutChan = &psyOutChannel[ch];
peChanData = &peData->peChannelData[ch];
@@ -436,22 +436,22 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
pahFlag = ahFlag[ch] + sfbGrp;
for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {
Word32 redThrExp = thrExp[ch][sfbGrp+sfb] + redVal;
-
+
if (((*pahFlag < AH_ACTIVE) || (deltaPe > 0)) && (redThrExp > 0) ) {
-
+
*psfbPeFactors = (*psfbNActiveLines) * (0x7fffffff / redThrExp);
normFactor = L_add(normFactor, *psfbPeFactors);
}
else {
- *psfbPeFactors = 0;
+ *psfbPeFactors = 0;
}
- psfbPeFactors++;
+ psfbPeFactors++;
pahFlag++; psfbNActiveLines++;
}
}
}
-
+
/* calculate new thresholds */
for(ch=0; ch<nChannels; ch++) {
psyOutChan = &psyOutChannel[ch];
@@ -464,7 +464,7 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/* pe difference for this sfb */
deltaSfbPe = *psfbPeFactors * deltaPe;
- /* thr3(n) = thr2(n)*2^deltaSfbPe/b(n) */
+ /* thr3(n) = thr2(n)*2^deltaSfbPe/b(n) */
if (*psfbNActiveLines > 0) {
/* new threshold */
Word32 thrFactor;
@@ -476,7 +476,7 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
reduce threshold
*/
thrFactor = pow2_xy(L_negate(deltaSfbPe), (normFactor* (*psfbNActiveLines)));
-
+
sfbThrReduced = L_mpy_ls(sfbThr, round16(thrFactor));
}
else {
@@ -484,28 +484,28 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
increase threshold
*/
thrFactor = pow2_xy(deltaSfbPe, (normFactor * (*psfbNActiveLines)));
-
-
+
+
if(thrFactor > sfbThr) {
shift = norm_l(thrFactor);
sfbThrReduced = Div_32( sfbThr << shift, thrFactor<<shift );
}
else {
- sfbThrReduced = MAX_32;
+ sfbThrReduced = MAX_32;
}
}
-
+
/* avoid hole */
sfbEn = L_mpy_ls(sfbEn, psyOutChan->sfbMinSnr[sfbGrp+sfb]);
-
+
if ((sfbThrReduced > sfbEn) &&
(*pahFlag == AH_INACTIVE)) {
sfbThrReduced = max(sfbEn, sfbThr);
- *pahFlag = AH_ACTIVE;
+ *pahFlag = AH_ACTIVE;
}
- psyOutChan->sfbThreshold[sfbGrp+sfb] = sfbThrReduced;
+ psyOutChan->sfbThreshold[sfbGrp+sfb] = sfbThrReduced;
}
pahFlag++; psfbNActiveLines++; psfbPeFactors++;
@@ -521,8 +521,8 @@ static void correctThresh(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
* description: if the desired pe can not be reached, reduce pe by reducing minSnr
*
**********************************************************************************/
-static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
- PE_DATA *peData,
+static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
+ PE_DATA *peData,
Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
const Word16 nChannels,
const Word16 desiredPe)
@@ -531,9 +531,9 @@ static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
Word16 deltaPe;
/* start at highest freq down to 0 */
- sfbSubWin = psyOutChannel[0].maxSfbPerGroup;
+ sfbSubWin = psyOutChannel[0].maxSfbPerGroup;
while (peData->pe > desiredPe && sfbSubWin > 0) {
-
+
sfbSubWin = sfbSubWin - 1;
/* loop over all subwindows */
for (sfb=sfbSubWin; sfb<psyOutChannel[0].sfbCnt;
@@ -541,10 +541,10 @@ static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/* loop over all channels */
PE_CHANNEL_DATA* peChan = peData->peChannelData;
PSY_OUT_CHANNEL* psyOutCh = psyOutChannel;
- for (ch=0; ch<nChannels; ch++) {
+ for (ch=0; ch<nChannels; ch++) {
if (ahFlag[ch][sfb] != NO_AH &&
psyOutCh->sfbMinSnr[sfb] < minSnrLimit) {
- psyOutCh->sfbMinSnr[sfb] = minSnrLimit;
+ psyOutCh->sfbMinSnr[sfb] = minSnrLimit;
psyOutCh->sfbThreshold[sfb] =
L_mpy_ls(psyOutCh->sfbEnergy[sfb], psyOutCh->sfbMinSnr[sfb]);
@@ -552,12 +552,12 @@ static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
deltaPe = ((peChan->sfbNLines4[sfb] + (peChan->sfbNLines4[sfb] >> 1)) >> 2) -
peChan->sfbPe[sfb];
peData->pe = peData->pe + deltaPe;
- peChan->pe = peChan->pe + deltaPe;
+ peChan->pe = peChan->pe + deltaPe;
}
peChan += 1; psyOutCh += 1;
}
/* stop if enough has been saved */
-
+
if (peData->pe <= desiredPe)
break;
}
@@ -567,13 +567,13 @@ static void reduceMinSnr(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/********************************************************************************
*
* function name:allowMoreHoles
-* description: if the desired pe can not be reached, some more scalefactor bands
+* description: if the desired pe can not be reached, some more scalefactor bands
* have to be quantized to zero
*
**********************************************************************************/
-static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
+static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
PSY_OUT_ELEMENT *psyOutElement,
- PE_DATA *peData,
+ PE_DATA *peData,
Word16 ahFlag[MAX_CHANNELS][MAX_GROUPED_SFB],
const AH_PARAM *ahParam,
const Word16 nChannels,
@@ -582,46 +582,46 @@ static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
Word16 ch, sfb;
Word16 actPe, shift;
- actPe = peData->pe;
+ actPe = peData->pe;
/* for MS allow hole in the channel with less energy */
-
+
if (nChannels==2 &&
psyOutChannel[0].windowSequence==psyOutChannel[1].windowSequence) {
PSY_OUT_CHANNEL *psyOutChanL = &psyOutChannel[0];
PSY_OUT_CHANNEL *psyOutChanR = &psyOutChannel[1];
for (sfb=0; sfb<psyOutChanL->sfbCnt; sfb++) {
Word32 minEn;
-
+
if (psyOutElement->toolsInfo.msMask[sfb]) {
/* allow hole in side channel ? */
minEn = L_mpy_ls(psyOutChanL->sfbEnergy[sfb], (minSnrLimit * psyOutChanL->sfbMinSnr[sfb]) >> 16);
-
+
if (ahFlag[1][sfb] != NO_AH &&
minEn > psyOutChanR->sfbEnergy[sfb]) {
- ahFlag[1][sfb] = NO_AH;
+ ahFlag[1][sfb] = NO_AH;
psyOutChanR->sfbThreshold[sfb] = L_add(psyOutChanR->sfbEnergy[sfb], psyOutChanR->sfbEnergy[sfb]);
actPe = actPe - peData->peChannelData[1].sfbPe[sfb];
}
/* allow hole in mid channel ? */
else {
minEn = L_mpy_ls(psyOutChanR->sfbEnergy[sfb], (minSnrLimit * psyOutChanR->sfbMinSnr[sfb]) >> 16);
-
+
if (ahFlag[0][sfb]!= NO_AH &&
minEn > psyOutChanL->sfbEnergy[sfb]) {
- ahFlag[0][sfb] = NO_AH;
+ ahFlag[0][sfb] = NO_AH;
psyOutChanL->sfbThreshold[sfb] = L_add(psyOutChanL->sfbEnergy[sfb], psyOutChanL->sfbEnergy[sfb]);
actPe = actPe - peData->peChannelData[0].sfbPe[sfb];
}
}
-
+
if (actPe < desiredPe)
break;
}
}
}
- /* subsequently erase bands */
+ /* subsequently erase bands */
if (actPe > desiredPe) {
Word16 startSfb[2];
Word32 avgEn, minEn;
@@ -634,20 +634,20 @@ static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/* do not go below startSfb */
for (ch=0; ch<nChannels; ch++) {
-
+
if (psyOutChannel[ch].windowSequence != SHORT_WINDOW)
startSfb[ch] = ahParam->startSfbL;
else
startSfb[ch] = ahParam->startSfbS;
}
- avgEn = 0;
- minEn = MAX_32;
- ahCnt = 0;
+ avgEn = 0;
+ minEn = MAX_32;
+ ahCnt = 0;
for (ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
for (sfb=startSfb[ch]; sfb<psyOutChan->sfbCnt; sfb++) {
-
+
if ((ahFlag[ch][sfb] != NO_AH) &&
(psyOutChan->sfbEnergy[sfb] > psyOutChan->sfbThreshold[sfb])) {
minEn = min(minEn, psyOutChan->sfbEnergy[sfb]);
@@ -656,7 +656,7 @@ static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
}
}
}
-
+
if(ahCnt) {
Word32 iahCnt;
shift = norm_l(ahCnt);
@@ -674,46 +674,46 @@ static void allowMoreHoles(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/* start with lowest energy border at highest sfb */
maxSfb = psyOutChannel[0].sfbCnt - 1;
- minSfb = startSfb[0];
-
+ minSfb = startSfb[0];
+
if (nChannels == 2) {
maxSfb = max(maxSfb, (psyOutChannel[1].sfbCnt - 1));
minSfb = min(minSfb, startSfb[1]);
}
- sfb = maxSfb;
- enIdx = 0;
- done = 0;
+ sfb = maxSfb;
+ enIdx = 0;
+ done = 0;
while (!done) {
-
+
for (ch=0; ch<nChannels; ch++) {
PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];
-
+
if (sfb>=startSfb[ch] && sfb<psyOutChan->sfbCnt) {
/* sfb energy below border ? */
-
+
if (ahFlag[ch][sfb] != NO_AH && psyOutChan->sfbEnergy[sfb] < en[enIdx]){
/* allow hole */
- ahFlag[ch][sfb] = NO_AH;
+ ahFlag[ch][sfb] = NO_AH;
psyOutChan->sfbThreshold[sfb] = L_add(psyOutChan->sfbEnergy[sfb], psyOutChan->sfbEnergy[sfb]);
actPe = actPe - peData->peChannelData[ch].sfbPe[sfb];
}
-
+
if (actPe < desiredPe) {
- done = 1;
+ done = 1;
break;
}
}
}
sfb = sfb - 1;
-
+
if (sfb < minSfb) {
/* restart with next energy border */
- sfb = maxSfb;
+ sfb = maxSfb;
enIdx = enIdx + 1;
-
+
if (enIdx - 4 >= 0)
- done = 1;
+ done = 1;
}
}
}
@@ -748,13 +748,13 @@ static void adaptThresholdsToPe(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
initAvoidHoleFlag(peData->ahFlag, psyOutChannel, psyOutElement, nChannels, ahParam);
- noRedPe = peData->pe;
- constPart = peData->constPart;
- nActiveLines = peData->nActiveLines;
+ noRedPe = peData->pe;
+ constPart = peData->constPart;
+ nActiveLines = peData->nActiveLines;
/* first guess of reduction value t^0.25 = 2^((a-pen)/4*b) */
avgThrExp = pow2_xy((constPart - noRedPe), (nActiveLines << 2));
-
+
/* r1 = 2^((a-per)/4*b) - t^0.25 */
redVal = pow2_xy((constPart - desiredPe), (nActiveLines << 2)) - avgThrExp;
@@ -763,40 +763,40 @@ static void adaptThresholdsToPe(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
/* pe after first guess */
calcSfbPe(peData, psyOutChannel, nChannels);
- redPe = peData->pe;
+ redPe = peData->pe;
- iter = 0;
+ iter = 0;
do {
/* pe for bands where avoid hole is inactive */
calcPeNoAH(&redPeNoAH, &constPartNoAH, &nActiveLinesNoAH,
peData, peData->ahFlag, psyOutChannel, nChannels);
desiredPeNoAH = desiredPe -(redPe - redPeNoAH);
-
+
if (desiredPeNoAH < 0) {
- desiredPeNoAH = 0;
+ desiredPeNoAH = 0;
}
/* second guess */
-
+
if (nActiveLinesNoAH > 0) {
-
+
avgThrExp = pow2_xy((constPartNoAH - redPeNoAH), (nActiveLinesNoAH << 2));
-
+
redVal = (redVal + pow2_xy((constPartNoAH - desiredPeNoAH), (nActiveLinesNoAH << 2))) - avgThrExp;
-
+
/* reduce thresholds */
reduceThresholds(psyOutChannel, peData->ahFlag, peData->thrExp, nChannels, redVal);
}
calcSfbPe(peData, psyOutChannel, nChannels);
- redPe = peData->pe;
+ redPe = peData->pe;
iter = iter+1;
-
+
} while ((20 * abs_s(redPe - desiredPe) > desiredPe) && (iter < 2));
-
+
if ((100 * redPe < 115 * desiredPe)) {
correctThresh(psyOutChannel, peData->ahFlag, peData, peData->thrExp, redVal,
nChannels, desiredPe - redPe);
@@ -863,7 +863,7 @@ static Word16 calcBitSpend(Word16 fillLevel,
if(clipHigh-clipLow)
bitspend = (minBitSpend + ((maxBitSpend - minBitSpend)*(fillLevel - clipLow) /
(clipHigh-clipLow)));
-
+
return (bitspend);
}
@@ -884,19 +884,19 @@ static void adjustPeMinMax(const Word16 currPe,
Word16 minFacHi, maxFacHi, minFacLo, maxFacLo;
Word16 diff;
Word16 minDiff = extract_l(currPe / 6);
- minFacHi = 30;
- maxFacHi = 100;
- minFacLo = 14;
- maxFacLo = 7;
+ minFacHi = 30;
+ maxFacHi = 100;
+ minFacLo = 14;
+ maxFacLo = 7;
diff = currPe - *peMax ;
-
+
if (diff > 0) {
*peMin = *peMin + ((diff * minFacHi) / 100);
*peMax = *peMax + ((diff * maxFacHi) / 100);
} else {
diff = *peMin - currPe;
-
+
if (diff > 0) {
*peMin = *peMin - ((diff * minFacLo) / 100);
*peMax = *peMax - ((diff * maxFacLo) / 100);
@@ -906,7 +906,7 @@ static void adjustPeMinMax(const Word16 currPe,
}
}
-
+
if ((*peMax - *peMin) < minDiff) {
Word16 partLo, partHi;
@@ -969,7 +969,7 @@ static Word16 bitresCalcBitFac( const Word16 bitresBits,
(adjThrChan->peMax - adjThrChan->peMin));
else
bitresFac = 0x7fff;
-
+
bitresFac = min(bitresFac,
(100-30 + extract_l((100 * bitresBits) / avgBits)));
@@ -995,23 +995,23 @@ void AdjThrInit(ADJ_THR_STATE *hAdjThr,
/* common for all elements: */
/* parameters for bitres control */
- hAdjThr->bresParamLong.clipSaveLow = 20;
- hAdjThr->bresParamLong.clipSaveHigh = 95;
- hAdjThr->bresParamLong.minBitSave = -5;
- hAdjThr->bresParamLong.maxBitSave = 30;
- hAdjThr->bresParamLong.clipSpendLow = 20;
- hAdjThr->bresParamLong.clipSpendHigh = 95;
- hAdjThr->bresParamLong.minBitSpend = -10;
- hAdjThr->bresParamLong.maxBitSpend = 40;
-
- hAdjThr->bresParamShort.clipSaveLow = 20;
- hAdjThr->bresParamShort.clipSaveHigh = 75;
- hAdjThr->bresParamShort.minBitSave = 0;
- hAdjThr->bresParamShort.maxBitSave = 20;
- hAdjThr->bresParamShort.clipSpendLow = 20;
- hAdjThr->bresParamShort.clipSpendHigh = 75;
- hAdjThr->bresParamShort.minBitSpend = -5;
- hAdjThr->bresParamShort.maxBitSpend = 50;
+ hAdjThr->bresParamLong.clipSaveLow = 20;
+ hAdjThr->bresParamLong.clipSaveHigh = 95;
+ hAdjThr->bresParamLong.minBitSave = -5;
+ hAdjThr->bresParamLong.maxBitSave = 30;
+ hAdjThr->bresParamLong.clipSpendLow = 20;
+ hAdjThr->bresParamLong.clipSpendHigh = 95;
+ hAdjThr->bresParamLong.minBitSpend = -10;
+ hAdjThr->bresParamLong.maxBitSpend = 40;
+
+ hAdjThr->bresParamShort.clipSaveLow = 20;
+ hAdjThr->bresParamShort.clipSaveHigh = 75;
+ hAdjThr->bresParamShort.minBitSave = 0;
+ hAdjThr->bresParamShort.maxBitSave = 20;
+ hAdjThr->bresParamShort.clipSpendLow = 20;
+ hAdjThr->bresParamShort.clipSpendHigh = 75;
+ hAdjThr->bresParamShort.minBitSpend = -5;
+ hAdjThr->bresParamShort.maxBitSpend = 50;
/* specific for each element: */
@@ -1020,7 +1020,7 @@ void AdjThrInit(ADJ_THR_STATE *hAdjThr,
atsElem->peMax = extract_l(((120*meanPe) / 100));
/* additional pe offset to correct pe2bits for low bitrates */
- atsElem->peOffset = 0;
+ atsElem->peOffset = 0;
if (chBitrate < 32000) {
atsElem->peOffset = max(50, (100 - extract_l((100 * chBitrate) / 32000)));
}
@@ -1039,24 +1039,24 @@ void AdjThrInit(ADJ_THR_STATE *hAdjThr,
/* minSnr adaptation */
/* maximum reduction of minSnr goes down to minSnr^maxRed */
- msaParam->maxRed = 0x20000000; /* *0.25f /
+ msaParam->maxRed = 0x20000000; /* *0.25f /
/* start adaptation of minSnr for avgEn/sfbEn > startRatio */
- msaParam->startRatio = 0x0ccccccd; /* 10 */
+ msaParam->startRatio = 0x0ccccccd; /* 10 */
/* maximum minSnr reduction to minSnr^maxRed is reached for
avgEn/sfbEn >= maxRatio */
- msaParam->maxRatio = 0x0020c49c; /* 1000 */
+ msaParam->maxRatio = 0x0020c49c; /* 1000 */
/* helper variables to interpolate minSnr reduction for
avgEn/sfbEn between startRatio and maxRatio */
- msaParam->redRatioFac = 0xfb333333; /* -0.75/20 */
+ msaParam->redRatioFac = 0xfb333333; /* -0.75/20 */
+
+ msaParam->redOffs = 0x30000000; /* msaParam->redRatioFac * 10*log10(msaParam->startRatio) */
- msaParam->redOffs = 0x30000000; /* msaParam->redRatioFac * 10*log10(msaParam->startRatio) */
-
/* pe correction */
- atsElem->peLast = 0;
- atsElem->dynBitsLast = 0;
- atsElem->peCorrectionFactor = 100; /* 1.0 */
+ atsElem->peLast = 0;
+ atsElem->dynBitsLast = 0;
+ atsElem->peCorrectionFactor = 100; /* 1.0 */
}
@@ -1069,20 +1069,20 @@ void AdjThrInit(ADJ_THR_STATE *hAdjThr,
*****************************************************************************/
static void calcPeCorrection(Word16 *correctionFac,
const Word16 peAct,
- const Word16 peLast,
- const Word16 bitsLast)
+ const Word16 peLast,
+ const Word16 bitsLast)
{
Word32 peAct100 = 100 * peAct;
Word32 peLast100 = 100 * peLast;
Word16 peBitsLast = bits2pe(bitsLast);
-
+
if ((bitsLast > 0) &&
(peAct100 < (150 * peLast)) && (peAct100 > (70 * peLast)) &&
((120 * peBitsLast) > peLast100 ) && (( 65 * peBitsLast) < peLast100))
{
Word16 newFac = (100 * peLast) / peBitsLast;
/* dead zone */
-
+
if (newFac < 100) {
newFac = min(((110 * newFac) / 100), 100);
newFac = max(newFac, 85);
@@ -1091,13 +1091,13 @@ static void calcPeCorrection(Word16 *correctionFac,
newFac = max(((90 * newFac) / 100), 100);
newFac = min(newFac, 115);
}
-
+
if ((newFac > 100 && *correctionFac < 100) ||
(newFac < 100 && *correctionFac > 100)) {
- *correctionFac = 100;
+ *correctionFac = 100;
}
/* faster adaptation towards 1.0, slower in the other direction */
-
+
if ((*correctionFac < 100 && newFac < *correctionFac) ||
(*correctionFac > 100 && newFac > *correctionFac))
*correctionFac = (85 * *correctionFac + 15 * newFac) / 100;
@@ -1107,7 +1107,7 @@ static void calcPeCorrection(Word16 *correctionFac,
*correctionFac = max(*correctionFac, 85);
}
else {
- *correctionFac = 100;
+ *correctionFac = 100;
}
}
@@ -1123,40 +1123,40 @@ void AdjustThresholds(ADJ_THR_STATE *adjThrState,
PSY_OUT_ELEMENT *psyOutElement,
Word16 *chBitDistribution,
Word16 logSfbEnergy[MAX_CHANNELS][MAX_GROUPED_SFB],
- Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB],
+ Word16 sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB],
QC_OUT_ELEMENT *qcOE,
ELEMENT_BITS *elBits,
const Word16 nChannels,
const Word16 maxBitFac)
{
- PE_DATA peData;
+ PE_DATA peData;
Word16 noRedPe, grantedPe, grantedPeCorr;
Word16 curWindowSequence;
Word16 bitFactor;
Word16 avgBits = (elBits->averageBits - (qcOE->staticBitsUsed + qcOE->ancBitsUsed));
- Word16 bitresBits = elBits->bitResLevel;
+ Word16 bitresBits = elBits->bitResLevel;
Word16 maxBitresBits = elBits->maxBits;
Word16 sideInfoBits = (qcOE->staticBitsUsed + qcOE->ancBitsUsed);
Word16 ch;
-
+
prepareSfbPe(&peData, psyOutChannel, logSfbEnergy, sfbNRelevantLines, nChannels, AdjThrStateElement->peOffset);
-
+
/* pe without reduction */
calcSfbPe(&peData, psyOutChannel, nChannels);
- noRedPe = peData.pe;
+ noRedPe = peData.pe;
- curWindowSequence = LONG_WINDOW;
-
+ curWindowSequence = LONG_WINDOW;
+
if (nChannels == 2) {
-
+
if ((psyOutChannel[0].windowSequence == SHORT_WINDOW) ||
(psyOutChannel[1].windowSequence == SHORT_WINDOW)) {
- curWindowSequence = SHORT_WINDOW;
+ curWindowSequence = SHORT_WINDOW;
}
}
else {
- curWindowSequence = psyOutChannel[0].windowSequence;
+ curWindowSequence = psyOutChannel[0].windowSequence;
}
@@ -1170,13 +1170,13 @@ void AdjustThresholds(ADJ_THR_STATE *adjThrState,
grantedPe = ((bitFactor * bits2pe(avgBits)) / 100);
/* correction of pe value */
- calcPeCorrection(&(AdjThrStateElement->peCorrectionFactor),
+ calcPeCorrection(&(AdjThrStateElement->peCorrectionFactor),
min(grantedPe, noRedPe),
- AdjThrStateElement->peLast,
+ AdjThrStateElement->peLast,
AdjThrStateElement->dynBitsLast);
grantedPeCorr = (grantedPe * AdjThrStateElement->peCorrectionFactor) / 100;
-
+
if (grantedPeCorr < noRedPe && noRedPe > peData.offset) {
/* calc threshold necessary for desired pe */
adaptThresholdsToPe(psyOutChannel,
@@ -1192,8 +1192,8 @@ void AdjustThresholds(ADJ_THR_STATE *adjThrState,
/* calculate relative distribution */
for (ch=0; ch<nChannels; ch++) {
Word16 peOffsDiff = peData.pe - peData.offset;
- chBitDistribution[ch] = 200;
-
+ chBitDistribution[ch] = 200;
+
if (peOffsDiff > 0) {
Word32 temp = 1000 - (nChannels * 200);
chBitDistribution[ch] = chBitDistribution[ch] +
@@ -1202,10 +1202,10 @@ void AdjustThresholds(ADJ_THR_STATE *adjThrState,
}
/* store pe */
- qcOE->pe = noRedPe;
+ qcOE->pe = noRedPe;
/* update last pe */
- AdjThrStateElement->peLast = grantedPe;
+ AdjThrStateElement->peLast = grantedPe;
}
/********************************************************************************
@@ -1217,7 +1217,7 @@ void AdjustThresholds(ADJ_THR_STATE *adjThrState,
void AdjThrUpdate(ATS_ELEMENT *AdjThrStateElement,
const Word16 dynBitsUsed)
{
- AdjThrStateElement->dynBitsLast = dynBitsUsed;
+ AdjThrStateElement->dynBitsLast = dynBitsUsed;
}