static int synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb,

                                       int length, int sb_min, int sb_max)

{

    int sb, j, k, n, ch, run, channels;

    int joined_stereo, zero_encoding;

    int type34_first;

    float type34_div = 0;

    float type34_predictor;

    float samples[10];

    int sign_bits[16];



    if (length == 0) {

        // If no data use noise

        for (sb=sb_min; sb < sb_max; sb++)

            build_sb_samples_from_noise (q, sb);



        return 0;

    }



    for (sb = sb_min; sb < sb_max; sb++) {

        channels = q->nb_channels;



        if (q->nb_channels <= 1 || sb < 12)

            joined_stereo = 0;

        else if (sb >= 24)

            joined_stereo = 1;

        else

            joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1 (gb) : 0;



        if (joined_stereo) {

            if (get_bits_left(gb) >= 16)

                for (j = 0; j < 16; j++)

                    sign_bits[j] = get_bits1 (gb);



            for (j = 0; j < 64; j++)

                if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])

                    q->coding_method[0][sb][j] = q->coding_method[1][sb][j];



            if (fix_coding_method_array(sb, q->nb_channels,

                                            q->coding_method)) {

                av_log(NULL, AV_LOG_ERROR, "coding method invalid\n");

                build_sb_samples_from_noise(q, sb);

                continue;

            }

            channels = 1;

        }



        for (ch = 0; ch < channels; ch++) {

            FIX_NOISE_IDX(q->noise_idx);

            zero_encoding = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;

            type34_predictor = 0.0;

            type34_first = 1;



            for (j = 0; j < 128; ) {

                switch (q->coding_method[ch][sb][j / 2]) {

                    case 8:

                        if (get_bits_left(gb) >= 10) {

                            if (zero_encoding) {

                                for (k = 0; k < 5; k++) {

                                    if ((j + 2 * k) >= 128)

                                        break;

                                    samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;

                                }

                            } else {

                                n = get_bits(gb, 8);

                                if (n >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (k = 0; k < 5; k++)

                                    samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];

                            }

                            for (k = 0; k < 5; k++)

                                samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        } else {

                            for (k = 0; k < 10; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 10;

                        break;



                    case 10:

                        if (get_bits_left(gb) >= 1) {

                            float f = 0.81;



                            if (get_bits1(gb))

                                f = -f;

                            f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;

                            samples[0] = f;

                        } else {

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 1;

                        break;



                    case 16:

                        if (get_bits_left(gb) >= 10) {

                            if (zero_encoding) {

                                for (k = 0; k < 5; k++) {

                                    if ((j + k) >= 128)

                                        break;

                                    samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];

                                }

                            } else {

                                n = get_bits (gb, 8);

                                if (n >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (k = 0; k < 5; k++)

                                    samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];

                            }

                        } else {

                            for (k = 0; k < 5; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 5;

                        break;



                    case 24:

                        if (get_bits_left(gb) >= 7) {

                            n = get_bits(gb, 7);

                            if (n >= 125) {

                                av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\n");

                                return AVERROR_INVALIDDATA;

                            }



                            for (k = 0; k < 3; k++)

                                samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;

                        } else {

                            for (k = 0; k < 3; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 3;

                        break;



                    case 30:

                        if (get_bits_left(gb) >= 4) {

                            unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);

                            if (index >= FF_ARRAY_ELEMS(type30_dequant)) {

                                av_log(NULL, AV_LOG_ERROR, "index %d out of type30_dequant array\n", index);

                                return AVERROR_INVALIDDATA;

                            }

                            samples[0] = type30_dequant[index];

                        } else

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);



                        run = 1;

                        break;



                    case 34:

                        if (get_bits_left(gb) >= 7) {

                            if (type34_first) {

                                type34_div = (float)(1 << get_bits(gb, 2));

                                samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;

                                type34_predictor = samples[0];

                                type34_first = 0;

                            } else {

                                unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);

                                if (index >= FF_ARRAY_ELEMS(type34_delta)) {

                                    av_log(NULL, AV_LOG_ERROR, "index %d out of type34_delta array\n", index);

                                    return AVERROR_INVALIDDATA;

                                }

                                samples[0] = type34_delta[index] / type34_div + type34_predictor;

                                type34_predictor = samples[0];

                            }

                        } else {

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 1;

                        break;



                    default:

                        samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        run = 1;

                        break;

                }



                if (joined_stereo) {

                    for (k = 0; k < run && j + k < 128; k++) {

                        q->sb_samples[0][j + k][sb] =

                            q->tone_level[0][sb][(j + k) / 2] * samples[k];

                        if (q->nb_channels == 2) {

                            if (sign_bits[(j + k) / 8])

                                q->sb_samples[1][j + k][sb] =

                                    q->tone_level[1][sb][(j + k) / 2] * -samples[k];

                            else

                                q->sb_samples[1][j + k][sb] =

                                    q->tone_level[1][sb][(j + k) / 2] * samples[k];

                        }

                    }

                } else {

                    for (k = 0; k < run; k++)

                        if ((j + k) < 128)

                            q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k];

                }



                j += run;

            } // j loop

        } // channel loop

    } // subband loop

    return 0;

}

static int synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb,

                                       int length, int sb_min, int sb_max)

