1 /* 2 ** Copyright 2003-2010, VisualOn, Inc. 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 /******************************************************************************* 17 File: band_nrg.c 18 19 Content: Band/Line energy calculations functions 20 21 *******************************************************************************/ 22 23 #include "basic_op.h" 24 #include "band_nrg.h" 25 26 #ifndef ARMV5E 27 /******************************************************************************** 28 * 29 * function name: CalcBandEnergy 30 * description: Calc sfb-bandwise mdct-energies for left and right channel 31 * 32 **********************************************************************************/ 33 void CalcBandEnergy(const Word32 *mdctSpectrum, 34 const Word16 *bandOffset, 35 const Word16 numBands, 36 Word32 *bandEnergy, 37 Word32 *bandEnergySum) 38 { 39 Word32 i, j; 40 Word32 accuSum = 0; 41 42 for (i=0; i<numBands; i++) { 43 Word32 accu = 0; 44 for (j=bandOffset[i]; j<bandOffset[i+1]; j++) 45 accu = L_add(accu, MULHIGH(mdctSpectrum[j], mdctSpectrum[j])); 46 47 accu = L_add(accu, accu); 48 accuSum = L_add(accuSum, accu); 49 bandEnergy[i] = accu; 50 } 51 *bandEnergySum = accuSum; 52 } 53 54 /******************************************************************************** 55 * 56 * function name: CalcBandEnergyMS 57 * description: Calc sfb-bandwise mdct-energies for left add or minus right channel 58 * 59 **********************************************************************************/ 60 void CalcBandEnergyMS(const Word32 *mdctSpectrumLeft, 61 const Word32 *mdctSpectrumRight, 62 const Word16 *bandOffset, 63 const Word16 numBands, 64 Word32 *bandEnergyMid, 65 Word32 *bandEnergyMidSum, 66 Word32 *bandEnergySide, 67 Word32 *bandEnergySideSum) 68 { 69 70 Word32 i, j; 71 Word32 accuMidSum = 0; 72 Word32 accuSideSum = 0; 73 74 75 for(i=0; i<numBands; i++) { 76 Word32 accuMid = 0; 77 Word32 accuSide = 0; 78 for (j=bandOffset[i]; j<bandOffset[i+1]; j++) { 79 Word32 specm, specs; 80 Word32 l, r; 81 82 l = mdctSpectrumLeft[j] >> 1; 83 r = mdctSpectrumRight[j] >> 1; 84 specm = l + r; 85 specs = l - r; 86 accuMid = L_add(accuMid, MULHIGH(specm, specm)); 87 accuSide = L_add(accuSide, MULHIGH(specs, specs)); 88 } 89 90 accuMid = L_add(accuMid, accuMid); 91 accuSide = L_add(accuSide, accuSide); 92 bandEnergyMid[i] = accuMid; 93 accuMidSum = L_add(accuMidSum, accuMid); 94 bandEnergySide[i] = accuSide; 95 accuSideSum = L_add(accuSideSum, accuSide); 96 97 } 98 *bandEnergyMidSum = accuMidSum; 99 *bandEnergySideSum = accuSideSum; 100 } 101 102 #endif 103