static void qdm2_decode_fft_packets(QDM2Context *q)

{

    int i, j, min, max, value, type, unknown_flag;

    GetBitContext gb;



    if (q->sub_packet_list_B[0].packet == NULL)

        return;



    /* reset minimum indexes for FFT coefficients */

    q->fft_coefs_index = 0;

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

        q->fft_coefs_min_index[i] = -1;



    /* process subpackets ordered by type, largest type first */

    for (i = 0, max = 256; i < q->sub_packets_B; i++) {

        QDM2SubPacket *packet = NULL;



        /* find subpacket with largest type less than max */

        for (j = 0, min = 0; j < q->sub_packets_B; j++) {

            value = q->sub_packet_list_B[j].packet->type;

            if (value > min && value < max) {

                min    = value;

                packet = q->sub_packet_list_B[j].packet;

            }

        }



        max = min;



        /* check for errors (?) */

        if (!packet)

            return;



        if (i == 0 &&

            (packet->type < 16 || packet->type >= 48 ||

             fft_subpackets[packet->type - 16]))

            return;



        /* decode FFT tones */

        init_get_bits(&gb, packet->data, packet->size * 8);



        if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])

            unknown_flag = 1;

        else

            unknown_flag = 0;



        type = packet->type;



        if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {

            int duration = q->sub_sampling + 5 - (type & 15);



            if (duration >= 0 && duration < 4)

                qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);

        } else if (type == 31) {

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

                qdm2_fft_decode_tones(q, j, &gb, unknown_flag);

        } else if (type == 46) {

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

                q->fft_level_exp[j] = get_bits(&gb, 6);

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

                qdm2_fft_decode_tones(q, j, &gb, unknown_flag);

        }

    } // Loop on B packets



    /* calculate maximum indexes for FFT coefficients */

    for (i = 0, j = -1; i < 5; i++)

        if (q->fft_coefs_min_index[i] >= 0) {

            if (j >= 0)

                q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];

            j = i;

        }

    if (j >= 0)

        q->fft_coefs_max_index[j] = q->fft_coefs_index;

}

static void qdm2_decode_fft_packets(QDM2Context *q)

{

    int i, j, min, max, value, type, unknown_flag;

    GetBitContext gb;



    if (q->sub_packet_list_B[0].packet == NULL)

        return;



    

    q->fft_coefs_index = 0;

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

        q->fft_coefs_min_index[i] = -1;



    

    for (i = 0, max = 256; i < q->sub_packets_B; i++) {

        QDM2SubPacket *packet = NULL;



        

        for (j = 0, min = 0; j < q->sub_packets_B; j++) {

            value = q->sub_packet_list_B[j].packet->type;

            if (value > min && value < max) {

                min    = value;

                packet = q->sub_packet_list_B[j].packet;

            }

        }



        max = min;



        

        if (!packet)

            return;



        if (i == 0 &&

            (packet->type < 16 || packet->type >= 48 ||

             fft_subpackets[packet->type - 16]))

            return;



        

        init_get_bits(&gb, packet->data, packet->size * 8);



        if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])

            unknown_flag = 1;

        else

            unknown_flag = 0;



        type = packet->type;



        if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {

            int duration = q->sub_sampling + 5 - (type & 15);



            if (duration >= 0 && duration < 4)

                qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);

        } else if (type == 31) {

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

                qdm2_fft_decode_tones(q, j, &gb, unknown_flag);

        } else if (type == 46) {

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

                q->fft_level_exp[j] = get_bits(&gb, 6);

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

                qdm2_fft_decode_tones(q, j, &gb, unknown_flag);

        }

    } 



    

    for (i = 0, j = -1; i < 5; i++)

        if (q->fft_coefs_min_index[i] >= 0) {

            if (j >= 0)

                q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];

            j = i;

        }

    if (j >= 0)

        q->fft_coefs_max_index[j] = q->fft_coefs_index;

}

