private int decodeChannelWordlen(int chNum){
  int ret;
  Channel chan=ctx.channels[chNum];
  Channel refChan=ctx.channels[0];
  int weightIdx=0;
  chan.fillMode=0;
switch (br.read(2)) {
case 0:
    for (int i=0; i < ctx.numQuantUnits; i++) {
      chan.quWordlen[i]=br.read(3);
    }
  break;
case 1:
if (chNum > 0) {
  ret=numCodedUnits(chan);
  if (ret < 0) {
    return ret;
  }
  if (chan.numCodedVals > 0) {
    VLC vlcTab=wl_vlc_tabs[br.read(2)];
    for (int i=0; i < chan.numCodedVals; i++) {
      int delta=vlcTab.getVLC2(br);
      chan.quWordlen[i]=(refChan.quWordlen[i] + delta) & 7;
    }
  }
}
 else {
  weightIdx=br.read(2);
  ret=numCodedUnits(chan);
  if (ret < 0) {
    return ret;
  }
  if (chan.numCodedVals > 0) {
    int pos=br.read(5);
    if (pos > chan.numCodedVals) {
      log.error(String.format("WL mode 1: invalid position %d",pos));
      return AT3P_ERROR;
    }
    int deltaBits=br.read(2);
    int minVal=br.read(3);
    for (int i=0; i < pos; i++) {
      chan.quWordlen[i]=br.read(3);
    }
    for (int i=pos; i < chan.numCodedVals; i++) {
      chan.quWordlen[i]=(minVal + getDelta(deltaBits)) & 7;
    }
  }
}
break;
case 2:
ret=numCodedUnits(chan);
if (ret < 0) {
return ret;
}
if (chNum > 0 && chan.numCodedVals > 0) {
VLC vlcTab=wl_vlc_tabs[br.read(2)];
int delta=vlcTab.getVLC2(br);
chan.quWordlen[0]=(refChan.quWordlen[0] + delta) & 7;
for (int i=1; i < chan.numCodedVals; i++) {
int diff=refChan.quWordlen[i] - refChan.quWordlen[i - 1];
delta=vlcTab.getVLC2(br);
chan.quWordlen[i]=(chan.quWordlen[i - 1] + diff + delta) & 7;
}
}
 else if (chan.numCodedVals > 0) {
boolean flag=br.readBool();
VLC vlcTab=wl_vlc_tabs[br.read(1)];
int startVal=br.read(3);
unpackVqShape(startVal,atrac3p_wl_shapes[startVal][br.read(4)],chan.quWordlen,chan.numCodedVals);
if (!flag) {
for (int i=0; i < chan.numCodedVals; i++) {
int delta=vlcTab.getVLC2(br);
chan.quWordlen[i]=(chan.quWordlen[i] + delta) & 7;
}
}
 else {
int i;
for (i=0; i < (chan.numCodedVals & -2); i+=2) {
if (!br.readBool()) {
chan.quWordlen[i]=(chan.quWordlen[i] + vlcTab.getVLC2(br)) & 7;
chan.quWordlen[i + 1]=(chan.quWordlen[i + 1] + vlcTab.getVLC2(br)) & 7;
}
}
if ((chan.numCodedVals & 1) != 0) {
chan.quWordlen[i]=(chan.quWordlen[i] + vlcTab.getVLC2(br)) & 7;
}
}
}
break;
case 3:
weightIdx=br.read(2);
ret=numCodedUnits(chan);
if (ret < 0) {
return ret;
}
if (chan.numCodedVals > 0) {
VLC vlcTab=wl_vlc_tabs[br.read(2)];
chan.quWordlen[0]=br.read(3);
for (int i=1; i < chan.numCodedVals; i++) {
int delta=vlcTab.getVLC2(br);
chan.quWordlen[i]=(chan.quWordlen[i - 1] + delta) & 7;
}
}
break;
}
if (chan.fillMode == 2) {
for (int i=chan.numCodedVals; i < ctx.numQuantUnits; i++) {
chan.quWordlen[i]=(chNum > 0 ? br.read1() : 1);
}
}
 else if (chan.fillMode == 3) {
int pos=(chNum > 0 ? chan.numCodedVals + chan.splitPoint : ctx.numQuantUnits - chan.splitPoint);
for (int i=chan.numCodedVals; i < pos; i++) {
chan.quWordlen[i]=1;
}
}
if (weightIdx != 0) {
return addWordlenWeights(chan,weightIdx);
}
return 0;
}

