static void qmf_32_subbands(DCAContext * s, int chans,
                            float samples_in[32][8], float *samples_out,
                            float scale, float bias)
{
    const float *prCoeff;
    int i, j;
    DECLARE_ALIGNED_16(float, raXin[32]);
    int hist_index= s->hist_index[chans];
    float *subband_fir_hist2 = s->subband_fir_noidea[chans];
    int subindex;
    scale *= sqrt(1/8.0);
    if (!s->multirate_inter)
        prCoeff = fir_32bands_nonperfect;
    else
        prCoeff = fir_32bands_perfect;
    for (subindex = 0; subindex < 8; subindex++) {
        float *subband_fir_hist = s->subband_fir_hist[chans] + hist_index;
        for (i = 0; i < s->subband_activity[chans]; i++){
            if((i-1)&2) raXin[i] = -samples_in[i][subindex];
            else        raXin[i] =  samples_in[i][subindex];
        }
        for (; i < 32; i++)
            raXin[i] = 0.0;
        ff_imdct_half(&s->imdct, subband_fir_hist, raXin);
        for (i = 0; i < 16; i++){
            float a= subband_fir_hist2[i   ];
            float b= subband_fir_hist2[i+16];
            float c= 0;
            float d= 0;
            for (j = 0; j < 512-hist_index; j += 64){
                a += prCoeff[i+j   ]*(-subband_fir_hist[15-i+j]);
                b += prCoeff[i+j+16]*( subband_fir_hist[   i+j]);
                c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j]);
                d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j]);
            }
            for (     ; j < 512; j += 64){
                a += prCoeff[i+j   ]*(-subband_fir_hist[15-i+j-512]);
                b += prCoeff[i+j+16]*( subband_fir_hist[   i+j-512]);
                c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j-512]);
                d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j-512]);
            }
            samples_out[i   ] = a * scale + bias;
            samples_out[i+16] = b * scale + bias;
            subband_fir_hist2[i   ] = c;
            subband_fir_hist2[i+16] = d;
        }
        samples_out+= 32;
        hist_index = (hist_index-32)&511;
    }
    s->hist_index[chans]= hist_index;
}
['static int dca_decode_frame(AVCodecContext * avctx,\n                            void *data, int *data_size,\n                            const uint8_t * buf, int buf_size)\n{\n    int i;\n    int16_t *samples = data;\n    DCAContext *s = avctx->priv_data;\n    int channels;\n    s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE);\n    if (s->dca_buffer_size == -1) {\n        av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\\n");\n        return -1;\n    }\n    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);\n    if (dca_parse_frame_header(s) < 0) {\n        *data_size=0;\n        return buf_size;\n    }\n    avctx->sample_rate = s->sample_rate;\n    avctx->bit_rate = s->bit_rate;\n    channels = s->prim_channels + !!s->lfe;\n    if(avctx->request_channels == 2 && s->prim_channels > 2) {\n        channels = 2;\n        s->output = DCA_STEREO;\n    }\n    if (!avctx->channels)\n        avctx->channels = channels;\n    if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)\n        return -1;\n    *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels;\n    for (i = 0; i < (s->sample_blocks / 8); i++) {\n        dca_decode_block(s);\n        s->dsp.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels);\n        samples += 256 * channels;\n    }\n    return buf_size;\n}', 'static int dca_parse_frame_header(DCAContext * s)\n{\n    int i, j;\n    static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };\n    static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };\n    static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };\n    s->bias = CONVERT_BIAS;\n    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);\n    get_bits(&s->gb, 32);\n    s->frame_type        = get_bits(&s->gb, 1);\n    s->samples_deficit   = get_bits(&s->gb, 5) + 1;\n    s->crc_present       = get_bits(&s->gb, 1);\n    s->sample_blocks     = get_bits(&s->gb, 7) + 1;\n    s->frame_size        = get_bits(&s->gb, 14) + 1;\n    if (s->frame_size < 95)\n        return -1;\n    s->amode             = get_bits(&s->gb, 6);\n    s->sample_rate       = dca_sample_rates[get_bits(&s->gb, 4)];\n    if (!s->sample_rate)\n        return -1;\n    s->bit_rate          = dca_bit_rates[get_bits(&s->gb, 5)];\n    if (!s->bit_rate)\n        return -1;\n    s->downmix           = get_bits(&s->gb, 1);\n    s->dynrange          = get_bits(&s->gb, 1);\n    s->timestamp         = get_bits(&s->gb, 1);\n    s->aux_data          = get_bits(&s->gb, 1);\n    s->hdcd              = get_bits(&s->gb, 1);\n    s->ext_descr         = get_bits(&s->gb, 3);\n    s->ext_coding        = get_bits(&s->gb, 1);\n    s->aspf              = get_bits(&s->gb, 1);\n    s->lfe               = get_bits(&s->gb, 2);\n    s->predictor_history = get_bits(&s->gb, 1);\n    if (s->crc_present)\n        s->header_crc    = get_bits(&s->gb, 16);\n    s->multirate_inter   = get_bits(&s->gb, 1);\n    s->version           = get_bits(&s->gb, 4);\n    s->copy_history      = get_bits(&s->gb, 2);\n    s->source_pcm_res    = get_bits(&s->gb, 3);\n    s->front_sum         = get_bits(&s->gb, 1);\n    s->surround_sum      = get_bits(&s->gb, 1);\n    s->dialog_norm       = get_bits(&s->gb, 4);\n    s->output = s->amode;\n    if(s->lfe) s->output |= DCA_LFE;\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\\n", s->frame_type);\n    av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\\n", s->samples_deficit);\n    av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\\n", s->crc_present);\n    av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\\n",\n           s->sample_blocks, s->sample_blocks * 32);\n    av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\\n", s->frame_size);\n    av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\\n",\n           s->amode, dca_channels[s->amode]);\n    av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i (%i Hz)\\n",\n           s->sample_rate, dca_sample_rates[s->sample_rate]);\n    av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i (%i bits/s)\\n",\n           s->bit_rate, dca_bit_rates[s->bit_rate]);\n    av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\\n", s->downmix);\n    av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\\n", s->dynrange);\n    av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\\n", s->timestamp);\n    av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\\n", s->aux_data);\n    av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\\n", s->hdcd);\n    av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\\n", s->ext_descr);\n    av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\\n", s->ext_coding);\n    av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\\n", s->aspf);\n    av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\\n", s->lfe);\n    av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\\n",\n           s->predictor_history);\n    av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\\n", s->header_crc);\n    av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\\n",\n           s->multirate_inter);\n    av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\\n", s->version);\n    av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\\n", s->copy_history);\n    av_log(s->avctx, AV_LOG_DEBUG,\n           "source pcm resolution: %i (%i bits/sample)\\n",\n           s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]);\n    av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\\n", s->front_sum);\n    av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\\n", s->surround_sum);\n    av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\\n", s->dialog_norm);\n    av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n#endif\n    s->subframes         = get_bits(&s->gb, 4) + 1;\n    s->total_channels    = get_bits(&s->gb, 3) + 1;\n    s->prim_channels     = s->total_channels;\n    if (s->prim_channels > DCA_PRIM_CHANNELS_MAX)\n        s->prim_channels = DCA_PRIM_CHANNELS_MAX;\n    for (i = 0; i < s->prim_channels; i++) {\n        s->subband_activity[i] = get_bits(&s->gb, 5) + 2;\n        if (s->subband_activity[i] > DCA_SUBBANDS)\n            s->subband_activity[i] = DCA_SUBBANDS;\n    }\n    for (i = 0; i < s->prim_channels; i++) {\n        s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;\n        if (s->vq_start_subband[i] > DCA_SUBBANDS)\n            s->vq_start_subband[i] = DCA_SUBBANDS;\n    }\n    get_array(&s->gb, s->joint_intensity,     s->prim_channels, 3);\n    get_array(&s->gb, s->transient_huffman,   s->prim_channels, 2);\n    get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3);\n    get_array(&s->gb, s->bitalloc_huffman,    s->prim_channels, 3);\n    memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));\n    for (j = 1; j < 11; j++)\n        for (i = 0; i < s->prim_channels; i++)\n            s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);\n    for (j = 0; j < 11; j++)\n        for (i = 0; i < s->prim_channels; i++)\n            s->scalefactor_adj[i][j] = 1;\n    for (j = 1; j < 11; j++)\n        for (i = 0; i < s->prim_channels; i++)\n            if (s->quant_index_huffman[i][j] < thr[j])\n                s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];\n    if (s->crc_present) {\n        get_bits(&s->gb, 16);\n    }\n    s->current_subframe = 0;\n    s->current_subsubframe = 0;\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\\n", s->subframes);\n    av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\\n", s->prim_channels);\n    for(i = 0; i < s->prim_channels; i++){\n        av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\\n", s->subband_activity[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\\n", s->vq_start_subband[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\\n", s->joint_intensity[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\\n", s->transient_huffman[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\\n", s->scalefactor_huffman[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\\n", s->bitalloc_huffman[i]);\n        av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:");\n        for (j = 0; j < 11; j++)\n            av_log(s->avctx, AV_LOG_DEBUG, " %i",\n                   s->quant_index_huffman[i][j]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n        av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:");\n        for (j = 0; j < 11; j++)\n            av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n#endif\n    return 0;\n}', 'static int dca_decode_block(DCAContext * s)\n{\n    if (s->current_subframe >= s->subframes) {\n        av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",\n               s->current_subframe, s->subframes);\n        return -1;\n    }\n    if (!s->current_subsubframe) {\n#ifdef TRACE\n        av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\\n");\n#endif\n        if (dca_subframe_header(s))\n            return -1;\n    }\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\\n");\n#endif\n    if (dca_subsubframe(s))\n        return -1;\n    s->current_subsubframe++;\n    if (s->current_subsubframe >= s->subsubframes) {\n        s->current_subsubframe = 0;\n        s->current_subframe++;\n    }\n    if (s->current_subframe >= s->subframes) {\n#ifdef TRACE\n        av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\\n");\n#endif\n        if (dca_subframe_footer(s))\n            return -1;\n    }\n    return 0;\n}', 'static int dca_subsubframe(DCAContext * s)\n{\n    int k, l;\n    int subsubframe = s->current_subsubframe;\n    const float *quant_step_table;\n    float subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8];\n    if (s->bit_rate == 0x1f)\n        quant_step_table = lossless_quant_d;\n    else\n        quant_step_table = lossy_quant_d;\n    for (k = 0; k < s->prim_channels; k++) {\n        for (l = 0; l < s->vq_start_subband[k]; l++) {\n            int m;\n            int abits = s->bitalloc[k][l];\n            float quant_step_size = quant_step_table[abits];\n            float rscale;\n            int sel = s->quant_index_huffman[k][abits];\n            if(!abits){\n                memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0]));\n            }else if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){\n                if(abits <= 7){\n                    int block_code1, block_code2, size, levels;\n                    int block[8];\n                    size = abits_sizes[abits-1];\n                    levels = abits_levels[abits-1];\n                    block_code1 = get_bits(&s->gb, size);\n                    decode_blockcode(block_code1, levels, block);\n                    block_code2 = get_bits(&s->gb, size);\n                    decode_blockcode(block_code2, levels, &block[4]);\n                    for (m = 0; m < 8; m++)\n                        subband_samples[k][l][m] = block[m];\n                }else{\n                    for (m = 0; m < 8; m++)\n                        subband_samples[k][l][m] = get_sbits(&s->gb, abits - 3);\n                }\n            }else{\n                for (m = 0; m < 8; m++)\n                    subband_samples[k][l][m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel);\n            }\n            if (s->transition_mode[k][l] &&\n                subsubframe >= s->transition_mode[k][l])\n                rscale = quant_step_size * s->scale_factor[k][l][1];\n            else\n                rscale = quant_step_size * s->scale_factor[k][l][0];\n            rscale *= s->scalefactor_adj[k][sel];\n            for (m = 0; m < 8; m++)\n                subband_samples[k][l][m] *= rscale;\n            if (s->prediction_mode[k][l]) {\n                int n;\n                for (m = 0; m < 8; m++) {\n                    for (n = 1; n <= 4; n++)\n                        if (m >= n)\n                            subband_samples[k][l][m] +=\n                                (adpcm_vb[s->prediction_vq[k][l]][n - 1] *\n                                 subband_samples[k][l][m - n] / 8192);\n                        else if (s->predictor_history)\n                            subband_samples[k][l][m] +=\n                                (adpcm_vb[s->prediction_vq[k][l]][n - 1] *\n                                 s->subband_samples_hist[k][l][m - n +\n                                                               4] / 8192);\n                }\n            }\n        }\n        for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {\n            int m;\n            if (!s->debug_flag & 0x01) {\n                av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\\n");\n                s->debug_flag |= 0x01;\n            }\n            for (m = 0; m < 8; m++) {\n                subband_samples[k][l][m] =\n                    high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 +\n                                                        m]\n                    * (float) s->scale_factor[k][l][0] / 16.0;\n            }\n        }\n    }\n    if (s->aspf || subsubframe == s->subsubframes - 1) {\n        if (0xFFFF == get_bits(&s->gb, 16)) {\n#ifdef TRACE\n            av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\\n");\n#endif\n        } else {\n            av_log(s->avctx, AV_LOG_ERROR, "Didn\'t get subframe DSYNC\\n");\n        }\n    }\n    for (k = 0; k < s->prim_channels; k++)\n        for (l = 0; l < s->vq_start_subband[k]; l++)\n            memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4],\n                        4 * sizeof(subband_samples[0][0][0]));\n    for (k = 0; k < s->prim_channels; k++) {\n         qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k],\n                            M_SQRT1_2   ,\n                            0   );\n    }\n    if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) {\n        dca_downmix(s->samples, s->amode, s->downmix_coef);\n    }\n    if (s->output & DCA_LFE) {\n        int lfe_samples = 2 * s->lfe * s->subsubframes;\n        int i_channels = dca_channels[s->output & DCA_CHANNEL_MASK];\n        lfe_interpolation_fir(s->lfe, 2 * s->lfe,\n                              s->lfe_data + lfe_samples +\n                              2 * s->lfe * subsubframe,\n                              &s->samples[256 * i_channels],\n                              256.0, 0  );\n    }\n    return 0;\n}', 'static void qmf_32_subbands(DCAContext * s, int chans,\n                            float samples_in[32][8], float *samples_out,\n                            float scale, float bias)\n{\n    const float *prCoeff;\n    int i, j;\n    DECLARE_ALIGNED_16(float, raXin[32]);\n    int hist_index= s->hist_index[chans];\n    float *subband_fir_hist2 = s->subband_fir_noidea[chans];\n    int subindex;\n    scale *= sqrt(1/8.0);\n    if (!s->multirate_inter)\n        prCoeff = fir_32bands_nonperfect;\n    else\n        prCoeff = fir_32bands_perfect;\n    for (subindex = 0; subindex < 8; subindex++) {\n        float *subband_fir_hist = s->subband_fir_hist[chans] + hist_index;\n        for (i = 0; i < s->subband_activity[chans]; i++){\n            if((i-1)&2) raXin[i] = -samples_in[i][subindex];\n            else        raXin[i] =  samples_in[i][subindex];\n        }\n        for (; i < 32; i++)\n            raXin[i] = 0.0;\n        ff_imdct_half(&s->imdct, subband_fir_hist, raXin);\n        for (i = 0; i < 16; i++){\n            float a= subband_fir_hist2[i   ];\n            float b= subband_fir_hist2[i+16];\n            float c= 0;\n            float d= 0;\n            for (j = 0; j < 512-hist_index; j += 64){\n                a += prCoeff[i+j   ]*(-subband_fir_hist[15-i+j]);\n                b += prCoeff[i+j+16]*( subband_fir_hist[   i+j]);\n                c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j]);\n                d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j]);\n            }\n            for (     ; j < 512; j += 64){\n                a += prCoeff[i+j   ]*(-subband_fir_hist[15-i+j-512]);\n                b += prCoeff[i+j+16]*( subband_fir_hist[   i+j-512]);\n                c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j-512]);\n                d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j-512]);\n            }\n            samples_out[i   ] = a * scale + bias;\n            samples_out[i+16] = b * scale + bias;\n            subband_fir_hist2[i   ] = c;\n            subband_fir_hist2[i+16] = d;\n        }\n        samples_out+= 32;\n        hist_index = (hist_index-32)&511;\n    }\n    s->hist_index[chans]= hist_index;\n}']