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

📄 cook.c

📁 Fixptcook[1].tar.gz, 固点运算的rm格式音频编解码源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
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]];    }}/** * 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, REAL_T *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_math(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, REAL_T *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 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, REAL_T *inbuffer,                      cook_gains *gains_ptr, REAL_T *previous_buffer){    REAL_T *buffer0 = q->mono_mdct_output;    REAL_T *buffer1 = q->mono_mdct_output + q->samples_per_channel;    int gain_size_factor = q->samples_per_channel/8;    int i;    imlt_math(q, inbuffer, gains_ptr->previous[0], previous_buffer);    /* Apply gain profile */    for (i = 0; i < 8; i++) {        if (gains_ptr->now[i] || gains_ptr->now[i + 1])            interpolate_math(q, &buffer1[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, REAL_T *mlt_buffer1,                         REAL_T *mlt_buffer2) {    int i,j;    int decouple_tab[SUBBAND_SIZE];    REAL_T decode_buffer[1060];    int idx;    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(REAL_T));    memset(mlt_buffer2,0, 1024*sizeof(REAL_T));

⌨️ 快捷键说明

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