private int decodeChannelWordlen ( int chNum ) { int ret ; Channel chan = ctx . channels [ chNum ] ; Channel refChan = ctx . channels [ 0 ] ; int weightIdx = 0 ; chan . fillMode = 0 ; switch ( br . read ( 2 ) ) { case 0 : for ( int i = 0 ; i < ctx . numQuantUnits ; i ++ ) { chan . quWordlen [ i ] = br . read ( 3 ) ; } break ; case 1 : if ( chNum > 0 ) { ret = numCodedUnits ( chan ) ; if ( ret < 0 ) { return ret ; } if ( chan . numCodedVals > 0 ) { VLC vlcTab = wl_vlc_tabs [ br . read ( 2 ) ] ; for ( int i = 0 ; i < chan . numCodedVals ; i ++ ) { int delta = vlcTab . getVLC2 ( br ) ; chan . quWordlen [ i ] = ( refChan . quWordlen [ i ] + delta ) & 7 ; } } } else { weightIdx = br . read ( 2 ) ; ret = numCodedUnits ( chan ) ; if ( ret < 0 ) { return ret ; } if ( chan . numCodedVals > 0 ) { int pos = br . read ( 5 ) ; if ( pos > chan . numCodedVals ) { log . error ( String . format ( "WL mode 1: invalid position %d" , pos ) ) ; return AT3P_ERROR ; } int deltaBits = br . read ( 2 ) ; int minVal = br . read ( 3 ) ; for ( int i = 0 ; i < pos ; i ++ ) { chan . quWordlen [ i ] = br . read ( 3 ) ; } for ( int i = pos ; i < chan . numCodedVals ; i ++ ) { chan . quWordlen [ i ] = ( minVal + getDelta ( deltaBits ) ) & 7 ; } } } break ; case 2 : ret = numCodedUnits ( chan ) ; if ( ret < 0 ) { return ret ; } if ( chNum > 0 && chan . numCodedVals > 0 ) { VLC vlcTab = wl_vlc_tabs [ br . read ( 2 ) ] ; int delta = vlcTab . getVLC2 ( br ) ; chan . quWordlen [ 0 ] = ( refChan . quWordlen [ 0 ] + delta ) & 7 ; for ( int i = 1 ; i < chan . numCodedVals ; i ++ ) { int diff = refChan . quWordlen [ i ] - refChan . quWordlen [ i - 1 ] ; delta = vlcTab . getVLC2 ( br ) ; chan . quWordlen [ i ] = ( chan . quWordlen [ i - 1 ] + diff + delta ) & 7 ; } } else if ( chan . numCodedVals > 0 ) { boolean flag = br . readBool ( ) ; VLC vlcTab = wl_vlc_tabs [ br . read ( 1 ) ] ; int startVal = br . read ( 3 ) ; unpackVqShape ( startVal , atrac3p_wl_shapes [ startVal ] [ br . read ( 4 ) ] , chan . quWordlen , chan . numCodedVals ) ; if ( ! flag ) { for ( int i = 0 ; i < chan . numCodedVals ; i ++ ) { int delta = vlcTab . getVLC2 ( br ) ; chan . quWordlen [ i ] = ( chan . quWordlen [ i ] + delta ) & 7 ; } } else { int i ; for ( i = 0 ; i < ( chan . numCodedVals & - 2 ) ; i += 2 ) { if ( ! br . readBool ( ) ) { chan . quWordlen [ i ] = ( chan . quWordlen [ i ] + vlcTab . getVLC2 ( br ) ) & 7 ; chan . quWordlen [ i + 1 ] = ( chan . quWordlen [ i + 1 ] + vlcTab . getVLC2 ( br ) ) & 7 ; } } if ( ( chan . numCodedVals & 1 ) != 0 ) { chan . quWordlen [ i ] = ( chan . quWordlen [ i ] + vlcTab . getVLC2 ( br ) ) & 7 ; } } } break ; case 3 : weightIdx = br . read ( 2 ) ; ret = numCodedUnits ( chan ) ; if ( ret < 0 ) { return ret ; } if ( chan . numCodedVals > 0 ) { VLC vlcTab = wl_vlc_tabs [ br . read ( 2 ) ] ; chan . quWordlen [ 0 ] = br . read ( 3 ) ; for ( int i = 1 ; i < chan . numCodedVals ; i ++ ) { int delta = vlcTab . getVLC2 ( br ) ; chan . quWordlen [ i ] = ( chan . quWordlen [ i - 1 ] + delta ) & 7 ; } } break ; } if ( chan . fillMode == 2 ) { for ( int i = chan . numCodedVals ; i < ctx . numQuantUnits ; i ++ ) { chan . quWordlen [ i ] = ( chNum > 0 ? br . read1 ( ) : 1 ) ; } } else if ( chan . fillMode == 3 ) { int pos = ( chNum > 0 ? chan . numCodedVals + chan . splitPoint : ctx . numQuantUnits - chan . splitPoint ) ; for ( int i = chan . numCodedVals ; i < pos ; i ++ ) { chan . quWordlen [ i ] = 1 ; } } if ( weightIdx != 0 ) { return addWordlenWeights ( chan , weightIdx ) ; } return 0 ; }
decode word length for each quantization unit of a channel .
