diff --git a/crates/ec-aac/src/lib.rs b/crates/ec-aac/src/lib.rs index 78197eea..c44b1d09 100644 --- a/crates/ec-aac/src/lib.rs +++ b/crates/ec-aac/src/lib.rs @@ -35,13 +35,13 @@ mod sbr_chain; mod sbr_env; mod sbr_hf; mod sbr_payload; -pub mod sbr_qmf; +mod sbr_qmf; mod sbr_qmf_window; mod ps_data; mod ps_dsp; mod ps_huff; mod sbr_tables; -pub mod tables; +mod tables; pub use config::{ AOT_AAC_LC, AOT_PS, AOT_SBR, AdtsHeader, AudioSpecificConfig, ProgramConfig, @@ -65,9 +65,6 @@ pub enum SbrSupport { /// SBR is signalled and **is** reconstructed: the decoded audio spans /// the full extension bandwidth at the extension sample rate. V1, - /// SBR is signalled but not reconstructed. Not produced by this decoder - /// any more: Parametric Stereo streams report [`SbrSupport::V1`]. - CoreOnly, } /// One decoded frame: interleaved `f32` in film channel order. diff --git a/crates/ec-aac/src/tables.rs b/crates/ec-aac/src/tables.rs index 02407588..68a9a612 100644 --- a/crates/ec-aac/src/tables.rs +++ b/crates/ec-aac/src/tables.rs @@ -1607,3 +1607,66 @@ pub static TNS_MAX_BANDS_LONG: [usize; 13] = [31, 31, 34, 40, 42, 51, 46, 46, 42 /// The same limit for 128-line windows. pub static TNS_MAX_BANDS_SHORT: [usize; 13] = [9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14]; + +#[cfg(test)] +mod tests { + use super::*; + + /// The derived tables have to be complete prefix codes, and that is checkable + /// without any oracle: a Kraft sum of exactly 1 with the entry count the + /// standard prescribes leaves no room for a transcription slip. + #[test] + fn every_codebook_is_a_complete_prefix_code() { + let expected = [81usize, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289]; + for (i, cb) in CODEBOOKS.iter().enumerate() { + assert_eq!( + cb.codes.len(), + expected[i], + "codebook {} entry count", + i + 1 + ); + let kraft: f64 = cb + .codes + .iter() + .map(|(l, _)| 2f64.powi(-i32::from(*l))) + .sum(); + assert!( + (kraft - 1.0).abs() < 1e-12, + "codebook {} Kraft sum {kraft}", + i + 1 + ); + assert_prefix_free(cb.codes, &format!("codebook {}", i + 1)); + } + let sf = SCALEFACTOR_CODES; + assert_eq!(sf.len(), 121, "scalefactor codebook entry count"); + let kraft: f64 = sf.iter().map(|(l, _)| 2f64.powi(-i32::from(*l))).sum(); + assert!((kraft - 1.0).abs() < 1e-12, "scalefactor Kraft sum {kraft}"); + assert_prefix_free(sf, "scalefactor codebook"); + } + + fn assert_prefix_free(codes: &[(u8, u32)], what: &str) { + for (i, &(li, ci)) in codes.iter().enumerate() { + for &(lj, cj) in codes.iter().skip(i + 1) { + let short = li.min(lj); + if (ci >> (li - short)) == (cj >> (lj - short)) { + panic!("{what}: {ci:b}/{li} and {cj:b}/{lj} share a prefix"); + } + } + } + } + + /// Band tables must be monotone and land exactly on the window length. + #[test] + fn band_tables_span_the_window() { + for (i, swb) in SWB_LONG.iter().enumerate() { + assert_eq!(swb[0], 0, "long index {i}"); + assert_eq!(*swb.last().unwrap(), 1024, "long index {i}"); + assert!(swb.windows(2).all(|w| w[0] < w[1]), "long index {i}"); + } + for (i, swb) in SWB_SHORT.iter().enumerate() { + assert_eq!(swb[0], 0, "short index {i}"); + assert_eq!(*swb.last().unwrap(), 128, "short index {i}"); + assert!(swb.windows(2).all(|w| w[0] < w[1]), "short index {i}"); + } + } +} diff --git a/crates/ec-aac/tests/it/main.rs b/crates/ec-aac/tests/it/main.rs index e31d506e..43b30aec 100644 --- a/crates/ec-aac/tests/it/main.rs +++ b/crates/ec-aac/tests/it/main.rs @@ -9,4 +9,5 @@ mod implicit_sbr; mod multichannel_parity; mod no_panic; mod ps_mp4; +mod oracle; mod ps_oracle; diff --git a/crates/ec-aac/tests/it/oracle.rs b/crates/ec-aac/tests/it/oracle.rs index 02802b2e..ae0022f6 100644 --- a/crates/ec-aac/tests/it/oracle.rs +++ b/crates/ec-aac/tests/it/oracle.rs @@ -670,64 +670,6 @@ fn encoder_output_decodes_in_ffmpeg_without_warnings() { } } -/// The derived tables have to be complete prefix codes, and that is checkable -/// without any oracle: a Kraft sum of exactly 1 with the entry count the -/// standard prescribes leaves no room for a transcription slip. -#[test] -fn every_codebook_is_a_complete_prefix_code() { - let expected = [81usize, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289]; - for (i, cb) in ec_aac::tables::CODEBOOKS.iter().enumerate() { - assert_eq!( - cb.codes.len(), - expected[i], - "codebook {} entry count", - i + 1 - ); - let kraft: f64 = cb - .codes - .iter() - .map(|(l, _)| 2f64.powi(-i32::from(*l))) - .sum(); - assert!( - (kraft - 1.0).abs() < 1e-12, - "codebook {} Kraft sum {kraft}", - i + 1 - ); - assert_prefix_free(cb.codes, &format!("codebook {}", i + 1)); - } - let sf = ec_aac::tables::SCALEFACTOR_CODES; - assert_eq!(sf.len(), 121, "scalefactor codebook entry count"); - let kraft: f64 = sf.iter().map(|(l, _)| 2f64.powi(-i32::from(*l))).sum(); - assert!((kraft - 1.0).abs() < 1e-12, "scalefactor Kraft sum {kraft}"); - assert_prefix_free(sf, "scalefactor codebook"); -} - -fn assert_prefix_free(codes: &[(u8, u32)], what: &str) { - for (i, &(li, ci)) in codes.iter().enumerate() { - for &(lj, cj) in codes.iter().skip(i + 1) { - let short = li.min(lj); - if (ci >> (li - short)) == (cj >> (lj - short)) { - panic!("{what}: {ci:b}/{li} and {cj:b}/{lj} share a prefix"); - } - } - } -} - -/// Band tables must be monotone and land exactly on the window length. -#[test] -fn band_tables_span_the_window() { - for (i, swb) in ec_aac::tables::SWB_LONG.iter().enumerate() { - assert_eq!(swb[0], 0, "long index {i}"); - assert_eq!(*swb.last().unwrap(), 1024, "long index {i}"); - assert!(swb.windows(2).all(|w| w[0] < w[1]), "long index {i}"); - } - for (i, swb) in ec_aac::tables::SWB_SHORT.iter().enumerate() { - assert_eq!(swb[0], 0, "short index {i}"); - assert_eq!(*swb.last().unwrap(), 128, "short index {i}"); - assert!(swb.windows(2).all(|w| w[0] < w[1]), "short index {i}"); - } -} - /// The AudioSpecificConfig this crate writes is byte-identical to the one the /// reference muxer puts in an `esds`, which is what "ffmpeg accepts our ASC" /// means in practice.