⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cook_fix_all.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 4 页
字号:
- * Calculate the category and category_index vector.
- *
- * @param q                     pointer to the COOKContext
- * @param quant_index_table     pointer to the array
- * @param category              pointer to the category array
- * @param category_index        pointer to the category_index array
- */
-
-static void categorize(COOKContext *q, int* quant_index_table,
-                       int* category, int* category_index){
-    int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j;
-    int exp_index2[102];
-    int exp_index1[102];
-
-    int tmp_categorize_array1[128];
-    int tmp_categorize_array1_idx=0;
-    int tmp_categorize_array2[128];
-    int tmp_categorize_array2_idx=0;
-    int category_index_size=0;
-
-    bits_left =  q->bits_per_subpacket - get_bits_count(&q->gb);
-
-    if(bits_left > q->samples_per_channel) {
-        bits_left = q->samples_per_channel +
-                    ((bits_left - q->samples_per_channel)*5)/8;
-        //av_log(NULL, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
-    }
-
-    memset(&exp_index1,0,102*sizeof(int));
-    memset(&exp_index2,0,102*sizeof(int));
-    memset(&tmp_categorize_array1,0,128*sizeof(int));
-    memset(&tmp_categorize_array2,0,128*sizeof(int));
-
-    bias=-32;
-
-    /* Estimate bias. */
-    for (i=32 ; i>0 ; i=i/2){
-        num_bits = 0;
-        index = 0;
-        for (j=q->total_subbands ; j>0 ; j--){
-            exp_idx = (i - quant_index_table[index] + bias) / 2;
-            if (exp_idx<0){
-                exp_idx=0;
-            } else if(exp_idx >7) {
-                exp_idx=7;
-            }
-            index++;
-            num_bits+=expbits_tab[exp_idx];
-        }
-        if(num_bits >= bits_left - 32){
-            bias+=i;
-        }
-    }
-
-    /* Calculate total number of bits. */
-    num_bits=0;
-    for (i=0 ; i<q->total_subbands ; i++) {
-        exp_idx = (bias - quant_index_table[i]) / 2;
-        if (exp_idx<0) {
-            exp_idx=0;
-        } else if(exp_idx >7) {
-            exp_idx=7;
-        }
-        num_bits += expbits_tab[exp_idx];
-        exp_index1[i] = exp_idx;
-        exp_index2[i] = exp_idx;
-    }
-    tmpbias = bias = num_bits;
-
-    for (j = 1 ; j < q->numvector_size ; j++) {
-        if (tmpbias + bias > 2*bits_left) {  /* ---> */
-            int max = -999999;
-            index=-1;
-            for (i=0 ; i<q->total_subbands ; i++){
-                if (exp_index1[i] < 7) {
-                    v = (-2*exp_index1[i]) - quant_index_table[i] - 32;
-                    if ( v >= max) {
-                        max = v;
-                        index = i;
-                    }
-                }
-            }
-            if(index==-1)break;
-            tmp_categorize_array1[tmp_categorize_array1_idx++] = index;
-            tmpbias -= expbits_tab[exp_index1[index]] -
-                       expbits_tab[exp_index1[index]+1];
-            ++exp_index1[index];
-        } else {  /* <--- */
-            int min = 999999;
-            index=-1;
-            for (i=0 ; i<q->total_subbands ; i++){
-                if(exp_index2[i] > 0){
-                    v = (-2*exp_index2[i])-quant_index_table[i];
-                    if ( v < min) {
-                        min = v;
-                        index = i;
-                    }
-                }
-            }
-            if(index == -1)break;
-            tmp_categorize_array2[tmp_categorize_array2_idx++] = index;
-            tmpbias -= expbits_tab[exp_index2[index]] -
-                       expbits_tab[exp_index2[index]-1];
-            --exp_index2[index];
-        }
-    }
-
-    for(i=0 ; i<q->total_subbands ; i++)
-        category[i] = exp_index2[i];
-
-    /* Concatenate the two arrays. */
-    for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--)
-        category_index[category_index_size++] =  tmp_categorize_array2[i];
-
-    for(i=0;i<tmp_categorize_array1_idx;i++)
-        category_index[category_index_size++ ] =  tmp_categorize_array1[i];
-
-    /* FIXME: mc_sich_ra8_20.rm triggers this, not sure with what we
-       should fill the remaining bytes. */
-    for(i=category_index_size;i<q->numvector_size;i++)
-        category_index[i]=0;
-
-}
-
-
-/**
- * Expand the category vector.
- *
- * @param q                     pointer to the COOKContext
- * @param category              pointer to the category array
- * @param category_index        pointer to the category_index array
- */
-
-static void inline expand_category(COOKContext *q, int* category,
-                                   int* category_index){
-    int i;
-    for(i=0 ; i<q->num_vectors ; i++){
-        ++category[category_index[i]];
-    }
-}
-
-/**
- * The real requantization of the mltcoefs
- *
- * @param q                     pointer to the COOKContext
- * @param index                 index
- * @param quant_index           quantisation index
- * @param subband_coef_index    array of indexes to quant_centroid_tab
- * @param subband_coef_sign     signs of coefficients
- * @param mlt_p                 pointer into the mlt buffer
- */
-
-static void scalar_dequant(COOKContext *q, int index, int quant_index,
-                           int* subband_coef_index, int* subband_coef_sign,
-                           float* mlt_p){
-    int i;
-    float f1;
-
-    for(i=0 ; i<SUBBAND_SIZE ; i++) {
-        if (subband_coef_index[i]) {
-            f1 = quant_centroid_tab[index][subband_coef_index[i]];
-            if (subband_coef_sign[i]) f1 = -f1;
-        } else {
-            /* noise coding if subband_coef_index[i] == 0 */
-            f1 = dither_tab[index];
-            if (av_random(&q->random_state) < 0x80000000) f1 = -f1;
-        }
-        mlt_p[i] = f1 * q->rootpow2tab[quant_index+63];
-    }
-}
-/**
- * Unpack the subband_coef_index and subband_coef_sign vectors.
- *
- * @param q                     pointer to the COOKContext
- * @param category              pointer to the category array
- * @param subband_coef_index    array of indexes to quant_centroid_tab
- * @param subband_coef_sign     signs of coefficients
- */
-
-static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
-                       int* subband_coef_sign) {
-    int i,j;
-    int vlc, vd ,tmp, result;
-    int ub;
-    int cb;
-
-    vd = vd_tab[category];
-    result = 0;
-    for(i=0 ; i<vpr_tab[category] ; i++){
-        ub = get_bits_count(&q->gb);
-        vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
-        cb = get_bits_count(&q->gb);
-        if (q->bits_per_subpacket < get_bits_count(&q->gb)){
-            vlc = 0;
-            result = 1;
-        }
-        for(j=vd-1 ; j>=0 ; j--){
-            tmp = (vlc * invradix_tab[category])/0x100000;
-            subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1);
-            vlc = tmp;
-        }
-        for(j=0 ; j<vd ; j++){
-            if (subband_coef_index[i*vd + j]) {
-                if(get_bits_count(&q->gb) < q->bits_per_subpacket){
-                    subband_coef_sign[i*vd+j] = get_bits1(&q->gb);
-                } else {
-                    result=1;
-                    subband_coef_sign[i*vd+j]=0;
-                }
-            } else {
-                subband_coef_sign[i*vd+j]=0;
-            }
-        }
-    }
-    return result;
-}
-
-
-/**
- * Fill the mlt_buffer with mlt coefficients.
- *
- * @param q                 pointer to the COOKContext
- * @param category          pointer to the category array
- * @param quant_index_table pointer to the array
- * @param mlt_buffer        pointer to mlt coefficients
- */
-
-
-static void decode_vectors(COOKContext* q, int* category,
-                           int *quant_index_table, float* mlt_buffer){
-    /* A zero in this table means that the subband coefficient is
-       random noise coded. */
-    int subband_coef_index[SUBBAND_SIZE];
-    /* A zero in this table means that the subband coefficient is a
-       positive multiplicator. */
-    int subband_coef_sign[SUBBAND_SIZE];
-    int band, j;
-    int index=0;
 
-    for(band=0 ; band<q->total_subbands ; band++){
-        index = category[band];
-        if(category[band] < 7){
-            if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_sign)){
-                index=7;
-                for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
-            }
-        }
-        if(index==7) {
-            memset(subband_coef_index, 0, sizeof(subband_coef_index));
-            memset(subband_coef_sign, 0, sizeof(subband_coef_sign));
-        }
-        scalar_dequant(q, index, quant_index_table[band],
-                       subband_coef_index, subband_coef_sign,
-                       &mlt_buffer[band * 20]);
-    }
-
-    if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
-        return;
-    } /* FIXME: should this be removed, or moved into loop above? */
-}
-
-
-/**
- * function for decoding mono data
- *
- * @param q                 pointer to the COOKContext
- * @param mlt_buffer1       pointer to left channel mlt coefficients
- * @param mlt_buffer2       pointer to right channel mlt coefficients
- */
-
-static void mono_decode(COOKContext *q, float* mlt_buffer) {
-
-    int category_index[128];
-    int quant_index_table[102];
-    int category[128];
-
-    memset(&category, 0, 128*sizeof(int));
-    memset(&category_index, 0, 128*sizeof(int));
-
-    decode_envelope(q, quant_index_table);
-    q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
-    categorize(q, quant_index_table, category, category_index);
-    expand_category(q, category, category_index);
-    decode_vectors(q, category, quant_index_table, mlt_buffer);
-}
-
-
-/**
- * the actual requantization of the timedomain samples
- *
- * @param q                 pointer to the COOKContext
- * @param buffer            pointer to the timedomain buffer
- * @param gain_index        index for the block multiplier
- * @param gain_index_next   index for the next block multiplier
- */
-
-static void interpolate(COOKContext *q, float* buffer,
-                        int gain_index, int gain_index_next){
-    int i;
-    float fc1, fc2;
-    fc1 = q->pow2tab[gain_index+63];
-
-    if(gain_index == gain_index_next){              //static gain
-        for(i=0 ; i<q->gain_size_factor ; i++){
-            buffer[i]*=fc1;
-        }
-        return;
-    } else {                                        //smooth gain
-        fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
-        for(i=0 ; i<q->gain_size_factor ; i++){
-            buffer[i]*=fc1;
-            fc1*=fc2;
-        }
-        return;
-    }
-}
-
-
-/**
- * The modulated lapped transform, this takes transform coefficients
- * and transforms them into timedomain samples.
- * Apply transform window, overlap buffers, apply gain profile
- * and buffer management.
- *
- * @param q                 pointer to the COOKContext
- * @param inbuffer          pointer to the mltcoefficients
- * @param gains_ptr         current and previous gains
- * @param previous_buffer   pointer to the previous buffer to be used for overlapping
- */
-
-static void imlt_gain(COOKContext *q, float *inbuffer,
-                      cook_gains *gains_ptr, float* previous_buffer)
-{
-    const float fc = q->pow2tab[gains_ptr->previous[0] + 63];
-    float *buffer0 = q->mono_mdct_output;
-    float *buffer1 = q->mono_mdct_output + q->samples_per_channel;
-    int i;
-
-    /* Inverse modified discrete cosine transform */
-    q->mdct_ctx.fft.imdct_calc(&q->mdct_ctx, q->mono_mdct_output,
-                               inbuffer, q->mdct_tmp);
-
-    /* The weird thing here, is that the two halves of the time domain
-     * buffer are swapped. Also, the newest data, that we save away for
-     * next frame, has the wrong sign. Hence the subtraction below.
-     * Almost sounds like a complex conjugate/reverse data/FFT effect.
-     */
-
-    /* Apply window and overlap */
-    for(i = 0; i < q->samples_per_channel; i++){
-        buffer1[i] = buffer1[i] * fc * q->mlt_window[i] -
-          previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i];
-    }
-
-    /* Apply gain profile */
-    for (i = 0; i < 8; i++) {
-        if (gains_ptr->now[i] || gains_ptr->now[i + 1])
-            interpolate(q, &buffer1[q->gain_size_factor * i],
-                        gains_ptr->now[i], gains_ptr->now[i + 1]);
-    }
-
-    /* Save away the current to be previous block. */
-    memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
-}
-
-
-/**
- * function for getting the jointstereo coupling information
- *
- * @param q                 pointer to the COOKContext
- * @param decouple_tab      decoupling array
- *
- */
-
-static void decouple_info(COOKContext *q, int* decouple_tab){
-    int length, i;
-
-    if(get_bits1(&q->gb)) {
-        if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
-
-        length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
-        for (i=0 ; i<length ; i++) {
-            decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
-        }
-        return;
-    }
-
-    if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
-
-    length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
-    for (i=0 ; i<length ; i++) {
-       decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
-    }
-    return;
-}
-
-
-/**
- * function for decoding joint stereo data
- *
- * @param q                 pointer to the COOKContext
- * @param mlt_buffer1       pointer to left channel mlt coefficients
- * @param mlt_buffer2       pointer to right channel mlt coefficients
- */
-
-static void joint_decode(COOKContext *q, float* mlt_buffer1,
-                         float* mlt_buffer2) {
-    int i,j;
-    int decouple_tab[SUBBAND_SIZE];
-    float decode_buffer[1060];
-    int idx, cpl_tmp,tmp_idx;
-    float f1,f2;
-    float* cplscale;
-
-    memset(decouple_tab, 0, sizeof(decouple_tab));
-    memset(decode_buffer, 0, sizeof(decode_buffer));
-
-    /* Make sure the buffers are zeroed out. */
-    memset(mlt_buffer1,0, 1024*sizeof(float));
-    memset(mlt_buffer2,0, 1024*sizeof(float));
-    decouple_info(q, decouple_tab);
-    mono_decode(q, decode_buffer);
-
-    /* The two channels are stored interleaved in decode_buffer. */
-    for (i=0 ; i<q->js_subband_start ; i++) {
-        for (j=0 ; j<SUBBAND_SIZE ; j++) {
-            mlt_buffer1[i*20+j] = decode_buffer[i*40+j];
-            mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j];
-        }
-    }
-
-    /* When we reach js_subband_start (the higher frequencies)
-       the coefficients are stored in a coupling scheme. */
-    idx = (1 << q->js_vlc_bits) - 1;
-    for (i=q->js_subband_start ; i<q->subbands ; i++) {
-        cpl_tmp = cplband[i];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -