- if (s->reset_block_lengths) {
- s->reset_block_lengths = 0;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->prev_block_len_bits = s->frame_len_bits - v;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->block_len_bits = s->frame_len_bits - v;
- } else {
- /* update block lengths */
- s->prev_block_len_bits = s->block_len_bits;
- s->block_len_bits = s->next_block_len_bits;
- }
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->next_block_len_bits = s->frame_len_bits - v;
- } else {
- /* fixed block len */
- s->next_block_len_bits = s->frame_len_bits;
- s->prev_block_len_bits = s->frame_len_bits;
- s->block_len_bits = s->frame_len_bits;
- }
-
- /* now check if the block length is coherent with the frame length */
- s->block_len = 1 << s->block_len_bits;
- if ((s->block_pos + s->block_len) > s->frame_len)
- return -E_INCOHERENT_BLOCK_LEN;
-
- if (s->ahi.channels == 2) {
- s->ms_stereo = get_bits1(&s->gb);
- }
- v = 0;
- for (ch = 0; ch < s->ahi.channels; ch++) {
- int a = get_bits1(&s->gb);
- s->channel_coded[ch] = a;
- v |= a;
- }
-
- bsize = s->frame_len_bits - s->block_len_bits;
-
- /* if no channel coded, no need to go further */
- /* XXX: fix potential framing problems */
- if (!v)
- goto next;
-
- /* read total gain and extract corresponding number of bits for
- coef escape coding */
- total_gain = 1;
- for (;;) {
- int a = get_bits(&s->gb, 7);
- total_gain += a;
- if (a != 127)
- break;
- }
-
- coef_nb_bits = wma_total_gain_to_bits(total_gain);
-
- /* compute number of coefficients */
- n = s->coefs_end[bsize] - s->coefs_start;
- for (ch = 0; ch < s->ahi.channels; ch++)
- nb_coefs[ch] = n;
-
- /* complex coding */
- if (s->use_noise_coding) {
- for (ch = 0; ch < s->ahi.channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, m, a;
- m = s->exponent_high_sizes[bsize];
- for (i = 0; i < m; i++) {
- a = get_bits1(&s->gb);
- s->high_band_coded[ch][i] = a;
- /* if noise coding, the coefficients are not transmitted */
- if (a)
- nb_coefs[ch] -=
- s->
- exponent_high_bands[bsize]
- [i];
- }
- }
- }
- for (ch = 0; ch < s->ahi.channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, val;
-
- n = s->exponent_high_sizes[bsize];
- val = (int) 0x80000000;
- for (i = 0; i < n; i++) {
- if (s->high_band_coded[ch][i]) {
- if (val == (int) 0x80000000) {
- val =
- get_bits(&s->gb,
- 7) - 19;
- } else {
- code =
- get_vlc2(&s->gb,
- s->
- hgain_vlc.
- table,
- HGAINVLCBITS,
- HGAINMAX);
- if (code < 0)
- return -1;
- val += code - 18;
- }
- s->high_band_values[ch][i] =
- val;
- }
- }
- }
- }
- }
-
- /* exponents can be reused in short blocks. */
- if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) {
- for (ch = 0; ch < s->ahi.channels; ch++) {
- if (s->channel_coded[ch]) {
- if (s->use_exp_vlc) {
- if (decode_exp_vlc(s, ch) < 0)
- return -1;
- } else {
- decode_exp_lsp(s, ch);
- }
- s->exponents_bsize[ch] = bsize;
- }