Example #1
0
void AdjustThresholds(ADJ_THR_STATE     *adjThrState,
                      ATS_ELEMENT       *AdjThrStateElement,
                      PSY_OUT_CHANNEL   psyOutChannel[MAX_CHANNELS],
                      PSY_OUT_ELEMENT   *psyOutElement,
                      float             *chBitDistribution,
                      float            sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB],
                      const int         nChannels,
                      QC_OUT_ELEMENT    *qcOE,
                      const int         avgBits,
                      const int         bitresBits,
                      const int         maxBitresBits,
                      const float       maxBitFac,
                      const int         sideInfoBits)
{
   float noRedPe, grantedPe, grantedPeCorr;
   int curWindowSequence;
   PE_DATA peData;
   float bitFactor;
   int ch;

   COUNT_sub_start("AdjustThresholds");

   INDIRECT(1); PTR_INIT(1); FUNC(5);
   preparePe(&peData, psyOutChannel, sfbFormFactor, nChannels, AdjThrStateElement->peOffset);

   PTR_INIT(1); FUNC(3);
   calcPe(&peData, psyOutChannel, nChannels);

   MOVE(1);
   noRedPe = peData.pe;

   MOVE(1);
   curWindowSequence = LONG_WINDOW;

   ADD(1); BRANCH(1);
   if (nChannels==2) {

     ADD(2); LOGIC(1);
     if ((psyOutChannel[0].windowSequence == SHORT_WINDOW) ||
         (psyOutChannel[1].windowSequence == SHORT_WINDOW)) {

       MOVE(1);
       curWindowSequence = SHORT_WINDOW;
     }
   }
   else {

     MOVE(1);
     curWindowSequence = psyOutChannel[0].windowSequence;
   }


   MULT(1); ADD(1); FUNC(8);
   bitFactor = bitresCalcBitFac(bitresBits, maxBitresBits,
                                noRedPe+5.0f*sideInfoBits,
                                curWindowSequence, avgBits, maxBitFac,
                                adjThrState,
                                AdjThrStateElement);

   FUNC(1); MULT(1);
   grantedPe = bitFactor * bits2pe((float)avgBits);

   INDIRECT(3); ADD(1); BRANCH(1); MOVE(1); /* min() */ PTR_INIT(1); FUNC(4);
   calcPeCorrection(&(AdjThrStateElement->peCorrectionFactor), 
                    min(grantedPe, noRedPe),
                    AdjThrStateElement->peLast, 
                    AdjThrStateElement->dynBitsLast);

   INDIRECT(1); MULT(1);
   grantedPeCorr = grantedPe * AdjThrStateElement->peCorrectionFactor;

   ADD(1); BRANCH(1);
   if (grantedPeCorr < noRedPe) {

      INDIRECT(2); PTR_INIT(3); FUNC(7);
      adaptThresholdsToPe(psyOutChannel,
                          psyOutElement,
                          &peData,
                          nChannels,
                          grantedPeCorr,
                          &AdjThrStateElement->ahParam,
                          &AdjThrStateElement->minSnrAdaptParam);
   }

   PTR_INIT(2); /* pointers for chBitDistribution[],
                                peData.peChannelData[]
                */
   LOOP(1);
   for (ch=0; ch<nChannels; ch++) {

     BRANCH(1);
     if (peData.pe) {

       DIV(1); MULT(2); ADD(2); STORE(1);
       chBitDistribution[ch] = 0.2f + (float)(1.0f-nChannels*0.2f) * (peData.peChannelData[ch].pe/peData.pe);
     } else {

       MOVE(1);
       chBitDistribution[ch] = 0.2f;
     }
   }

   INDIRECT(1); MOVE(1);
   qcOE->pe= noRedPe;

   INDIRECT(1); MOVE(1);
   AdjThrStateElement->peLast = grantedPe;

   COUNT_sub_end();
}
Example #2
0
void AdjustThresholds(ADJ_THR_STATE     *adjThrState,
                      ATS_ELEMENT       *AdjThrStateElement,
                      PSY_OUT_CHANNEL   psyOutChannel[MAX_CHANNELS],
                      PSY_OUT_ELEMENT   *psyOutElement,
                      float             *chBitDistribution,
                      float            sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB],
                      const int         nChannels,
                      QC_OUT_ELEMENT    *qcOE,
                      const int         avgBits,
                      const int         bitresBits,
                      const int         maxBitresBits,
                      const float       maxBitFac,
                      const int         sideInfoBits)
{
   float noRedPe, grantedPe, grantedPeCorr;
   int curWindowSequence;
   PE_DATA peData;
   float bitFactor;
   int ch;

   

     
   preparePe(&peData, psyOutChannel, sfbFormFactor, nChannels, AdjThrStateElement->peOffset);

    
   calcPe(&peData, psyOutChannel, nChannels);

   
   noRedPe = peData.pe;

   
   curWindowSequence = LONG_WINDOW;

    
   if (nChannels==2) {

      
     if ((psyOutChannel[0].windowSequence == SHORT_WINDOW) ||
         (psyOutChannel[1].windowSequence == SHORT_WINDOW)) {

       
       curWindowSequence = SHORT_WINDOW;
     }
   }
   else {

     
     curWindowSequence = psyOutChannel[0].windowSequence;
   }


     
   bitFactor = bitresCalcBitFac(bitresBits, maxBitresBits,
                                noRedPe+5.0f*sideInfoBits,
                                curWindowSequence, avgBits, maxBitFac,
                                adjThrState,
                                AdjThrStateElement);

    
   grantedPe = bitFactor * bits2pe((float)avgBits);

       /* min() */  
   calcPeCorrection(&(AdjThrStateElement->peCorrectionFactor), 
                    min(grantedPe, noRedPe),
                    AdjThrStateElement->peLast, 
                    AdjThrStateElement->dynBitsLast);

    
   grantedPeCorr = grantedPe * AdjThrStateElement->peCorrectionFactor;

    
   if (grantedPeCorr < noRedPe) {

        
      adaptThresholdsToPe(psyOutChannel,
                          psyOutElement,
                          &peData,
                          nChannels,
                          grantedPeCorr,
                          &AdjThrStateElement->ahParam,
                          &AdjThrStateElement->minSnrAdaptParam);
   }

    /* pointers for chBitDistribution[],
                                peData.peChannelData[]
                */
   
   for (ch=0; ch<nChannels; ch++) {

     
     if (peData.pe) {

          
       chBitDistribution[ch] = 0.2f + (float)(1.0f-nChannels*0.2f) * (peData.peChannelData[ch].pe/peData.pe);
     } else {

       
       chBitDistribution[ch] = 0.2f;
     }
   }

    
   qcOE->pe= noRedPe;

    
   AdjThrStateElement->peLast = grantedPe;

   
}