static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)

{

    int k, l;

    int subsubframe = s->current_subsubframe;



    const float *quant_step_table;



    /* FIXME */

    float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];

    LOCAL_ALIGNED_16(int32_t, block, [8 * DCA_SUBBANDS]);



    /*

     * Audio data

     */



    /* Select quantization step size table */

    if (s->bit_rate_index == 0x1f)

        quant_step_table = lossless_quant_d;

    else

        quant_step_table = lossy_quant_d;



    for (k = base_channel; k < s->prim_channels; k++) {

        float rscale[DCA_SUBBANDS];



        if (get_bits_left(&s->gb) < 0)

            return AVERROR_INVALIDDATA;



        for (l = 0; l < s->vq_start_subband[k]; l++) {

            int m;



            /* Select the mid-tread linear quantizer */

            int abits = s->bitalloc[k][l];



            float quant_step_size = quant_step_table[abits];



            /*

             * Determine quantization index code book and its type

             */



            /* Select quantization index code book */

            int sel = s->quant_index_huffman[k][abits];



            /*

             * Extract bits from the bit stream

             */

            if (!abits) {

                rscale[l] = 0;

                memset(block + 8 * l, 0, 8 * sizeof(block[0]));

            } else {

                /* Deal with transients */

                int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l];

                rscale[l] = quant_step_size * s->scale_factor[k][l][sfi] *

                               s->scalefactor_adj[k][sel];



                if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {

                    if (abits <= 7) {

                        /* Block code */

                        int block_code1, block_code2, size, levels, err;



                        size   = abits_sizes[abits - 1];

                        levels = abits_levels[abits - 1];



                        block_code1 = get_bits(&s->gb, size);

                        block_code2 = get_bits(&s->gb, size);

                        err = decode_blockcodes(block_code1, block_code2,

                                                levels, block + 8 * l);

                        if (err) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "ERROR: block code look-up failed\n");

                            return AVERROR_INVALIDDATA;

                        }

                    } else {

                        /* no coding */

                        for (m = 0; m < 8; m++)

                            block[8 * l + m] = get_sbits(&s->gb, abits - 3);

                    }

                } else {

                    /* Huffman coded */

                    for (m = 0; m < 8; m++)

                        block[8 * l + m] = get_bitalloc(&s->gb,

                                                &dca_smpl_bitalloc[abits], sel);

                }



            }

        }



        s->fmt_conv.int32_to_float_fmul_array8(&s->fmt_conv, subband_samples[k][0],

                                               block, rscale, 8 * s->vq_start_subband[k]);



        for (l = 0; l < s->vq_start_subband[k]; l++) {

            int m;

            /*

             * Inverse ADPCM if in prediction mode

             */

            if (s->prediction_mode[k][l]) {

                int n;

                if (s->predictor_history)

                    subband_samples[k][l][0] += (adpcm_vb[s->prediction_vq[k][l]][0] *

                                                 s->subband_samples_hist[k][l][3] +

                                                 adpcm_vb[s->prediction_vq[k][l]][1] *

                                                 s->subband_samples_hist[k][l][2] +

                                                 adpcm_vb[s->prediction_vq[k][l]][2] *

                                                 s->subband_samples_hist[k][l][1] +

                                                 adpcm_vb[s->prediction_vq[k][l]][3] *

                                                 s->subband_samples_hist[k][l][0]) *

                                                (1.0f / 8192);

                for (m = 1; m < 8; m++) {

                    float sum = adpcm_vb[s->prediction_vq[k][l]][0] *

                                subband_samples[k][l][m - 1];

                    for (n = 2; n <= 4; n++)

                        if (m >= n)

                            sum += adpcm_vb[s->prediction_vq[k][l]][n - 1] *

                                   subband_samples[k][l][m - n];

                        else if (s->predictor_history)

                            sum += adpcm_vb[s->prediction_vq[k][l]][n - 1] *

                                   s->subband_samples_hist[k][l][m - n + 4];

                    subband_samples[k][l][m] += sum * 1.0f / 8192;

                }

            }

        }



        /*

         * Decode VQ encoded high frequencies

         */

        for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {

            /* 1 vector -> 32 samples but we only need the 8 samples

             * for this subsubframe. */

            int hfvq = s->high_freq_vq[k][l];



            if (!s->debug_flag & 0x01) {

                av_log(s->avctx, AV_LOG_DEBUG,

                       "Stream with high frequencies VQ coding\n");

                s->debug_flag |= 0x01;

            }



            int8x8_fmul_int32(&s->dcadsp, subband_samples[k][l],

                              &high_freq_vq[hfvq][subsubframe * 8],

                              s->scale_factor[k][l][0]);

        }

    }



    /* Check for DSYNC after subsubframe */

    if (s->aspf || subsubframe == s->subsubframes[s->current_subframe] - 1) {

        if (0xFFFF == get_bits(&s->gb, 16)) {   /* 0xFFFF */

#ifdef TRACE

            av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");

#endif

        } else {

            av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");

            return AVERROR_INVALIDDATA;

        }

    }



    /* Backup predictor history for adpcm */

    for (k = base_channel; k < s->prim_channels; k++)

        for (l = 0; l < s->vq_start_subband[k]; l++)

            AV_COPY128(s->subband_samples_hist[k][l], &subband_samples[k][l][4]);



    return 0;

}

