From 38347b4d307e9eca2070e10c098dad41d71db7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 6 Sep 2026 22:49:22 +0300 Subject: [PATCH] test(opus): print the analysis bandwidth histogram in the diagnostics test The detected-bandwidth clamp needs analysis.bandwidth <= 18 to do anything; on every gate source it is 20 on every valid frame (hein 20:1500, reell 20:1498, reelo 20:1499), which is why EC_OPUS_BW_DETECT reproduces the shipped rows byte for byte. --- crates/ec-opus/tests/conformance.rs | 11 +++++++++++ lanes/opus-opusmode-r1.sweep.txt | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lanes/opus-opusmode-r1.sweep.txt diff --git a/crates/ec-opus/tests/conformance.rs b/crates/ec-opus/tests/conformance.rs index 257de1f8..6437aa9c 100644 --- a/crates/ec-opus/tests/conformance.rs +++ b/crates/ec-opus/tests/conformance.rs @@ -5765,6 +5765,9 @@ fn analysis_music_prob_separates_speech_from_music() { let mut sum = [0.0f64; 4]; let mut n = 0usize; let mut valid = 0usize; + // Histogram of the detected bandwidth index, which drives + // `opus_encoder.c`'s `detected_bandwidth` clamp. + let mut bw_hist = [0u32; 21]; for chunk in pcm.chunks_exact(FRAME * CHANNELS) { enc.encode_float(chunk, FRAME, &mut out).expect("encode"); let d = enc.last_celt_diag(); @@ -5775,9 +5778,17 @@ fn analysis_music_prob_separates_speech_from_music() { sum[1] += f64::from(d.tonality); sum[2] += f64::from(d.tonality_slope); sum[3] += f64::from(d.activity); + bw_hist[(d.analysis_bandwidth.clamp(0, 20)) as usize] += 1; } } assert!(valid * 10 > n * 9, "{tag}: analysis valid on only {valid}/{n} frames"); + let bw: Vec = bw_hist + .iter() + .enumerate() + .filter(|&(_, &c)| c > 0) + .map(|(i, c)| format!("{i}:{c}")) + .collect(); + println!("analysis {tag}: bandwidth histogram {}", bw.join(" ")); let m = sum.map(|v| v / valid as f64); println!( "analysis {tag}: music {:.3} tonality {:.3} slope {:.4} activity {:.3} over {valid}/{n} frames (music={is_music})", diff --git a/lanes/opus-opusmode-r1.sweep.txt b/lanes/opus-opusmode-r1.sweep.txt new file mode 100644 index 00000000..b5cd9117 --- /dev/null +++ b/lanes/opus-opusmode-r1.sweep.txt @@ -0,0 +1,15 @@ +# ec-opus encoder vs ffmpeg libopus — encoders-only gate (r1) +# both bitstreams decoded by ec-opus; 120s cap; VBR; 48kHz stereo +# source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap Q_ours Q_ref err_ratio minsec_ours minsec_ref drop_ours drop_ref +nik 64 69.1 69.2 -0.1 0.9887 0.9864 -0.0024 -95.23 -154.78 0.708 0.9766 0.9745 0 0 +nik 96 100.9 101.0 -0.1 0.9947 0.9940 -0.0007 -29.86 -31.55 0.985 0.9889 0.9888 0 0 +reelo 64 63.6 63.6 -0.0 0.9893 0.9866 -0.0027 -202.82 -123.36 1.510 0.9702 0.9686 0 0 +reelo 96 93.4 93.9 -0.5 0.9947 0.9937 -0.0009 -114.74 -125.18 0.940 0.9862 0.9854 0 0 +her 64 67.7 67.9 -0.4 0.9834 0.9794 -0.0040 -365.72 -339.00 1.103 0.9477 0.9406 0 0 +her 96 101.0 101.5 -0.5 0.9914 0.9902 -0.0012 -202.07 -191.50 1.051 0.9728 0.9728 0 0 +reell 64 71.3 71.3 -0.0 0.9908 0.9880 -0.0029 -351.70 -128.39 2.697 0.9721 0.9644 0 0 +reell 96 105.3 105.4 -0.0 0.9956 0.9948 -0.0008 -301.83 -29.16 4.499 0.9856 0.9804 0 0 +dl8a 64 65.7 65.8 -0.1 0.9889 0.9865 -0.0025 -227.54 -378.84 0.552 0.9787 0.9723 0 0 +dl8a 96 96.5 96.8 -0.3 0.9942 0.9934 -0.0009 -177.70 -423.47 0.374 0.9881 0.9864 0 0 +hein 64 64.8 64.9 -0.2 0.9888 0.9874 -0.0014 -344.06 -388.31 0.853 0.9318 0.9148 0 0 +hein 96 86.8 86.9 -0.2 0.9946 0.9930 -0.0016 -117.91 -246.46 0.528 0.9689 0.9499 0 0