static int parse_tonal(DCALbrDecoder *s, int group)

{

    unsigned int amp[DCA_LBR_CHANNELS_TOTAL];

    unsigned int phs[DCA_LBR_CHANNELS_TOTAL];

    unsigned int diff, main_amp, shift;

    int sf, sf_idx, ch, main_ch, freq;

    int ch_nbits = av_ceil_log2(s->nchannels_total);



    // Parse subframes for this group

    for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) {

        sf_idx = ((s->framenum << group) + sf) & 31;

        s->tonal_bounds[group][sf_idx][0] = s->ntones;



        // Parse tones for this subframe

        for (freq = 1;; freq++) {

            if (get_bits_left(&s->gb) < 1) {

                av_log(s->avctx, AV_LOG_ERROR, "Tonal group chunk too short\n");

                return -1;

            }



            diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 2);

            if (diff >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) {

                av_log(s->avctx, AV_LOG_ERROR, "Invalid tonal frequency diff\n");

                return -1;

            }



            diff = get_bitsz(&s->gb, diff >> 2) + ff_dca_fst_amp[diff];

            if (diff <= 1)

                break;  // End of subframe



            freq += diff - 2;

            if (freq >> (5 - group) > s->nsubbands * 4 - 5) {

                av_log(s->avctx, AV_LOG_ERROR, "Invalid spectral line offset\n");

                return -1;

            }



            // Main channel

            main_ch = get_bitsz(&s->gb, ch_nbits);

            main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 2)

                + s->tonal_scf[ff_dca_freq_to_sb[freq >> (7 - group)]]

                + s->limited_range - 2;

            amp[main_ch] = main_amp < AMP_MAX ? main_amp : 0;

            phs[main_ch] = get_bits(&s->gb, 3);



            // Secondary channels

            for (ch = 0; ch < s->nchannels_total; ch++) {

                if (ch == main_ch)

                    continue;

                if (get_bits1(&s->gb)) {

                    amp[ch] = amp[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_damp, 1);

                    phs[ch] = phs[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_dph,  1);

                } else {

                    amp[ch] = 0;

                    phs[ch] = 0;

                }

            }



            if (amp[main_ch]) {

                // Allocate new tone

                DCALbrTone *t = &s->tones[s->ntones];

                s->ntones = (s->ntones + 1) & (DCA_LBR_TONES - 1);



                t->x_freq = freq >> (5 - group);

                t->f_delt = (freq & ((1 << (5 - group)) - 1)) << group;

                t->ph_rot = 256 - (t->x_freq & 1) * 128 - t->f_delt * 4;



                shift = ff_dca_ph0_shift[(t->x_freq & 3) * 2 + (freq & 1)]

                    - ((t->ph_rot << (5 - group)) - t->ph_rot);



                for (ch = 0; ch < s->nchannels; ch++) {

                    t->amp[ch] = amp[ch] < AMP_MAX ? amp[ch] : 0;

                    t->phs[ch] = 128 - phs[ch] * 32 + shift;

                }

            }

        }



        s->tonal_bounds[group][sf_idx][1] = s->ntones;

    }



    return 0;

}

static int parse_tonal(DCALbrDecoder *s, int group)

