return b;
}
//sectionDataResilience = hDecoder->aacSectionDataResilienceFlag
public static void decodeReorderedSpectralData(ICStream ics, BitStream in, short[] spectralData, boolean sectionDataResilience) throws AACException {
final ICSInfo info = ics.getInfo();
final int windowGroupCount = info.getWindowGroupCount();
final int maxSFB = info.getMaxSFB();
final int[] swbOffsets = info.getSWBOffsets();
final int swbOffsetMax = info.getSWBOffsetMax();
//TODO:
//final SectionData sectData = ics.getSectionData();
final int[][] sectStart = null; //sectData.getSectStart();
final int[][] sectEnd = null; //sectData.getSectEnd();
final int[] numSec = null; //sectData.getNumSec();
final int[][] sectCB = null; //sectData.getSectCB();
final int[][] sectSFBOffsets = null; //info.getSectSFBOffsets();
//check parameter
final int spDataLen = ics.getReorderedSpectralDataLength();
if(spDataLen==0) return;
final int longestLen = ics.getLongestCodewordLength();
if(longestLen==0||longestLen>=spDataLen) throw new AACException("length of longest HCR codeword out of range");
//create spOffsets
final int[] spOffsets = new int[8];
final int shortFrameLen = spectralData.length/8;
spOffsets[0] = 0;
int g;
for(g = 1; g<windowGroupCount; g++) {
spOffsets[g] = spOffsets[g-1]+shortFrameLen*info.getWindowGroupLength(g-1);
}
final Codeword[] codeword = new Codeword[512];
final BitsBuffer[] segment = new BitsBuffer[512];
int lastCB;
int[] preSortCB;
if(sectionDataResilience) {
preSortCB = PRE_SORT_CB_ER;
lastCB = NUM_CB_ER;
}
else {
preSortCB = PRE_SORT_CB_STD;
lastCB = NUM_CB;
}
int PCWs_done = 0;
int segmentsCount = 0;
int numberOfCodewords = 0;
int bitsread = 0;
int sfb, w_idx, i, thisCB, thisSectCB, cws;
//step 1: decode PCW's (set 0), and stuff data in easier-to-use format
for(int sortloop = 0; sortloop<lastCB; sortloop++) {
//select codebook to process this pass
thisCB = preSortCB[sortloop];
for(sfb = 0; sfb<maxSFB; sfb++) {
for(w_idx = 0; 4*w_idx<(Math.min(swbOffsets[sfb+1], swbOffsetMax)-swbOffsets[sfb]); w_idx++) {
for(g = 0; g<windowGroupCount; g++) {
for(i = 0; i<numSec[g]; i++) {
if((sectStart[g][i]<=sfb)&&(sectEnd[g][i]>sfb)) {
/* check whether codebook used here is the one we want to process */
thisSectCB = sectCB[g][i];
if(isGoodCB(thisCB, thisSectCB)) {
//precalculation
int sect_sfb_size = sectSFBOffsets[g][sfb+1]-sectSFBOffsets[g][sfb];
int inc = (thisSectCB<HCB.FIRST_PAIR_HCB) ? 4 : 2;
int group_cws_count = (4*info.getWindowGroupLength(g))/inc;
int segwidth = Math.min(MAX_CW_LEN[thisSectCB], longestLen);
//read codewords until end of sfb or end of window group
for(cws = 0; (cws<group_cws_count)&&((cws+w_idx*group_cws_count)<sect_sfb_size); cws++) {
int sp = spOffsets[g]+sectSFBOffsets[g][sfb]+inc*(cws+w_idx*group_cws_count);