📄 sbr_hfadj.c
字号:
current_res_band++; current_res_band_size = 1; } acc2 += QUANTISE2INT(sbr->E_curr[ch][m][l]/1024.0); } acc1 += QUANTISE2INT(pow2(-10 + log2_int_tab[current_res_band_size] + find_log2_E(sbr, current_res_band, l, ch))); acc1 = QUANTISE2REAL( log2(EPS + acc1) ); /* calculate the maximum gain */ /* ratio of the energy of the original signal and the energy * of the HF generated signal */ G_max = acc1 - QUANTISE2REAL(log2(EPS + acc2)) + QUANTISE2REAL(limGain[sbr->bs_limiter_gains]); G_max = min(G_max, QUANTISE2REAL(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 += QUANTISE2INT(pow2(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 = -10 + log2(sbr->E_curr[ch][m][l]); E_orig = -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(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(-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] = QUANTISE2REAL(Q_M); G_lim[m] = QUANTISE2REAL(G); if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) { Q_M_size++; } } else { /* G > G_max */ Q_M_lim[m] = QUANTISE2REAL(Q_M) + G_max - QUANTISE2REAL(G); G_lim[m] = G_max; /* accumulate limited Q_M */ if ((S_index_mapped == 0) && (l != sbr->l_A[ch])) { den += QUANTISE2INT(pow2(Q_M_lim[m])); } } /* accumulate the total energy */ /* E_curr changes for every m so we do need to accumulate every m */ den += QUANTISE2INT(pow2(E_curr + G_lim[m])); } /* accumulate last range of equal Q_Ms */ if (Q_M_size > 0) { den += QUANTISE2INT(pow2(log2_int_tab[Q_M_size] + Q_M)); } /* calculate the final gain */ /* G_boost: [0..2.51188643] */ G_boost = acc1 - QUANTISE2REAL(log2(den + EPS)); G_boost = min(G_boost, QUANTISE2REAL(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] = QUANTISE2REAL(pow2((G_lim[m] + G_boost) / 2.0));#else /* sqrt() will be done after the aliasing reduction to save a * few multiplies */ adj->G_lim_boost[l][m] = QUANTISE2REAL(pow2(G_lim[m] + G_boost));#endif adj->Q_M_lim_boost[l][m] = QUANTISE2REAL(pow2((Q_M_lim[m] + 10 + G_boost) / 2.0)); if (S_M[m] != LOG2_MIN_INF) { adj->S_M_boost[l][m] = QUANTISE2REAL(pow2((S_M[m] + 10 + G_boost) / 2.0)); } else { adj->S_M_boost[l][m] = 0; } } } }}#elsestatic void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch){ static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 }; uint8_t m, l, k; uint8_t current_t_noise_band = 0; uint8_t S_mapped; ALIGN real_t Q_M_lim[MAX_M]; ALIGN real_t G_lim[MAX_M]; ALIGN real_t G_boost; ALIGN real_t S_M[MAX_M]; for (l = 0; l < sbr->L_E[ch]; l++) { uint8_t current_f_noise_band = 0; uint8_t current_res_band = 0; uint8_t current_res_band2 = 0; uint8_t current_hi_res_band = 0; real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1; S_mapped = get_S_mapped(sbr, ch, l, current_res_band2); if (sbr->t_E[ch][l+1] > sbr->t_Q[ch][current_t_noise_band+1]) { current_t_noise_band++; } 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; uint8_t current_res_band_size = 0; uint8_t ml1, ml2; ml1 = sbr->f_table_lim[sbr->bs_limiter_bands][k]; ml2 = sbr->f_table_lim[sbr->bs_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -