static void fill_tone_level_array (QDM2Context *q, int flag)

{

    int i, sb, ch, sb_used;

    int tmp, tab;



    // This should never happen

    if (q->nb_channels <= 0)

        return;



    for (ch = 0; ch < q->nb_channels; ch++)

        for (sb = 0; sb < 30; sb++)

            for (i = 0; i < 8; i++) {

                if ((tab=coeff_per_sb_for_dequant[q->coeff_per_sb_select][sb]) < (last_coeff[q->coeff_per_sb_select] - 1))

                    tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+

                          q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];

                else

                    tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];

                if(tmp < 0)

                    tmp += 0xff;

                q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;

            }



    sb_used = QDM2_SB_USED(q->sub_sampling);



    if ((q->superblocktype_2_3 != 0) && !flag) {

        for (sb = 0; sb < sb_used; sb++)

            for (ch = 0; ch < q->nb_channels; ch++)

                for (i = 0; i < 64; i++) {

                    q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];

                    if (q->tone_level_idx[ch][sb][i] < 0)

                        q->tone_level[ch][sb][i] = 0;

                    else

                        q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];

                }

    } else {

        tab = q->superblocktype_2_3 ? 0 : 1;

        for (sb = 0; sb < sb_used; sb++) {

            if ((sb >= 4) && (sb <= 23)) {

                for (ch = 0; ch < q->nb_channels; ch++)

                    for (i = 0; i < 64; i++) {

                        tmp = q->tone_level_idx_base[ch][sb][i / 8] -

                              q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -

                              q->tone_level_idx_mid[ch][sb - 4][i / 8] -

                              q->tone_level_idx_hi2[ch][sb - 4];

                        q->tone_level_idx[ch][sb][i] = tmp & 0xff;

                        if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                            q->tone_level[ch][sb][i] = 0;

                        else

                            q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                }

            } else {

                if (sb > 4) {

                    for (ch = 0; ch < q->nb_channels; ch++)

                        for (i = 0; i < 64; i++) {

                            tmp = q->tone_level_idx_base[ch][sb][i / 8] -

                                  q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -

                                  q->tone_level_idx_hi2[ch][sb - 4];

                            q->tone_level_idx[ch][sb][i] = tmp & 0xff;

                            if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                                q->tone_level[ch][sb][i] = 0;

                            else

                                q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                    }

                } else {

                    for (ch = 0; ch < q->nb_channels; ch++)

                        for (i = 0; i < 64; i++) {

                            tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];

                            if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                                q->tone_level[ch][sb][i] = 0;

                            else

                                q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                        }

                }

            }

        }

    }



    return;

}

static void fill_tone_level_array (QDM2Context *q, int flag)

{

    int i, sb, ch, sb_used;

    int tmp, tab;



    

    if (q->nb_channels <= 0)

        return;



    for (ch = 0; ch < q->nb_channels; ch++)

        for (sb = 0; sb < 30; sb++)

            for (i = 0; i < 8; i++) {

                if ((tab=coeff_per_sb_for_dequant[q->coeff_per_sb_select][sb]) < (last_coeff[q->coeff_per_sb_select] - 1))

                    tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+

                          q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];

                else

                    tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];

                if(tmp < 0)

                    tmp += 0xff;

                q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;

            }



    sb_used = QDM2_SB_USED(q->sub_sampling);



    if ((q->superblocktype_2_3 != 0) && !flag) {

        for (sb = 0; sb < sb_used; sb++)

            for (ch = 0; ch < q->nb_channels; ch++)

                for (i = 0; i < 64; i++) {

                    q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];

                    if (q->tone_level_idx[ch][sb][i] < 0)

                        q->tone_level[ch][sb][i] = 0;

                    else

                        q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];

                }

    } else {

        tab = q->superblocktype_2_3 ? 0 : 1;

        for (sb = 0; sb < sb_used; sb++) {

            if ((sb >= 4) && (sb <= 23)) {

                for (ch = 0; ch < q->nb_channels; ch++)

                    for (i = 0; i < 64; i++) {

                        tmp = q->tone_level_idx_base[ch][sb][i / 8] -

                              q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -

                              q->tone_level_idx_mid[ch][sb - 4][i / 8] -

                              q->tone_level_idx_hi2[ch][sb - 4];

                        q->tone_level_idx[ch][sb][i] = tmp & 0xff;

                        if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                            q->tone_level[ch][sb][i] = 0;

                        else

                            q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                }

            } else {

                if (sb > 4) {

                    for (ch = 0; ch < q->nb_channels; ch++)

                        for (i = 0; i < 64; i++) {

                            tmp = q->tone_level_idx_base[ch][sb][i / 8] -

                                  q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -

                                  q->tone_level_idx_hi2[ch][sb - 4];

                            q->tone_level_idx[ch][sb][i] = tmp & 0xff;

                            if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                                q->tone_level[ch][sb][i] = 0;

                            else

                                q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                    }

                } else {

                    for (ch = 0; ch < q->nb_channels; ch++)

                        for (i = 0; i < 64; i++) {

                            tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];

                            if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))

                                q->tone_level[ch][sb][i] = 0;

                            else

                                q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];

                        }

                }

            }

        }

    }



    return;

}