static void FUNC_0(QDM2Context *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    GetBitContext gb;



    if (VAR_0->sub_packet_list_B[0].packet == NULL)

        return;



    

    VAR_0->fft_coefs_index = 0;

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

        VAR_0->fft_coefs_min_index[VAR_1] = -1;



    

    for (VAR_1 = 0, VAR_4 = 256; VAR_1 < VAR_0->sub_packets_B; VAR_1++) {

        QDM2SubPacket *packet = NULL;



        

        for (VAR_2 = 0, VAR_3 = 0; VAR_2 < VAR_0->sub_packets_B; VAR_2++) {

            VAR_5 = VAR_0->sub_packet_list_B[VAR_2].packet->VAR_6;

            if (VAR_5 > VAR_3 && VAR_5 < VAR_4) {

                VAR_3    = VAR_5;

                packet = VAR_0->sub_packet_list_B[VAR_2].packet;

            }

        }



        VAR_4 = VAR_3;



        

        if (!packet)

            return;



        if (VAR_1 == 0 &&

            (packet->VAR_6 < 16 || packet->VAR_6 >= 48 ||

             fft_subpackets[packet->VAR_6 - 16]))

            return;



        

        init_get_bits(&gb, packet->data, packet->size * 8);



        if (packet->VAR_6 >= 32 && packet->VAR_6 < 48 && !fft_subpackets[packet->VAR_6 - 16])

            VAR_7 = 1;

        else

            VAR_7 = 0;



        VAR_6 = packet->VAR_6;



        if ((VAR_6 >= 17 && VAR_6 < 24) || (VAR_6 >= 33 && VAR_6 < 40)) {

            int duration = VAR_0->sub_sampling + 5 - (VAR_6 & 15);



            if (duration >= 0 && duration < 4)

                qdm2_fft_decode_tones(VAR_0, duration, &gb, VAR_7);

        } else if (VAR_6 == 31) {

            for (VAR_2 = 0; VAR_2 < 4; VAR_2++)

                qdm2_fft_decode_tones(VAR_0, VAR_2, &gb, VAR_7);

        } else if (VAR_6 == 46) {

            for (VAR_2 = 0; VAR_2 < 6; VAR_2++)

                VAR_0->fft_level_exp[VAR_2] = get_bits(&gb, 6);

            for (VAR_2 = 0; VAR_2 < 4; VAR_2++)

                qdm2_fft_decode_tones(VAR_0, VAR_2, &gb, VAR_7);

        }

    } 



    

    for (VAR_1 = 0, VAR_2 = -1; VAR_1 < 5; VAR_1++)

        if (VAR_0->fft_coefs_min_index[VAR_1] >= 0) {

            if (VAR_2 >= 0)

                VAR_0->fft_coefs_max_index[VAR_2] = VAR_0->fft_coefs_min_index[VAR_1];

            VAR_2 = VAR_1;

        }

    if (VAR_2 >= 0)

        VAR_0->fft_coefs_max_index[VAR_2] = VAR_0->fft_coefs_index;

}

static void FUNC_0(QDM2Context *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; GetBitContext gb; if (VAR_0->sub_packet_list_B[0].packet == NULL)
return; VAR_0->fft_coefs_index = 0; for (VAR_1 = 0; VAR_1 < 5; VAR_1++) VAR_0->fft_coefs_min_index[VAR_1] = -1; for (VAR_1 = 0, VAR_4 = 256; VAR_1 < VAR_0->sub_packets_B; VAR_1++) { QDM2SubPacket *packet = NULL; for (VAR_2 = 0, VAR_3 = 0; VAR_2 < VAR_0->sub_packets_B; VAR_2++) { VAR_5 = VAR_0->sub_packet_list_B[VAR_2].packet->VAR_6; if (VAR_5 > VAR_3 && VAR_5 < VAR_4) { VAR_3    = VAR_5; packet = VAR_0->sub_packet_list_B[VAR_2].packet; } } VAR_4 = VAR_3; if (!packet)
return; if (VAR_1 == 0 &&
(packet->VAR_6 < 16 || packet->VAR_6 >= 48 ||
fft_subpackets[packet->VAR_6 - 16]))
return; init_get_bits(&gb, packet->data, packet->size * 8); if (packet->VAR_6 >= 32 && packet->VAR_6 < 48 && !fft_subpackets[packet->VAR_6 - 16])
VAR_7 = 1; else
VAR_7 = 0; VAR_6 = packet->VAR_6; if ((VAR_6 >= 17 && VAR_6 < 24) || (VAR_6 >= 33 && VAR_6 < 40)) { int duration = VAR_0->sub_sampling + 5 - (VAR_6 & 15); if (duration >= 0 && duration < 4)
qdm2_fft_decode_tones(VAR_0, duration, &gb, VAR_7); } else if (VAR_6 == 31) { for (VAR_2 = 0; VAR_2 < 4; VAR_2++) qdm2_fft_decode_tones(VAR_0, VAR_2, &gb, VAR_7); } else if (VAR_6 == 46) { for (VAR_2 = 0; VAR_2 < 6; VAR_2++) VAR_0->fft_level_exp[VAR_2] = get_bits(&gb, 6); for (VAR_2 = 0; VAR_2 < 4; VAR_2++) qdm2_fft_decode_tones(VAR_0, VAR_2, &gb, VAR_7); } } for (VAR_1 = 0, VAR_2 = -1; VAR_1 < 5; VAR_1++) if (VAR_0->fft_coefs_min_index[VAR_1] >= 0) { if (VAR_2 >= 0)
VAR_0->fft_coefs_max_index[VAR_2] = VAR_0->fft_coefs_min_index[VAR_1]; VAR_2 = VAR_1; } if (VAR_2 >= 0)
VAR_0->fft_coefs_max_index[VAR_2] = VAR_0->fft_coefs_index; }