forge
Explore
Log in

Don't you dare go Hollow

ec-aac test: lag-search window skipped digital silence; own-core reference interpolates linearly. Root cause (measured with pinned ffmpeg, f32le): decoder timing is right, instruments were not. (1) ps_06 is 4x53 AUs; AUs 53-55 of ffmpeg output are digital silence (rms 0 over [108544,112640)). With the now-correct 2048/AU length (434176/ch, = ffmpeg) every lag search anchored at len/4 = 108544 lands exactly there, so corr is noise and the winner sits at the +/-100000 / +/-20000 bound (sbr_real_library_matches_reference, per_au_low_band_divergence, sbr_header_feature_table, synthetic_heaac_matrix ps_06). On main the shorter output moved the window to loud audio, hence the earlier pass. window_start() (single source for 4 copies) advances to the first 4x1024 block louder than 1e-4 of mean power in both signals, unchanged when the base block is loud. (2) full_chain_low_band ps_04 corr 0.964 at lag -961: nearest-neighbor 2x of the core carries a half-sample error; hold-resampling ffmpeg's own ps_04 output gives at best 0.9578 for any decoder, linear interpolation 0.9936 (cm_48_2: 0.9985 -> 0.9999, matches observed 0.9987). upsample_2x is linear; threshold stays 0.99. Also ch0 of a PS stream is not the mono core (ffmpeg ps_06 corr(L,L+R) 0.937 over 10 s), so the comparison stops where the channels first differ (mono_prefix). Decoder evidence: ours vs ffmpeg ps_04 lag 0 corr 1.000000, 52/53 windows exactly 1.0 (1 silent), len 217088 = 106*2048, pre-header AUs included; ps_06 headers only from AU 106. cargo check -p ec-aac --all-targets clean; tests not run

Browse files at this commit