static void FUNC_0 (QDM2Context *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7;



    

    if (VAR_0->nb_channels <= 0)

        return;



    for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++)

        for (VAR_3 = 0; VAR_3 < 30; VAR_3++)

            for (VAR_2 = 0; VAR_2 < 8; VAR_2++) {

                if ((VAR_7=coeff_per_sb_for_dequant[VAR_0->coeff_per_sb_select][VAR_3]) < (last_coeff[VAR_0->coeff_per_sb_select] - 1))

                    VAR_6 = VAR_0->quantized_coeffs[VAR_4][VAR_7 + 1][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7 + 1][VAR_3]+

                          VAR_0->quantized_coeffs[VAR_4][VAR_7][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7][VAR_3];

                else

                    VAR_6 = VAR_0->quantized_coeffs[VAR_4][VAR_7][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7][VAR_3];

                if(VAR_6 < 0)

                    VAR_6 += 0xff;

                VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2] = (VAR_6 / 256) & 0xff;

            }



    VAR_5 = QDM2_SB_USED(VAR_0->sub_sampling);



    if ((VAR_0->superblocktype_2_3 != 0) && !VAR_1) {

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

            for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++)

                for (VAR_2 = 0; VAR_2 < 64; VAR_2++) {

                    VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8];

                    if (VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] < 0)

                        VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0;

                    else

                        VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[0][VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] & 0x3f];

                }

    } else {

        VAR_7 = VAR_0->superblocktype_2_3 ? 0 : 1;

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

            if ((VAR_3 >= 4) && (VAR_3 <= 23)) {

                for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++)

                    for (VAR_2 = 0; VAR_2 < 64; VAR_2++) {

                        VAR_6 = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8] -

                              VAR_0->tone_level_idx_hi1[VAR_4][VAR_3 / 8][VAR_2 / 8][VAR_2 % 8] -

                              VAR_0->tone_level_idx_mid[VAR_4][VAR_3 - 4][VAR_2 / 8] -

                              VAR_0->tone_level_idx_hi2[VAR_4][VAR_3 - 4];

                        VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_6 & 0xff;

                        if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))

                            VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0;

                        else

                            VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f];

                }

            } else {

                if (VAR_3 > 4) {

                    for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++)

                        for (VAR_2 = 0; VAR_2 < 64; VAR_2++) {

                            VAR_6 = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8] -

                                  VAR_0->tone_level_idx_hi1[VAR_4][2][VAR_2 / 8][VAR_2 % 8] -

                                  VAR_0->tone_level_idx_hi2[VAR_4][VAR_3 - 4];

                            VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_6 & 0xff;

                            if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))

                                VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0;

                            else

                                VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f];

                    }

                } else {

                    for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++)

                        for (VAR_2 = 0; VAR_2 < 64; VAR_2++) {

                            VAR_6 = VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8];

                            if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))

                                VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0;

                            else

                                VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f];

                        }

                }

            }

        }

    }



    return;

}

static void FUNC_0 (QDM2Context *VAR_0, int VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7; if (VAR_0->nb_channels <= 0)
return; for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) for (VAR_3 = 0; VAR_3 < 30; VAR_3++) for (VAR_2 = 0; VAR_2 < 8; VAR_2++) { if ((VAR_7=coeff_per_sb_for_dequant[VAR_0->coeff_per_sb_select][VAR_3]) < (last_coeff[VAR_0->coeff_per_sb_select] - 1))
VAR_6 = VAR_0->quantized_coeffs[VAR_4][VAR_7 + 1][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7 + 1][VAR_3]+
VAR_0->quantized_coeffs[VAR_4][VAR_7][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7][VAR_3]; else
VAR_6 = VAR_0->quantized_coeffs[VAR_4][VAR_7][VAR_2] * dequant_table[VAR_0->coeff_per_sb_select][VAR_7][VAR_3]; if(VAR_6 < 0)
VAR_6 += 0xff; VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2] = (VAR_6 / 256) & 0xff; } VAR_5 = QDM2_SB_USED(VAR_0->sub_sampling); if ((VAR_0->superblocktype_2_3 != 0) && !VAR_1) { for (VAR_3 = 0; VAR_3 < VAR_5; VAR_3++) for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) for (VAR_2 = 0; VAR_2 < 64; VAR_2++) { VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8]; if (VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] < 0)
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0; else
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[0][VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] & 0x3f]; } } else { VAR_7 = VAR_0->superblocktype_2_3 ? 0 : 1; for (VAR_3 = 0; VAR_3 < VAR_5; VAR_3++) { if ((VAR_3 >= 4) && (VAR_3 <= 23)) { for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) for (VAR_2 = 0; VAR_2 < 64; VAR_2++) { VAR_6 = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8] -
VAR_0->tone_level_idx_hi1[VAR_4][VAR_3 / 8][VAR_2 / 8][VAR_2 % 8] -
VAR_0->tone_level_idx_mid[VAR_4][VAR_3 - 4][VAR_2 / 8] -
VAR_0->tone_level_idx_hi2[VAR_4][VAR_3 - 4]; VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_6 & 0xff; if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0; else
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f]; } } else { if (VAR_3 > 4) { for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) for (VAR_2 = 0; VAR_2 < 64; VAR_2++) { VAR_6 = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8] -
VAR_0->tone_level_idx_hi1[VAR_4][2][VAR_2 / 8][VAR_2 % 8] -
VAR_0->tone_level_idx_hi2[VAR_4][VAR_3 - 4]; VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_6 & 0xff; if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0; else
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f]; } } else { for (VAR_4 = 0; VAR_4 < VAR_0->nb_channels; VAR_4++) for (VAR_2 = 0; VAR_2 < 64; VAR_2++) { VAR_6 = VAR_0->tone_level_idx[VAR_4][VAR_3][VAR_2] = VAR_0->tone_level_idx_base[VAR_4][VAR_3][VAR_2 / 8]; if ((VAR_6 < 0) || (!VAR_0->superblocktype_2_3 && !VAR_6))
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = 0; else
VAR_0->tone_level[VAR_4][VAR_3][VAR_2] = fft_tone_level_table[VAR_7][VAR_6 & 0x3f]; } } } } } return; }