From e24087509a752d8f4dcc679b304fc1745ff768b0 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 3 Oct 2003 22:23:26 +0000 Subject: synced with current cvs git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10990 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libfaad2/sbr_hfadj.c | 355 +++------------------------------------------------ 1 file changed, 15 insertions(+), 340 deletions(-) (limited to 'libfaad2/sbr_hfadj.c') diff --git a/libfaad2/sbr_hfadj.c b/libfaad2/sbr_hfadj.c index e85abb3de8..2fc35a333c 100644 --- a/libfaad2/sbr_hfadj.c +++ b/libfaad2/sbr_hfadj.c @@ -22,7 +22,7 @@ ** Commercial non-GPL licensing of this software is possible. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. ** -** $Id: sbr_hfadj.c,v 1.1 2003/07/29 08:20:13 menno Exp $ +** $Id: sbr_hfadj.c,v 1.4 2003/09/09 18:37:32 menno Exp $ **/ /* High Frequency adjustment */ @@ -54,16 +54,12 @@ void hf_adjustment(sbr_info *sbr, qmf_t *Xsbr calculate_gain(sbr, &adj, ch); -#if 1 - #ifdef SBR_LOW_POWER calc_gain_groups(sbr, &adj, deg, ch); aliasing_reduction(sbr, &adj, deg, ch); #endif hf_assembly(sbr, &adj, Xsbr, ch); - -#endif } static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) @@ -143,15 +139,6 @@ static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) } else { adj->S_index_mapped[m - sbr->kx][l] = 0; } - -#if 0 - if (sbr->frame == 95) - { - printf("%d %d %d %d %d\n", adj->S_index_mapped[m - sbr->kx][l], - sbr->bs_add_harmonic[ch][i], sbr->bs_add_harmonic_prev[ch][i], - l, sbr->l_A[ch]); - } -#endif } } } @@ -222,26 +209,18 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t { nrg = 0; - for (i = l_i + tHFAdj; i < u_i + tHFAdj; i++) + for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++) { -#ifdef FIXED_POINT - nrg += ((QMF_RE(Xsbr[(i<<6) + m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[(i<<6) + m + sbr->kx])+(1<<(REAL_BITS-1)))>>REAL_BITS); -#else nrg += MUL(QMF_RE(Xsbr[(i<<6) + m + sbr->kx]), QMF_RE(Xsbr[(i<<6) + m + sbr->kx])) #ifndef SBR_LOW_POWER + MUL(QMF_IM(Xsbr[(i<<6) + m + sbr->kx]), QMF_IM(Xsbr[(i<<6) + m + sbr->kx])) #endif ; -#endif } sbr->E_curr[ch][m][l] = nrg / div; #ifdef SBR_LOW_POWER -#ifdef FIXED_POINT - sbr->E_curr[ch][m][l] <<= 1; -#else sbr->E_curr[ch][m][l] *= 2; -#endif #endif } } @@ -263,29 +242,21 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t div = (real_t)((u_i - l_i)*(k_h - k_l + 1)); - for (i = l_i + tHFAdj; i < u_i + tHFAdj; i++) + for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++) { for (j = k_l; j < k_h; j++) { -#ifdef FIXED_POINT - nrg += ((QMF_RE(Xsbr[(i<<6) + j])+(1<<(REAL_BITS-1)))>>REAL_BITS)*((QMF_RE(Xsbr[(i<<6) + j])+(1<<(REAL_BITS-1)))>>REAL_BITS); -#else nrg += MUL(QMF_RE(Xsbr[(i<<6) + j]), QMF_RE(Xsbr[(i<<6) + j])) #ifndef SBR_LOW_POWER + MUL(QMF_IM(Xsbr[(i<<6) + j]), QMF_IM(Xsbr[(i<<6) + j])) #endif ; -#endif } } sbr->E_curr[ch][k - sbr->kx][l] = nrg / div; #ifdef SBR_LOW_POWER -#ifdef FIXED_POINT - sbr->E_curr[ch][k - sbr->kx][l] <<= 1; -#else sbr->E_curr[ch][k - sbr->kx][l] *= 2; -#endif #endif } } @@ -293,254 +264,11 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t } } -#ifdef FIXED_POINT -#define step(shift) \ - if ((0x40000000l >> shift) + root <= value) \ - { \ - value -= (0x40000000l >> shift) + root; \ - root = (root >> 1) | (0x40000000l >> shift); \ - } else { \ - root = root >> 1; \ - } - -/* fixed point square root approximation */ -real_t sbr_sqrt(real_t value) -{ - real_t root = 0; - - step( 0); step( 2); step( 4); step( 6); - step( 8); step(10); step(12); step(14); - step(16); step(18); step(20); step(22); - step(24); step(26); step(28); step(30); - - if (root < value) - ++root; - - root <<= (REAL_BITS/2); - - return root; -} -real_t sbr_sqrt_int(real_t value) -{ - real_t root = 0; - - step( 0); step( 2); step( 4); step( 6); - step( 8); step(10); step(12); step(14); - step(16); step(18); step(20); step(22); - step(24); step(26); step(28); step(30); - - if (root < value) - ++root; - - return root; -} -#define SBR_SQRT_FIX(A) sbr_sqrt(A) -#define SBR_SQRT_INT(A) sbr_sqrt_int(A) -#endif - -#ifdef FIXED_POINT -#define EPS (1) /* smallest number available in fixed point */ -#else #define EPS (1e-12) -#endif -#ifdef FIXED_POINT -#define ONE (REAL_CONST(1)>>10) -#else #define ONE (1) -#endif - - -#ifdef FIXED_POINT -static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) -{ - uint8_t m, l, k, i; - - real_t Q_M_lim[64]; - real_t G_lim[64]; - real_t G_boost; - real_t S_M[64]; - uint8_t table_map_res_to_m[64]; - - - for (l = 0; l < sbr->L_E[ch]; l++) - { - real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1; - - for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++) - { - for (m = sbr->f_table_res[sbr->f[ch][l]][i]; m < sbr->f_table_res[sbr->f[ch][l]][i+1]; m++) - { - table_map_res_to_m[m - sbr->kx] = i; - } - } - - for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++) - { - real_t G_max; - real_t den = 0; - real_t acc1 = 0; - real_t acc2 = 0; - - for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k]; - m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++) - { - /* E_orig: integer */ - acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l]; - /* E_curr: integer */ - acc2 += sbr->E_curr[ch][m][l]; - } - - /* G_max: fixed point */ - if (acc2 == 0) - { - G_max = 0xFFF; - } else { - G_max = (((int64_t)acc1)<bs_limiter_gains) - { - case 0: G_max >>= 1; break; - case 2: G_max <<= 1; break; - default: break; - } - } - - //printf("%f %d %d\n", G_max /(float)(1<f_table_lim[sbr->bs_limiter_bands][k]; - m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++) - { - real_t d, Q_M, G; - real_t div2; - - /* Q_mapped: fixed point */ - /* div2: fixed point COEF */ - real_t tmp2 = adj->Q_mapped[m][l] << (COEF_BITS-REAL_BITS); - real_t tmp = COEF_CONST(1) + tmp2; - if (tmp == 0) - div2 = COEF_CONST(1); - else - div2 = (((int64_t)tmp2 << COEF_BITS)/tmp); - - //printf("%f\n", div2 / (float)(1<E_orig[ch][table_map_res_to_m[m]][l], div2); - - //printf("%d\n", Q_M /* / (float)(1<S_mapped[m][l] == 0) - { - real_t tmp, tmp2; - - S_M[m] = 0; - - /* d: fixed point */ - tmp2 = adj->Q_mapped[m][l] /* << (COEF_BITS-REAL_BITS)*/; - tmp = REAL_CONST(1) + delta*tmp2; - d = (((int64_t)REAL_CONST(1))<E_orig[ch][table_map_res_to_m[m]][l])<E_curr[ch][m][l]); - G = MUL(G, d); - - //printf("%f\n", G/(float)(1<Q_mapped[m][l] << (COEF_BITS-REAL_BITS)); - real_t tmp2 = COEF_CONST(adj->S_mapped[m][l]); - if (tmp == 0) - div = COEF_CONST(1); - else - div = (((int64_t)tmp2 << COEF_BITS)/tmp); - - //printf("%f\n", div/(float)(1<E_orig[ch][table_map_res_to_m[m]][l], div); - - //printf("%d\n", S_M[m]); - - /* G: fixed_point */ - if ((ONE + sbr->E_curr[ch][m][l]) == 0) - G = 0xFFF; // uhm??? - else { - real_t tmp = ONE + sbr->E_curr[ch][m][l]; - /* tmp2: fixed point */ - real_t tmp2 = (((int64_t)(sbr->E_orig[ch][table_map_res_to_m[m]][l]))< G) - { - Q_M_lim[m] = Q_M; - G_lim[m] = G; - } else { - real_t tmp; - if (G == 0) - tmp = 0xFFF; - else - tmp = SBR_DIV(G_max, G); - Q_M_lim[m] = MUL(Q_M, tmp); - G_lim[m] = G_max; - } - - /* E_curr: integer, using MUL() is NOT OK */ - den += MUL(sbr->E_curr[ch][m][l], G_lim[m]); - if (adj->S_index_mapped[m][l]) - den += S_M[m]; - else if (l != sbr->l_A[ch]) - den += Q_M_lim[m]; - } - - //printf("%d\n", den); - - /* G_boost: fixed point */ - if ((den + EPS) == 0) - G_boost = REAL_CONST(2.51188643); - else - G_boost = (((int64_t)(acc1 + EPS))<f_table_lim[sbr->bs_limiter_bands][k]; - m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++) - { - /* apply compensation to gain, noise floor sf's and sinusoid levels */ -#ifndef SBR_LOW_POWER - /* G_lim_boost: fixed point */ - adj->G_lim_boost[l][m] = SBR_SQRT_FIX(MUL(G_lim[m], G_boost)); -#else - /* sqrt() will be done after the aliasing reduction to save a - * few multiplies - */ - /* G_lim_boost: fixed point */ - adj->G_lim_boost[l][m] = MUL(G_lim[m], G_boost); -#endif - /* Q_M_lim_boost: integer */ - adj->Q_M_lim_boost[l][m] = SBR_SQRT_INT(MUL(Q_M_lim[m], G_boost)); - /* S_M_boost: integer */ - if (adj->S_index_mapped[m][l]) - adj->S_M_boost[l][m] = SBR_SQRT_INT(MUL(S_M[m], G_boost)); - else - adj->S_M_boost[l][m] = 0; - } - } - } -} -#else static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) { static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 }; @@ -582,8 +310,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) G_max = ((EPS + acc1)/(EPS + acc2)) * limGain[sbr->bs_limiter_gains]; G_max = min(G_max, 1e10); - //printf("%f %d %d\n", G_max, (int)floor((acc1+EPS)/1024.), (int)floor((acc2+EPS)/1024.)); - for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k]; m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++) { @@ -591,40 +317,21 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) real_t div2; div2 = adj->Q_mapped[m][l] / (1 + adj->Q_mapped[m][l]); - - //printf("%f\n", div2); - Q_M = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div2; - //printf("%f\n", Q_M/1024.); - if (adj->S_mapped[m][l] == 0) { S_M[m] = 0; /* fixed point: delta* can stay since it's either 1 or 0 */ d = (1 + sbr->E_curr[ch][m][l]) * (1 + delta*adj->Q_mapped[m][l]); - - //printf("%f\n", d/1024.); - G = sbr->E_orig[ch][table_map_res_to_m[m]][l] / d; - - //printf("%f\n", G); - } else { real_t div; div = adj->S_mapped[m][l] / (1. + adj->Q_mapped[m][l]); - - //printf("%f\n", div); - S_M[m] = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div; - - //printf("%f\n", S_M[m]/1024.); - G = (sbr->E_orig[ch][table_map_res_to_m[m]][l] / (1. + sbr->E_curr[ch][m][l])) * div2; - - //printf("%f\n", G); } /* limit the additional noise energy level */ @@ -636,8 +343,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) } else { Q_M_lim[m] = Q_M * G_max / G; G_lim[m] = G_max; - - //printf("%f\n", Q_M_lim[m] / 1024.); } den += sbr->E_curr[ch][m][l] * G_lim[m]; @@ -647,8 +352,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) den += Q_M_lim[m]; } - //printf("%f\n", den/1024.); - G_boost = (acc1 + EPS) / (den + EPS); G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */); @@ -674,7 +377,6 @@ static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch) } } } -#endif #ifdef SBR_LOW_POWER static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch) @@ -745,11 +447,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, if ((E_total_est + EPS) == 0) G_target = 0; else -#ifdef FIXED_POINT - G_target = (((int64_t)(E_total))<f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++) @@ -775,11 +473,8 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, if (acc + EPS == 0) acc = 0; else -#ifdef FIXED_POINT - acc = (((int64_t)(E_total))<f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++) { adj->G_lim_boost[l][m-sbr->kx] = MUL(acc, adj->G_lim_boost[l][m-sbr->kx]); @@ -794,11 +489,7 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k]; m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++) { -#ifdef FIXED_POINT - adj->G_lim_boost[l][m] = SBR_SQRT_FIX(adj->G_lim_boost[l][m]); -#else adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]); -#endif } } } @@ -894,33 +585,17 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt; -#if 0 - if (sbr->frame == 155) - { - printf("%f\n", G_filt); - } -#endif - /* add noise to the output */ fIndexNoise = (fIndexNoise + 1) & 511; -#if 0 - printf("%d %f\n", Q_filt, RE(V[fIndexNoise])/(float)(1<kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx])) - + MUL_R_C((Q_filt<kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx])) + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx])) + MUL_R_C(Q_filt, RE(V[fIndexNoise])); -#endif if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42) - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = 16428320; + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = 16428320; #ifndef SBR_LOW_POWER - QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx])) + QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx])) + MUL_R_C(Q_filt, IM(V[fIndexNoise])); #endif @@ -929,34 +604,34 @@ static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, { int8_t rev = ((m + sbr->kx) & 1) ? -1 : 1; QMF_RE(psi) = MUL(adj->S_M_boost[l][m], phi_re[fIndexSine]); - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) += QMF_RE(psi); + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_RE(psi); #ifndef SBR_LOW_POWER QMF_IM(psi) = rev * MUL(adj->S_M_boost[l][m], phi_im[fIndexSine]); - QMF_IM(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) += QMF_IM(psi); + QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_IM(psi); #else i_min1 = (fIndexSine - 1) & 3; i_plus1 = (fIndexSine + 1) & 3; if (m == 0) { - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx - 1]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx - 1]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815))); - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][1], phi_re[i_plus1]), COEF_CONST(0.00815))); } if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16)) { - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815))); - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_plus1]), COEF_CONST(0.00815))); } if ((m == sbr->M - 1) && (sinusoids < 16) && (m + sbr->kx + 1 < 63)) { - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815))); - QMF_RE(Xsbr[((i + tHFAdj)<<6) + m+sbr->kx + 1]) -= + QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx + 1]) -= (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_min1]), COEF_CONST(0.00815))); } -- cgit v1.2.3