static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)

{

    int k, l;

    int subsubframe = s->current_subsubframe;



    const float *quant_step_table;



    

    float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];

    LOCAL_ALIGNED_16(int32_t, block, [8 * DCA_SUBBANDS]);



    







    

    if (s->bit_rate_index == 0x1f)

        quant_step_table = lossless_quant_d;

    else

        quant_step_table = lossy_quant_d;



    for (k = base_channel; k < s->prim_channels; k++) {

        float rscale[DCA_SUBBANDS];



        if (get_bits_left(&s->gb) < 0)

            return AVERROR_INVALIDDATA;



        for (l = 0; l < s->vq_start_subband[k]; l++) {

            int m;



            

            int abits = s->bitalloc[k][l];



            float quant_step_size = quant_step_table[abits];



            







            

            int sel = s->quant_index_huffman[k][abits];



            





            if (!abits) {

                rscale[l] = 0;

                memset(block + 8 * l, 0, 8 * sizeof(block[0]));

            } else {

                

                int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l];

                rscale[l] = quant_step_size * s->scale_factor[k][l][sfi] *

                               s->scalefactor_adj[k][sel];



                if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {

                    if (abits <= 7) {

                        

                        int block_code1, block_code2, size, levels, err;



                        size   = abits_sizes[abits - 1];

                        levels = abits_levels[abits - 1];



                        block_code1 = get_bits(&s->gb, size);

                        block_code2 = get_bits(&s->gb, size);

                        err = decode_blockcodes(block_code1, block_code2,

                                                levels, block + 8 * l);

                        if (err) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "ERROR: block code look-up failed\n");

                            return AVERROR_INVALIDDATA;

                        }

                    } else {

                        

                        for (m = 0; m < 8; m++)

                            block[8 * l + m] = get_sbits(&s->gb, abits - 3);

                    }

                } else {

                    

                    for (m = 0; m < 8; m++)

                        block[8 * l + m] = get_bitalloc(&s->gb,

                                                &dca_smpl_bitalloc[abits], sel);

                }



            }

        }



        s->fmt_conv.int32_to_float_fmul_array8(&s->fmt_conv, subband_samples[k][0],

                                               block, rscale, 8 * s->vq_start_subband[k]);



        for (l = 0; l < s->vq_start_subband[k]; l++) {

            int m;

            





            if (s->prediction_mode[k][l]) {

                int n;

                if (s->predictor_history)

                    subband_samples[k][l][0] += (adpcm_vb[s->prediction_vq[k][l]][0] *

                                                 s->subband_samples_hist[k][l][3] +

                                                 adpcm_vb[s->prediction_vq[k][l]][1] *

                                                 s->subband_samples_hist[k][l][2] +

                                                 adpcm_vb[s->prediction_vq[k][l]][2] *

                                                 s->subband_samples_hist[k][l][1] +

                                                 adpcm_vb[s->prediction_vq[k][l]][3] *

                                                 s->subband_samples_hist[k][l][0]) *

                                                (1.0f / 8192);

                for (m = 1; m < 8; m++) {

                    float sum = adpcm_vb[s->prediction_vq[k][l]][0] *

                                subband_samples[k][l][m - 1];

                    for (n = 2; n <= 4; n++)

                        if (m >= n)

                            sum += adpcm_vb[s->prediction_vq[k][l]][n - 1] *

                                   subband_samples[k][l][m - n];

                        else if (s->predictor_history)

                            sum += adpcm_vb[s->prediction_vq[k][l]][n - 1] *

                                   s->subband_samples_hist[k][l][m - n + 4];

                    subband_samples[k][l][m] += sum * 1.0f / 8192;

                }

            }

        }



        





        for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {

            



            int hfvq = s->high_freq_vq[k][l];



            if (!s->debug_flag & 0x01) {

                av_log(s->avctx, AV_LOG_DEBUG,

                       "Stream with high frequencies VQ coding\n");

                s->debug_flag |= 0x01;

            }



            int8x8_fmul_int32(&s->dcadsp, subband_samples[k][l],

                              &high_freq_vq[hfvq][subsubframe * 8],

                              s->scale_factor[k][l][0]);

        }

    }



    

    if (s->aspf || subsubframe == s->subsubframes[s->current_subframe] - 1) {

        if (0xFFFF == get_bits(&s->gb, 16)) {   

#ifdef TRACE

            av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");

#endif

        } else {

            av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");

            return AVERROR_INVALIDDATA;

        }

    }



    

    for (k = base_channel; k < s->prim_channels; k++)

        for (l = 0; l < s->vq_start_subband[k]; l++)

            AV_COPY128(s->subband_samples_hist[k][l], &subband_samples[k][l][4]);



    return 0;

}

