diff options
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/quantize.c')
-rw-r--r-- | media/libstagefright/codecs/aacenc/src/quantize.c | 382 |
1 files changed, 191 insertions, 191 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/quantize.c b/media/libstagefright/codecs/aacenc/src/quantize.c index 205f167..973554e 100644 --- a/media/libstagefright/codecs/aacenc/src/quantize.c +++ b/media/libstagefright/codecs/aacenc/src/quantize.c @@ -1,27 +1,27 @@ -/*
- ** 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: quantize.c
-
- Content: quantization 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: quantize.c + + Content: quantization functions + *******************************************************************************/ -#include "typedef.h"
-#include "basic_op.h"
+#include "typedef.h" +#include "basic_op.h" #include "oper_32b.h" #include "quantize.h" #include "aac_rom.h" @@ -77,14 +77,14 @@ static Word16 quantizeSingleLine(const Word16 gain, const Word32 absSpectrum) x += XROUND >> (INT_BITS - finalShift); - /* shift and quantize */
- finalShift--;
-
- if(finalShift >= 0)
- x >>= finalShift;
- else
- x <<= (-finalShift);
-
+ /* shift and quantize */ + finalShift--; + + if(finalShift >= 0) + x >>= finalShift; + else + x <<= (-finalShift); + qua = saturate(x); } } @@ -108,29 +108,29 @@ static void quantizeLines(const Word16 gain, { Word32 line; Word32 m = gain&3; - Word32 g = (gain >> 2) + 4;
- Word32 mdctSpeL;
+ Word32 g = (gain >> 2) + 4; + Word32 mdctSpeL; Word16 *pquat; - /* gain&3 */
-
- pquat = quantBorders[m];
-
- g += 16;
-
- if(g >= 0)
- {
+ /* gain&3 */ + + pquat = quantBorders[m]; + + g += 16; + + if(g >= 0) + { for (line=0; line<noOfLines; line++) { Word32 qua; qua = 0; -
- mdctSpeL = mdctSpectrum[line];
+ + mdctSpeL = mdctSpectrum[line]; if (mdctSpeL) { Word32 sa; Word32 saShft; sa = L_abs(mdctSpeL); - //saShft = L_shr(sa, 16 + g);
+ //saShft = L_shr(sa, 16 + g); saShft = sa >> g; if (saShft > pquat[0]) { @@ -163,54 +163,54 @@ static void quantizeLines(const Word16 gain, } } quaSpectrum[line] = qua ; - }
- }
- else
- {
- for (line=0; line<noOfLines; line++) {
- Word32 qua;
- qua = 0;
-
- mdctSpeL = mdctSpectrum[line];
-
- if (mdctSpeL) {
- Word32 sa;
- Word32 saShft;
-
- sa = L_abs(mdctSpeL);
- 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;
- }
- }
- }
- }
- }
- quaSpectrum[line] = qua ;
- }
+ } + } + else + { + for (line=0; line<noOfLines; line++) { + Word32 qua; + qua = 0; + + mdctSpeL = mdctSpectrum[line]; + + if (mdctSpeL) { + Word32 sa; + Word32 saShft; + + sa = L_abs(mdctSpeL); + 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; + } + } + } + } + } + quaSpectrum[line] = qua ; + } } } @@ -266,10 +266,10 @@ static void iquantizeLines(const Word16 gain, /* get approperiate exponent shifter */ specExp = specExpTableComb_enc[iquantizermod][specExp]; - specExp += iquantizershift + 1;
- if(specExp >= 0)
- mdctSpectrum[line] = accu << specExp;
- else
+ specExp += iquantizershift + 1; + if(specExp >= 0) + mdctSpectrum[line] = accu << specExp; + else mdctSpectrum[line] = accu >> (-specExp); } else { @@ -331,19 +331,69 @@ Word32 calcSfbDist(const Word32 *spec, Word32 line; Word32 dist; Word32 m = gain&3; - Word32 g = (gain >> 2) + 4;
- Word32 g2 = (g << 1) + 1;
- Word16 *pquat, *repquat;
+ Word32 g = (gain >> 2) + 4; + Word32 g2 = (g << 1) + 1; + Word16 *pquat, *repquat; /* gain&3 */ -
- pquat = quantBorders[m];
+ + pquat = quantBorders[m]; repquat = quantRecon[m]; -
- dist = 0;
- g += 16;
- if(g2 < 0 && g >= 0)
+ + dist = 0; + g += 16; + if(g2 < 0 && g >= 0) { - g2 = -g2;
+ g2 = -g2; + for(line=0; line<sfbWidth; line++) { + if (spec[line]) { + Word32 diff; + Word32 distSingle; + Word32 sa; + Word32 saShft; + sa = L_abs(spec[line]); + //saShft = round16(L_shr(sa, g)); + //saShft = L_shr(sa, 16+g); + saShft = sa >> g; + + if (saShft < pquat[0]) { + 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; + } + else { + Word16 qua = quantizeSingleLine(gain, sa); + Word32 iqval, diff32; + /* now that we have quantized x, re-quantize it. */ + iquantizeLines(gain, 1, &qua, &iqval); + diff32 = sa - iqval; + distSingle = fixmul(diff32, diff32); + } + } + } + } + + dist = L_add(dist, distSingle); + } + } + } + else + { for(line=0; line<sfbWidth; line++) { if (spec[line]) { Word32 diff; @@ -352,93 +402,43 @@ Word32 calcSfbDist(const Word32 *spec, Word32 saShft; sa = L_abs(spec[line]); //saShft = round16(L_shr(sa, g)); - //saShft = L_shr(sa, 16+g);
- saShft = sa >> g;
- - if (saShft < pquat[0]) {
- 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;
- }
- else {
- Word16 qua = quantizeSingleLine(gain, sa);
- Word32 iqval, diff32;
- /* now that we have quantized x, re-quantize it. */
- iquantizeLines(gain, 1, &qua, &iqval);
- diff32 = sa - iqval;
- distSingle = fixmul(diff32, diff32);
- }
- }
- }
- }
-
- dist = L_add(dist, distSingle);
+ saShft = L_shr(sa, g); + + if (saShft < pquat[0]) { + 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); + } + else { + Word16 qua = quantizeSingleLine(gain, sa); + Word32 iqval, diff32; + /* now that we have quantized x, re-quantize it. */ + iquantizeLines(gain, 1, &qua, &iqval); + diff32 = sa - iqval; + distSingle = fixmul(diff32, diff32); + } + } + } + } + dist = L_add(dist, distSingle); } - }
- }
- else
- {
- for(line=0; line<sfbWidth; line++) {
- if (spec[line]) {
- Word32 diff;
- Word32 distSingle;
- Word32 sa;
- Word32 saShft;
- sa = L_abs(spec[line]);
- //saShft = round16(L_shr(sa, g));
- saShft = L_shr(sa, g);
-
- if (saShft < pquat[0]) {
- 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);
- }
- else {
- Word16 qua = quantizeSingleLine(gain, sa);
- Word32 iqval, diff32;
- /* now that we have quantized x, re-quantize it. */
- iquantizeLines(gain, 1, &qua, &iqval);
- diff32 = sa - iqval;
- distSingle = fixmul(diff32, diff32);
- }
- }
- }
- }
- dist = L_add(dist, distSingle);
- }
- }
+ } } return dist; |