int calc_noise(gr_info const *const cod_info, FLOAT const *l3_xmin, FLOAT * distort, calc_noise_result * const res, calc_noise_data * prev_noise) { int sfb, l, over = 0; FLOAT over_noise_db = 0; FLOAT tot_noise_db = 0; /* 0 dB relative to masking */ FLOAT max_noise = -20.0; /* -200 dB relative to masking */ int j = 0; const int *scalefac = cod_info->scalefac; res->over_SSD = 0; for (sfb = 0; sfb < cod_info->psymax; sfb++) { int const s = cod_info->global_gain - (((*scalefac++) + (cod_info->preflag ? pretab[sfb] : 0)) << (cod_info->scalefac_scale + 1)) - cod_info->subblock_gain[cod_info->window[sfb]] * 8; FLOAT const r_l3_xmin = 1.f / *l3_xmin++; FLOAT distort_ = 0.0f; FLOAT noise = 0.0f; if (prev_noise && (prev_noise->step[sfb] == s)) { /* use previously computed values */ j += cod_info->width[sfb]; distort_ = r_l3_xmin * prev_noise->noise[sfb]; noise = prev_noise->noise_log[sfb]; } else { FLOAT const step = POW20(s); l = cod_info->width[sfb] >> 1; if ((j + cod_info->width[sfb]) > cod_info->max_nonzero_coeff) { int usefullsize; usefullsize = cod_info->max_nonzero_coeff - j + 1; if (usefullsize > 0) l = usefullsize >> 1; else l = 0; } noise = calc_noise_core_c(cod_info, &j, l, step); if (prev_noise) { /* save noise values */ prev_noise->step[sfb] = s; prev_noise->noise[sfb] = noise; } distort_ = r_l3_xmin * noise; /* multiplying here is adding in dB, but can overflow */ noise = FAST_LOG10(Max(distort_, 1E-20f)); if (prev_noise) { /* save noise values */ prev_noise->noise_log[sfb] = noise; } }
int calc_noise( const lame_internal_flags * const gfc, const int ix [576], const gr_info * const cod_info, const III_psy_xmin * const l3_xmin, const III_scalefac_t * const scalefac, III_psy_xmin * xfsf, calc_noise_result * const res ) { int sfb, l, i, over=0; FLOAT8 over_noise_db = 0; FLOAT8 tot_noise_db = 0; /* 0 dB relative to masking */ FLOAT8 max_noise = 1E-20; /* -200 dB relative to masking */ double klemm_noise = 1E-37; int j = 0; for (sfb = 0; sfb < cod_info->psy_lmax; sfb++) { int s = cod_info->global_gain - ((scalefac->l[sfb] + (cod_info->preflag ? pretab[sfb] : 0)) << (cod_info->scalefac_scale + 1)); FLOAT8 step; FLOAT8 noise = 0.0; if (s<0) { step = pow(2.0, (double)(s - 210) * 0.25); }else{ /* use table lookup. allegedly faster */ step = POW20(s); } l = gfc->scalefac_band.l[sfb+1] - gfc->scalefac_band.l[sfb]; do { FLOAT8 temp = fabs(cod_info->xr[j]) - pow43[ix[j]] * step; noise += temp * temp; j++; } while (--l > 0); noise = xfsf->l[sfb] = noise / l3_xmin->l[sfb]; max_noise=Max(max_noise,noise); klemm_noise += penalties (noise); noise = FAST_LOG10(Max(noise,1E-20)); /* multiplying here is adding in dB, but can overflow */ //tot_noise *= Max(noise, 1E-20); tot_noise_db += noise; if (noise > 0.0) { over++; /* multiplying here is adding in dB -but can overflow */ //over_noise *= noise; over_noise_db += noise; } } for (sfb = cod_info->sfb_smin; sfb < cod_info->psy_smax; sfb++) { int width = gfc->scalefac_band.s[sfb+1] - gfc->scalefac_band.s[sfb]; for ( i = 0; i < 3; i++ ) { int s = cod_info->global_gain - (scalefac->s[sfb][i] << (cod_info->scalefac_scale + 1)) - cod_info->subblock_gain[i] * 8; FLOAT8 step = POW20(s); FLOAT8 noise = 0.0; l = width; do { FLOAT8 temp; temp = pow43[ix[j]] * step - fabs(cod_info->xr[j]); noise += temp * temp; j++; } while (--l > 0); noise = xfsf->s[sfb][i] = noise / l3_xmin->s[sfb][i]; max_noise = Max(max_noise,noise); klemm_noise += penalties (noise); noise = FAST_LOG10(Max(noise,1E-20)); tot_noise_db += noise; if (noise > 0.0) { over++; over_noise_db += noise; } } } res->over_count = over; res->tot_noise = 10.*tot_noise_db; res->over_noise = 10.*over_noise_db; res->max_noise = 10.*FAST_LOG10(max_noise); res->klemm_noise = klemm_noise; return over; }