private int decodeSpectrumAndDequant(float coef[],float sf[],boolean pulsePresent,Pulse pulse,IndividualChannelStream ics,int bandType[]){
  int idx=0;
  final int c=1024 / ics.numWindows;
  final int offsets[]=ics.swbOffset;
  for (int g=0; g < ics.numWindows; g++) {
    Arrays.fill(coef,g * 128 + offsets[ics.maxSfb],g * 128 + c,0f);
  }
  int coefOffset=0;
  for (int g=0; g < ics.numWindowGroups; g++) {
    int gLen=ics.groupLen[g];
    for (int i=0; i < ics.maxSfb; i++, idx++) {
      final int cbtM1=bandType[idx] == 0 ? Integer.MAX_VALUE : bandType[idx] - 1;
      int cfo=coefOffset + offsets[i];
      int offLen=offsets[i + 1] - offsets[i];
      if (cbtM1 >= INTENSITY_BT2 - 1) {
        for (int group=0; group < gLen; group++, cfo+=128) {
          Arrays.fill(coef,cfo,cfo + offLen,0f);
        }
      }
 else       if (cbtM1 == NOISE_BT - 1) {
        for (int group=0; group < gLen; group++, cfo+=128) {
          for (int k=0; k < offLen; k++) {
            ac.randomState=lcgRandom(ac.randomState);
            coef[cfo + k]=ac.randomState;
          }
          float bandEnergy=FloatDSP.scalarproduct(coef,cfo,coef,cfo,offLen);
          float scale=sf[idx] / (float)sqrt(bandEnergy);
          FloatDSP.vectorFmulScalar(coef,cfo,coef,cfo,scale,offLen);
        }
      }
 else {
        final float vq[]=ff_aac_codebook_vector_vals[cbtM1];
        final int cbVertexIdx[]=ff_aac_codebook_vector_idx[cbtM1];
        VLC vlc=vlc_spectral[cbtM1];
switch (cbtM1 >> 1) {
case 0:
          for (int group=0; group < gLen; group++, cfo+=128) {
            int cf=cfo;
            for (int len=offLen; len != 0; len-=4) {
              int code=vlc.getVLC2(br,2);
              int cbIdx=cbVertexIdx[code];
              cf=VMUL4(coef,cf,vq,0,cbIdx,sf[idx]);
            }
          }
        break;
case 1:
      for (int group=0; group < gLen; group++, cfo+=128) {
        int cf=cfo;
        for (int len=offLen; len != 0; len-=4) {
          int code=vlc.getVLC2(br,2);
          int cbIdx=cbVertexIdx[code];
          int nnz=(cbIdx >> 8) & 15;
          int bits=nnz != 0 ? br.peek(32) : 0;
          br.skip(nnz);
          cf=VMUL4S(coef,cf,vq,0,cbIdx,bits,sf[idx]);
        }
      }
    break;
case 2:
  for (int group=0; group < gLen; group++, cfo+=128) {
    int cf=cfo;
    for (int len=offLen; len != 0; len-=2) {
      int code=vlc.getVLC2(br,2);
      int cbIdx=cbVertexIdx[code];
      cf=VMUL2(coef,cf,vq,0,cbIdx,sf[idx]);
    }
  }
break;
case 3:
case 4:
for (int group=0; group < gLen; group++, cfo+=128) {
int cf=cfo;
for (int len=offLen; len != 0; len-=2) {
  int code=vlc.getVLC2(br,2);
  int cbIdx=cbVertexIdx[code];
  int nnz=(cbIdx >> 8) & 15;
  int sign=nnz != 0 ? (br.peek(nnz) << (cbIdx >> 12)) : 0;
  br.skip(nnz);
  cf=VMUL2S(coef,cf,vq,0,cbIdx,sign,sf[idx]);
}
}
break;
default :
for (int group=0; group < gLen; group++, cfo+=128) {
int icf=cfo;
for (int len=offLen; len != 0; len-=2) {
int code=vlc.getVLC2(br,2);
if (code == 0) {
coef[icf++]=0f;
coef[icf++]=0f;
continue;
}
int cbIdx=cbVertexIdx[code];
int nnz=cbIdx >> 12;
int nzt=cbIdx >> 8;
int bits=br.read(nnz) << (32 - nnz);
for (int j=0; j < 2; j++) {
if ((nzt & (1 << j)) != 0) {
  int b=br.peek(32);
  b=31 - avLog2(~b);
  if (b > 8) {
    log.error(String.format("error in spectral data, ESC overflow"));
    return AAC_ERROR;
  }
  br.skip(b + 1);
  b+=4;
  int n=(1 << b) + br.read(b);
  coef[icf++]=Float.intBitsToFloat(cbrt_tab[n] | (bits & (1 << 31)));
  bits<<=1;
}
 else {
  float v=vq[cbIdx & 15];
  if (v == 0f) {
    coef[icf++]=0f;
  }
 else {
    if ((bits & (1 << 31)) != 0) {
      v=-v;
    }
    coef[icf++]=v;
    bits<<=1;
  }
}
cbIdx>>=4;
}
}
FloatDSP.vectorFmulScalar(coef,cfo,coef,cfo,sf[idx],offLen);
}
break;
}
}
}
coefOffset+=gLen << 7;
}
if (pulsePresent) {
idx=0;
for (int i=0; i < pulse.numPulse; i++) {
float co=coef[pulse.pos[i]];
while (offsets[idx + 1] <= pulse.pos[i]) {
idx++;
}
if (bandType[idx] != NOISE_BT && sf[idx] != 0f) {
float ico=-pulse.amp[i];
if (co != 0f) {
co/=sf[idx];
ico=co / (float)Math.sqrt(Math.sqrt(Math.abs(co))) + (co > 0f ? -ico : ico);
}
coef[pulse.pos[i]]=(float)Math.cbrt(Math.abs(ico)) * ico * sf[idx];
}
}
}
return 0;
}

private int decodeSpectrumAndDequant ( float coef [ ] , float sf [ ] , boolean pulsePresent , Pulse pulse , IndividualChannelStream ics , int bandType [ ] ) { int idx = 0 ; final int c = 1024 / ics . numWindows ; final int offsets [ ] = ics . swbOffset ; for ( int g = 0 ; g < ics . numWindows ; g ++ ) { Arrays . fill ( coef , g * 128 + offsets [ ics . maxSfb ] , g * 128 + c , 0f ) ; } int coefOffset = 0 ; for ( int g = 0 ; g < ics . numWindowGroups ; g ++ ) { int gLen = ics . groupLen [ g ] ; for ( int i = 0 ; i < ics . maxSfb ; i ++ , idx ++ ) { final int cbtM1 = bandType [ idx ] == 0 ? Integer . MAX_VALUE : bandType [ idx ] - 1 ; int cfo = coefOffset + offsets [ i ] ; int offLen = offsets [ i + 1 ] - offsets [ i ] ; if ( cbtM1 >= INTENSITY_BT2 - 1 ) { for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { Arrays . fill ( coef , cfo , cfo + offLen , 0f ) ; } } else if ( cbtM1 == NOISE_BT - 1 ) { for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { for ( int k = 0 ; k < offLen ; k ++ ) { ac . randomState = lcgRandom ( ac . randomState ) ; coef [ cfo + k ] = ac . randomState ; } float bandEnergy = FloatDSP . scalarproduct ( coef , cfo , coef , cfo , offLen ) ; float scale = sf [ idx ] / ( float ) sqrt ( bandEnergy ) ; FloatDSP . vectorFmulScalar ( coef , cfo , coef , cfo , scale , offLen ) ; } } else { final float vq [ ] = ff_aac_codebook_vector_vals [ cbtM1 ] ; final int cbVertexIdx [ ] = ff_aac_codebook_vector_idx [ cbtM1 ] ; VLC vlc = vlc_spectral [ cbtM1 ] ; switch ( cbtM1 > > 1 ) { case 0 : for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { int cf = cfo ; for ( int len = offLen ; len != 0 ; len -= 4 ) { int code = vlc . getVLC2 ( br , 2 ) ; int cbIdx = cbVertexIdx [ code ] ; cf = VMUL4 ( coef , cf , vq , 0 , cbIdx , sf [ idx ] ) ; } } break ; case 1 : for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { int cf = cfo ; for ( int len = offLen ; len != 0 ; len -= 4 ) { int code = vlc . getVLC2 ( br , 2 ) ; int cbIdx = cbVertexIdx [ code ] ; int nnz = ( cbIdx > > 8 ) & 15 ; int bits = nnz != 0 ? br . peek ( 32 ) : 0 ; br . skip ( nnz ) ; cf = VMUL4S ( coef , cf , vq , 0 , cbIdx , bits , sf [ idx ] ) ; } } break ; case 2 : for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { int cf = cfo ; for ( int len = offLen ; len != 0 ; len -= 2 ) { int code = vlc . getVLC2 ( br , 2 ) ; int cbIdx = cbVertexIdx [ code ] ; cf = VMUL2 ( coef , cf , vq , 0 , cbIdx , sf [ idx ] ) ; } } break ; case 3 : case 4 : for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { int cf = cfo ; for ( int len = offLen ; len != 0 ; len -= 2 ) { int code = vlc . getVLC2 ( br , 2 ) ; int cbIdx = cbVertexIdx [ code ] ; int nnz = ( cbIdx > > 8 ) & 15 ; int sign = nnz != 0 ? ( br . peek ( nnz ) << ( cbIdx > > 12 ) ) : 0 ; br . skip ( nnz ) ; cf = VMUL2S ( coef , cf , vq , 0 , cbIdx , sign , sf [ idx ] ) ; } } break ; default : for ( int group = 0 ; group < gLen ; group ++ , cfo += 128 ) { int icf = cfo ; for ( int len = offLen ; len != 0 ; len -= 2 ) { int code = vlc . getVLC2 ( br , 2 ) ; if ( code == 0 ) { coef [ icf ++ ] = 0f ; coef [ icf ++ ] = 0f ; continue ; } int cbIdx = cbVertexIdx [ code ] ; int nnz = cbIdx > > 12 ; int nzt = cbIdx > > 8 ; int bits = br . read ( nnz ) << ( 32 - nnz ) ; for ( int j = 0 ; j < 2 ; j ++ ) { if ( ( nzt & ( 1 << j ) ) != 0 ) { int b = br . peek ( 32 ) ; b = 31 - avLog2 ( ~ b ) ; if ( b > 8 ) { log . error ( String . format ( "error in spectral data, ESC overflow" ) ) ; return AAC_ERROR ; } br . skip ( b + 1 ) ; b += 4 ; int n = ( 1 << b ) + br . read ( b ) ; coef [ icf ++ ] = Float . intBitsToFloat ( cbrt_tab [ n ] | ( bits & ( 1 << 31 ) ) ) ; bits <<= 1 ; } else { float v = vq [ cbIdx & 15 ] ; if ( v == 0f ) { coef [ icf ++ ] = 0f ; } else { if ( ( bits & ( 1 << 31 ) ) != 0 ) { v = - v ; } coef [ icf ++ ] = v ; bits <<= 1 ; } } cbIdx >>= 4 ; } } FloatDSP . vectorFmulScalar ( coef , cfo , coef , cfo , sf [ idx ] , offLen ) ; } break ; } } } coefOffset += gLen << 7 ; } if ( pulsePresent ) { idx = 0 ; for ( int i = 0 ; i < pulse . numPulse ; i ++ ) { float co = coef [ pulse . pos [ i ] ] ; while ( offsets [ idx + 1 ] <= pulse . pos [ i ] ) { idx ++ ; } if ( bandType [ idx ] != NOISE_BT && sf [ idx ] != 0f ) { float ico = - pulse . amp [ i ] ; if ( co != 0f ) { co /= sf [ idx ] ; ico = co / ( float ) Math . sqrt ( Math . sqrt ( Math . abs ( co ) ) ) + ( co > 0f ? - ico : ico ) ; } coef [ pulse . pos [ i ] ] = ( float ) Math . cbrt ( Math . abs ( ico ) ) * ico * sf [ idx ] ; } } } return 0 ; }
decode spectral data ; reference : table 4 . 50 . dequantize and scale spectral data ; reference : 4 . 6 . 3 . 3 .