static int FUNC_0(DCAContext *VAR_0, int VAR_1, int VAR_2)

{

    int VAR_3, VAR_4;

    int VAR_5 = VAR_0->current_subsubframe;



    const float *VAR_6;



    

    float (*VAR_7)[DCA_SUBBANDS][8] = VAR_0->VAR_7[VAR_2];

    LOCAL_ALIGNED_16(int32_t, block, [8 * DCA_SUBBANDS]);



    







    

    if (VAR_0->bit_rate_index == 0x1f)

        VAR_6 = lossless_quant_d;

    else

        VAR_6 = lossy_quant_d;



    for (VAR_3 = VAR_1; VAR_3 < VAR_0->prim_channels; VAR_3++) {

        float rscale[DCA_SUBBANDS];



        if (get_bits_left(&VAR_0->gb) < 0)

            return AVERROR_INVALIDDATA;



        for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++) {

            int m;



            

            int abits = VAR_0->bitalloc[VAR_3][VAR_4];



            float quant_step_size = VAR_6[abits];



            







            

            int sel = VAR_0->quant_index_huffman[VAR_3][abits];



            





            if (!abits) {

                rscale[VAR_4] = 0;

                memset(block + 8 * VAR_4, 0, 8 * sizeof(block[0]));

            } else {

                

                int sfi = VAR_0->transition_mode[VAR_3][VAR_4] && VAR_5 >= VAR_0->transition_mode[VAR_3][VAR_4];

                rscale[VAR_4] = quant_step_size * VAR_0->scale_factor[VAR_3][VAR_4][sfi] *

                               VAR_0->scalefactor_adj[VAR_3][sel];



                if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {

                    if (abits <= 7) {

                        

                        int block_code1, block_code2, size, levels, err;



                        size   = abits_sizes[abits - 1];

                        levels = abits_levels[abits - 1];



                        block_code1 = get_bits(&VAR_0->gb, size);

                        block_code2 = get_bits(&VAR_0->gb, size);

                        err = decode_blockcodes(block_code1, block_code2,

                                                levels, block + 8 * VAR_4);

                        if (err) {

                            av_log(VAR_0->avctx, AV_LOG_ERROR,

                                   "ERROR: block code look-up failed\n");

                            return AVERROR_INVALIDDATA;

                        }

                    } else {

                        

                        for (m = 0; m < 8; m++)

                            block[8 * VAR_4 + m] = get_sbits(&VAR_0->gb, abits - 3);

                    }

                } else {

                    

                    for (m = 0; m < 8; m++)

                        block[8 * VAR_4 + m] = get_bitalloc(&VAR_0->gb,

                                                &dca_smpl_bitalloc[abits], sel);

                }



            }

        }



        VAR_0->fmt_conv.int32_to_float_fmul_array8(&VAR_0->fmt_conv, VAR_7[VAR_3][0],

                                               block, rscale, 8 * VAR_0->vq_start_subband[VAR_3]);



        for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++) {

            int m;

            





            if (VAR_0->prediction_mode[VAR_3][VAR_4]) {

                int n;

                if (VAR_0->predictor_history)

                    VAR_7[VAR_3][VAR_4][0] += (adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][0] *

                                                 VAR_0->subband_samples_hist[VAR_3][VAR_4][3] +

                                                 adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][1] *

                                                 VAR_0->subband_samples_hist[VAR_3][VAR_4][2] +

                                                 adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][2] *

                                                 VAR_0->subband_samples_hist[VAR_3][VAR_4][1] +

                                                 adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][3] *

                                                 VAR_0->subband_samples_hist[VAR_3][VAR_4][0]) *

                                                (1.0f / 8192);

                for (m = 1; m < 8; m++) {

                    float sum = adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][0] *

                                VAR_7[VAR_3][VAR_4][m - 1];

                    for (n = 2; n <= 4; n++)

                        if (m >= n)

                            sum += adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][n - 1] *

                                   VAR_7[VAR_3][VAR_4][m - n];

                        else if (VAR_0->predictor_history)

                            sum += adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][n - 1] *

                                   VAR_0->subband_samples_hist[VAR_3][VAR_4][m - n + 4];

                    VAR_7[VAR_3][VAR_4][m] += sum * 1.0f / 8192;

                }

            }

        }



        





        for (VAR_4 = VAR_0->vq_start_subband[VAR_3]; VAR_4 < VAR_0->subband_activity[VAR_3]; VAR_4++) {

            



            int hfvq = VAR_0->high_freq_vq[VAR_3][VAR_4];



            if (!VAR_0->debug_flag & 0x01) {

                av_log(VAR_0->avctx, AV_LOG_DEBUG,

                       "Stream with high frequencies VQ coding\n");

                VAR_0->debug_flag |= 0x01;

            }



            int8x8_fmul_int32(&VAR_0->dcadsp, VAR_7[VAR_3][VAR_4],

                              &high_freq_vq[hfvq][VAR_5 * 8],

                              VAR_0->scale_factor[VAR_3][VAR_4][0]);

        }

    }



    

    if (VAR_0->aspf || VAR_5 == VAR_0->subsubframes[VAR_0->current_subframe] - 1) {

        if (0xFFFF == get_bits(&VAR_0->gb, 16)) {   

#ifdef TRACE

            av_log(VAR_0->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");

#endif

        } else {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");

            return AVERROR_INVALIDDATA;

        }

    }



    

    for (VAR_3 = VAR_1; VAR_3 < VAR_0->prim_channels; VAR_3++)

        for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++)

            AV_COPY128(VAR_0->subband_samples_hist[VAR_3][VAR_4], &VAR_7[VAR_3][VAR_4][4]);



    return 0;

}

