summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacenc/src/psy_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/codecs/aacenc/src/psy_main.c')
-rw-r--r--media/libstagefright/codecs/aacenc/src/psy_main.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/media/libstagefright/codecs/aacenc/src/psy_main.c b/media/libstagefright/codecs/aacenc/src/psy_main.c
index 8746a72..3d0a355 100644
--- a/media/libstagefright/codecs/aacenc/src/psy_main.c
+++ b/media/libstagefright/codecs/aacenc/src/psy_main.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: psy_main.c
-
- Content: Psychoacoustic major 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: psy_main.c
+
+ Content: Psychoacoustic major functions
+
*******************************************************************************/
-#include "typedef.h"
-#include "basic_op.h"
+#include "typedef.h"
+#include "basic_op.h"
#include "oper_32b.h"
#include "psy_const.h"
#include "block_switch.h"
@@ -77,27 +77,27 @@ static Word16 advancePsychShortMS (PSY_DATA psyData[MAX_CHANNELS],
*****************************************************************************/
Word16 PsyNew(PSY_KERNEL *hPsy, Word32 nChan, VO_MEM_OPERATOR *pMemOP)
{
- Word16 i;
- Word32 *mdctSpectrum;
- Word32 *scratchTNS;
- Word16 *mdctDelayBuffer;
-
- mdctSpectrum = (Word32 *)mem_malloc(pMemOP, nChan * FRAME_LEN_LONG * sizeof(Word32), 32, VO_INDEX_ENC_AAC);
- if(NULL == mdctSpectrum)
- return 1;
-
- scratchTNS = (Word32 *)mem_malloc(pMemOP, nChan * FRAME_LEN_LONG * sizeof(Word32), 32, VO_INDEX_ENC_AAC);
- if(NULL == scratchTNS)
- {
- return 1;
- }
-
- mdctDelayBuffer = (Word16 *)mem_malloc(pMemOP, nChan * BLOCK_SWITCHING_OFFSET * sizeof(Word16), 32, VO_INDEX_ENC_AAC);
- if(NULL == mdctDelayBuffer)
- {
+ Word16 i;
+ Word32 *mdctSpectrum;
+ Word32 *scratchTNS;
+ Word16 *mdctDelayBuffer;
+
+ mdctSpectrum = (Word32 *)mem_malloc(pMemOP, nChan * FRAME_LEN_LONG * sizeof(Word32), 32, VO_INDEX_ENC_AAC);
+ if(NULL == mdctSpectrum)
+ return 1;
+
+ scratchTNS = (Word32 *)mem_malloc(pMemOP, nChan * FRAME_LEN_LONG * sizeof(Word32), 32, VO_INDEX_ENC_AAC);
+ if(NULL == scratchTNS)
+ {
return 1;
- }
-
+ }
+
+ mdctDelayBuffer = (Word16 *)mem_malloc(pMemOP, nChan * BLOCK_SWITCHING_OFFSET * sizeof(Word16), 32, VO_INDEX_ENC_AAC);
+ if(NULL == mdctDelayBuffer)
+ {
+ return 1;
+ }
+
for (i=0; i<nChan; i++){
hPsy->psyData[i].mdctDelayBuffer = mdctDelayBuffer + i*BLOCK_SWITCHING_OFFSET;
hPsy->psyData[i].mdctSpectrum = mdctSpectrum + i*FRAME_LEN_LONG;
@@ -118,27 +118,27 @@ Word16 PsyNew(PSY_KERNEL *hPsy, Word32 nChan, VO_MEM_OPERATOR *pMemOP)
*****************************************************************************/
Word16 PsyDelete(PSY_KERNEL *hPsy, VO_MEM_OPERATOR *pMemOP)
{
- Word32 nch;
-
- if(hPsy)
- {
- if(hPsy->psyData[0].mdctDelayBuffer)
- mem_free(pMemOP, hPsy->psyData[0].mdctDelayBuffer, VO_INDEX_ENC_AAC);
-
- if(hPsy->psyData[0].mdctSpectrum)
- mem_free(pMemOP, hPsy->psyData[0].mdctSpectrum, VO_INDEX_ENC_AAC);
-
- for (nch=0; nch<MAX_CHANNELS; nch++){
- hPsy->psyData[nch].mdctDelayBuffer = NULL;
- hPsy->psyData[nch].mdctSpectrum = NULL;
- }
-
- if(hPsy->pScratchTns)
- {
- mem_free(pMemOP, hPsy->pScratchTns, VO_INDEX_ENC_AAC);
- hPsy->pScratchTns = NULL;
- }
- }
+ Word32 nch;
+
+ if(hPsy)
+ {
+ if(hPsy->psyData[0].mdctDelayBuffer)
+ mem_free(pMemOP, hPsy->psyData[0].mdctDelayBuffer, VO_INDEX_ENC_AAC);
+
+ if(hPsy->psyData[0].mdctSpectrum)
+ mem_free(pMemOP, hPsy->psyData[0].mdctSpectrum, VO_INDEX_ENC_AAC);
+
+ for (nch=0; nch<MAX_CHANNELS; nch++){
+ hPsy->psyData[nch].mdctDelayBuffer = NULL;
+ hPsy->psyData[nch].mdctSpectrum = NULL;
+ }
+
+ if(hPsy->pScratchTns)
+ {
+ mem_free(pMemOP, hPsy->pScratchTns, VO_INDEX_ENC_AAC);
+ hPsy->pScratchTns = NULL;
+ }
+ }
return 0;
}
@@ -196,10 +196,10 @@ Word16 psyMainInit(PSY_KERNEL *hPsy,
err = InitPsyConfigurationLong(channelBitRate,
sampleRate,
bandwidth,
- &(hPsy->psyConfLong));
-
+ &(hPsy->psyConfLong));
+
if (!err) {
- hPsy->sampleRateIdx = hPsy->psyConfLong.sampRateIdx;
+ hPsy->sampleRateIdx = hPsy->psyConfLong.sampRateIdx;
err = InitTnsConfigurationLong(bitRate, sampleRate, channels,
&hPsy->psyConfLong.tnsConf, &hPsy->psyConfLong, tnsMask&2);
}
@@ -263,7 +263,7 @@ Word16 psyMain(Word16 nChannels,
channels = elemInfo->nChannelsInEl;
maxScale = 0;
- /* block switching */
+ /* block switching */
for(ch = 0; ch < channels; ch++) {
BlockSwitching(&psyData[ch].blockSwitchingControl,
timeSignal+elemInfo->ChannelIndex[ch],
@@ -477,11 +477,11 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
{
Word32 i;
Word32 normEnergyShift = (psyData->mdctScale + 1) << 1; /* in reference code, mdct spectrum must be multipied with 2, so +1 */
- Word32 clipEnergy = hPsyConfLong->clipEnergy >> normEnergyShift;
+ Word32 clipEnergy = hPsyConfLong->clipEnergy >> normEnergyShift;
Word32 *data0, *data1, tdata;
/* low pass */
- data0 = psyData->mdctSpectrum + hPsyConfLong->lowpassLine;
+ data0 = psyData->mdctSpectrum + hPsyConfLong->lowpassLine;
for(i=hPsyConfLong->lowpassLine; i<FRAME_LEN_LONG; i++) {
*data0++ = 0;
}
@@ -525,11 +525,11 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
psyData->blockSwitchingControl.windowSequence);
/* first part of threshold calculation */
- data0 = psyData->sfbEnergy.sfbLong;
- data1 = psyData->sfbThreshold.sfbLong;
+ data0 = psyData->sfbEnergy.sfbLong;
+ data1 = psyData->sfbThreshold.sfbLong;
for (i=hPsyConfLong->sfbCnt; i; i--) {
tdata = L_mpy_ls(*data0++, hPsyConfLong->ratio);
- *data1++ = min(tdata, clipEnergy);
+ *data1++ = min(tdata, clipEnergy);
}
/* Calc sfb-bandwise mdct-energies for left and right channel again */
@@ -540,12 +540,12 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
hPsyConfLong->sfbActive - tnsStartBand,
psyData->sfbEnergy.sfbLong+tnsStartBand,
&psyData->sfbEnergySum.sfbLong);
-
- data0 = psyData->sfbEnergy.sfbLong;
- tdata = psyData->sfbEnergySum.sfbLong;
+
+ data0 = psyData->sfbEnergy.sfbLong;
+ tdata = psyData->sfbEnergySum.sfbLong;
for (i=0; i<tnsStartBand; i++)
- tdata += *data0++;
-
+ tdata += *data0++;
+
psyData->sfbEnergySum.sfbLong = tdata;
}
@@ -557,20 +557,20 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
psyData->sfbThreshold.sfbLong);
/* threshold in quiet */
- data0 = psyData->sfbThreshold.sfbLong;
- data1 = hPsyConfLong->sfbThresholdQuiet;
+ data0 = psyData->sfbThreshold.sfbLong;
+ data1 = hPsyConfLong->sfbThresholdQuiet;
for (i=hPsyConfLong->sfbCnt; i; i--)
- {
- *data0 = max(*data0, (*data1 >> normEnergyShift));
- data0++; data1++;
+ {
+ *data0 = max(*data0, (*data1 >> normEnergyShift));
+ data0++; data1++;
}
/* preecho control */
if (psyData->blockSwitchingControl.windowSequence == STOP_WINDOW) {
- data0 = psyData->sfbThresholdnm1;
- for (i=hPsyConfLong->sfbCnt; i; i--) {
- *data0++ = MAX_32;
- }
+ data0 = psyData->sfbThresholdnm1;
+ for (i=hPsyConfLong->sfbCnt; i; i--) {
+ *data0++ = MAX_32;
+ }
psyData->mdctScalenm1 = 0;
}
@@ -585,7 +585,7 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
if (psyData->blockSwitchingControl.windowSequence== START_WINDOW) {
- data0 = psyData->sfbThresholdnm1;
+ data0 = psyData->sfbThresholdnm1;
for (i=hPsyConfLong->sfbCnt; i; i--) {
*data0++ = MAX_32;
}
@@ -600,10 +600,10 @@ static Word16 advancePsychLong(PSY_DATA* psyData,
/* spreaded energy */
- data0 = psyData->sfbSpreadedEnergy.sfbLong;
- data1 = psyData->sfbEnergy.sfbLong;
+ data0 = psyData->sfbSpreadedEnergy.sfbLong;
+ data1 = psyData->sfbEnergy.sfbLong;
for (i=hPsyConfLong->sfbCnt; i; i--) {
- //psyData->sfbSpreadedEnergy.sfbLong[i] = psyData->sfbEnergy.sfbLong[i];
+ //psyData->sfbSpreadedEnergy.sfbLong[i] = psyData->sfbEnergy.sfbLong[i];
*data0++ = *data1++;
}
@@ -657,14 +657,14 @@ static Word16 advancePsychShort(PSY_DATA* psyData,
Word32 w;
Word32 normEnergyShift = (psyData->mdctScale + 1) << 1; /* in reference code, mdct spectrum must be multipied with 2, so +1 */
Word32 clipEnergy = hPsyConfShort->clipEnergy >> normEnergyShift;
- Word32 wOffset = 0;
+ Word32 wOffset = 0;
Word32 *data0, *data1;
for(w = 0; w < TRANS_FAC; w++) {
Word32 i, tdata;
/* low pass */
- data0 = psyData->mdctSpectrum + wOffset + hPsyConfShort->lowpassLine;
+ data0 = psyData->mdctSpectrum + wOffset + hPsyConfShort->lowpassLine;
for(i=hPsyConfShort->lowpassLine; i<FRAME_LEN_SHORT; i++){
*data0++ = 0;
}
@@ -706,11 +706,11 @@ static Word16 advancePsychShort(PSY_DATA* psyData,
psyData->blockSwitchingControl.windowSequence);
/* first part of threshold calculation */
- data0 = psyData->sfbThreshold.sfbShort[w];
- data1 = psyData->sfbEnergy.sfbShort[w];
+ data0 = psyData->sfbThreshold.sfbShort[w];
+ data1 = psyData->sfbEnergy.sfbShort[w];
for (i=hPsyConfShort->sfbCnt; i; i--) {
tdata = L_mpy_ls(*data1++, hPsyConfShort->ratio);
- *data0++ = min(tdata, clipEnergy);
+ *data0++ = min(tdata, clipEnergy);
}
/* Calc sfb-bandwise mdct-energies for left and right channel again */
@@ -720,13 +720,13 @@ static Word16 advancePsychShort(PSY_DATA* psyData,
hPsyConfShort->sfbOffset+tnsStartBand,
(hPsyConfShort->sfbActive - tnsStartBand),
psyData->sfbEnergy.sfbShort[w]+tnsStartBand,
- &psyData->sfbEnergySum.sfbShort[w]);
+ &psyData->sfbEnergySum.sfbShort[w]);
- tdata = psyData->sfbEnergySum.sfbShort[w];
- data0 = psyData->sfbEnergy.sfbShort[w];
+ tdata = psyData->sfbEnergySum.sfbShort[w];
+ data0 = psyData->sfbEnergy.sfbShort[w];
for (i=tnsStartBand; i; i--)
- tdata += *data0++;
-
+ tdata += *data0++;
+
psyData->sfbEnergySum.sfbShort[w] = tdata;
}
@@ -738,14 +738,14 @@ static Word16 advancePsychShort(PSY_DATA* psyData,
/* threshold in quiet */
- data0 = psyData->sfbThreshold.sfbShort[w];
- data1 = hPsyConfShort->sfbThresholdQuiet;
+ data0 = psyData->sfbThreshold.sfbShort[w];
+ data1 = hPsyConfShort->sfbThresholdQuiet;
for (i=hPsyConfShort->sfbCnt; i; i--)
- {
- *data0 = max(*data0, (*data1 >> normEnergyShift));
-
- data0++; data1++;
- }
+ {
+ *data0 = max(*data0, (*data1 >> normEnergyShift));
+
+ data0++; data1++;
+ }
/* preecho */
@@ -764,8 +764,8 @@ static Word16 advancePsychShort(PSY_DATA* psyData,
psyData->sfbThreshold.sfbShort[w]);
/* spreaded energy */
- data0 = psyData->sfbSpreadedEnergy.sfbShort[w];
- data1 = psyData->sfbEnergy.sfbShort[w];
+ data0 = psyData->sfbSpreadedEnergy.sfbShort[w];
+ data1 = psyData->sfbEnergy.sfbShort[w];
for (i=hPsyConfShort->sfbCnt; i; i--) {
*data0++ = *data1++;
}