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

📄 sbr_hfadj.c

📁 the mpeg2/4 aac decoder
💻 C
📖 第 1 页 / 共 5 页
字号:
            /* calculate the accumulated E_orig and E_curr over the limiter band */            for (m = ml1; m < ml2; m++)            {                if ((m + sbr->kx) < sbr->f_table_res[sbr->f[ch][l]][current_res_band+1])                {                    current_res_band_size++;                } else {                    acc1 += pow2_int(-REAL_CONST(10) + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch));                    current_res_band++;                    current_res_band_size = 1;                }                acc2 += sbr->E_curr[ch][m][l];            }            acc1 += pow2_int(-REAL_CONST(10) + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch));            if (acc1 == 0)                acc1 = LOG2_MIN_INF;            else                acc1 = log2_int(acc1);            /* calculate the maximum gain */            /* ratio of the energy of the original signal and the energy             * of the HF generated signal             */            G_max = acc1 - log2_int(acc2) + limGain[sbr->bs_limiter_gains];            G_max = min(G_max, limGain[3]);            for (m = ml1; m < ml2; m++)            {                real_t G;                real_t E_curr, E_orig;                real_t Q_orig, Q_orig_plus1;                uint8_t S_index_mapped;                /* check if m is on a noise band border */                if ((m + sbr->kx) == sbr->f_table_noise[current_f_noise_band+1])                {                    /* step to next noise band */                    current_f_noise_band++;                }                /* check if m is on a resolution band border */                if ((m + sbr->kx) == sbr->f_table_res[sbr->f[ch][l]][current_res_band2+1])                {                    /* accumulate a whole range of equal Q_Ms */                    if (Q_M_size > 0)                        den += pow2_int(log2_int_tab[Q_M_size] + Q_M);                    Q_M_size = 0;                    /* step to next resolution band */                    current_res_band2++;                    /* if we move to a new resolution band, we should check if we are                     * going to add a sinusoid in this band                     */                    S_mapped = get_S_mapped(sbr, ch, l, current_res_band2);                }                /* check if m is on a HI_RES band border */                if ((m + sbr->kx) == sbr->f_table_res[HI_RES][current_hi_res_band+1])                {                    /* step to next HI_RES band */                    current_hi_res_band++;                }                /* find S_index_mapped                 * S_index_mapped can only be 1 for the m in the middle of the                 * current HI_RES band                 */                S_index_mapped = 0;                if ((l >= sbr->l_A[ch]) ||                    (sbr->bs_add_harmonic_prev[ch][current_hi_res_band] && sbr->bs_add_harmonic_flag_prev[ch]))                {                    /* find the middle subband of the HI_RES frequency band */                    if ((m + sbr->kx) == (sbr->f_table_res[HI_RES][current_hi_res_band+1] + sbr->f_table_res[HI_RES][current_hi_res_band]) >> 1)                        S_index_mapped = sbr->bs_add_harmonic[ch][current_hi_res_band];                }                /* find bitstream parameters */                if (sbr->E_curr[ch][m][l] == 0)                    E_curr = LOG2_MIN_INF;                else                    E_curr = log2_int(sbr->E_curr[ch][m][l]);                E_orig = -REAL_CONST(10) + find_log2_E(sbr, current_res_band2, l, ch);                Q_orig = find_log2_Q(sbr, current_f_noise_band, current_t_noise_band, ch);                Q_orig_plus1 = find_log2_Qplus1(sbr, current_f_noise_band, current_t_noise_band, ch);                /* Q_M only depends on E_orig and Q_div2:                 * since N_Q <= N_Low <= N_High we only need to recalculate Q_M on                 * a change of current res band (HI or LO)                 */                Q_M = E_orig + Q_orig - Q_orig_plus1;                /* S_M only depends on E_orig, Q_div and S_index_mapped:                 * S_index_mapped can only be non-zero once per HI_RES band                 */                if (S_index_mapped == 0)                {                    S_M[m] = LOG2_MIN_INF; /* -inf */                } else {                    S_M[m] = E_orig - Q_orig_plus1;                    /* accumulate sinusoid part of the total energy */                    den += pow2_int(S_M[m]);                }                /* calculate gain */                /* ratio of the energy of the original signal and the energy                 * of the HF generated signal                 */                /* E_curr here is officially E_curr+1 so the log2() of that can never be < 0 */                /* scaled by -10 */                G = E_orig - max(-REAL_CONST(10), E_curr);                if ((S_mapped == 0) && (delta == 1))                {                    /* G = G * 1/(1+Q) */                    G -= Q_orig_plus1;                } else if (S_mapped == 1) {                    /* G = G * Q/(1+Q) */                    G += Q_orig - Q_orig_plus1;                }                /* limit the additional noise energy level */                /* and apply the limiter */                if (G_max > G)                {                    Q_M_lim[m] = Q_M;                    G_lim[m] = G;                    if ((S_index_mapped == 0) && (l != sbr->l_A[ch]))                    {                        Q_M_size++;                    }                } else {                    /* G > G_max */                    Q_M_lim[m] = Q_M + G_max - G;                    G_lim[m] = G_max;                    /* accumulate limited Q_M */                    if ((S_index_mapped == 0) && (l != sbr->l_A[ch]))                    {                        den += pow2_int(Q_M_lim[m]);                    }                }                /* accumulate the total energy */                /* E_curr changes for every m so we do need to accumulate every m */                den += pow2_int(E_curr + G_lim[m]);            }            /* accumulate last range of equal Q_Ms */            if (Q_M_size > 0)            {                den += pow2_int(log2_int_tab[Q_M_size] + Q_M);            }            /* calculate the final gain */            /* G_boost: [0..2.51188643] */            G_boost = acc1 - log2_int(den /*+ EPS*/);            G_boost = min(G_boost, REAL_CONST(1.328771237) /* log2(1.584893192 ^ 2) */);            for (m = ml1; m < ml2; m++)            {                /* apply compensation to gain, noise floor sf's and sinusoid levels */#ifndef SBR_LOW_POWER                adj->G_lim_boost[l][m] = pow2_fix((G_lim[m] + G_boost) >> 1);#else                /* sqrt() will be done after the aliasing reduction to save a                 * few multiplies                 */                adj->G_lim_boost[l][m] = pow2_fix(G_lim[m] + G_boost);#endif                adj->Q_M_lim_boost[l][m] = pow2_fix((Q_M_lim[m] + G_boost) >> 1);                if (S_M[m] != LOG2_MIN_INF)                {                    adj->S_M_boost[l][m] = pow2_int((S_M[m] + G_boost) >> 1);                } else {                    adj->S_M_boost[l][m] = 0;                }            }        }    }}#else//#define LOG2_TEST#ifdef LOG2_TEST#define LOG2_MIN_INF -100000__inline float pow2(float val){    return pow(2.0, val);}__inline float log2(float val){    return log(val)/log(2.0);}#define RB 14float QUANTISE2REAL(float val){    __int32 ival = (__int32)(val * (1<<RB));    return (float)ival / (float)((1<<RB));}float QUANTISE2INT(float val){    return floor(val);}/* log2 values of [0..63] */static const real_t log2_int_tab[] = {

⌨️ 快捷键说明

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