summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacenc/src/quantize.c
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/quantize.c')
-rw-r--r--media/libstagefright/codecs/aacenc/src/quantize.c130
1 files changed, 65 insertions, 65 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/quantize.c b/media/libstagefright/codecs/aacenc/src/quantize.c
index 973554e..54add2f 100644
--- a/media/libstagefright/codecs/aacenc/src/quantize.c
+++ b/media/libstagefright/codecs/aacenc/src/quantize.c
@@ -34,32 +34,32 @@ static const Word32 XROUND = 0x33e425af; /* final rounding constant (-0.0946f+ 0
/*****************************************************************************
*
-* function name:pow34
-* description: calculate $x^{\frac{3}{4}}, for 0.5 < x < 1.0$.
+* function name:pow34
+* description: calculate $x^{\frac{3}{4}}, for 0.5 < x < 1.0$.
*
*****************************************************************************/
__inline Word32 pow34(Word32 x)
{
/* index table using MANT_DIGITS bits, but mask out the sign bit and the MSB
- which is always one */
+ which is always one */
return mTab_3_4[(x >> (INT_BITS-2-MANT_DIGITS)) & (MANT_SIZE-1)];
}
/*****************************************************************************
*
-* function name:quantizeSingleLine
-* description: quantizes spectrum
-* quaSpectrum = mdctSpectrum^3/4*2^(-(3/16)*gain)
+* function name:quantizeSingleLine
+* description: quantizes spectrum
+* quaSpectrum = mdctSpectrum^3/4*2^(-(3/16)*gain)
*
*****************************************************************************/
static Word16 quantizeSingleLine(const Word16 gain, const Word32 absSpectrum)
{
Word32 e, minusFinalExp, finalShift;
Word32 x;
- Word16 qua = 0;
+ Word16 qua = 0;
+
-
if (absSpectrum) {
e = norm_l(absSpectrum);
x = pow34(absSpectrum << e);
@@ -71,7 +71,7 @@ static Word16 quantizeSingleLine(const Word16 gain, const Word32 absSpectrum)
/* separate the exponent into a shift, and a multiply */
finalShift = minusFinalExp >> 4;
-
+
if (finalShift < INT_BITS) {
x = L_mpy_wx(x, pow2tominusNover16[minusFinalExp & 15]);
@@ -84,7 +84,7 @@ static Word16 quantizeSingleLine(const Word16 gain, const Word32 absSpectrum)
x >>= finalShift;
else
x <<= (-finalShift);
-
+
qua = saturate(x);
}
}
@@ -94,10 +94,10 @@ static Word16 quantizeSingleLine(const Word16 gain, const Word32 absSpectrum)
/*****************************************************************************
*
-* function name:quantizeLines
-* description: quantizes spectrum lines
-* quaSpectrum = mdctSpectrum^3/4*2^(-(3/16)*gain)
-* input: global gain, number of lines to process, spectral data
+* function name:quantizeLines
+* description: quantizes spectrum lines
+* quaSpectrum = mdctSpectrum^3/4*2^(-(3/16)*gain)
+* input: global gain, number of lines to process, spectral data
* output: quantized spectrum
*
*****************************************************************************/
@@ -116,15 +116,15 @@ static void quantizeLines(const Word16 gain,
pquat = quantBorders[m];
g += 16;
-
+
if(g >= 0)
{
for (line=0; line<noOfLines; line++) {
Word32 qua;
- qua = 0;
-
+ qua = 0;
+
mdctSpeL = mdctSpectrum[line];
-
+
if (mdctSpeL) {
Word32 sa;
Word32 saShft;
@@ -134,27 +134,27 @@ static void quantizeLines(const Word16 gain,
saShft = sa >> g;
if (saShft > pquat[0]) {
-
+
if (saShft < pquat[1]) {
-
+
qua = mdctSpeL>0 ? 1 : -1;
}
else {
-
+
if (saShft < pquat[2]) {
-
+
qua = mdctSpeL>0 ? 2 : -2;
}
else {
-
+
if (saShft < pquat[3]) {
-
+
qua = mdctSpeL>0 ? 3 : -3;
}
else {
qua = quantizeSingleLine(gain, sa);
/* adjust the sign. Since 0 < qua < 1, this cannot overflow. */
-
+
if (mdctSpeL < 0)
qua = -qua;
}
@@ -162,17 +162,17 @@ static void quantizeLines(const Word16 gain,
}
}
}
- quaSpectrum[line] = qua ;
+ quaSpectrum[line] = qua ;
}
}
else
{
for (line=0; line<noOfLines; line++) {
Word32 qua;
- qua = 0;
-
+ qua = 0;
+
mdctSpeL = mdctSpectrum[line];
-
+
if (mdctSpeL) {
Word32 sa;
Word32 saShft;
@@ -181,27 +181,27 @@ static void quantizeLines(const Word16 gain,
saShft = sa << g;
if (saShft > pquat[0]) {
-
+
if (saShft < pquat[1]) {
-
+
qua = mdctSpeL>0 ? 1 : -1;
}
else {
-
+
if (saShft < pquat[2]) {
-
+
qua = mdctSpeL>0 ? 2 : -2;
}
else {
-
+
if (saShft < pquat[3]) {
-
+
qua = mdctSpeL>0 ? 3 : -3;
}
else {
qua = quantizeSingleLine(gain, sa);
/* adjust the sign. Since 0 < qua < 1, this cannot overflow. */
-
+
if (mdctSpeL < 0)
qua = -qua;
}
@@ -209,8 +209,8 @@ static void quantizeLines(const Word16 gain,
}
}
}
- quaSpectrum[line] = qua ;
- }
+ quaSpectrum[line] = qua ;
+ }
}
}
@@ -218,10 +218,10 @@ static void quantizeLines(const Word16 gain,
/*****************************************************************************
*
-* function name:iquantizeLines
+* function name:iquantizeLines
* description: iquantizes spectrum lines without sign
-* mdctSpectrum = iquaSpectrum^4/3 *2^(0.25*gain)
-* input: global gain, number of lines to process,quantized spectrum
+* mdctSpectrum = iquaSpectrum^4/3 *2^(0.25*gain)
+* input: global gain, number of lines to process,quantized spectrum
* output: spectral data
*
*****************************************************************************/
@@ -234,11 +234,11 @@ static void iquantizeLines(const Word16 gain,
Word32 iquantizershift;
Word32 line;
- iquantizermod = gain & 3;
+ iquantizermod = gain & 3;
iquantizershift = gain >> 2;
for (line=0; line<noOfLines; line++) {
-
+
if( quantSpectrum[line] != 0 ) {
Word32 accu;
Word32 ex;
@@ -252,19 +252,19 @@ static void iquantizeLines(const Word16 gain,
accu = accu << ex;
specExp = INT_BITS-1 - ex;
- tabIndex = (accu >> (INT_BITS-2-MANT_DIGITS)) & (~MANT_SIZE);
+ tabIndex = (accu >> (INT_BITS-2-MANT_DIGITS)) & (~MANT_SIZE);
/* calculate "mantissa" ^4/3 */
- s = mTab_4_3[tabIndex];
+ s = mTab_4_3[tabIndex];
/* get approperiate exponent multiplier for specExp^3/4 combined with scfMod */
- t = specExpMantTableComb_enc[iquantizermod][specExp];
+ t = specExpMantTableComb_enc[iquantizermod][specExp];
/* multiply "mantissa" ^4/3 with exponent multiplier */
accu = MULHIGH(s, t);
/* get approperiate exponent shifter */
- specExp = specExpTableComb_enc[iquantizermod][specExp];
+ specExp = specExpTableComb_enc[iquantizermod][specExp];
specExp += iquantizershift + 1;
if(specExp >= 0)
@@ -273,7 +273,7 @@ static void iquantizeLines(const Word16 gain,
mdctSpectrum[line] = accu >> (-specExp);
}
else {
- mdctSpectrum[line] = 0;
+ mdctSpectrum[line] = 0;
}
}
}
@@ -301,7 +301,7 @@ void QuantizeSpectrum(Word16 sfbCnt,
for(sfbOffs=0;sfbOffs<sfbCnt;sfbOffs+=sfbPerGroup) {
Word32 sfbNext ;
for (sfb = 0; sfb < maxSfbPerGroup; sfb = sfbNext) {
- Word16 scalefactor = scalefactors[sfbOffs+sfb];
+ Word16 scalefactor = scalefactors[sfbOffs+sfb];
/* coalesce sfbs with the same scalefactor */
for (sfbNext = sfb+1;
sfbNext < maxSfbPerGroup && scalefactor == scalefactors[sfbOffs+sfbNext];
@@ -318,7 +318,7 @@ void QuantizeSpectrum(Word16 sfbCnt,
/*****************************************************************************
*
-* function name:calcSfbDist
+* function name:calcSfbDist
* description: quantizes and requantizes lines to calculate distortion
* input: number of lines to be quantized, ...
* output: distortion
@@ -338,14 +338,14 @@ Word32 calcSfbDist(const Word32 *spec,
pquat = quantBorders[m];
repquat = quantRecon[m];
-
- dist = 0;
+
+ dist = 0;
g += 16;
if(g2 < 0 && g >= 0)
- {
+ {
g2 = -g2;
- for(line=0; line<sfbWidth; line++) {
- if (spec[line]) {
+ for(line=0; line<sfbWidth; line++) {
+ if (spec[line]) {
Word32 diff;
Word32 distSingle;
Word32 sa;
@@ -359,19 +359,19 @@ Word32 calcSfbDist(const Word32 *spec,
distSingle = (saShft * saShft) >> g2;
}
else {
-
+
if (saShft < pquat[1]) {
diff = saShft - repquat[0];
distSingle = (diff * diff) >> g2;
}
else {
-
+
if (saShft < pquat[2]) {
diff = saShft - repquat[1];
distSingle = (diff * diff) >> g2;
}
else {
-
+
if (saShft < pquat[3]) {
diff = saShft - repquat[2];
distSingle = (diff * diff) >> g2;
@@ -387,15 +387,15 @@ Word32 calcSfbDist(const Word32 *spec,
}
}
}
-
+
dist = L_add(dist, distSingle);
}
}
}
else
{
- for(line=0; line<sfbWidth; line++) {
- if (spec[line]) {
+ for(line=0; line<sfbWidth; line++) {
+ if (spec[line]) {
Word32 diff;
Word32 distSingle;
Word32 sa;
@@ -408,19 +408,19 @@ Word32 calcSfbDist(const Word32 *spec,
distSingle = L_shl((saShft * saShft), g2);
}
else {
-
+
if (saShft < pquat[1]) {
diff = saShft - repquat[0];
distSingle = L_shl((diff * diff), g2);
}
else {
-
+
if (saShft < pquat[2]) {
diff = saShft - repquat[1];
distSingle = L_shl((diff * diff), g2);
}
else {
-
+
if (saShft < pquat[3]) {
diff = saShft - repquat[2];
distSingle = L_shl((diff * diff), g2);
@@ -438,7 +438,7 @@ Word32 calcSfbDist(const Word32 *spec,
}
dist = L_add(dist, distSingle);
}
- }
+ }
}
return dist;