feat(common-dsp): add ITU-R BS.1770 K-weighting
KWeighting is one channel of the standard's pre-filter and RLB high-pass, computed from the analog prototypes so every sample rate is exact. lufs() turns a mean square summed over channels into LUFS. A full-scale 997 Hz sine reads -3.01 LUFS within 0.03 LU from 44.1 to 192 kHz.
This commit is contained in:
1 parent
3d316cbe49
commit
d77b88c7a9
3 files changed
+98
No files matched your search
@@ -80,3 +80,29 @@ fn wave_round_trip_keeps_root_and_wavetable_chunks() {
|
||||
assert_eq!(wav::decode(&bytes).unwrap(), w);
|
||||
assert!(wav::decode(&bytes[..40]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn k_weighting_reads_a_full_scale_997_hz_sine_at_minus_3_lufs() {
|
||||
use common_dsp::loudness::{lufs, KWeighting};
|
||||
let level = |rate: f32, hz: f64| {
|
||||
let mut k = KWeighting::new(rate);
|
||||
let n = rate as usize;
|
||||
let mut sum = 0f64;
|
||||
for i in 0..2 * n {
|
||||
let x = (std::f64::consts::TAU * hz * i as f64 / rate as f64).sin() as f32;
|
||||
let y = k.process(x) as f64;
|
||||
if i >= n {
|
||||
sum += y * y;
|
||||
}
|
||||
}
|
||||
lufs(sum / n as f64)
|
||||
};
|
||||
// BS.1770-4: a 0 dBFS 997 Hz sine in one channel reads −3.01 LKFS, at every rate.
|
||||
for rate in [44100., 48000., 96000., 192000.] {
|
||||
let got = level(rate, 997.);
|
||||
// BS.1770 allows meters 0.1 LU; the prototypes land within 0.03 up to 192 kHz.
|
||||
assert!((got + 3.01).abs() < 0.05, "{rate}: {got}");
|
||||
}
|
||||
// The RLB high-pass counts a 30 Hz sub much less than the mids.
|
||||
assert!(level(48000., 30.) < level(48000., 997.) - 5.);
|
||||
}
|
||||
Reference in new issue
Block a user