a62782ec30b80caed4890f70f8f4b4ae3da0a78aAhmet Kaan GümüşParent: 90f2426
crates/ec-aac/tests/sbr_real_library/chunk_a.rsmodified+7 -2
@@ -164,9 +164,14 @@ pub(super) fn full_chain_low_band_matches_own_core() {
164164 // sample-for-sample with the full-chain output's rate --
165165 // crude, but a low-pass well below the core Nyquist erases the
166166 // stairstep artifacts this introduces.
167- let up: Vec<f32> = core[ch].iter().flat_map(|&s| [s, s]).collect();
167+ let up = upsample_2x(&core[ch]);
168168 let cutoff = f64::from(core_rate) * 0.4;
169- let ol = lowpass(&full[ch], full_rate, cutoff);
169+ let keep = if full.len() > core.len() {
170+ mono_prefix(&full)
171+ } else {
172+ full[ch].len()
173+ };
174+ let ol = lowpass(&full[ch][..keep], full_rate, cutoff);
170175 let ul = lowpass(&up, full_rate, cutoff);
171176 // Escalating search: narrow (`WIDE_LAG_MAX`=20_000, the file's
172177 // original bound) first, widen to `SEARCH_LAG_MAX` only if that
crates/ec-aac/tests/sbr_real_library/helpers.rsmodified+38 -20
@@ -231,11 +231,7 @@ pub(super) fn correlation(a: &[f32], b: &[f32]) -> f64 {
231231 /// case the coarse slice picked a noisy lag) gives the reported number.
232232 pub(super) fn best_lag_correlation_ex(ours: &[f32], theirs: &[f32], lag_max: i64) -> (i64, f64, bool) {
233233 const COARSE: usize = 4_096;
234- let start = ours
235- .len()
236- .min(theirs.len())
237- .saturating_sub(WINDOW)
238- .min(ours.len() / 4);
234+ let start = window_start(ours, theirs);
239235 let slice_at = |lag: i64, len: usize| -> Option<(usize, usize)> {
240236 let (oa, ob) = if lag >= 0 {
241237 (start, start + lag as usize)
@@ -365,11 +361,7 @@ pub(super) fn best_lag_correlation_wide(ours: &[f32], theirs: &[f32], lag_max: i
365361 /// refinement it replaces, so the resolution is simply not worth trading.
366362 pub(super) fn exhaustive_lag_correlation(ours: &[f32], theirs: &[f32], lag_max: i64) -> (i64, f64, bool) {
367363 const COARSE: usize = 4_096;
368- let start = ours
369- .len()
370- .min(theirs.len())
371- .saturating_sub(WINDOW)
372- .min(ours.len() / 4);
364+ let start = window_start(ours, theirs);
373365 let slice_at = |lag: i64, len: usize| -> Option<(usize, usize)> {
374366 let (oa, ob) = if lag >= 0 {
375367 (start, start + lag as usize)
@@ -421,11 +413,7 @@ pub(super) fn robust_lag_topk(
421413 k: usize,
422414 ) -> (i64, f64, bool) {
423415 const COARSE: usize = 4_096;
424- let start = ours
425- .len()
426- .min(theirs.len())
427- .saturating_sub(WINDOW)
428- .min(ours.len() / 4);
416+ let start = window_start(ours, theirs);
429417 let slice_at = |lag: i64, len: usize| -> Option<(usize, usize)> {
430418 let (oa, ob) = if lag >= 0 {
431419 (start, start + lag as usize)
@@ -477,6 +465,40 @@ pub(super) fn robust_lag_topk(
477465 best
478466 }
479467
468+pub(super) fn window_start(ours: &[f32], theirs: &[f32]) -> usize {
469+ const CHUNK: usize = 1_024;
470+ const CHUNKS: usize = 4;
471+ let end = ours.len().min(theirs.len());
472+ let base = end.saturating_sub(WINDOW).min(ours.len() / 4);
473+ let power = |s: &[f32]| {
474+ s.iter().map(|v| f64::from(*v) * f64::from(*v)).sum::<f64>() / s.len().max(1) as f64
475+ };
476+ let floor = 1e-4 * power(&ours[base..end]).min(power(&theirs[base..end]));
477+ let loud = |p: usize| {
478+ p + CHUNK * CHUNKS <= end
479+ && (p..p + CHUNK * CHUNKS)
480+ .step_by(CHUNK)
481+ .all(|a| power(&ours[a..a + CHUNK]) > floor && power(&theirs[a..a + CHUNK]) > floor)
482+ };
483+ (base..end).step_by(CHUNK).find(|&p| loud(p)).unwrap_or(base)
484+}
485+
486+pub(super) fn upsample_2x(core: &[f32]) -> Vec<f32> {
487+ let mut out = Vec::with_capacity(core.len() * 2);
488+ for (i, &s) in core.iter().enumerate() {
489+ out.push(s);
490+ out.push((s + core.get(i + 1).copied().unwrap_or(s)) * 0.5);
491+ }
492+ out
493+}
494+
495+pub(super) fn mono_prefix(planes: &[Vec<f32>]) -> usize {
496+ let first = &planes[0];
497+ planes.get(1).map_or(first.len(), |second| {
498+ first.iter().zip(second).position(|(a, b)| a != b).unwrap_or(first.len())
499+ })
500+}
501+
480502 /// Signed correlation of `ours` against `theirs` at one fixed `lag`, full
481503 /// `WINDOW`-sized, anchored at the SAME `start` offset `best_lag_correlation`
482504 /// uses internally -- used to test a hypothesized sign inversion by reusing
@@ -486,11 +508,7 @@ pub(super) fn robust_lag_topk(
486508 /// match `best_lag_correlation`'s `start`, not sample 0 -- the two windows
487509 /// otherwise cover different seconds of audio and are not comparable.
488510 pub(super) fn correlation_at_lag(ours: &[f32], theirs: &[f32], lag: i64) -> f64 {
489- let start = ours
490- .len()
491- .min(theirs.len())
492- .saturating_sub(WINDOW)
493- .min(ours.len() / 4);
511+ let start = window_start(ours, theirs);
494512 let (oa, ob) = if lag >= 0 {
495513 (start, start + lag as usize)
496514 } else {