forge
Explore
Log in

Don't you dare go Hollow

U10: ec-aac make sbr_qmf and tables private, drop SbrSupport::CoreOnly (edith matches only NotSignalled), move the two table-shape tests into tables.rs, merge oracle.rs into tests/it

Browse files at this commit

a318d977870ed05f3a5c5c72a624c9ae69a0c169Ahmet Kaan GümüşParent: f4b503f
crates/ec-aac/src/lib.rsmodified+2 -5
@@ -35,13 +35,13 @@ mod sbr_chain;
35 mod sbr_env;35 mod sbr_env;
36 mod sbr_hf;36 mod sbr_hf;
37 mod sbr_payload;37 mod sbr_payload;
38-pub mod sbr_qmf;38+mod sbr_qmf;
39 mod sbr_qmf_window;39 mod sbr_qmf_window;
40 mod ps_data;40 mod ps_data;
41 mod ps_dsp;41 mod ps_dsp;
42 mod ps_huff;42 mod ps_huff;
43 mod sbr_tables;43 mod sbr_tables;
44-pub mod tables;44+mod tables;
45 45
46 pub use config::{46 pub use config::{
47 AOT_AAC_LC, AOT_PS, AOT_SBR, AdtsHeader, AudioSpecificConfig, ProgramConfig,47 AOT_AAC_LC, AOT_PS, AOT_SBR, AdtsHeader, AudioSpecificConfig, ProgramConfig,
@@ -65,9 +65,6 @@ pub enum SbrSupport {
65 /// SBR is signalled and **is** reconstructed: the decoded audio spans65 /// SBR is signalled and **is** reconstructed: the decoded audio spans
66 /// the full extension bandwidth at the extension sample rate.66 /// the full extension bandwidth at the extension sample rate.
67 V1,67 V1,
68- /// SBR is signalled but not reconstructed. Not produced by this decoder
69- /// any more: Parametric Stereo streams report [`SbrSupport::V1`].
70- CoreOnly,
71 }68 }
72 69
73 /// One decoded frame: interleaved `f32` in film channel order.70 /// One decoded frame: interleaved `f32` in film channel order.
crates/ec-aac/src/tables.rsmodified+63 -0
@@ -1607,3 +1607,66 @@ pub static TNS_MAX_BANDS_LONG: [usize; 13] = [31, 31, 34, 40, 42, 51, 46, 46, 42
1607 1607
1608 /// The same limit for 128-line windows.1608 /// The same limit for 128-line windows.
1609 pub static TNS_MAX_BANDS_SHORT: [usize; 13] = [9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14];1609 pub static TNS_MAX_BANDS_SHORT: [usize; 13] = [9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14];
1610+
1611+#[cfg(test)]
1612+mod tests {
1613+ use super::*;
1614+
1615+ /// The derived tables have to be complete prefix codes, and that is checkable
1616+ /// without any oracle: a Kraft sum of exactly 1 with the entry count the
1617+ /// standard prescribes leaves no room for a transcription slip.
1618+ #[test]
1619+ fn every_codebook_is_a_complete_prefix_code() {
1620+ let expected = [81usize, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289];
1621+ for (i, cb) in CODEBOOKS.iter().enumerate() {
1622+ assert_eq!(
1623+ cb.codes.len(),
1624+ expected[i],
1625+ "codebook {} entry count",
1626+ i + 1
1627+ );
1628+ let kraft: f64 = cb
1629+ .codes
1630+ .iter()
1631+ .map(|(l, _)| 2f64.powi(-i32::from(*l)))
1632+ .sum();
1633+ assert!(
1634+ (kraft - 1.0).abs() < 1e-12,
1635+ "codebook {} Kraft sum {kraft}",
1636+ i + 1
1637+ );
1638+ assert_prefix_free(cb.codes, &format!("codebook {}", i + 1));
1639+ }
1640+ let sf = SCALEFACTOR_CODES;
1641+ assert_eq!(sf.len(), 121, "scalefactor codebook entry count");
1642+ let kraft: f64 = sf.iter().map(|(l, _)| 2f64.powi(-i32::from(*l))).sum();
1643+ assert!((kraft - 1.0).abs() < 1e-12, "scalefactor Kraft sum {kraft}");
1644+ assert_prefix_free(sf, "scalefactor codebook");
1645+ }
1646+
1647+ fn assert_prefix_free(codes: &[(u8, u32)], what: &str) {
1648+ for (i, &(li, ci)) in codes.iter().enumerate() {
1649+ for &(lj, cj) in codes.iter().skip(i + 1) {
1650+ let short = li.min(lj);
1651+ if (ci >> (li - short)) == (cj >> (lj - short)) {
1652+ panic!("{what}: {ci:b}/{li} and {cj:b}/{lj} share a prefix");
1653+ }
1654+ }
1655+ }
1656+ }
1657+
1658+ /// Band tables must be monotone and land exactly on the window length.
1659+ #[test]
1660+ fn band_tables_span_the_window() {
1661+ for (i, swb) in SWB_LONG.iter().enumerate() {
1662+ assert_eq!(swb[0], 0, "long index {i}");
1663+ assert_eq!(*swb.last().unwrap(), 1024, "long index {i}");
1664+ assert!(swb.windows(2).all(|w| w[0] < w[1]), "long index {i}");
1665+ }
1666+ for (i, swb) in SWB_SHORT.iter().enumerate() {
1667+ assert_eq!(swb[0], 0, "short index {i}");
1668+ assert_eq!(*swb.last().unwrap(), 128, "short index {i}");
1669+ assert!(swb.windows(2).all(|w| w[0] < w[1]), "short index {i}");
1670+ }
1671+ }
1672+}
crates/ec-aac/tests/it/main.rsmodified+1 -0
@@ -9,4 +9,5 @@ mod implicit_sbr;
9 mod multichannel_parity;9 mod multichannel_parity;
10 mod no_panic;10 mod no_panic;
11 mod ps_mp4;11 mod ps_mp4;
12+mod oracle;
12 mod ps_oracle;13 mod ps_oracle;
crates/ec-aac/tests/it/oracle.rsmodified+0 -58
@@ -670,64 +670,6 @@ fn encoder_output_decodes_in_ffmpeg_without_warnings() {
670 }670 }
671 }671 }
672 672
673-/// The derived tables have to be complete prefix codes, and that is checkable
674-/// without any oracle: a Kraft sum of exactly 1 with the entry count the
675-/// standard prescribes leaves no room for a transcription slip.
676-#[test]
677-fn every_codebook_is_a_complete_prefix_code() {
678- let expected = [81usize, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289];
679- for (i, cb) in ec_aac::tables::CODEBOOKS.iter().enumerate() {
680- assert_eq!(
681- cb.codes.len(),
682- expected[i],
683- "codebook {} entry count",
684- i + 1
685- );
686- let kraft: f64 = cb
687- .codes
688- .iter()
689- .map(|(l, _)| 2f64.powi(-i32::from(*l)))
690- .sum();
691- assert!(
692- (kraft - 1.0).abs() < 1e-12,
693- "codebook {} Kraft sum {kraft}",
694- i + 1
695- );
696- assert_prefix_free(cb.codes, &format!("codebook {}", i + 1));
697- }
698- let sf = ec_aac::tables::SCALEFACTOR_CODES;
699- assert_eq!(sf.len(), 121, "scalefactor codebook entry count");
700- let kraft: f64 = sf.iter().map(|(l, _)| 2f64.powi(-i32::from(*l))).sum();
701- assert!((kraft - 1.0).abs() < 1e-12, "scalefactor Kraft sum {kraft}");
702- assert_prefix_free(sf, "scalefactor codebook");
703-}
704-
705-fn assert_prefix_free(codes: &[(u8, u32)], what: &str) {
706- for (i, &(li, ci)) in codes.iter().enumerate() {
707- for &(lj, cj) in codes.iter().skip(i + 1) {
708- let short = li.min(lj);
709- if (ci >> (li - short)) == (cj >> (lj - short)) {
710- panic!("{what}: {ci:b}/{li} and {cj:b}/{lj} share a prefix");
711- }
712- }
713- }
714-}
715-
716-/// Band tables must be monotone and land exactly on the window length.
717-#[test]
718-fn band_tables_span_the_window() {
719- for (i, swb) in ec_aac::tables::SWB_LONG.iter().enumerate() {
720- assert_eq!(swb[0], 0, "long index {i}");
721- assert_eq!(*swb.last().unwrap(), 1024, "long index {i}");
722- assert!(swb.windows(2).all(|w| w[0] < w[1]), "long index {i}");
723- }
724- for (i, swb) in ec_aac::tables::SWB_SHORT.iter().enumerate() {
725- assert_eq!(swb[0], 0, "short index {i}");
726- assert_eq!(*swb.last().unwrap(), 128, "short index {i}");
727- assert!(swb.windows(2).all(|w| w[0] < w[1]), "short index {i}");
728- }
729-}
730-
731 /// The AudioSpecificConfig this crate writes is byte-identical to the one the673 /// The AudioSpecificConfig this crate writes is byte-identical to the one the
732 /// reference muxer puts in an `esds`, which is what "ffmpeg accepts our ASC"674 /// reference muxer puts in an `esds`, which is what "ffmpeg accepts our ASC"
733 /// means in practice.675 /// means in practice.