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

📄 takehiro.c

📁 音频编码
💻 C
📖 第 1 页 / 共 3 页
字号:
int ix_max(const int *ix, const int *end){    int max1 = 0, max2 = 0;    do {	int x1 = *ix++;	int x2 = *ix++;	if (max1 < x1) 	    max1 = x1;	if (max2 < x2) 	    max2 = x2;    } while (ix < end);    if (max1 < max2) 	max1 = max2;    return max1;}intcount_bit_ESC(     const int *       ix,     const int * const end,           int         t1,    const int         t2,          int * const s ){    /* ESC-table is used */    int linbits = ht[t1].xlen * 65536 + ht[t2].xlen;    int sum = 0, sum2;    do {	int x = *ix++;	int y = *ix++;	if (x != 0) {	    if (x > 14) {		x = 15;		sum += linbits;	    }	    x *= 16;	}	if (y != 0) {	    if (y > 14) {		y = 15;		sum += linbits;	    }	    x += y;	}	sum += largetbl[x];    } while (ix < end);    sum2 = sum & 0xffff;    sum >>= 16;    if (sum > sum2) {	sum = sum2;	t1 = t2;    }    *s += sum;    return t1;}inline static intcount_bit_noESC(const int * ix, const int * const end, int * const s){    /* No ESC-words */    int	sum1 = 0;    const char *hlen1 = ht[1].hlen;    do {	int x = ix[0] * 2 + ix[1];	ix += 2;	sum1 += hlen1[x];    } while (ix < end);    *s += sum1;    return 1;}inline static intcount_bit_noESC_from2(    const int *       ix,     const int * const end,          int         t1,          int * const s ){    /* No ESC-words */    unsigned int sum = 0, sum2;    const int xlen = ht[t1].xlen;    const unsigned int *hlen;    if (t1 == 2)	hlen = table23;    else	hlen = table56;    do {	int x = ix[0] * xlen + ix[1];	ix += 2;	sum += hlen[x];    } while (ix < end);    sum2 = sum & 0xffff;    sum >>= 16;    if (sum > sum2) {	sum = sum2;	t1++;    }    *s += sum;    return t1;}inline static intcount_bit_noESC_from3(    const int *       ix,     const int * const end,          int         t1,          int * const s ){    /* No ESC-words */    int	sum1 = 0;    int	sum2 = 0;    int	sum3 = 0;    const int xlen = ht[t1].xlen;    const char *hlen1 = ht[t1].hlen;    const char *hlen2 = ht[t1+1].hlen;    const char *hlen3 = ht[t1+2].hlen;    int t;    do {	int x = ix[0] * xlen + ix[1];	ix += 2;	sum1 += hlen1[x];	sum2 += hlen2[x];	sum3 += hlen3[x];    } while (ix < end);    t = t1;    if (sum1 > sum2) {	sum1 = sum2;	t++;    }    if (sum1 > sum3) {	sum1 = sum3;	t = t1+2;    }    *s += sum1;    return t;}/*************************************************************************//*	      choose table						 *//*************************************************************************//*  Choose the Huffman table that will encode ix[begin..end] with  the fewest bits.  Note: This code contains knowledge about the sizes and characteristics  of the Huffman tables as defined in the IS (Table B.7), and will not work  with any arbitrary tables.*/static int choose_table_nonMMX(    const int *       ix,     const int * const end,          int * const s ){    int max;    int choice, choice2;    static const int huf_tbl_noESC[] = {	1, 2, 5, 7, 7,10,10,13,13,13,13,13,13,13,13    };    max = ix_max(ix, end);    switch (max) {    case 0:	return max;    case 1:	return count_bit_noESC(ix, end, s);    case 2:    case 3:	return count_bit_noESC_from2(ix, end, huf_tbl_noESC[max - 1], s);    case 4: case 5: case 6:    case 7: case 8: case 9:    case 10: case 11: case 12:    case 13: case 14: case 15:	return count_bit_noESC_from3(ix, end, huf_tbl_noESC[max - 1], s);    default:	/* try tables with linbits */	if (max > IXMAX_VAL) {	    *s = LARGE_BITS;	    return -1;	}	max -= 15;	for (choice2 = 24; choice2 < 32; choice2++) {	    if (ht[choice2].linmax >= max) {		break;	    }	}	for (choice = choice2 - 8; choice < 24; choice++) {	    if (ht[choice].linmax >= max) {		break;	    }	}	return count_bit_ESC(ix, end, choice, choice2, s);    }}/*************************************************************************//*	      count_bit							 *//*************************************************************************/int noquant_count_bits(          lame_internal_flags * const gfc,           gr_info * const gi,          calc_noise_data* prev_noise){    int bits = 0;    int i, a1, a2;    int *const ix = gi->l3_enc;    i = Min(576, ((gi->max_nonzero_coeff+2)>>1)<<1);    if (prev_noise)        prev_noise->sfb_count1 = 0;    /* Determine count1 region */    for (; i > 1; i -= 2) 	    if (ix[i - 1] | ix[i - 2])	        break;    gi->count1 = i;    /* Determines the number of bits to encode the quadruples. */    a1 = a2 = 0;    for (; i > 3; i -= 4) {	    int p;	    /* hack to check if all values <= 1 */	    if ((unsigned int)(ix[i-1] | ix[i-2] | ix[i-3] | ix[i-4]) > 1)	        break;	    p = ((ix[i-4] * 2 + ix[i-3]) * 2 + ix[i-2]) * 2 + ix[i-1];	    a1 += t32l[p];	    a2 += t33l[p];    }    bits = a1;    gi->count1table_select = 0;    if (a1 > a2) {	bits = a2;	gi->count1table_select = 1;    }    gi->count1bits = bits;    gi->big_values = i;    if (i == 0)	    return bits;    if (gi->block_type == SHORT_TYPE) {      a1=3*gfc->scalefac_band.s[3];      if (a1 > gi->big_values) a1 = gi->big_values;      a2 = gi->big_values;    }else if (gi->block_type == NORM_TYPE) {	assert(i <= 576); /* bv_scf has 576 entries (0..575) */        a1 = gi->region0_count = gfc->bv_scf[i-2];	a2 = gi->region1_count = gfc->bv_scf[i-1];	assert(a1+a2+2 < SBPSY_l);        a2 = gfc->scalefac_band.l[a1 + a2 + 2];	a1 = gfc->scalefac_band.l[a1 + 1];	if (a2 < i)	  gi->table_select[2] = gfc->choose_table(ix + a2, ix + i, &bits);    } else {	gi->region0_count = 7;	/*gi->region1_count = SBPSY_l - 7 - 1;*/	gi->region1_count = SBMAX_l -1 - 7 - 1;	a1 = gfc->scalefac_band.l[7 + 1];	a2 = i;	if (a1 > a2) {	    a1 = a2;	}    }    /* have to allow for the case when bigvalues < region0 < region1 */    /* (and region0, region1 are ignored) */    a1 = Min(a1,i);    a2 = Min(a2,i);        assert( a1 >= 0 );    assert( a2 >= 0 );    /* Count the number of bits necessary to code the bigvalues region. */    if (0 < a1)	gi->table_select[0] = gfc->choose_table(ix, ix + a1, &bits);    if (a1 < a2)	gi->table_select[1] = gfc->choose_table(ix + a1, ix + a2, &bits);    if (gfc->use_best_huffman == 2) {	gi->part2_3_length = bits;	best_huffman_divide (gfc, gi);	bits = gi->part2_3_length;    }    if (prev_noise) {        if (gi->block_type == NORM_TYPE) {            int line = 0;            int sfb = 0;            while (gfc->scalefac_band.l[sfb] < gi->big_values) {                sfb++;            }            prev_noise->sfb_count1 = sfb;        }    }    return bits;}int count_bits(          lame_internal_flags * const gfc,     const FLOAT  * const xr,          gr_info * const gi,          calc_noise_data* prev_noise	  ){    int *const ix = gi->l3_enc;    /* since quantize_xrpow uses table lookup, we need to check this first: */    FLOAT w = (IXMAX_VAL) / IPOW20(gi->global_gain);    if (gi->xrpow_max > w)        return LARGE_BITS;    	quantize_xrpow(xr, ix, IPOW20(gi->global_gain), gi, prev_noise, gfc);    if (gfc->substep_shaping & 2) {	int sfb, j = 0;	/* 0.634521682242439 = 0.5946*2**(.5*0.1875) */	const FLOAT roundfac =	    0.634521682242439 / IPOW20(gi->global_gain+gi->scalefac_scale);	for (sfb = 0; sfb < gi->sfbmax; sfb++) {	    int width = gi->width[sfb];	    int l;        assert( width >= 0 );	    j += width;	    if (!gfc->pseudohalf[sfb])		continue;	    for (l = -width; l < 0; l++)		if (xr[j+l] < roundfac)		    ix[j+l] = 0.0;	}    }    return noquant_count_bits(gfc, gi, prev_noise);}/***********************************************************************  re-calculate the best scalefac_compress using scfsi  the saved bits are kept in the bit reservoir. **********************************************************************/inline static voidrecalc_divide_init(    const lame_internal_flags * const gfc,          gr_info         *cod_info,          int     * const ix,          int             r01_bits[],          int             r01_div [],          int             r0_tbl  [],          int             r1_tbl  [] ){    int r0, r1, bigv, r0t, r1t, bits;    bigv = cod_info->big_values;    for (r0 = 0; r0 <= 7 + 15; r0++) {	r01_bits[r0] = LARGE_BITS;    }    for (r0 = 0; r0 < 16; r0++) {	int a1 = gfc->scalefac_band.l[r0 + 1], r0bits;	if (a1 >= bigv)	    break;	r0bits = 0;	r0t = gfc->choose_table(ix, ix + a1, &r0bits);	for (r1 = 0; r1 < 8; r1++) {	    int a2 = gfc->scalefac_band.l[r0 + r1 + 2];	    if (a2 >= bigv)		break;	    bits = r0bits;	    r1t = gfc->choose_table(ix + a1, ix + a2, &bits);	    if (r01_bits[r0 + r1] > bits) {		r01_bits[r0 + r1] = bits;		r01_div[r0 + r1] = r0;		r0_tbl[r0 + r1] = r0t;		r1_tbl[r0 + r1] = r1t;	    }	}    }}inline static voidrecalc_divide_sub(    const lame_internal_flags * const gfc,    const gr_info         *cod_info2,          gr_info * const gi,    const int     * const ix,    const int             r01_bits[],    const int             r01_div [],    const int             r0_tbl  [],    const int             r1_tbl  [] ){    int bits, r2, a2, bigv, r2t;    bigv = cod_info2->big_values;    for (r2 = 2; r2 < SBMAX_l + 1; r2++) {	a2 = gfc->scalefac_band.l[r2];	if (a2 >= bigv) 	    break;	bits = r01_bits[r2 - 2] + cod_info2->count1bits;	if (gi->part2_3_length <= bits)	    break;	r2t = gfc->choose_table(ix + a2, ix + bigv, &bits);	if (gi->part2_3_length <= bits)	    continue;	memcpy(gi, cod_info2, sizeof(gr_info));	gi->part2_3_length = bits;	gi->region0_count = r01_div[r2 - 2];	gi->region1_count = r2 - 2 - r01_div[r2 - 2];	gi->table_select[0] = r0_tbl[r2 - 2];	gi->table_select[1] = r1_tbl[r2 - 2];	gi->table_select[2] = r2t;    }}void best_huffman_divide(    const lame_internal_flags * const gfc,    gr_info * const gi){    int i, a1, a2;    gr_info cod_info2;    int * const ix = gi->l3_enc;    int r01_bits[7 + 15 + 1];

⌨️ 快捷键说明

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