private int decodeScalefactors(float sf[],int globalGain,IndividualChannelStream ics,int bandType[],int bandTypeRunEnd[]){
  int idx=0;
  int offset[]={globalGain,globalGain - 90,0};
  boolean noiseFlag=true;
  for (int g=0; g < ics.numWindowGroups; g++) {
    for (int i=0; i < ics.maxSfb; ) {
      int runEnd=bandTypeRunEnd[idx];
      if (bandType[idx] == ZERO_BT) {
        for (; i < runEnd; i++, idx++) {
          sf[idx]=0f;
        }
      }
 else       if (bandType[idx] == INTENSITY_BT || bandType[idx] == INTENSITY_BT2) {
        for (; i < runEnd; i++, idx++) {
          offset[2]+=vlc_scalefactors.getVLC2(br,3) - 60;
          int clippedOffset=Utilities.clip(offset[2],-155,100);
          if (offset[2] != clippedOffset) {
            log.warn(String.format("Clipped intensity stereo position (%d -> %d)",offset[2],clippedOffset));
          }
          sf[idx]=ff_aac_pow2sf_tab[-clippedOffset + POW_SF2_ZERO];
        }
      }
 else       if (bandType[idx] == NOISE_BT) {
        for (; i < runEnd; i++, idx++) {
          if (noiseFlag) {
            offset[1]+=br.read(9) - 256;
            noiseFlag=false;
          }
 else {
            offset[1]+=vlc_scalefactors.getVLC2(br,3) - 60;
          }
          int clippedOffset=Utilities.clip(offset[1],-100,155);
          if (offset[1] != clippedOffset) {
            log.warn(String.format("Clipped intensity stereo position (%d -> %d)",offset[1],clippedOffset));
          }
          sf[idx]=-ff_aac_pow2sf_tab[clippedOffset + POW_SF2_ZERO];
        }
      }
 else {
        for (; i < runEnd; i++, idx++) {
          offset[0]+=vlc_scalefactors.getVLC2(br,3) - 60;
          if (offset[0] > 255) {
            log.error(String.format("Scalefactor (%d) out of range",offset[0]));
            return AAC_ERROR;
          }
          sf[idx]=-ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
        }
      }
    }
  }
  return 0;
}

private int decodeScalefactors ( float sf [ ] , int globalGain , IndividualChannelStream ics , int bandType [ ] , int bandTypeRunEnd [ ] ) { int idx = 0 ; int offset [ ] = { globalGain , globalGain - 90 , 0 } ; boolean noiseFlag = true ; for ( int g = 0 ; g < ics . numWindowGroups ; g ++ ) { for ( int i = 0 ; i < ics . maxSfb ; ) { int runEnd = bandTypeRunEnd [ idx ] ; if ( bandType [ idx ] == ZERO_BT ) { for ( ; i < runEnd ; i ++ , idx ++ ) { sf [ idx ] = 0f ; } } else if ( bandType [ idx ] == INTENSITY_BT || bandType [ idx ] == INTENSITY_BT2 ) { for ( ; i < runEnd ; i ++ , idx ++ ) { offset [ 2 ] += vlc_scalefactors . getVLC2 ( br , 3 ) - 60 ; int clippedOffset = Utilities . clip ( offset [ 2 ] , - 155 , 100 ) ; if ( offset [ 2 ] != clippedOffset ) { log . warn ( String . format ( "Clipped intensity stereo position (%d -> %d)" , offset [ 2 ] , clippedOffset ) ) ; } sf [ idx ] = ff_aac_pow2sf_tab [ - clippedOffset + POW_SF2_ZERO ] ; } } else if ( bandType [ idx ] == NOISE_BT ) { for ( ; i < runEnd ; i ++ , idx ++ ) { if ( noiseFlag ) { offset [ 1 ] += br . read ( 9 ) - 256 ; noiseFlag = false ; } else { offset [ 1 ] += vlc_scalefactors . getVLC2 ( br , 3 ) - 60 ; } int clippedOffset = Utilities . clip ( offset [ 1 ] , - 100 , 155 ) ; if ( offset [ 1 ] != clippedOffset ) { log . warn ( String . format ( "Clipped intensity stereo position (%d -> %d)" , offset [ 1 ] , clippedOffset ) ) ; } sf [ idx ] = - ff_aac_pow2sf_tab [ clippedOffset + POW_SF2_ZERO ] ; } } else { for ( ; i < runEnd ; i ++ , idx ++ ) { offset [ 0 ] += vlc_scalefactors . getVLC2 ( br , 3 ) - 60 ; if ( offset [ 0 ] > 255 ) { log . error ( String . format ( "Scalefactor (%d) out of range" , offset [ 0 ] ) ) ; return AAC_ERROR ; } sf [ idx ] = - ff_aac_pow2sf_tab [ offset [ 0 ] - 100 + POW_SF2_ZERO ] ; } } } } return 0 ; }
decode scalefactors ; reference : table 4 . 47 .