{

    int sb, j, k, n, ch, run, channels;

    int joined_stereo, zero_encoding;

    int type34_first;

    float type34_div = 0;

    float type34_predictor;

    float samples[10];

    int sign_bits[16];



    if (length == 0) {

        

        for (sb=sb_min; sb < sb_max; sb++)

            build_sb_samples_from_noise (q, sb);



        return 0;

    }



    for (sb = sb_min; sb < sb_max; sb++) {

        channels = q->nb_channels;



        if (q->nb_channels <= 1 || sb < 12)

            joined_stereo = 0;

        else if (sb >= 24)

            joined_stereo = 1;

        else

            joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1 (gb) : 0;



        if (joined_stereo) {

            if (get_bits_left(gb) >= 16)

                for (j = 0; j < 16; j++)

                    sign_bits[j] = get_bits1 (gb);



            for (j = 0; j < 64; j++)

                if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])

                    q->coding_method[0][sb][j] = q->coding_method[1][sb][j];



            if (fix_coding_method_array(sb, q->nb_channels,

                                            q->coding_method)) {

                av_log(NULL, AV_LOG_ERROR, "coding method invalid\n");

                build_sb_samples_from_noise(q, sb);

                continue;

            }

            channels = 1;

        }



        for (ch = 0; ch < channels; ch++) {

            FIX_NOISE_IDX(q->noise_idx);

            zero_encoding = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;

            type34_predictor = 0.0;

            type34_first = 1;



            for (j = 0; j < 128; ) {

                switch (q->coding_method[ch][sb][j / 2]) {

                    case 8:

                        if (get_bits_left(gb) >= 10) {

                            if (zero_encoding) {

                                for (k = 0; k < 5; k++) {

                                    if ((j + 2 * k) >= 128)

                                        break;

                                    samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;

                                }

                            } else {

                                n = get_bits(gb, 8);

                                if (n >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (k = 0; k < 5; k++)

                                    samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];

                            }

                            for (k = 0; k < 5; k++)

                                samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        } else {

                            for (k = 0; k < 10; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 10;

                        break;



                    case 10:

                        if (get_bits_left(gb) >= 1) {

                            float f = 0.81;



                            if (get_bits1(gb))

                                f = -f;

                            f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;

                            samples[0] = f;

                        } else {

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 1;

                        break;



                    case 16:

                        if (get_bits_left(gb) >= 10) {

                            if (zero_encoding) {

                                for (k = 0; k < 5; k++) {

                                    if ((j + k) >= 128)

                                        break;

                                    samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];

                                }

                            } else {

                                n = get_bits (gb, 8);

                                if (n >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (k = 0; k < 5; k++)

                                    samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];

                            }

                        } else {

                            for (k = 0; k < 5; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 5;

                        break;



                    case 24:

                        if (get_bits_left(gb) >= 7) {

                            n = get_bits(gb, 7);

                            if (n >= 125) {

                                av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\n");

                                return AVERROR_INVALIDDATA;

                            }



                            for (k = 0; k < 3; k++)

                                samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;

                        } else {

                            for (k = 0; k < 3; k++)

                                samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 3;

                        break;



                    case 30:

                        if (get_bits_left(gb) >= 4) {

                            unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);

                            if (index >= FF_ARRAY_ELEMS(type30_dequant)) {

                                av_log(NULL, AV_LOG_ERROR, "index %d out of type30_dequant array\n", index);

                                return AVERROR_INVALIDDATA;

                            }

                            samples[0] = type30_dequant[index];

                        } else

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);



                        run = 1;

                        break;



                    case 34:

                        if (get_bits_left(gb) >= 7) {

                            if (type34_first) {

                                type34_div = (float)(1 << get_bits(gb, 2));

                                samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;

                                type34_predictor = samples[0];

                                type34_first = 0;

                            } else {

                                unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);

                                if (index >= FF_ARRAY_ELEMS(type34_delta)) {

                                    av_log(NULL, AV_LOG_ERROR, "index %d out of type34_delta array\n", index);

                                    return AVERROR_INVALIDDATA;

                                }

                                samples[0] = type34_delta[index] / type34_div + type34_predictor;

                                type34_predictor = samples[0];

                            }

                        } else {

                            samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        }

                        run = 1;

                        break;



                    default:

                        samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);

                        run = 1;

                        break;

                }



                if (joined_stereo) {

                    for (k = 0; k < run && j + k < 128; k++) {

                        q->sb_samples[0][j + k][sb] =

                            q->tone_level[0][sb][(j + k) / 2] * samples[k];

                        if (q->nb_channels == 2) {

                            if (sign_bits[(j + k) / 8])

                                q->sb_samples[1][j + k][sb] =

                                    q->tone_level[1][sb][(j + k) / 2] * -samples[k];

                            else

                                q->sb_samples[1][j + k][sb] =

                                    q->tone_level[1][sb][(j + k) / 2] * samples[k];

                        }

                    }

                } else {

                    for (k = 0; k < run; k++)

                        if ((j + k) < 128)

                            q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k];

                }



                j += run;

            } 

        } 

    } 

    return 0;

}

