Improvement: Double constants hunting

This commit is contained in:
Antoine SOULIER
2022-04-20 14:54:06 +02:00
parent c3831b7b24
commit ddc6522790
5 changed files with 50 additions and 48 deletions

View File

@@ -52,7 +52,7 @@ bool lc3_attdet_run(enum lc3_dt dt, enum lc3_srate sr,
for (int j = 0; j < 40; j++, x += 2, xn2 = xn1, xn1 = xn) {
xn = x[0] + x[1];
xf = 0.375 * xn - 0.5 * xn1 + 0.125 * xn2;
xf = 0.375f * xn - 0.5f * xn1 + 0.125f * xn2;
e[i] += xf * xf;
}
}
@@ -64,7 +64,7 @@ bool lc3_attdet_run(enum lc3_dt dt, enum lc3_srate sr,
for (int j = 0; j < 40; j++, x += 3, xn2 = xn1, xn1 = xn) {
xn = x[0] + x[1] + x[2];
xf = 0.375 * xn - 0.5 * xn1 + 0.125 * xn2;
xf = 0.375f * xn - 0.5f * xn1 + 0.125f * xn2;
e[i] += xf * xf;
}
}
@@ -78,10 +78,10 @@ bool lc3_attdet_run(enum lc3_dt dt, enum lc3_srate sr,
float a[4];
for (int i = 0; i < nblk; i++) {
a[i] = fmaxf(0.25 * attdet->an1, attdet->en1);
a[i] = fmaxf(0.25f * attdet->an1, attdet->en1);
attdet->en1 = e[i], attdet->an1 = a[i];
if (e[i] > 8.5 * a[i])
if (e[i] > 8.5f * a[i])
p_att = i + 1;
}

View File

@@ -50,8 +50,8 @@ static inline void resample_12k8_template(const enum lc3_srate sr,
const int w = 5 * LC3_SRATE_KHZ(sr) / 8;
const int b_scale = p >> (sr == LC3_SRATE_8K);
const float a1 = -1.965293373, b1 = -1.965589417 * b_scale;
const float a2 = 0.965885461, b2 = 0.982794708 * b_scale;
const float a1 = -1.965293373f, b1 = -1.965589417f * b_scale;
const float a2 = 0.965885461f, b2 = 0.982794708f * b_scale;
/* --- Resampling ---
* The value `15*8 * n` is divisible by all resampling factors `p`,
@@ -291,7 +291,7 @@ static bool detect_pitch(
correlate(x, x - r0, n, r, nr);
int t1 = argmax_weighted(r, nr, -.5/(nr-1), &rm1);
int t1 = argmax_weighted(r, nr, -.5f/(nr-1), &rm1);
int t2 = k0 + argmax(r + k0, nk, &rm2);
const float *x1 = x - (r0 + t1);
@@ -303,11 +303,11 @@ static bool detect_pitch(
float nc2 = rm2 <= 0 ? 0 :
rm2 / sqrtf(dot(x, x, n) * dot(x2, x2, n));
int t1sel = nc2 <= 0.85 * nc1;
int t1sel = nc2 <= 0.85f * nc1;
ltpf->tc = (t1sel ? t1 : t2);
*tc = r0 + ltpf->tc;
return (t1sel ? nc1 : nc2) > 0.6;
return (t1sel ? nc1 : nc2) > 0.6f;
}
/**
@@ -408,12 +408,12 @@ bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr,
float nc_diff = nc - ltpf->nc[0];
data->active = pitch_present &&
((nc > 0.9) || (nc > 0.84 && pitch_diff < 8 && nc_diff > -0.1));
((nc > 0.9f) || (nc > 0.84f && pitch_diff < 8 && nc_diff > -0.1f));
} else {
data->active = pitch_present &&
( (dt == LC3_DT_10M || ltpf->nc[1] > 0.94) &&
(ltpf->nc[0] > 0.94 && nc > 0.94) );
( (dt == LC3_DT_10M || ltpf->nc[1] > 0.94f) &&
(ltpf->nc[0] > 0.94f && nc > 0.94f) );
}
ltpf->active = data->active;

View File

@@ -269,47 +269,47 @@ static void compute_scale_factors(enum lc3_dt dt, enum lc3_srate sr,
float e_sum = 0;
for (int i = 0; i < LC3_NUM_BANDS-1; ) {
e[i] = (e0 * 0.25 + e1 * 0.5 + (e2 = e[i+1]) * 0.25) * ge[i];
e[i] = (e0 * 0.25f + e1 * 0.5f + (e2 = e[i+1]) * 0.25f) * ge[i];
e_sum += e[i++];
e[i] = (e1 * 0.25 + e2 * 0.5 + (e0 = e[i+1]) * 0.25) * ge[i];
e[i] = (e1 * 0.25f + e2 * 0.5f + (e0 = e[i+1]) * 0.25f) * ge[i];
e_sum += e[i++];
e[i] = (e2 * 0.25 + e0 * 0.5 + (e1 = e[i+1]) * 0.25) * ge[i];
e[i] = (e2 * 0.25f + e0 * 0.5f + (e1 = e[i+1]) * 0.25f) * ge[i];
e_sum += e[i++];
}
e[LC3_NUM_BANDS-1] = (e0 * 0.25 + e1 * 0.75) * ge[LC3_NUM_BANDS-1];
e[LC3_NUM_BANDS-1] = (e0 * 0.25f + e1 * 0.75f) * ge[LC3_NUM_BANDS-1];
e_sum += e[LC3_NUM_BANDS-1];
float noise_floor = fmaxf(e_sum * (1e-4 / 64), 0x1p-32);
float noise_floor = fmaxf(e_sum * (1e-4f / 64), 0x1p-32f);
for (int i = 0; i < LC3_NUM_BANDS; i++)
e[i] = log2f(fmaxf(e[i], noise_floor)) * 0.5;
e[i] = log2f(fmaxf(e[i], noise_floor)) * 0.5f;
/* --- Grouping & scaling --- */
float scf_sum;
scf[0] = (e[0] + e[4]) * 1./12 +
(e[0] + e[3]) * 2./12 +
(e[1] + e[2]) * 3./12 ;
scf[0] = (e[0] + e[4]) * 1.f/12 +
(e[0] + e[3]) * 2.f/12 +
(e[1] + e[2]) * 3.f/12 ;
scf_sum = scf[0];
for (int i = 1; i < 15; i++) {
scf[i] = (e[4*i-1] + e[4*i+4]) * 1./12 +
(e[4*i ] + e[4*i+3]) * 2./12 +
(e[4*i+1] + e[4*i+2]) * 3./12 ;
scf[i] = (e[4*i-1] + e[4*i+4]) * 1.f/12 +
(e[4*i ] + e[4*i+3]) * 2.f/12 +
(e[4*i+1] + e[4*i+2]) * 3.f/12 ;
scf_sum += scf[i];
}
scf[15] = (e[59] + e[63]) * 1./12 +
(e[60] + e[63]) * 2./12 +
(e[61] + e[62]) * 3./12 ;
scf[15] = (e[59] + e[63]) * 1.f/12 +
(e[60] + e[63]) * 2.f/12 +
(e[61] + e[62]) * 3.f/12 ;
scf_sum += scf[15];
for (int i = 0; i < 16; i++)
scf[i] = 0.85 * (scf[i] - scf_sum * 1./16);
scf[i] = 0.85f * (scf[i] - scf_sum * 1.f/16);
/* --- Attack handling --- */
@@ -319,23 +319,23 @@ static void compute_scale_factors(enum lc3_dt dt, enum lc3_srate sr,
float s0, s1 = scf[0], s2 = scf[1], s3 = scf[2], s4 = scf[3];
float sn = s1 + s2;
scf[0] = (sn += s3) * 1./3;
scf[1] = (sn += s4) * 1./4;
scf[0] = (sn += s3) * 1.f/3;
scf[1] = (sn += s4) * 1.f/4;
scf_sum = scf[0] + scf[1];
for (int i = 2; i < 14; i++, sn -= s0) {
s0 = s1, s1 = s2, s2 = s3, s3 = s4, s4 = scf[i+2];
scf[i] = (sn += s4) * 1./5;
scf[i] = (sn += s4) * 1.f/5;
scf_sum += scf[i];
}
scf[14] = (sn ) * 1./4;
scf[15] = (sn -= s1) * 1./3;
scf[14] = (sn ) * 1.f/4;
scf[15] = (sn -= s1) * 1.f/3;
scf_sum += scf[14] + scf[15];
for (int i = 0; i < 16; i++)
scf[i] = (dt == LC3_DT_7M5 ? 0.3 : 0.5) *
(scf[i] - scf_sum * 1./16);
scf[i] = (dt == LC3_DT_7M5 ? 0.3f : 0.5f) *
(scf[i] - scf_sum * 1.f/16);
}
/**
@@ -446,7 +446,7 @@ static void quantize(const float *scf, int lfcb_idx, int hfcb_idx,
xm_sum += xm[i];
}
float proj_factor = (6 - 1) / fmaxf(xm_sum, 1e-31);
float proj_factor = (6 - 1) / fmaxf(xm_sum, 1e-31f);
float corr = 0, energy = 0;
int npulses = 0;
@@ -684,19 +684,19 @@ static void spectral_shaping(enum lc3_dt dt, enum lc3_srate sr,
scf[0] = scf[1] = s1;
for (int i = 0; i < 15; i++) {
s0 = s1, s1 = inv ? -scf_q[i+1] : scf_q[i+1];
scf[4*i+2] = s0 + 0.125 * (s1 - s0);
scf[4*i+3] = s0 + 0.375 * (s1 - s0);
scf[4*i+4] = s0 + 0.625 * (s1 - s0);
scf[4*i+5] = s0 + 0.875 * (s1 - s0);
scf[4*i+2] = s0 + 0.125f * (s1 - s0);
scf[4*i+3] = s0 + 0.375f * (s1 - s0);
scf[4*i+4] = s0 + 0.625f * (s1 - s0);
scf[4*i+5] = s0 + 0.875f * (s1 - s0);
}
scf[62] = s1 + 0.125 * (s1 - s0);
scf[63] = s1 + 0.375 * (s1 - s0);
scf[62] = s1 + 0.125f * (s1 - s0);
scf[63] = s1 + 0.375f * (s1 - s0);
int nb = LC3_MIN(lc3_band_lim[dt][sr][LC3_NUM_BANDS], LC3_NUM_BANDS);
int n2 = LC3_NUM_BANDS - nb;
for (int i2 = 0; i2 < n2; i2++)
scf[i2] = 0.5 * (scf[2*i2] + scf[2*i2+1]);
scf[i2] = 0.5f * (scf[2*i2] + scf[2*i2+1]);
if (n2 > 0)
memmove(scf + n2, scf + 2*n2, (nb - n2) * sizeof(float));

View File

@@ -97,7 +97,7 @@ static int estimate_gain(
}
}
if (v > nbits * 1.4 * 28./20)
if (v > nbits * 1.4f * 28.f/20)
g_int += i;
}
@@ -758,7 +758,7 @@ void lc3_spec_analyze(enum lc3_dt dt, enum lc3_srate sr,
float nbits_off = spec->nbits_off + spec->nbits_spare;
nbits_off = fminf(fmaxf(nbits_off, -40), 40);
nbits_off = 0.8 * spec->nbits_off + 0.2 * nbits_off;
nbits_off = 0.8f * spec->nbits_off + 0.2f * nbits_off;
int g_off = resolve_gain_offset(sr, nbytes);

View File

@@ -150,7 +150,9 @@ static void compute_lpc_coeffs(enum lc3_dt dt, enum lc3_bandwidth bw,
*/
static void lpc_weighting(float pred_gain, float *a)
{
float gamma = 1. - (1. - 0.85) * (2. - pred_gain) / (2. - 1.5), g = 1;
float gamma = 1.f - (1.f - 0.85f) * (2.f - pred_gain) / (2.f - 1.5f);
float g = 1.f;
for (int i = 1; i < 9; i++)
a[i] *= (g *= gamma);
}
@@ -354,10 +356,10 @@ void lc3_tns_analyze(enum lc3_dt dt, enum lc3_bandwidth bw,
for (int f = 0; f < data->nfilters; f++) {
data->rc_order[f] = 0;
if (nn_flag || pred_gain[f] <= 1.5)
if (nn_flag || pred_gain[f] <= 1.5f)
continue;
if (data->lpc_weighting && pred_gain[f] < 2)
if (data->lpc_weighting && pred_gain[f] < 2.f)
lpc_weighting(pred_gain[f], a[f]);
lpc_reflection(a[f], rc[f]);