static int FUNC_0(DCAContext *VAR_0, int VAR_1, int VAR_2)
{ int VAR_3, VAR_4; int VAR_5 = VAR_0->current_subsubframe; const float *VAR_6; float (*VAR_7)[DCA_SUBBANDS][8] = VAR_0->VAR_7[VAR_2]; LOCAL_ALIGNED_16(int32_t, block, [8 * DCA_SUBBANDS]); if (VAR_0->bit_rate_index == 0x1f)
VAR_6 = lossless_quant_d; else
VAR_6 = lossy_quant_d; for (VAR_3 = VAR_1; VAR_3 < VAR_0->prim_channels; VAR_3++) { float rscale[DCA_SUBBANDS]; if (get_bits_left(&VAR_0->gb) < 0)
return AVERROR_INVALIDDATA; for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++) { int m; int abits = VAR_0->bitalloc[VAR_3][VAR_4]; float quant_step_size = VAR_6[abits]; int sel = VAR_0->quant_index_huffman[VAR_3][abits]; if (!abits) { rscale[VAR_4] = 0; memset(block + 8 * VAR_4, 0, 8 * sizeof(block[0])); } else { int sfi = VAR_0->transition_mode[VAR_3][VAR_4] && VAR_5 >= VAR_0->transition_mode[VAR_3][VAR_4]; rscale[VAR_4] = quant_step_size * VAR_0->scale_factor[VAR_3][VAR_4][sfi] *
VAR_0->scalefactor_adj[VAR_3][sel]; if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) { if (abits <= 7) { int block_code1, block_code2, size, levels, err; size   = abits_sizes[abits - 1]; levels = abits_levels[abits - 1]; block_code1 = get_bits(&VAR_0->gb, size); block_code2 = get_bits(&VAR_0->gb, size); err = decode_blockcodes(block_code1, block_code2,
levels, block + 8 * VAR_4); if (err) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"ERROR: block code look-up failed\n"); return AVERROR_INVALIDDATA; } } else { for (m = 0; m < 8; m++) block[8 * VAR_4 + m] = get_sbits(&VAR_0->gb, abits - 3); } } else { for (m = 0; m < 8; m++) block[8 * VAR_4 + m] = get_bitalloc(&VAR_0->gb,
&dca_smpl_bitalloc[abits], sel); } } } VAR_0->fmt_conv.int32_to_float_fmul_array8(&VAR_0->fmt_conv, VAR_7[VAR_3][0],
block, rscale, 8 * VAR_0->vq_start_subband[VAR_3]); for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++) { int m; if (VAR_0->prediction_mode[VAR_3][VAR_4]) { int n; if (VAR_0->predictor_history)
VAR_7[VAR_3][VAR_4][0] += (adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][0] *
VAR_0->subband_samples_hist[VAR_3][VAR_4][3] +
adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][1] *
VAR_0->subband_samples_hist[VAR_3][VAR_4][2] +
adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][2] *
VAR_0->subband_samples_hist[VAR_3][VAR_4][1] +
adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][3] *
VAR_0->subband_samples_hist[VAR_3][VAR_4][0]) *
(1.0f / 8192); for (m = 1; m < 8; m++) { float sum = adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][0] *
VAR_7[VAR_3][VAR_4][m - 1]; for (n = 2; n <= 4; n++) if (m >= n)
sum += adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][n - 1] *
VAR_7[VAR_3][VAR_4][m - n]; else if (VAR_0->predictor_history)
sum += adpcm_vb[VAR_0->prediction_vq[VAR_3][VAR_4]][n - 1] *
VAR_0->subband_samples_hist[VAR_3][VAR_4][m - n + 4]; VAR_7[VAR_3][VAR_4][m] += sum * 1.0f / 8192; } } } for (VAR_4 = VAR_0->vq_start_subband[VAR_3]; VAR_4 < VAR_0->subband_activity[VAR_3]; VAR_4++) { int hfvq = VAR_0->high_freq_vq[VAR_3][VAR_4]; if (!VAR_0->debug_flag & 0x01) { av_log(VAR_0->avctx, AV_LOG_DEBUG,
"Stream with high frequencies VQ coding\n"); VAR_0->debug_flag |= 0x01; } int8x8_fmul_int32(&VAR_0->dcadsp, VAR_7[VAR_3][VAR_4],
&high_freq_vq[hfvq][VAR_5 * 8],
VAR_0->scale_factor[VAR_3][VAR_4][0]); } } if (VAR_0->aspf || VAR_5 == VAR_0->subsubframes[VAR_0->current_subframe] - 1) { if (0xFFFF == get_bits(&VAR_0->gb, 16)) { #ifdef TRACE
av_log(VAR_0->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n"); #endif
} else { av_log(VAR_0->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n"); return AVERROR_INVALIDDATA; } } for (VAR_3 = VAR_1; VAR_3 < VAR_0->prim_channels; VAR_3++) for (VAR_4 = 0; VAR_4 < VAR_0->vq_start_subband[VAR_3]; VAR_4++) AV_COPY128(VAR_0->subband_samples_hist[VAR_3][VAR_4], &VAR_7[VAR_3][VAR_4][4]); return 0; }