static int FUNC_0(QDM2Context *VAR_0, GetBitContext *VAR_1,

                                       int VAR_2, int VAR_3, int VAR_4)

{

    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    int VAR_12, VAR_13;

    int VAR_14;

    float VAR_15 = 0;

    float VAR_16;

    float VAR_17[10];

    int VAR_18[16];



    if (VAR_2 == 0) {

        

        for (VAR_5=VAR_3; VAR_5 < VAR_4; VAR_5++)

            build_sb_samples_from_noise (VAR_0, VAR_5);



        return 0;

    }



    for (VAR_5 = VAR_3; VAR_5 < VAR_4; VAR_5++) {

        VAR_11 = VAR_0->nb_channels;



        if (VAR_0->nb_channels <= 1 || VAR_5 < 12)

            VAR_12 = 0;

        else if (VAR_5 >= 24)

            VAR_12 = 1;

        else

            VAR_12 = (get_bits_left(VAR_1) >= 1) ? get_bits1 (VAR_1) : 0;



        if (VAR_12) {

            if (get_bits_left(VAR_1) >= 16)

                for (VAR_6 = 0; VAR_6 < 16; VAR_6++)

                    VAR_18[VAR_6] = get_bits1 (VAR_1);



            for (VAR_6 = 0; VAR_6 < 64; VAR_6++)

                if (VAR_0->coding_method[1][VAR_5][VAR_6] > VAR_0->coding_method[0][VAR_5][VAR_6])

                    VAR_0->coding_method[0][VAR_5][VAR_6] = VAR_0->coding_method[1][VAR_5][VAR_6];



            if (fix_coding_method_array(VAR_5, VAR_0->nb_channels,

                                            VAR_0->coding_method)) {

                av_log(NULL, AV_LOG_ERROR, "coding method invalid\VAR_8");

                build_sb_samples_from_noise(VAR_0, VAR_5);

                continue;

            }

            VAR_11 = 1;

        }



        for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9++) {

            FIX_NOISE_IDX(VAR_0->noise_idx);

            VAR_13 = (get_bits_left(VAR_1) >= 1) ? get_bits1(VAR_1) : 0;

            VAR_16 = 0.0;

            VAR_14 = 1;



            for (VAR_6 = 0; VAR_6 < 128; ) {

                switch (VAR_0->coding_method[VAR_9][VAR_5][VAR_6 / 2]) {

                    case 8:

                        if (get_bits_left(VAR_1) >= 10) {

                            if (VAR_13) {

                                for (VAR_7 = 0; VAR_7 < 5; VAR_7++) {

                                    if ((VAR_6 + 2 * VAR_7) >= 128)

                                        break;

                                    VAR_17[2 * VAR_7] = get_bits1(VAR_1) ? dequant_1bit[VAR_12][2 * get_bits1(VAR_1)] : 0;

                                }

                            } else {

                                VAR_8 = get_bits(VAR_1, 8);

                                if (VAR_8 >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\VAR_8");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (VAR_7 = 0; VAR_7 < 5; VAR_7++)

                                    VAR_17[2 * VAR_7] = dequant_1bit[VAR_12][random_dequant_index[VAR_8][VAR_7]];

                            }

                            for (VAR_7 = 0; VAR_7 < 5; VAR_7++)

                                VAR_17[2 * VAR_7 + 1] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        } else {

                            for (VAR_7 = 0; VAR_7 < 10; VAR_7++)

                                VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        }

                        VAR_10 = 10;

                        break;



                    case 10:

                        if (get_bits_left(VAR_1) >= 1) {

                            float VAR_19 = 0.81;



                            if (get_bits1(VAR_1))

                                VAR_19 = -VAR_19;

                            VAR_19 -= noise_samples[((VAR_5 + 1) * (VAR_6 +5 * VAR_9 + 1)) & 127] * 9.0 / 40.0;

                            VAR_17[0] = VAR_19;

                        } else {

                            VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        }

                        VAR_10 = 1;

                        break;



                    case 16:

                        if (get_bits_left(VAR_1) >= 10) {

                            if (VAR_13) {

                                for (VAR_7 = 0; VAR_7 < 5; VAR_7++) {

                                    if ((VAR_6 + VAR_7) >= 128)

                                        break;

                                    VAR_17[VAR_7] = (get_bits1(VAR_1) == 0) ? 0 : dequant_1bit[VAR_12][2 * get_bits1(VAR_1)];

                                }

                            } else {

                                VAR_8 = get_bits (VAR_1, 8);

                                if (VAR_8 >= 243) {

                                    av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\VAR_8");

                                    return AVERROR_INVALIDDATA;

                                }



                                for (VAR_7 = 0; VAR_7 < 5; VAR_7++)

                                    VAR_17[VAR_7] = dequant_1bit[VAR_12][random_dequant_index[VAR_8][VAR_7]];

                            }

                        } else {

                            for (VAR_7 = 0; VAR_7 < 5; VAR_7++)

                                VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        }

                        VAR_10 = 5;

                        break;



                    case 24:

                        if (get_bits_left(VAR_1) >= 7) {

                            VAR_8 = get_bits(VAR_1, 7);

                            if (VAR_8 >= 125) {

                                av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\VAR_8");

                                return AVERROR_INVALIDDATA;

                            }



                            for (VAR_7 = 0; VAR_7 < 3; VAR_7++)

                                VAR_17[VAR_7] = (random_dequant_type24[VAR_8][VAR_7] - 2.0) * 0.5;

                        } else {

                            for (VAR_7 = 0; VAR_7 < 3; VAR_7++)

                                VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        }

                        VAR_10 = 3;

                        break;



                    case 30:

                        if (get_bits_left(VAR_1) >= 4) {

                            unsigned VAR_21 = qdm2_get_vlc(VAR_1, &vlc_tab_type30, 0, 1);

                            if (VAR_21 >= FF_ARRAY_ELEMS(type30_dequant)) {

                                av_log(NULL, AV_LOG_ERROR, "VAR_21 %d out of type30_dequant array\VAR_8", VAR_21);

                                return AVERROR_INVALIDDATA;

                            }

                            VAR_17[0] = type30_dequant[VAR_21];

                        } else

                            VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);



                        VAR_10 = 1;

                        break;



                    case 34:

                        if (get_bits_left(VAR_1) >= 7) {

                            if (VAR_14) {

                                VAR_15 = (float)(1 << get_bits(VAR_1, 2));

                                VAR_17[0] = ((float)get_bits(VAR_1, 5) - 16.0) / 15.0;

                                VAR_16 = VAR_17[0];

                                VAR_14 = 0;

                            } else {

                                unsigned VAR_21 = qdm2_get_vlc(VAR_1, &vlc_tab_type34, 0, 1);

                                if (VAR_21 >= FF_ARRAY_ELEMS(type34_delta)) {

                                    av_log(NULL, AV_LOG_ERROR, "VAR_21 %d out of type34_delta array\VAR_8", VAR_21);

                                    return AVERROR_INVALIDDATA;

                                }

                                VAR_17[0] = type34_delta[VAR_21] / VAR_15 + VAR_16;

                                VAR_16 = VAR_17[0];

                            }

                        } else {

                            VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        }

                        VAR_10 = 1;

                        break;



                    default:

                        VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx);

                        VAR_10 = 1;

                        break;

                }



                if (VAR_12) {

                    for (VAR_7 = 0; VAR_7 < VAR_10 && VAR_6 + VAR_7 < 128; VAR_7++) {

                        VAR_0->sb_samples[0][VAR_6 + VAR_7][VAR_5] =

                            VAR_0->tone_level[0][VAR_5][(VAR_6 + VAR_7) / 2] * VAR_17[VAR_7];

                        if (VAR_0->nb_channels == 2) {

                            if (VAR_18[(VAR_6 + VAR_7) / 8])

                                VAR_0->sb_samples[1][VAR_6 + VAR_7][VAR_5] =

                                    VAR_0->tone_level[1][VAR_5][(VAR_6 + VAR_7) / 2] * -VAR_17[VAR_7];

                            else

                                VAR_0->sb_samples[1][VAR_6 + VAR_7][VAR_5] =

                                    VAR_0->tone_level[1][VAR_5][(VAR_6 + VAR_7) / 2] * VAR_17[VAR_7];

                        }

                    }

                } else {

                    for (VAR_7 = 0; VAR_7 < VAR_10; VAR_7++)

                        if ((VAR_6 + VAR_7) < 128)

                            VAR_0->sb_samples[VAR_9][VAR_6 + VAR_7][VAR_5] = VAR_0->tone_level[VAR_9][VAR_5][(VAR_6 + VAR_7)/2] * VAR_17[VAR_7];

                }



                VAR_6 += VAR_10;

            } 

        } 

    } 

    return 0;

}