{

    unsigned int amp[DCA_LBR_CHANNELS_TOTAL];

    unsigned int phs[DCA_LBR_CHANNELS_TOTAL];

    unsigned int diff, main_amp, shift;

    int sf, sf_idx, ch, main_ch, freq;

    int ch_nbits = av_ceil_log2(s->nchannels_total);



    

    for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) {

        sf_idx = ((s->framenum << group) + sf) & 31;

        s->tonal_bounds[group][sf_idx][0] = s->ntones;



        

        for (freq = 1;; freq++) {

            if (get_bits_left(&s->gb) < 1) {

                av_log(s->avctx, AV_LOG_ERROR, "Tonal group chunk too short\n");

                return -1;

            }



            diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 2);

            if (diff >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) {

                av_log(s->avctx, AV_LOG_ERROR, "Invalid tonal frequency diff\n");

                return -1;

            }



            diff = get_bitsz(&s->gb, diff >> 2) + ff_dca_fst_amp[diff];

            if (diff <= 1)

                break;  



            freq += diff - 2;

            if (freq >> (5 - group) > s->nsubbands * 4 - 5) {

                av_log(s->avctx, AV_LOG_ERROR, "Invalid spectral line offset\n");

                return -1;

            }



            

            main_ch = get_bitsz(&s->gb, ch_nbits);

            main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 2)

                + s->tonal_scf[ff_dca_freq_to_sb[freq >> (7 - group)]]

                + s->limited_range - 2;

            amp[main_ch] = main_amp < AMP_MAX ? main_amp : 0;

            phs[main_ch] = get_bits(&s->gb, 3);



            

            for (ch = 0; ch < s->nchannels_total; ch++) {

                if (ch == main_ch)

                    continue;

                if (get_bits1(&s->gb)) {

                    amp[ch] = amp[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_damp, 1);

                    phs[ch] = phs[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_dph,  1);

                } else {

                    amp[ch] = 0;

                    phs[ch] = 0;

                }

            }



            if (amp[main_ch]) {

                

                DCALbrTone *t = &s->tones[s->ntones];

                s->ntones = (s->ntones + 1) & (DCA_LBR_TONES - 1);



                t->x_freq = freq >> (5 - group);

                t->f_delt = (freq & ((1 << (5 - group)) - 1)) << group;

                t->ph_rot = 256 - (t->x_freq & 1) * 128 - t->f_delt * 4;



                shift = ff_dca_ph0_shift[(t->x_freq & 3) * 2 + (freq & 1)]

                    - ((t->ph_rot << (5 - group)) - t->ph_rot);



                for (ch = 0; ch < s->nchannels; ch++) {

                    t->amp[ch] = amp[ch] < AMP_MAX ? amp[ch] : 0;

                    t->phs[ch] = 128 - phs[ch] * 32 + shift;

                }

            }

        }



        s->tonal_bounds[group][sf_idx][1] = s->ntones;

    }



    return 0;

}

            if (freq >> (5 - group) > s->nsubbands * 4 - 5) {
static int FUNC_0(DCALbrDecoder *VAR_0, int VAR_1)

{

    unsigned int VAR_2[DCA_LBR_CHANNELS_TOTAL];

    unsigned int VAR_3[DCA_LBR_CHANNELS_TOTAL];

    unsigned int VAR_4, VAR_5, VAR_6;

    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    int VAR_12 = av_ceil_log2(VAR_0->nchannels_total);



    

    for (VAR_7 = 0; VAR_7 < 1 << VAR_1; VAR_7 += VAR_4 ? 8 : 1) {

        VAR_8 = ((VAR_0->framenum << VAR_1) + VAR_7) & 31;

        VAR_0->tonal_bounds[VAR_1][VAR_8][0] = VAR_0->ntones;



        

        for (VAR_11 = 1;; VAR_11++) {

            if (get_bits_left(&VAR_0->gb) < 1) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Tonal VAR_1 chunk too short\n");

                return -1;

            }



            VAR_4 = parse_vlc(&VAR_0->gb, &ff_dca_vlc_tnl_grp[VAR_1], 2);

            if (VAR_4 >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid tonal frequency VAR_4\n");

                return -1;

            }



            VAR_4 = get_bitsz(&VAR_0->gb, VAR_4 >> 2) + ff_dca_fst_amp[VAR_4];

            if (VAR_4 <= 1)

                break;  



            VAR_11 += VAR_4 - 2;

            if (VAR_11 >> (5 - VAR_1) > VAR_0->nsubbands * 4 - 5) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid spectral line offset\n");

                return -1;

            }



            

            VAR_10 = get_bitsz(&VAR_0->gb, VAR_12);

            VAR_5 = parse_vlc(&VAR_0->gb, &ff_dca_vlc_tnl_scf, 2)

                + VAR_0->tonal_scf[ff_dca_freq_to_sb[VAR_11 >> (7 - VAR_1)]]

                + VAR_0->limited_range - 2;

            VAR_2[VAR_10] = VAR_5 < AMP_MAX ? VAR_5 : 0;

            VAR_3[VAR_10] = get_bits(&VAR_0->gb, 3);



            

            for (VAR_9 = 0; VAR_9 < VAR_0->nchannels_total; VAR_9++) {

                if (VAR_9 == VAR_10)

                    continue;

                if (get_bits1(&VAR_0->gb)) {

                    VAR_2[VAR_9] = VAR_2[VAR_10] - parse_vlc(&VAR_0->gb, &ff_dca_vlc_damp, 1);

                    VAR_3[VAR_9] = VAR_3[VAR_10] - parse_vlc(&VAR_0->gb, &ff_dca_vlc_dph,  1);

                } else {

                    VAR_2[VAR_9] = 0;

                    VAR_3[VAR_9] = 0;

                }

            }



            if (VAR_2[VAR_10]) {

                

                DCALbrTone *t = &VAR_0->tones[VAR_0->ntones];

                VAR_0->ntones = (VAR_0->ntones + 1) & (DCA_LBR_TONES - 1);



                t->x_freq = VAR_11 >> (5 - VAR_1);

                t->f_delt = (VAR_11 & ((1 << (5 - VAR_1)) - 1)) << VAR_1;

                t->ph_rot = 256 - (t->x_freq & 1) * 128 - t->f_delt * 4;



                VAR_6 = ff_dca_ph0_shift[(t->x_freq & 3) * 2 + (VAR_11 & 1)]

                    - ((t->ph_rot << (5 - VAR_1)) - t->ph_rot);



                for (VAR_9 = 0; VAR_9 < VAR_0->nchannels; VAR_9++) {

                    t->VAR_2[VAR_9] = VAR_2[VAR_9] < AMP_MAX ? VAR_2[VAR_9] : 0;

                    t->VAR_3[VAR_9] = 128 - VAR_3[VAR_9] * 32 + VAR_6;

                }

            }

        }



        VAR_0->tonal_bounds[VAR_1][VAR_8][1] = VAR_0->ntones;

    }



    return 0;

}

