Home | History | Annotate | Download | only in src
      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:		interface.c
     18 
     19 	Content:	Interface psychoaccoustic/quantizer functions
     20 
     21 *******************************************************************************/
     22 
     23 #include "basic_op.h"
     24 #include "oper_32b.h"
     25 #include "psy_const.h"
     26 #include "interface.h"
     27 
     28 /*****************************************************************************
     29 *
     30 * function name: BuildInterface
     31 * description:  update output parameter
     32 *
     33 **********************************************************************************/
     34 void BuildInterface(Word32                  *groupedMdctSpectrum,
     35                     const Word16             mdctScale,
     36                     SFB_THRESHOLD           *groupedSfbThreshold,
     37                     SFB_ENERGY              *groupedSfbEnergy,
     38                     SFB_ENERGY              *groupedSfbSpreadedEnergy,
     39                     const SFB_ENERGY_SUM     sfbEnergySumLR,
     40                     const SFB_ENERGY_SUM     sfbEnergySumMS,
     41                     const Word16             windowSequence,
     42                     const Word16             windowShape,
     43                     const Word16             groupedSfbCnt,
     44                     const Word16            *groupedSfbOffset,
     45                     const Word16             maxSfbPerGroup,
     46                     const Word16            *groupedSfbMinSnr,
     47                     const Word16             noOfGroups,
     48                     const Word16            *groupLen,
     49                     PSY_OUT_CHANNEL         *psyOutCh)
     50 {
     51   Word32 j;
     52   Word32 grp;
     53   Word32 mask;
     54   Word16 *tmpV;
     55 
     56   /*
     57   copy values to psyOut
     58   */
     59   psyOutCh->maxSfbPerGroup    = maxSfbPerGroup;
     60   psyOutCh->sfbCnt            = groupedSfbCnt;
     61   if(noOfGroups)
     62 	psyOutCh->sfbPerGroup     = groupedSfbCnt/ noOfGroups;
     63   else
     64 	psyOutCh->sfbPerGroup     = 0x7fff;
     65   psyOutCh->windowSequence    = windowSequence;
     66   psyOutCh->windowShape       = windowShape;
     67   psyOutCh->mdctScale         = mdctScale;
     68   psyOutCh->mdctSpectrum      = groupedMdctSpectrum;
     69   psyOutCh->sfbEnergy         = groupedSfbEnergy->sfbLong;
     70   psyOutCh->sfbThreshold      = groupedSfbThreshold->sfbLong;
     71   psyOutCh->sfbSpreadedEnergy = groupedSfbSpreadedEnergy->sfbLong;
     72 
     73   tmpV = psyOutCh->sfbOffsets;
     74   for(j=0; j<groupedSfbCnt + 1; j++) {
     75       *tmpV++ = groupedSfbOffset[j];
     76   }
     77 
     78   tmpV = psyOutCh->sfbMinSnr;
     79   for(j=0;j<groupedSfbCnt; j++) {
     80 	  *tmpV++ =   groupedSfbMinSnr[j];
     81   }
     82 
     83   /* generate grouping mask */
     84   mask = 0;
     85   for (grp = 0; grp < noOfGroups; grp++) {
     86     mask = mask << 1;
     87     for (j=1; j<groupLen[grp]; j++) {
     88       mask = mask << 1;
     89       mask |= 1;
     90     }
     91   }
     92   psyOutCh->groupingMask = mask;
     93 
     94   if (windowSequence != SHORT_WINDOW) {
     95     psyOutCh->sfbEnSumLR =  sfbEnergySumLR.sfbLong;
     96     psyOutCh->sfbEnSumMS =  sfbEnergySumMS.sfbLong;
     97   }
     98   else {
     99     Word32 i;
    100     Word32 accuSumMS=0;
    101     Word32 accuSumLR=0;
    102 	Word32 *pSumMS = sfbEnergySumMS.sfbShort;
    103 	Word32 *pSumLR = sfbEnergySumLR.sfbShort;
    104 
    105     for (i=TRANS_FAC; i; i--) {
    106       accuSumLR = L_add(accuSumLR, *pSumLR); pSumLR++;
    107       accuSumMS = L_add(accuSumMS, *pSumMS); pSumMS++;
    108     }
    109     psyOutCh->sfbEnSumMS = accuSumMS;
    110     psyOutCh->sfbEnSumLR = accuSumLR;
    111   }
    112 }
    113