static int FUNC_0(QDM2Context *VAR_0, GetBitContext *VAR_1,
int VAR_2, int VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; int VAR_12, VAR_13; int VAR_14; float VAR_15 = 0; float VAR_16; float VAR_17[10]; int VAR_18[16]; if (VAR_2 == 0) { for (VAR_5=VAR_3; VAR_5 < VAR_4; VAR_5++) build_sb_samples_from_noise (VAR_0, VAR_5); return 0; } for (VAR_5 = VAR_3; VAR_5 < VAR_4; VAR_5++) { VAR_11 = VAR_0->nb_channels; if (VAR_0->nb_channels <= 1 || VAR_5 < 12)
VAR_12 = 0; else if (VAR_5 >= 24)
VAR_12 = 1; else
VAR_12 = (get_bits_left(VAR_1) >= 1) ? get_bits1 (VAR_1) : 0; if (VAR_12) { if (get_bits_left(VAR_1) >= 16)
for (VAR_6 = 0; VAR_6 < 16; VAR_6++) VAR_18[VAR_6] = get_bits1 (VAR_1); for (VAR_6 = 0; VAR_6 < 64; VAR_6++) if (VAR_0->coding_method[1][VAR_5][VAR_6] > VAR_0->coding_method[0][VAR_5][VAR_6])
VAR_0->coding_method[0][VAR_5][VAR_6] = VAR_0->coding_method[1][VAR_5][VAR_6]; if (fix_coding_method_array(VAR_5, VAR_0->nb_channels,
VAR_0->coding_method)) { av_log(NULL, AV_LOG_ERROR, "coding method invalid\VAR_8"); build_sb_samples_from_noise(VAR_0, VAR_5); continue; } VAR_11 = 1; } for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9++) { FIX_NOISE_IDX(VAR_0->noise_idx); VAR_13 = (get_bits_left(VAR_1) >= 1) ? get_bits1(VAR_1) : 0; VAR_16 = 0.0; VAR_14 = 1; for (VAR_6 = 0; VAR_6 < 128; ) { switch (VAR_0->coding_method[VAR_9][VAR_5][VAR_6 / 2]) { case 8:
if (get_bits_left(VAR_1) >= 10) { if (VAR_13) { for (VAR_7 = 0; VAR_7 < 5; VAR_7++) { if ((VAR_6 + 2 * VAR_7) >= 128)
break; VAR_17[2 * VAR_7] = get_bits1(VAR_1) ? dequant_1bit[VAR_12][2 * get_bits1(VAR_1)] : 0; } } else { VAR_8 = get_bits(VAR_1, 8); if (VAR_8 >= 243) { av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\VAR_8"); return AVERROR_INVALIDDATA; } for (VAR_7 = 0; VAR_7 < 5; VAR_7++) VAR_17[2 * VAR_7] = dequant_1bit[VAR_12][random_dequant_index[VAR_8][VAR_7]]; } for (VAR_7 = 0; VAR_7 < 5; VAR_7++) VAR_17[2 * VAR_7 + 1] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } else { for (VAR_7 = 0; VAR_7 < 10; VAR_7++) VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } VAR_10 = 10; break; case 10:
if (get_bits_left(VAR_1) >= 1) { float VAR_19 = 0.81; if (get_bits1(VAR_1))
VAR_19 = -VAR_19; VAR_19 -= noise_samples[((VAR_5 + 1) * (VAR_6 +5 * VAR_9 + 1)) & 127] * 9.0 / 40.0; VAR_17[0] = VAR_19; } else { VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } VAR_10 = 1; break; case 16:
if (get_bits_left(VAR_1) >= 10) { if (VAR_13) { for (VAR_7 = 0; VAR_7 < 5; VAR_7++) { if ((VAR_6 + VAR_7) >= 128)
break; VAR_17[VAR_7] = (get_bits1(VAR_1) == 0) ? 0 : dequant_1bit[VAR_12][2 * get_bits1(VAR_1)]; } } else { VAR_8 = get_bits (VAR_1, 8); if (VAR_8 >= 243) { av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\VAR_8"); return AVERROR_INVALIDDATA; } for (VAR_7 = 0; VAR_7 < 5; VAR_7++) VAR_17[VAR_7] = dequant_1bit[VAR_12][random_dequant_index[VAR_8][VAR_7]]; } } else { for (VAR_7 = 0; VAR_7 < 5; VAR_7++) VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } VAR_10 = 5; break; case 24:
if (get_bits_left(VAR_1) >= 7) { VAR_8 = get_bits(VAR_1, 7); if (VAR_8 >= 125) { av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\VAR_8"); return AVERROR_INVALIDDATA; } for (VAR_7 = 0; VAR_7 < 3; VAR_7++) VAR_17[VAR_7] = (random_dequant_type24[VAR_8][VAR_7] - 2.0) * 0.5; } else { for (VAR_7 = 0; VAR_7 < 3; VAR_7++) VAR_17[VAR_7] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } VAR_10 = 3; break; case 30:
if (get_bits_left(VAR_1) >= 4) { unsigned VAR_21 = qdm2_get_vlc(VAR_1, &vlc_tab_type30, 0, 1); if (VAR_21 >= FF_ARRAY_ELEMS(type30_dequant)) { av_log(NULL, AV_LOG_ERROR, "VAR_21 %d out of type30_dequant array\VAR_8", VAR_21); return AVERROR_INVALIDDATA; } VAR_17[0] = type30_dequant[VAR_21]; } else VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); VAR_10 = 1; break; case 34:
if (get_bits_left(VAR_1) >= 7) { if (VAR_14) { VAR_15 = (float)(1 << get_bits(VAR_1, 2)); VAR_17[0] = ((float)get_bits(VAR_1, 5) - 16.0) / 15.0; VAR_16 = VAR_17[0]; VAR_14 = 0; } else { unsigned VAR_21 = qdm2_get_vlc(VAR_1, &vlc_tab_type34, 0, 1); if (VAR_21 >= FF_ARRAY_ELEMS(type34_delta)) { av_log(NULL, AV_LOG_ERROR, "VAR_21 %d out of type34_delta array\VAR_8", VAR_21); return AVERROR_INVALIDDATA; } VAR_17[0] = type34_delta[VAR_21] / VAR_15 + VAR_16; VAR_16 = VAR_17[0]; } } else { VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); } VAR_10 = 1; break; default:
VAR_17[0] = SB_DITHERING_NOISE(VAR_5,VAR_0->noise_idx); VAR_10 = 1; break; } if (VAR_12) { for (VAR_7 = 0; VAR_7 < VAR_10 && VAR_6 + VAR_7 < 128; VAR_7++) { VAR_0->sb_samples[0][VAR_6 + VAR_7][VAR_5] =
VAR_0->tone_level[0][VAR_5][(VAR_6 + VAR_7) / 2] * VAR_17[VAR_7]; if (VAR_0->nb_channels == 2) { if (VAR_18[(VAR_6 + VAR_7) / 8])
VAR_0->sb_samples[1][VAR_6 + VAR_7][VAR_5] =
VAR_0->tone_level[1][VAR_5][(VAR_6 + VAR_7) / 2] * -VAR_17[VAR_7]; else
VAR_0->sb_samples[1][VAR_6 + VAR_7][VAR_5] =
VAR_0->tone_level[1][VAR_5][(VAR_6 + VAR_7) / 2] * VAR_17[VAR_7]; } } } else { for (VAR_7 = 0; VAR_7 < VAR_10; VAR_7++) if ((VAR_6 + VAR_7) < 128)
VAR_0->sb_samples[VAR_9][VAR_6 + VAR_7][VAR_5] = VAR_0->tone_level[VAR_9][VAR_5][(VAR_6 + VAR_7)/2] * VAR_17[VAR_7]; } VAR_6 += VAR_10; } } } return 0; }