static int FUNC_0(DCALbrDecoder *VAR_0, int VAR_1)
{ unsigned int VAR_2[DCA_LBR_CHANNELS_TOTAL]; unsigned int VAR_3[DCA_LBR_CHANNELS_TOTAL]; unsigned int VAR_4, VAR_5, VAR_6; int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; int VAR_12 = av_ceil_log2(VAR_0->nchannels_total); for (VAR_7 = 0; VAR_7 < 1 << VAR_1; VAR_7 += VAR_4 ? 8 : 1) { VAR_8 = ((VAR_0->framenum << VAR_1) + VAR_7) & 31; VAR_0->tonal_bounds[VAR_1][VAR_8][0] = VAR_0->ntones; for (VAR_11 = 1;; VAR_11++) { if (get_bits_left(&VAR_0->gb) < 1) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Tonal VAR_1 chunk too short\n"); return -1; } VAR_4 = parse_vlc(&VAR_0->gb, &ff_dca_vlc_tnl_grp[VAR_1], 2); if (VAR_4 >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid tonal frequency VAR_4\n"); return -1; } VAR_4 = get_bitsz(&VAR_0->gb, VAR_4 >> 2) + ff_dca_fst_amp[VAR_4]; if (VAR_4 <= 1)
break; VAR_11 += VAR_4 - 2; if (VAR_11 >> (5 - VAR_1) > VAR_0->nsubbands * 4 - 5) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid spectral line offset\n"); return -1; } VAR_10 = get_bitsz(&VAR_0->gb, VAR_12); VAR_5 = parse_vlc(&VAR_0->gb, &ff_dca_vlc_tnl_scf, 2)
+ VAR_0->tonal_scf[ff_dca_freq_to_sb[VAR_11 >> (7 - VAR_1)]]
+ VAR_0->limited_range - 2; VAR_2[VAR_10] = VAR_5 < AMP_MAX ? VAR_5 : 0; VAR_3[VAR_10] = get_bits(&VAR_0->gb, 3); for (VAR_9 = 0; VAR_9 < VAR_0->nchannels_total; VAR_9++) { if (VAR_9 == VAR_10)
continue; if (get_bits1(&VAR_0->gb)) { VAR_2[VAR_9] = VAR_2[VAR_10] - parse_vlc(&VAR_0->gb, &ff_dca_vlc_damp, 1); VAR_3[VAR_9] = VAR_3[VAR_10] - parse_vlc(&VAR_0->gb, &ff_dca_vlc_dph,  1); } else { VAR_2[VAR_9] = 0; VAR_3[VAR_9] = 0; } } if (VAR_2[VAR_10]) { DCALbrTone *t = &VAR_0->tones[VAR_0->ntones]; VAR_0->ntones = (VAR_0->ntones + 1) & (DCA_LBR_TONES - 1); t->x_freq = VAR_11 >> (5 - VAR_1); t->f_delt = (VAR_11 & ((1 << (5 - VAR_1)) - 1)) << VAR_1; t->ph_rot = 256 - (t->x_freq & 1) * 128 - t->f_delt * 4; VAR_6 = ff_dca_ph0_shift[(t->x_freq & 3) * 2 + (VAR_11 & 1)]
- ((t->ph_rot << (5 - VAR_1)) - t->ph_rot); for (VAR_9 = 0; VAR_9 < VAR_0->nchannels; VAR_9++) { t->VAR_2[VAR_9] = VAR_2[VAR_9] < AMP_MAX ? VAR_2[VAR_9] : 0; t->VAR_3[VAR_9] = 128 - VAR_3[VAR_9] * 32 + VAR_6; } } } VAR_0->tonal_bounds[VAR_1][VAR_8][1] = VAR_0->ntones; } return 0; }