mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 11:38:08 +00:00
audio-dsp: the click remover keeps a sample that is not finite as silence
A NaN or infinite input sample went into the analysis span unchanged. It stopped the prediction for that span and came out of a later block. Such a sample is now kept as silence.
This commit is contained in:
@@ -653,6 +653,23 @@ fn click_remover_repairs_clicks() {
|
||||
assert!(db(after / before) < -20.0, "error {before} → {after}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn click_remover_keeps_a_non_finite_sample_as_silence() {
|
||||
let n = SR as usize / 2;
|
||||
let clean = sine(440.0, 0.3, SR as f64, n, 0.0);
|
||||
let mut dirty = clean.clone();
|
||||
dirty[5000] = f32::NAN;
|
||||
dirty[9000] = f32::INFINITY;
|
||||
// A click in the same span as the NaN.
|
||||
dirty[5100] += 0.6;
|
||||
let mut e = fx("click_remover", &[]);
|
||||
let lat = e.latency();
|
||||
let (y, _) = run(e.as_mut(), &dirty, &dirty);
|
||||
assert!(y.iter().all(|v| v.is_finite()), "a sample that is not finite came out");
|
||||
let click = (y[5100 + lat] - clean[5100]).abs();
|
||||
assert!(click < 0.1, "the click next to the NaN was left at {click}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channel_and_stereo_tools() {
|
||||
let n = 4800;
|
||||
|
||||
@@ -220,7 +220,9 @@ impl AudioEffect for ClickRemover {
|
||||
for (ci, chan) in channels.iter_mut().enumerate().take(nch) {
|
||||
let c = &mut self.ch[ci];
|
||||
for v in chan[..n].iter_mut() {
|
||||
let x = *v;
|
||||
// A sample that is not finite is kept as silence, so it does not stop the
|
||||
// analysis of the span it is in or come out of a later block.
|
||||
let x = if v.is_finite() { *v } else { 0.0 };
|
||||
*v = c.out[c.pos];
|
||||
c.buf[SPAN - BLOCK + c.pos] = x;
|
||||
c.pos += 1;
|
||||
|
||||
Reference in New Issue
Block a user