style: apply cargo fmt across the crate (A20)
The repo never enforced rustfmt, so formatting had drifted broadly. This is a single mechanical `cargo fmt` pass over the whole crate (no behavioral change; lib suite green, 493 passed). Going forward fmt should be enforced (planned CI fmt --check step). Part of the 0.6.1 hygiene pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+29
-7
@@ -283,8 +283,14 @@ mod tests {
|
||||
let q = echo.len() / 4;
|
||||
let early = erle(&echo[..q], &cleaned[..q]);
|
||||
let late = erle(&echo[3 * q..], &cleaned[3 * q..]);
|
||||
assert!(late > early + 10.0, "should improve markedly: early {early:.1} late {late:.1}");
|
||||
assert!(late > 20.0, "converged ERLE should exceed 20 dB, got {late:.1}");
|
||||
assert!(
|
||||
late > early + 10.0,
|
||||
"should improve markedly: early {early:.1} late {late:.1}"
|
||||
);
|
||||
assert!(
|
||||
late > 20.0,
|
||||
"converged ERLE should exceed 20 dB, got {late:.1}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -307,7 +313,10 @@ mod tests {
|
||||
let mut aec = Nlms::new(128, 0.5, 1e-6);
|
||||
let out = aec.process(&silent_ref, &near);
|
||||
for (a, b) in near.iter().zip(&out) {
|
||||
assert!((a - b).abs() < 1e-6, "near-end should pass through: {a} vs {b}");
|
||||
assert!(
|
||||
(a - b).abs() < 1e-6,
|
||||
"near-end should pass through: {a} vs {b}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,14 +350,24 @@ mod tests {
|
||||
let mut late_hits = 0;
|
||||
for i in 0..far.len() {
|
||||
if dtd.update(far[i], mic[i]) {
|
||||
if i < onset { early_hits += 1 } else { late_hits += 1 }
|
||||
if i < onset {
|
||||
early_hits += 1
|
||||
} else {
|
||||
late_hits += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
// Echo-only stretch should rarely trip; near-end stretch should trip a lot.
|
||||
let early_rate = early_hits as f32 / onset as f32;
|
||||
let late_rate = late_hits as f32 / (far.len() - onset) as f32;
|
||||
assert!(early_rate < 0.10, "false-positive rate {early_rate:.2} too high");
|
||||
assert!(late_rate > 0.50, "missed double-talk, rate only {late_rate:.2}");
|
||||
assert!(
|
||||
early_rate < 0.10,
|
||||
"false-positive rate {early_rate:.2} too high"
|
||||
);
|
||||
assert!(
|
||||
late_rate > 0.50,
|
||||
"missed double-talk, rate only {late_rate:.2}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -380,6 +399,9 @@ mod tests {
|
||||
erle_dtd > erle_no + 15.0,
|
||||
"DTD should hold the echo path: with {erle_dtd:.1} dB vs without {erle_no:.1} dB"
|
||||
);
|
||||
assert!(erle_dtd > 15.0, "held filter should still cancel echo: {erle_dtd:.1} dB");
|
||||
assert!(
|
||||
erle_dtd > 15.0,
|
||||
"held filter should still cancel echo: {erle_dtd:.1} dB"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,10 @@ mod tests {
|
||||
let path = EchoPath::synthetic(480, 480, 0.5, 99);
|
||||
let echo = path.apply(&far);
|
||||
let ratio = rms(&echo) / rms(&far);
|
||||
assert!((0.3..0.7).contains(&ratio), "echo/far rms ratio {ratio} off target");
|
||||
assert!(
|
||||
(0.3..0.7).contains(&ratio),
|
||||
"echo/far rms ratio {ratio} off target"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+4
-1
@@ -141,7 +141,10 @@ mod tests {
|
||||
buf[0] = Complex::new(1.0, 0.0);
|
||||
fft(&mut buf);
|
||||
for c in &buf {
|
||||
assert!(approx(c.magnitude(), 1.0, 1e-9), "expected flat 1.0, got {c:?}");
|
||||
assert!(
|
||||
approx(c.magnitude(), 1.0, 1e-9),
|
||||
"expected flat 1.0, got {c:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-5
@@ -62,11 +62,31 @@ pub struct Band {
|
||||
|
||||
/// Voice-relevant bands for spotting *where* residual echo or noise lives.
|
||||
pub const VOICE_BANDS: &[Band] = &[
|
||||
Band { label: "low (80-300)", low_hz: 80.0, high_hz: 300.0 },
|
||||
Band { label: "low-mid (300-1k)", low_hz: 300.0, high_hz: 1000.0 },
|
||||
Band { label: "mid (1k-3k)", low_hz: 1000.0, high_hz: 3000.0 },
|
||||
Band { label: "high-mid (3k-6k)", low_hz: 3000.0, high_hz: 6000.0 },
|
||||
Band { label: "high (6k-12k)", low_hz: 6000.0, high_hz: 12000.0 },
|
||||
Band {
|
||||
label: "low (80-300)",
|
||||
low_hz: 80.0,
|
||||
high_hz: 300.0,
|
||||
},
|
||||
Band {
|
||||
label: "low-mid (300-1k)",
|
||||
low_hz: 300.0,
|
||||
high_hz: 1000.0,
|
||||
},
|
||||
Band {
|
||||
label: "mid (1k-3k)",
|
||||
low_hz: 1000.0,
|
||||
high_hz: 3000.0,
|
||||
},
|
||||
Band {
|
||||
label: "high-mid (3k-6k)",
|
||||
low_hz: 3000.0,
|
||||
high_hz: 6000.0,
|
||||
},
|
||||
Band {
|
||||
label: "high (6k-12k)",
|
||||
low_hz: 6000.0,
|
||||
high_hz: 12000.0,
|
||||
},
|
||||
];
|
||||
|
||||
/// Sums the linear magnitude energy within `[low_hz, high_hz)` across a single
|
||||
|
||||
+7
-2
@@ -202,7 +202,8 @@ fn legend(opts: &RenderOpts) -> String {
|
||||
if opts.ascii {
|
||||
for i in 0..steps {
|
||||
let v = i as f32 / (steps - 1) as f32;
|
||||
let idx = ((v * (ASCII_RAMP.len() - 1) as f32).round() as usize).min(ASCII_RAMP.len() - 1);
|
||||
let idx =
|
||||
((v * (ASCII_RAMP.len() - 1) as f32).round() as usize).min(ASCII_RAMP.len() - 1);
|
||||
s.push(ASCII_RAMP[idx] as char);
|
||||
}
|
||||
} else {
|
||||
@@ -243,7 +244,11 @@ mod tests {
|
||||
fn render_produces_grid_of_expected_height() {
|
||||
let sig = generators::sine(2000.0, 0.8, 48_000, 48_000);
|
||||
let spec = stft::analyze(&sig, 48_000, 1024, 512);
|
||||
let opts = RenderOpts { width: 40, height: 10, ..Default::default() };
|
||||
let opts = RenderOpts {
|
||||
width: 40,
|
||||
height: 10,
|
||||
..Default::default()
|
||||
};
|
||||
let out = render(&spec, &opts);
|
||||
// Header + 10 body rows + time axis (2) + legend = non-trivial.
|
||||
let lines = out.lines().count();
|
||||
|
||||
+4
-1
@@ -94,7 +94,10 @@ mod tests {
|
||||
.unwrap()
|
||||
.0;
|
||||
let peak_hz = s.bin_hz(peak_bin);
|
||||
assert!((peak_hz - freq as f32).abs() < 100.0, "peak at {peak_hz} Hz, want {freq}");
|
||||
assert!(
|
||||
(peak_hz - freq as f32).abs() < 100.0,
|
||||
"peak at {peak_hz} Hz, want {freq}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+13
-3
@@ -34,7 +34,12 @@ pub fn read(path: &Path) -> Result<WavData, String> {
|
||||
let mut pos = 12usize;
|
||||
while pos + 8 <= bytes.len() {
|
||||
let id = &bytes[pos..pos + 4];
|
||||
let size = u32::from_le_bytes([bytes[pos + 4], bytes[pos + 5], bytes[pos + 6], bytes[pos + 7]]) as usize;
|
||||
let size = u32::from_le_bytes([
|
||||
bytes[pos + 4],
|
||||
bytes[pos + 5],
|
||||
bytes[pos + 6],
|
||||
bytes[pos + 7],
|
||||
]) as usize;
|
||||
let body_start = pos + 8;
|
||||
let body_end = (body_start + size).min(bytes.len());
|
||||
match id {
|
||||
@@ -45,7 +50,9 @@ pub fn read(path: &Path) -> Result<WavData, String> {
|
||||
sample_rate = u32::from_le_bytes([fmt[4], fmt[5], fmt[6], fmt[7]]);
|
||||
bits = u16::from_le_bytes([fmt[14], fmt[15]]);
|
||||
if audio_format != 1 {
|
||||
return Err(format!("unsupported WAV format tag {audio_format} (need PCM=1)"));
|
||||
return Err(format!(
|
||||
"unsupported WAV format tag {audio_format} (need PCM=1)"
|
||||
));
|
||||
}
|
||||
}
|
||||
b"data" => {
|
||||
@@ -75,7 +82,10 @@ pub fn read(path: &Path) -> Result<WavData, String> {
|
||||
samples.push(avg / 32768.0);
|
||||
}
|
||||
|
||||
Ok(WavData { samples, sample_rate })
|
||||
Ok(WavData {
|
||||
samples,
|
||||
sample_rate,
|
||||
})
|
||||
}
|
||||
|
||||
/// Writes mono `f32` samples (clamped to `[-1, 1]`) as a 16-bit PCM WAV. Used by
|
||||
|
||||
Reference in New Issue
Block a user