Merge branch 'simplify/u12' into simplify/w1b
Browse files at this commit29 changed files +39 -2988
- crates/ec-ac3/src/bsi.rs +1 -1
- crates/ec-ac3/src/decode.rs +1 -1
- crates/ec-ac3/src/decoder.rs +2 -10
- crates/ec-ac3/src/eac3.rs +1 -9
- crates/ec-ac3/src/encode.rs +13 -15
- crates/ec-ac3/src/lib.rs +6 -7
- crates/ec-ac3/src/stack_budget.rs +0 -945
- crates/ec-ac3/src/transform.rs +0 -6
- crates/ec-ac3/tests/it/decode_matrix.rs +0 -309
- crates/ec-ac3/tests/it/dependent.rs +0 -250
- crates/ec-ac3/tests/it/encode_matrix.rs +0 -397
- crates/ec-ac3/tests/it/main.rs +0 -3
- crates/ec-dts/devscripts/cmp_all.sh +0 -23
- crates/ec-dts/devscripts/cmp_float.sh +0 -22
- crates/ec-dts/devscripts/compare.py +0 -44
- crates/ec-dts/examples/dec.rs +0 -64
- crates/ec-dts/gen_dts_tables.py +7 -41
- crates/ec-dts/src/lib.rs +5 -9
- crates/ec-dts/src/tables_data.rs +1 -28
- crates/ec-dts/src/tables_residual.rs +2 -0
- crates/ec-dts/tests/fate_vectors.rs +0 -120
- crates/ec-dts/tests/spec_tables.rs +0 -145
- crates/ec-dts/tests/spec_ts102114_tables.txt +0 -75
- crates/ec-truehd/examples/bench.rs +0 -64
- crates/ec-truehd/src/sync.rs +0 -5
- crates/ec-truehd/tests/it/atmos_synth.rs +0 -227
- crates/ec-truehd/tests/it/library.rs +0 -29
- crates/ec-truehd/tests/it/main.rs +0 -3
- crates/ec-truehd/tests/it/refused_au_recovery.rs +0 -136
crates/ec-ac3/src/bsi.rsmodified+1 -1
| @@ -249,7 +249,7 @@ pub fn parse_from(r: &mut BitReader<'_>) -> Result<Bsi> { | |||
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | /// A presence bit followed by an `n`-bit value. | 251 | /// A presence bit followed by an `n`-bit value. |
| 252 | -fn read_optional(r: &mut BitReader<'_>, n: u32) -> Result<Option<u8>> { | 252 | +pub(crate) fn read_optional(r: &mut BitReader<'_>, n: u32) -> Result<Option<u8>> { |
| 253 | if r.read_bit()? { | 253 | if r.read_bit()? { |
| 254 | Ok(Some(r.read_bits(n)? as u8)) | 254 | Ok(Some(r.read_bits(n)? as u8)) |
| 255 | } else { | 255 | } else { |
crates/ec-ac3/src/decode.rsmodified+1 -1
| @@ -47,7 +47,7 @@ pub(crate) struct Core { | |||
| 47 | /// Boxed, with `bap`, `coeffs` and `delay`, because the four are 16896 of | 47 | /// Boxed, with `bap`, `coeffs` and `delay`, because the four are 16896 of |
| 48 | /// `Core`'s 19728 bytes and `Core` sits inline in the `Ac3Decoder` that | 48 | /// `Core`'s 19728 bytes and `Core` sits inline in the `Ac3Decoder` that |
| 49 | /// `Ac3Decoder::new` hands a caller BY VALUE. Indexing and `&mut self.f[ch]` | 49 | /// `Ac3Decoder::new` hands a caller BY VALUE. Indexing and `&mut self.f[ch]` |
| 50 | - /// read through the box unchanged. `Stack`: crate::stack_budget. | 50 | + /// read through the box unchanged. |
| 51 | pub(crate) exps: Box<[[u8; COEFFS]; CHANNELS]>, | 51 | pub(crate) exps: Box<[[u8; COEFFS]; CHANNELS]>, |
| 52 | /// Bit allocation pointers per channel. | 52 | /// Bit allocation pointers per channel. |
| 53 | pub(crate) bap: Box<[[u8; COEFFS]; CHANNELS]>, | 53 | pub(crate) bap: Box<[[u8; COEFFS]; CHANNELS]>, |
crates/ec-ac3/src/decoder.rsmodified+2 -10
| @@ -12,9 +12,6 @@ use crate::eac3; | |||
| 12 | use crate::syncinfo; | 12 | use crate::syncinfo; |
| 13 | use crate::transform::BLOCK_SAMPLES; | 13 | use crate::transform::BLOCK_SAMPLES; |
| 14 | 14 | ||
| 15 | -/// Blocks per AC-3 syncframe (A/52 §5.3.3); E-AC-3 states its own count. | ||
| 16 | -const AC3_BLOCKS: usize = 6; | ||
| 17 | - | ||
| 18 | /// How the decoder should fold the coded channels down, if at all. | 15 | /// How the decoder should fold the coded channels down, if at all. |
| 19 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | 16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 20 | pub enum Downmix { | 17 | pub enum Downmix { |
| @@ -137,11 +134,6 @@ impl Ac3Decoder { | |||
| 137 | } | 134 | } |
| 138 | } | 135 | } |
| 139 | 136 | ||
| 140 | - /// The options in force; changes take effect on the next packet. | ||
| 141 | - pub fn options_mut(&mut self) -> &mut Options { | ||
| 142 | - &mut self.options | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | /// What the last decoded frame's header said. | 137 | /// What the last decoded frame's header said. |
| 146 | pub fn frame_info(&self) -> Option<&FrameInfo> { | 138 | pub fn frame_info(&self) -> Option<&FrameInfo> { |
| 147 | self.info.as_ref() | 139 | self.info.as_ref() |
| @@ -290,11 +282,11 @@ impl Ac3Decoder { | |||
| 290 | self.core.dither_on = self.options.dither; | 282 | self.core.dither_on = self.options.dither; |
| 291 | self.core | 283 | self.core |
| 292 | .start_frame(Syntax::Ac3, sync.fscod as usize, &bsi); | 284 | .start_frame(Syntax::Ac3, sync.fscod as usize, &bsi); |
| 293 | - for blk in 0..AC3_BLOCKS { | 285 | + for blk in 0..crate::AC3_BLOCKS_PER_FRAME { |
| 294 | self.core.block(&mut r, blk, out)?; | 286 | self.core.block(&mut r, blk, out)?; |
| 295 | } | 287 | } |
| 296 | Ok(( | 288 | Ok(( |
| 297 | - self.info_from(Syntax::Ac3, sync.sample_rate, &bsi, AC3_BLOCKS), | 289 | + self.info_from(Syntax::Ac3, sync.sample_rate, &bsi, crate::AC3_BLOCKS_PER_FRAME), |
| 298 | sync.frame_size, | 290 | sync.frame_size, |
| 299 | )) | 291 | )) |
| 300 | } else { | 292 | } else { |
crates/ec-ac3/src/eac3.rsmodified+1 -9
| @@ -11,7 +11,7 @@ | |||
| 11 | use ec_core::{BitReader, Error, Result}; | 11 | use ec_core::{BitReader, Error, Result}; |
| 12 | 12 | ||
| 13 | use crate::bitalloc::{BitAllocParams, DeltaBa}; | 13 | use crate::bitalloc::{BitAllocParams, DeltaBa}; |
| 14 | -use crate::bsi::{Acmod, Bsi}; | 14 | +use crate::bsi::{Acmod, Bsi, read_optional}; |
| 15 | use crate::decode::{CHANNELS, COEFFS, CPL, Core, LFE, Syntax}; | 15 | use crate::decode::{CHANNELS, COEFFS, CPL, Core, LFE, Syntax}; |
| 16 | use crate::exps::{self, Strategy}; | 16 | use crate::exps::{self, Strategy}; |
| 17 | 17 | ||
| @@ -424,14 +424,6 @@ fn read_mixdata_option4(r: &mut BitReader<'_>, _nblocks: usize) -> Result<()> { | |||
| 424 | Ok(()) | 424 | Ok(()) |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | -fn read_optional(r: &mut BitReader<'_>, n: u32) -> Result<Option<u8>> { | ||
| 428 | - if r.read_bit()? { | ||
| 429 | - Ok(Some(r.read_bits(n)? as u8)) | ||
| 430 | - } else { | ||
| 431 | - Ok(None) | ||
| 432 | - } | ||
| 433 | -} | ||
| 434 | - | ||
| 435 | /// The frame-level strategy fields of `audfrm()` (Table E1.3). | 427 | /// The frame-level strategy fields of `audfrm()` (Table E1.3). |
| 436 | #[derive(Debug, Clone)] | 428 | #[derive(Debug, Clone)] |
| 437 | struct AudFrm { | 429 | struct AudFrm { |
crates/ec-ac3/src/encode.rsmodified+13 -15
| @@ -28,8 +28,6 @@ use crate::tables::{BIT_RATE_KBPS, FRAME_SIZE_WORDS, QNTZTAB, QUANT_LEVELS, SAMP | |||
| 28 | 28 | ||
| 29 | /// Samples per channel one syncframe codes. | 29 | /// Samples per channel one syncframe codes. |
| 30 | const FRAME_SAMPLES: usize = 1536; | 30 | const FRAME_SAMPLES: usize = 1536; |
| 31 | -/// Blocks per syncframe. | ||
| 32 | -const BLOCKS: usize = 6; | ||
| 33 | /// Coefficients per channel per block ([`crate::decode::COEFFS`], not public). | 31 | /// Coefficients per channel per block ([`crate::decode::COEFFS`], not public). |
| 34 | const COEFFS: usize = 256; | 32 | const COEFFS: usize = 256; |
| 35 | /// Lowest bit rate per coded channel this encoder accepts: below it the | 33 | /// Lowest bit rate per coded channel this encoder accepts: below it the |
| @@ -392,15 +390,15 @@ impl Ac3Encoder { | |||
| 392 | fn encode_frame(&mut self, interleaved: &[f32]) -> Vec<u8> { | 390 | fn encode_frame(&mut self, interleaved: &[f32]) -> Vec<u8> { |
| 393 | // Deinterleave into coded-channel order, pick long or short transform | 391 | // Deinterleave into coded-channel order, pick long or short transform |
| 394 | // per block from the transient detector, and run the MDCT. | 392 | // per block from the transient detector, and run the MDCT. |
| 395 | - let mut coeffs = vec![vec![[0.0f32; COEFFS]; self.coded]; BLOCKS]; | 393 | + let mut coeffs = vec![vec![[0.0f32; COEFFS]; self.coded]; crate::AC3_BLOCKS_PER_FRAME]; |
| 396 | - let mut blksw = vec![vec![false; self.coded]; BLOCKS]; | 394 | + let mut blksw = vec![vec![false; self.coded]; crate::AC3_BLOCKS_PER_FRAME]; |
| 397 | for ch in 0..self.coded { | 395 | for ch in 0..self.coded { |
| 398 | let slot = if ch < self.nfchans { | 396 | let slot = if ch < self.nfchans { |
| 399 | self.order.iter().position(|&s| s == Some(ch)).unwrap() | 397 | self.order.iter().position(|&s| s == Some(ch)).unwrap() |
| 400 | } else { | 398 | } else { |
| 401 | self.order.iter().position(|&s| s.is_none()).unwrap() | 399 | self.order.iter().position(|&s| s.is_none()).unwrap() |
| 402 | }; | 400 | }; |
| 403 | - for blk in 0..BLOCKS { | 401 | + for blk in 0..crate::AC3_BLOCKS_PER_FRAME { |
| 404 | let mut window_in = [0.0f32; 512]; | 402 | let mut window_in = [0.0f32; 512]; |
| 405 | window_in[..256].copy_from_slice(&self.history[ch]); | 403 | window_in[..256].copy_from_slice(&self.history[ch]); |
| 406 | for n in 0..256 { | 404 | for n in 0..256 { |
| @@ -477,7 +475,7 @@ impl Ac3Encoder { | |||
| 477 | self.stats.csnroffst_sum += u64::from(csnroffst); | 475 | self.stats.csnroffst_sum += u64::from(csnroffst); |
| 478 | self.stats.bits_used += w.bit_len(); | 476 | self.stats.bits_used += w.bit_len(); |
| 479 | self.stats.bits_budget += budget_bits; | 477 | self.stats.bits_budget += budget_bits; |
| 480 | - for blk in 0..BLOCKS { | 478 | + for blk in 0..crate::AC3_BLOCKS_PER_FRAME { |
| 481 | for ch in 0..self.nfchans { | 479 | for ch in 0..self.nfchans { |
| 482 | self.stats.blksw_blocks += u64::from(blksw[blk][ch]); | 480 | self.stats.blksw_blocks += u64::from(blksw[blk][ch]); |
| 483 | match plan.strategy[blk][ch] { | 481 | match plan.strategy[blk][ch] { |
| @@ -520,14 +518,14 @@ impl Ac3Encoder { | |||
| 520 | .collect(); | 518 | .collect(); |
| 521 | let mut plan = Plan { | 519 | let mut plan = Plan { |
| 522 | blksw: blksw.to_vec(), | 520 | blksw: blksw.to_vec(), |
| 523 | - strategy: vec![vec![Strategy::Reuse; self.coded]; BLOCKS], | 521 | + strategy: vec![vec![Strategy::Reuse; self.coded]; crate::AC3_BLOCKS_PER_FRAME], |
| 524 | - sent: vec![vec![Vec::new(); self.coded]; BLOCKS], | 522 | + sent: vec![vec![Vec::new(); self.coded]; crate::AC3_BLOCKS_PER_FRAME], |
| 525 | - exps: vec![vec![[24u8; COEFFS]; self.coded]; BLOCKS], | 523 | + exps: vec![vec![[24u8; COEFFS]; self.coded]; crate::AC3_BLOCKS_PER_FRAME], |
| 526 | }; | 524 | }; |
| 527 | for ch in 0..self.coded { | 525 | for ch in 0..self.coded { |
| 528 | let mut starts = vec![0usize]; | 526 | let mut starts = vec![0usize]; |
| 529 | if !conservative { | 527 | if !conservative { |
| 530 | - for blk in 1..BLOCKS { | 528 | + for blk in 1..crate::AC3_BLOCKS_PER_FRAME { |
| 531 | let last = *starts.last().unwrap(); | 529 | let last = *starts.last().unwrap(); |
| 532 | if blksw[blk][ch] != blksw[blk - 1][ch] | 530 | if blksw[blk][ch] != blksw[blk - 1][ch] |
| 533 | || envelope_moved(&ideal[blk][ch], &ideal[last][ch], endmant[ch]) | 531 | || envelope_moved(&ideal[blk][ch], &ideal[last][ch], endmant[ch]) |
| @@ -537,7 +535,7 @@ impl Ac3Encoder { | |||
| 537 | } | 535 | } |
| 538 | } | 536 | } |
| 539 | for (i, &start) in starts.iter().enumerate() { | 537 | for (i, &start) in starts.iter().enumerate() { |
| 540 | - let end = starts.get(i + 1).copied().unwrap_or(BLOCKS); | 538 | + let end = starts.get(i + 1).copied().unwrap_or(crate::AC3_BLOCKS_PER_FRAME); |
| 541 | let mut env = ideal[start][ch]; | 539 | let mut env = ideal[start][ch]; |
| 542 | for blk in start + 1..end { | 540 | for blk in start + 1..end { |
| 543 | for bin in 0..endmant[ch] { | 541 | for bin in 0..endmant[ch] { |
| @@ -575,10 +573,10 @@ impl Ac3Encoder { | |||
| 575 | // §7.2.2.1.1: all-zero SNR offsets mean no mantissa bits at all — | 573 | // §7.2.2.1.1: all-zero SNR offsets mean no mantissa bits at all — |
| 576 | // the decoder short-circuits there instead of running the model. | 574 | // the decoder short-circuits there instead of running the model. |
| 577 | if csnroffst == 0 && fsnroffst == 0 { | 575 | if csnroffst == 0 && fsnroffst == 0 { |
| 578 | - return vec![vec![[0u8; COEFFS]; self.coded]; BLOCKS]; | 576 | + return vec![vec![[0u8; COEFFS]; self.coded]; crate::AC3_BLOCKS_PER_FRAME]; |
| 579 | } | 577 | } |
| 580 | - let mut out: Vec<Vec<[u8; COEFFS]>> = Vec::with_capacity(BLOCKS); | 578 | + let mut out: Vec<Vec<[u8; COEFFS]>> = Vec::with_capacity(crate::AC3_BLOCKS_PER_FRAME); |
| 581 | - for blk in 0..BLOCKS { | 579 | + for blk in 0..crate::AC3_BLOCKS_PER_FRAME { |
| 582 | let baps = (0..self.coded) | 580 | let baps = (0..self.coded) |
| 583 | .map(|ch| { | 581 | .map(|ch| { |
| 584 | if blk > 0 && plan.strategy[blk][ch] == Strategy::Reuse { | 582 | if blk > 0 && plan.strategy[blk][ch] == Strategy::Reuse { |
| @@ -652,7 +650,7 @@ impl Ac3Encoder { | |||
| 652 | w.write_bit(false); // timecod2 | 650 | w.write_bit(false); // timecod2 |
| 653 | w.write_bit(false); // addbsi | 651 | w.write_bit(false); // addbsi |
| 654 | 652 | ||
| 655 | - for blk in 0..BLOCKS { | 653 | + for blk in 0..crate::AC3_BLOCKS_PER_FRAME { |
| 656 | self.write_block(&mut w, blk, coeffs, plan, endmant, bap, csnroffst, fsnroffst); | 654 | self.write_block(&mut w, blk, coeffs, plan, endmant, bap, csnroffst, fsnroffst); |
| 657 | } | 655 | } |
| 658 | w | 656 | w |
crates/ec-ac3/src/lib.rsmodified+6 -7
| @@ -60,20 +60,19 @@ | |||
| 60 | mod aht; | 60 | mod aht; |
| 61 | mod aht_tables; | 61 | mod aht_tables; |
| 62 | 62 | ||
| 63 | -pub mod bitalloc; | 63 | +mod bitalloc; |
| 64 | pub mod bsi; | 64 | pub mod bsi; |
| 65 | pub mod eac3; | 65 | pub mod eac3; |
| 66 | -pub mod exps; | 66 | +mod exps; |
| 67 | -pub mod mantissa; | 67 | +mod mantissa; |
| 68 | -mod stack_budget; | ||
| 69 | pub mod syncinfo; | 68 | pub mod syncinfo; |
| 70 | -pub mod tables; | 69 | +mod tables; |
| 71 | -pub mod transform; | 70 | +mod transform; |
| 72 | 71 | ||
| 73 | mod decode; | 72 | mod decode; |
| 74 | mod dependent; | 73 | mod dependent; |
| 75 | mod decoder; | 74 | mod decoder; |
| 76 | -pub mod encode; | 75 | +mod encode; |
| 77 | 76 | ||
| 78 | pub use decode::Syntax; | 77 | pub use decode::Syntax; |
| 79 | pub use decoder::{Ac3Decoder, Downmix, FrameInfo, Options}; | 78 | pub use decoder::{Ac3Decoder, Downmix, FrameInfo, Options}; |
crates/ec-ac3/src/stack_budget.rsdeleted+0 -945
| @@ -1,945 +0,0 @@ | |||
| 1 | -#![cfg(test)] | ||
| 2 | -//! A measured bound on the crate's BY-VALUE types, and a gate that bites. | ||
| 3 | -//! | ||
| 4 | -//! # The class | ||
| 5 | -//! | ||
| 6 | -//! A large struct returned BY VALUE from a public constructor is a stack cost, | ||
| 7 | -//! not a heap cost, and the cost is paid by the CALLER. The constructors here | ||
| 8 | -//! nest -- `Ac3Decoder::new` -> `Ac3Decoder::with_options` -> `Core::new` for | ||
| 9 | -//! the decoder -- and in an unoptimized build each level materialises its whole | ||
| 10 | -//! return slot before the inner call returns. So one value's `size_of` is the | ||
| 11 | -//! MULTIPLIER, and the chain length is the other factor. | ||
| 12 | -//! | ||
| 13 | -//! That is not hypothetical. `Ac3Decoder` was **20,024** bytes by value -- its | ||
| 14 | -//! inline `decode::Core` carried four per-channel coefficient planes | ||
| 15 | -//! (`exps`, `bap`, `coeffs`, `delay`) that are **16,896** of `Core`'s 19,728 | ||
| 16 | -//! bytes -- and every `Ac3Decoder::new()` / `Ac3Decoder::with_options()` call | ||
| 17 | -//! made the caller pay all of it on its own stack. `.cargo/config.toml` | ||
| 18 | -//! carries `RUST_MIN_STACK = 67108864`, which HIDES the class from this | ||
| 19 | -//! workspace's own runs -- a band-aid a library consumer does not get. Boxing | ||
| 20 | -//! those four fields took `Core` to **2,864** and `Ac3Decoder` to **3,160**; | ||
| 21 | -//! [`the_crate_private_core_stays_behind_a_box`] is the pin that keeps them | ||
| 22 | -//! there. | ||
| 23 | -//! | ||
| 24 | -//! # Why this module exists when that boxing already exists | ||
| 25 | -//! | ||
| 26 | -//! The boxing fixed ONE type. The class was not swept: nothing stopped the | ||
| 27 | -//! next 18 KB inline plane from landing in `Core`, and nothing said which types | ||
| 28 | -//! had been checked. This module is the sweep: | ||
| 29 | -//! | ||
| 30 | -//! 1. [`BY_VALUE_TYPES`] is the inventory -- every public type in this crate | ||
| 31 | -//! that a public `fn` can return by value, with a measured `size_of` floor | ||
| 32 | -//! recorded as of this commit. | ||
| 33 | -//! [`the_measured_inventory_is_accurate`] fails if a type's size moves, so | ||
| 34 | -//! the table cannot rot into a list of stale small numbers. | ||
| 35 | -//! 2. [`STACK_BUDGET`] is the bound, and | ||
| 36 | -//! [`every_by_value_type_fits_the_stack_budget`] asserts it BY NAME for | ||
| 37 | -//! every row, so a regression reds naming the type that caused it. | ||
| 38 | -//! 3. [`the_crate_private_core_stays_behind_a_box`] pins the four `Box` field | ||
| 39 | -//! spellings, with a negative control, so the fix is not silently reverted. | ||
| 40 | -//! 4. [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] is the | ||
| 41 | -//! capability arm: it really constructs the heavy types on a deliberately | ||
| 42 | -//! tight thread, so the old layout ABORTS THE PROCESS rather than quietly | ||
| 43 | -//! costing margin. | ||
| 44 | -//! 5. [`every_by_value_public_return_is_in_the_inventory`] is the sweep's | ||
| 45 | -//! teeth against NEW types: a source scan re-derives the set of by-value | ||
| 46 | -//! public returns from the crate source, so a lane that adds a 40 KB struct | ||
| 47 | -//! to a `pub fn` return reds here until it is measured and listed. | ||
| 48 | -//! [`the_inventory_scan_is_not_vacuous`] is its control, and | ||
| 49 | -//! [`every_by_value_module_is_scanned`] keeps the scan's file list derived | ||
| 50 | -//! from `lib.rs` rather than curated. | ||
| 51 | -//! | ||
| 52 | -//! # The bound, and why this number | ||
| 53 | -//! | ||
| 54 | -//! [`STACK_BUDGET`] = 8192 bytes (8 KiB). It is bounded from BOTH sides by | ||
| 55 | -//! measurement, and both sides are asserted in | ||
| 56 | -//! [`every_by_value_type_fits_the_stack_budget`] so neither can rot silently. | ||
| 57 | -//! | ||
| 58 | -//! **The quantity being bounded.** Not `size_of` in the abstract, but *what a | ||
| 59 | -//! caller can be made to owe*: the size of one by-value return, multiplied by | ||
| 60 | -//! how many constructor levels hold a copy of it at once. Three inputs: | ||
| 61 | -//! | ||
| 62 | -//! 1. **The smallest stack a caller can hand this crate is 2,101,248 bytes.** | ||
| 63 | -//! Measured, not assumed, by | ||
| 64 | -//! [`test_threads_get_the_stack_they_are_given`] reading | ||
| 65 | -//! `/proc/self/task/<tid>/maps`. That is libtest's default test thread and | ||
| 66 | -//! also what `std::thread::Builder::new()` gives a caller who does not ask | ||
| 67 | -//! for a size. A library consumer gets no `.cargo/config.toml`. | ||
| 68 | -//! 2. **The deepest PUBLIC by-value chain is 2** ([`DEEPEST_PUBLIC_CHAIN`]): | ||
| 69 | -//! `Ac3Decoder::new` (decoder.rs:117) -> `Ac3Decoder::with_options` | ||
| 70 | -//! (decoder.rs:122), which calls `Core::new()` (decode.rs:136) as a third, | ||
| 71 | -//! crate-private level carrying a 2,864-byte `Core`. The encoder's | ||
| 72 | -//! `Ac3Encoder::new` is a single level -- it builds the struct inline in | ||
| 73 | -//! its `Ok(..)` and does not nest -- and `Ac3Decoder::decode_frame`'s | ||
| 74 | -//! `Result<AudioFrame>` is a single level too. The test asserts | ||
| 75 | -//! `DEEPEST_PUBLIC_CHAIN * worst * 8 <= 2 MiB` -- i.e. the by-value return | ||
| 76 | -//! slots may claim at most an EIGHTH of a caller's stack, leaving the rest | ||
| 77 | -//! for the decode, which is the thing that actually needs it. | ||
| 78 | -//! 3. **The budget applies only to types a `pub fn` returns.** The | ||
| 79 | -//! crate-private 2,864-byte `Core` is measured and listed but is NOT | ||
| 80 | -//! bounded, because no caller can reach it by value -- every field that | ||
| 81 | -//! holds one of its 16,896-byte planes is a `Box`, which | ||
| 82 | -//! [`the_crate_private_core_stays_behind_a_box`] pins by source. Bounding | ||
| 83 | -//! it would calibrate the number to something unreachable. | ||
| 84 | -//! | ||
| 85 | -//! **Where the number sits.** At 8 KiB with the worst public return at 3,160 | ||
| 86 | -//! bytes ([`Ac3Decoder`]), the worst a caller owes is `2 x 3160 = 6,320` bytes | ||
| 87 | -//! -- **0.30%** of a 2 MiB thread -- and the budget itself is 2.59x above the | ||
| 88 | -//! incumbent. `Ac3Decoder` is also the row closest to the budget, at **38.6%** | ||
| 89 | -//! of it: **5,032 bytes of margin**, the least of any row here. | ||
| 90 | -//! [`Ac3Encoder`] is second, at 34.0% and 5,408 bytes of margin. Both | ||
| 91 | -//! directions have room, which is the point: a bound the largest type sits | ||
| 92 | -//! just under is a bound the next lane will quietly raise. | ||
| 93 | -//! | ||
| 94 | -//! **What it catches.** A pre-fix `Ac3Decoder` (20,024 B) is **2.44x over** | ||
| 95 | -//! budget. The pre-fix `Core` (19,728 B) behind it is **2.41x over** the same | ||
| 96 | -//! number -- that is the ratio the layout fix removed, not one this gate | ||
| 97 | -//! enforces, because no `pub fn` returns `Core`; the pin on its four `Box` | ||
| 98 | -//! fields is what keeps it there. Both the historical defect and the | ||
| 99 | -//! near-miss red by a factor, not by a hair. | ||
| 100 | -//! | ||
| 101 | -//! **What it does not claim.** `size_of` is layout, not stack depth, and the | ||
| 102 | -//! gap between the two is the nesting multiplier plus every frame a call owns | ||
| 103 | -//! for its own work. `Ac3Encoder::new` is the clearest case: its 2,784-byte | ||
| 104 | -//! return is nowhere near the budget, yet building it needs ~80 KiB of thread | ||
| 105 | -//! in a debug build, because it materialises a `[0.0f32; 512]` window, an | ||
| 106 | -//! `Mdct::new(512)` plan and a per-`COEFFS` IMDCT basis sweep. So this module | ||
| 107 | -//! does not trust the arithmetic: | ||
| 108 | -//! [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] constructs both | ||
| 109 | -//! heavy types for real on a real thread, and its measured threshold is the | ||
| 110 | -//! number that settles it. | ||
| 111 | - | ||
| 112 | -use crate::decoder::{Ac3Decoder, Options}; | ||
| 113 | -use crate::encode::Ac3Encoder; | ||
| 114 | - | ||
| 115 | -/// The per-type ceiling for a type a CALLER can be made to hold by value, in | ||
| 116 | -/// bytes. See the module docs for the derivation; it is two-sided, and both | ||
| 117 | -/// sides are measured. | ||
| 118 | -pub(crate) const STACK_BUDGET: usize = 8192; | ||
| 119 | - | ||
| 120 | -/// The deepest PUBLIC by-value constructor chain in this crate, counted from | ||
| 121 | -/// the source: | ||
| 122 | -/// | ||
| 123 | -/// * `Ac3Decoder::new` (decoder.rs:117) -> `Ac3Decoder::with_options` | ||
| 124 | -/// (decoder.rs:122): TWO public levels, both returning a 3,160-byte | ||
| 125 | -/// `Ac3Decoder` by value. `with_options` calls `Core::new()` | ||
| 126 | -/// (decode.rs:136), a third level, but that one is `pub(crate)` and carries | ||
| 127 | -/// a 2,864-byte `Core`, so it is not a public return. | ||
| 128 | -/// * `Ac3Encoder::new` (encode.rs:254): ONE level. It builds the struct | ||
| 129 | -/// inline in its `Ok(Ac3Encoder { .. })` (encode.rs:306) and never calls | ||
| 130 | -/// another constructor that returns it by value. | ||
| 131 | -/// * `Ac3Decoder::decode_frame` (decoder.rs:156) -> `Result<AudioFrame>`: | ||
| 132 | -/// ONE level, 96 bytes. It does not nest. | ||
| 133 | -/// | ||
| 134 | -/// The budget is checked against two, the worst of the three. | ||
| 135 | -#[cfg(test)] | ||
| 136 | -const DEEPEST_PUBLIC_CHAIN: usize = 2; | ||
| 137 | - | ||
| 138 | -/// Every public type in this crate a public `fn` can return BY VALUE, with the | ||
| 139 | -/// `size_of` measured at the commit that wrote this table. `None` means "not | ||
| 140 | -/// yet measured", which [`the_measured_inventory_is_accurate`] rejects. | ||
| 141 | -/// | ||
| 142 | -/// The third column names the return path, so a reader can see why a type is | ||
| 143 | -/// here rather than a coincidence of the type system. | ||
| 144 | -pub(crate) const BY_VALUE_TYPES: &[(&str, Option<usize>, bool, &str)] = &[ | ||
| 145 | - // -- decoder.rs: the headline row ------------------------------------- | ||
| 146 | - ( | ||
| 147 | - "Ac3Decoder", | ||
| 148 | - Some(3704), | ||
| 149 | - true, | ||
| 150 | - "Ac3Decoder::new / with_options -> Ac3Decoder, nesting two deep. Was \ | ||
| 151 | - 20024 bytes with decode::Core's four coefficient planes inline, i.e. \ | ||
| 152 | - 2.44x over the 8192-byte budget. 3184 since the dependents Vec (24 bytes, \ | ||
| 153 | - heap-allocated: one Core per dependent substream of a packet). 3704 since \ | ||
| 154 | - the dither generator became ffmpeg's 64-word lagged-Fibonacci state \ | ||
| 155 | - (two instances, +520 bytes), so that the noise matches ffmpeg's", | ||
| 156 | - ), | ||
| 157 | - // -- encode.rs: the second-closest row to the budget ------------------- | ||
| 158 | - ( | ||
| 159 | - "Ac3Encoder", | ||
| 160 | - Some(2784), | ||
| 161 | - true, | ||
| 162 | - "Ac3Encoder::new -> Result<Ac3Encoder>, one level, no nesting. \ | ||
| 163 | - 34.0% of the budget, 5408 bytes of margin; Ac3Decoder above is the \ | ||
| 164 | - closest row at 38.6%", | ||
| 165 | - ), | ||
| 166 | - ( | ||
| 167 | - "EncoderConfig", | ||
| 168 | - Some(12), | ||
| 169 | - true, | ||
| 170 | - "consumed by value by Ac3Encoder::new, which copies it into the \ | ||
| 171 | - encoder it returns", | ||
| 172 | - ), | ||
| 173 | - ( | ||
| 174 | - "EncodeStats", | ||
| 175 | - Some(72), | ||
| 176 | - true, | ||
| 177 | - "Ac3Encoder::stats -> EncodeStats, by value out of the encoder's field", | ||
| 178 | - ), | ||
| 179 | - // -- decoder.rs: the header/option surface --------------------------- | ||
| 180 | - ( | ||
| 181 | - "Options", | ||
| 182 | - Some(8), | ||
| 183 | - true, | ||
| 184 | - "Ac3Decoder::with_options(Options) takes it by value and keeps it", | ||
| 185 | - ), | ||
| 186 | - ( | ||
| 187 | - "FrameInfo", | ||
| 188 | - Some(48), | ||
| 189 | - true, | ||
| 190 | - "built by value in Ac3Decoder's private info_from; handed back as \ | ||
| 191 | - Option<&FrameInfo>, a BORROW, so the row is about the move the \ | ||
| 192 | - decoder makes internally", | ||
| 193 | - ), | ||
| 194 | - ( | ||
| 195 | - "Downmix", | ||
| 196 | - Some(1), | ||
| 197 | - true, | ||
| 198 | - "Options::downmix, a field of the by-value Options above", | ||
| 199 | - ), | ||
| 200 | - ( | ||
| 201 | - "AudioFrame", | ||
| 202 | - Some(96), | ||
| 203 | - true, | ||
| 204 | - "Ac3Decoder::decode_frame -> Result<AudioFrame>, one level, no \ | ||
| 205 | - nesting. From ec_core, not this crate, but it is a public return of \ | ||
| 206 | - this crate and the sweep finds it by name", | ||
| 207 | - ), | ||
| 208 | - // -- decode.rs ------------------------------------------------------- | ||
| 209 | - ( | ||
| 210 | - "Syntax", | ||
| 211 | - Some(1), | ||
| 212 | - true, | ||
| 213 | - "re-exported from decode; a field of FrameInfo and of Ac3Decoder::Core", | ||
| 214 | - ), | ||
| 215 | - // -- the header parsers ---------------------------------------------- | ||
| 216 | - ( | ||
| 217 | - "Bsi", | ||
| 218 | - Some(56), | ||
| 219 | - true, | ||
| 220 | - "bsi::parse / bsi::parse_from -> Result<Bsi>, one level each", | ||
| 221 | - ), | ||
| 222 | - ("Acmod", Some(1), true, "bsi::Acmod::from_code -> Acmod"), | ||
| 223 | - ( | ||
| 224 | - "SyncInfo", | ||
| 225 | - Some(24), | ||
| 226 | - true, | ||
| 227 | - "syncinfo::parse / syncinfo::parse_from -> Result<SyncInfo>", | ||
| 228 | - ), | ||
| 229 | - ( | ||
| 230 | - "Eac3Bsi", | ||
| 231 | - Some(96), | ||
| 232 | - true, | ||
| 233 | - "eac3::bsi::parse / eac3::bsi::parse_from -> Result<Eac3Bsi>", | ||
| 234 | - ), | ||
| 235 | - ( | ||
| 236 | - "StreamType", | ||
| 237 | - Some(1), | ||
| 238 | - true, | ||
| 239 | - "a field of the by-value Eac3Bsi above; eac3::StreamType::Dependent \ | ||
| 240 | - is the first-substream refusal", | ||
| 241 | - ), | ||
| 242 | - // -- transform.rs / mantissa.rs / exps.rs ---------------------------- | ||
| 243 | - ( | ||
| 244 | - "Imdct", | ||
| 245 | - Some(472), | ||
| 246 | - true, | ||
| 247 | - "transform::Imdct::new -> Imdct, one level. Held inline in both Core \ | ||
| 248 | - and Ac3Encoder, the largest type in the crate that is NOT a public \ | ||
| 249 | - return", | ||
| 250 | - ), | ||
| 251 | - ( | ||
| 252 | - "Mantissas", | ||
| 253 | - Some(56), | ||
| 254 | - true, | ||
| 255 | - "mantissa::Mantissas::new -> Mantissas, one level", | ||
| 256 | - ), | ||
| 257 | - ( | ||
| 258 | - "Strategy", | ||
| 259 | - Some(1), | ||
| 260 | - true, | ||
| 261 | - "exps::Strategy::from_code -> Strategy; a field of Core's inline \ | ||
| 262 | - [Strategy; CHANNELS]", | ||
| 263 | - ), | ||
| 264 | - // -- bitalloc.rs ----------------------------------------------------- | ||
| 265 | - ( | ||
| 266 | - "BitAllocParams", | ||
| 267 | - Some(5), | ||
| 268 | - true, | ||
| 269 | - "bitalloc::BitAllocParams::default, copied into Core's inline copy", | ||
| 270 | - ), | ||
| 271 | - ( | ||
| 272 | - "DeltaBa", | ||
| 273 | - Some(32), | ||
| 274 | - true, | ||
| 275 | - "bitalloc::DeltaBa, built by value per block", | ||
| 276 | - ), | ||
| 277 | - ( | ||
| 278 | - "Allocation", | ||
| 279 | - Some(56), | ||
| 280 | - true, | ||
| 281 | - "bitalloc::Allocation<'_>, built by value and passed to \ | ||
| 282 | - bitalloc::compute by reference; the move copies the struct, not the \ | ||
| 283 | - borrowed slices", | ||
| 284 | - ), | ||
| 285 | - ( | ||
| 286 | - "Channel", | ||
| 287 | - Some(12), | ||
| 288 | - true, | ||
| 289 | - "bitalloc::Channel, moved out of the per-block channel table", | ||
| 290 | - ), | ||
| 291 | - // -- crate-private: never a public return, and every one of its four | ||
| 292 | - // -- large planes is behind a Box now. The budget does not apply; the | ||
| 293 | - // -- pin that does is `the_crate_private_core_stays_behind_a_box`. | ||
| 294 | - ( | ||
| 295 | - "Core", | ||
| 296 | - Some(3384), | ||
| 297 | - false, | ||
| 298 | - "decode::Core::new -> Core, pub(crate), held inline in Ac3Decoder. \ | ||
| 299 | - Was 19728 bytes with exps/bap/coeffs/delay inline; those four are \ | ||
| 300 | - 16896 of them and are boxed now", | ||
| 301 | - ), | ||
| 302 | -]; | ||
| 303 | - | ||
| 304 | -/// The live `size_of` for every inventoried type, keyed BY NAME. | ||
| 305 | -/// | ||
| 306 | -/// Keyed rather than positional on purpose: `Bsi`, `Mantissas` and | ||
| 307 | -/// `Allocation` are all 56 bytes, and `Eac3Bsi` and `AudioFrame` are both 96, | ||
| 308 | -/// so a row inserted into [`BY_VALUE_TYPES`] without a matching insert here | ||
| 309 | -/// would zip cleanly and assert the wrong type's size against the wrong | ||
| 310 | -/// recorded one. A name key makes that mistake loud instead. | ||
| 311 | -#[cfg(test)] | ||
| 312 | -fn measured_by_name() -> Vec<(&'static str, usize)> { | ||
| 313 | - vec![ | ||
| 314 | - ("Ac3Decoder", std::mem::size_of::<Ac3Decoder>()), | ||
| 315 | - ("Ac3Encoder", std::mem::size_of::<Ac3Encoder>()), | ||
| 316 | - ( | ||
| 317 | - "EncoderConfig", | ||
| 318 | - std::mem::size_of::<crate::encode::EncoderConfig>(), | ||
| 319 | - ), | ||
| 320 | - ( | ||
| 321 | - "EncodeStats", | ||
| 322 | - std::mem::size_of::<crate::encode::EncodeStats>(), | ||
| 323 | - ), | ||
| 324 | - ("Options", std::mem::size_of::<Options>()), | ||
| 325 | - ( | ||
| 326 | - "FrameInfo", | ||
| 327 | - std::mem::size_of::<crate::decoder::FrameInfo>(), | ||
| 328 | - ), | ||
| 329 | - ("Downmix", std::mem::size_of::<crate::decoder::Downmix>()), | ||
| 330 | - ("AudioFrame", std::mem::size_of::<ec_core::AudioFrame>()), | ||
| 331 | - ("Syntax", std::mem::size_of::<crate::decode::Syntax>()), | ||
| 332 | - ("Bsi", std::mem::size_of::<crate::bsi::Bsi>()), | ||
| 333 | - ("Acmod", std::mem::size_of::<crate::bsi::Acmod>()), | ||
| 334 | - ("SyncInfo", std::mem::size_of::<crate::syncinfo::SyncInfo>()), | ||
| 335 | - ("Eac3Bsi", std::mem::size_of::<crate::eac3::Eac3Bsi>()), | ||
| 336 | - ("StreamType", std::mem::size_of::<crate::eac3::StreamType>()), | ||
| 337 | - ("Imdct", std::mem::size_of::<crate::transform::Imdct>()), | ||
| 338 | - ( | ||
| 339 | - "Mantissas", | ||
| 340 | - std::mem::size_of::<crate::mantissa::Mantissas>(), | ||
| 341 | - ), | ||
| 342 | - ("Strategy", std::mem::size_of::<crate::exps::Strategy>()), | ||
| 343 | - ( | ||
| 344 | - "BitAllocParams", | ||
| 345 | - std::mem::size_of::<crate::bitalloc::BitAllocParams>(), | ||
| 346 | - ), | ||
| 347 | - ("DeltaBa", std::mem::size_of::<crate::bitalloc::DeltaBa>()), | ||
| 348 | - ( | ||
| 349 | - "Allocation", | ||
| 350 | - std::mem::size_of::<crate::bitalloc::Allocation<'static>>(), | ||
| 351 | - ), | ||
| 352 | - ("Channel", std::mem::size_of::<crate::bitalloc::Channel>()), | ||
| 353 | - ("Core", std::mem::size_of::<crate::decode::Core>()), | ||
| 354 | - ] | ||
| 355 | -} | ||
| 356 | - | ||
| 357 | -/// The stack [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] | ||
| 358 | -/// constructs on. | ||
| 359 | -/// | ||
| 360 | -/// 1 MiB: half of what an unconfigured caller gives this crate, and far above | ||
| 361 | -/// what the deepest measured chain needs in a debug build. The threshold was | ||
| 362 | -/// swept in an unoptimized build and is reproducible with | ||
| 363 | -/// `EC_AC3_TIGHT_STACK_BYTES`. | ||
| 364 | -const TIGHT_STACK: usize = 1024 * 1024; | ||
| 365 | - | ||
| 366 | -#[cfg(test)] | ||
| 367 | -mod tests { | ||
| 368 | - use super::{ | ||
| 369 | - BY_VALUE_TYPES, DEEPEST_PUBLIC_CHAIN, STACK_BUDGET, TIGHT_STACK, measured_by_name, | ||
| 370 | - }; | ||
| 371 | - use crate::decoder::{Ac3Decoder, Downmix, Options}; | ||
| 372 | - use crate::encode::{Ac3Encoder, EncoderConfig}; | ||
| 373 | - | ||
| 374 | - /// Return types that are not a by-value copy of anything the caller has to | ||
| 375 | - /// own: a pointer, a slice, a `Vec` (three words, and the heap is not the | ||
| 376 | - /// stack), or a primitive. `Self` is a by-value copy of the impl's type, | ||
| 377 | - /// which the inventory rows already cover, so it is exempt from the scan | ||
| 378 | - /// and not from the table. | ||
| 379 | - const THIN: &[&str] = &[ | ||
| 380 | - "Box", "Rc", "Arc", "Cow", "Vec", "VecDeque", "String", "OsString", "PathBuf", "HashMap", | ||
| 381 | - "BTreeMap", "BTreeSet", "HashSet", "str", "u8", "u16", "u32", "u64", "usize", "i8", "i16", | ||
| 382 | - "i32", "i64", "isize", "f32", "f64", "bool", "char", "Self", | ||
| 383 | - ]; | ||
| 384 | - | ||
| 385 | - /// The type name a `pub fn` line returns BY VALUE, or `None` when the line | ||
| 386 | - /// returns a pointer, a `Vec`, a primitive, or nothing. | ||
| 387 | - /// | ||
| 388 | - /// One function, shared by the sweep and its control, so the control | ||
| 389 | - /// cannot pass while the sweep's copy of the logic rotted. | ||
| 390 | - fn by_value_return_name(line: &str) -> Option<String> { | ||
| 391 | - let trimmed = line.trim_start(); | ||
| 392 | - if !trimmed.starts_with("pub fn ") { | ||
| 393 | - return None; | ||
| 394 | - } | ||
| 395 | - let arrow = line.find("->")?; | ||
| 396 | - let rest = &line[arrow + 2..]; | ||
| 397 | - let end = rest.find('{').unwrap_or(rest.len()); | ||
| 398 | - let ret = rest[..end].trim(); | ||
| 399 | - if ret.is_empty() { | ||
| 400 | - return None; | ||
| 401 | - } | ||
| 402 | - // Unwrap one `Result<..>` / `Option<..>` layer. A deeper nesting is | ||
| 403 | - // not a shape this crate uses, and flagging one as uninventoried is | ||
| 404 | - // the safe direction to be wrong in. | ||
| 405 | - let inner = { | ||
| 406 | - let t = ret | ||
| 407 | - .strip_prefix("Result<") | ||
| 408 | - .or_else(|| ret.strip_prefix("Option<")) | ||
| 409 | - .unwrap_or(ret); | ||
| 410 | - t.split('>').next().unwrap_or(t) | ||
| 411 | - }; | ||
| 412 | - // Drop the error type and any lifetime or generic argument: | ||
| 413 | - // `Result<Bsi, Error>`, `Allocation<'a>` and `AudioFrame` are all the | ||
| 414 | - // bare name for this purpose. Splitting on the comma is load-bearing: | ||
| 415 | - // the first version of this matcher cut only at `>` and so read | ||
| 416 | - // `Result<Bsi, Error>` as the name "Bsi, Error". `ec_av1`'s control | ||
| 417 | - // caught exactly that, which is why the control is not optional. | ||
| 418 | - let name = inner.split(['<', ',']).next().unwrap_or(inner).trim(); | ||
| 419 | - if name.is_empty() || THIN.contains(&name) { | ||
| 420 | - return None; | ||
| 421 | - } | ||
| 422 | - // A generic parameter, not a concrete type. | ||
| 423 | - if !name.chars().next().is_some_and(char::is_uppercase) { | ||
| 424 | - return None; | ||
| 425 | - } | ||
| 426 | - Some(name.to_string()) | ||
| 427 | - } | ||
| 428 | - | ||
| 429 | - /// The source files the by-value scan reads. Every module that can expose | ||
| 430 | - /// a `pub fn` returning a named type; a new module added to `lib.rs` needs | ||
| 431 | - /// adding here, and | ||
| 432 | - /// [`every_by_value_module_is_scanned`] is what keeps that honest. | ||
| 433 | - const FILES: &[(&str, &str)] = &[ | ||
| 434 | - ("aht.rs", include_str!("aht.rs")), | ||
| 435 | - ("aht_tables.rs", include_str!("aht_tables.rs")), | ||
| 436 | - ("bitalloc.rs", include_str!("bitalloc.rs")), | ||
| 437 | - ("bsi.rs", include_str!("bsi.rs")), | ||
| 438 | - ("decode.rs", include_str!("decode.rs")), | ||
| 439 | - ("decoder.rs", include_str!("decoder.rs")), | ||
| 440 | - ("dependent.rs", include_str!("dependent.rs")), | ||
| 441 | - ("eac3.rs", include_str!("eac3.rs")), | ||
| 442 | - ("encode.rs", include_str!("encode.rs")), | ||
| 443 | - ("exps.rs", include_str!("exps.rs")), | ||
| 444 | - ("lib.rs", include_str!("lib.rs")), | ||
| 445 | - ("mantissa.rs", include_str!("mantissa.rs")), | ||
| 446 | - ("stack_budget.rs", include_str!("stack_budget.rs")), | ||
| 447 | - ("syncinfo.rs", include_str!("syncinfo.rs")), | ||
| 448 | - ("tables.rs", include_str!("tables.rs")), | ||
| 449 | - ("transform.rs", include_str!("transform.rs")), | ||
| 450 | - ]; | ||
| 451 | - | ||
| 452 | - /// Every module `lib.rs` declares, so the scan's file list cannot silently | ||
| 453 | - /// fall behind a new module. A new `mod foo;` with a by-value `pub fn` | ||
| 454 | - /// that the scan never reads is exactly the hole this class would come | ||
| 455 | - /// back through, so the list is derived, not curated. | ||
| 456 | - #[test] | ||
| 457 | - fn every_by_value_module_is_scanned() { | ||
| 458 | - let lib = include_str!("lib.rs"); | ||
| 459 | - let mut declared: Vec<&str> = Vec::new(); | ||
| 460 | - for line in lib.lines() { | ||
| 461 | - let t = line.trim(); | ||
| 462 | - let rest = t | ||
| 463 | - .strip_prefix("pub mod ") | ||
| 464 | - .or_else(|| t.strip_prefix("mod ")) | ||
| 465 | - .unwrap_or(""); | ||
| 466 | - if rest.is_empty() { | ||
| 467 | - continue; | ||
| 468 | - } | ||
| 469 | - let name = rest.split([';', ' ']).next().unwrap_or(""); | ||
| 470 | - if !name.is_empty() && name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { | ||
| 471 | - declared.push(name); | ||
| 472 | - } | ||
| 473 | - } | ||
| 474 | - assert!( | ||
| 475 | - declared.len() > 10, | ||
| 476 | - "only {} module declarations parsed out of lib.rs, so the \ | ||
| 477 | - derived file list is broken rather than small", | ||
| 478 | - declared.len() | ||
| 479 | - ); | ||
| 480 | - let scanned: Vec<&str> = FILES.iter().map(|(n, _)| *n).collect(); | ||
| 481 | - let mut missing: Vec<String> = declared | ||
| 482 | - .iter() | ||
| 483 | - .filter(|d| !scanned.iter().any(|s| *s == format!("{d}.rs"))) | ||
| 484 | - .map(|d| (*d).to_string()) | ||
| 485 | - .collect(); | ||
| 486 | - missing.sort(); | ||
| 487 | - assert!( | ||
| 488 | - missing.is_empty(), | ||
| 489 | - "lib.rs declares modules the by-value scan never reads: {:?}. Add \ | ||
| 490 | - them to FILES, or the sweep cannot see a new by-value return that \ | ||
| 491 | - lands in one of them.", | ||
| 492 | - missing | ||
| 493 | - ); | ||
| 494 | - } | ||
| 495 | - | ||
| 496 | - /// The bound, asserted BY NAME. A regression in any inventoried type reds | ||
| 497 | - /// here naming the type, not "some type is too big". | ||
| 498 | - #[test] | ||
| 499 | - fn every_by_value_type_fits_the_stack_budget() { | ||
| 500 | - let live = measured_by_name(); | ||
| 501 | - let mut checked = 0usize; | ||
| 502 | - for (name, _, public, path) in BY_VALUE_TYPES { | ||
| 503 | - if !public { | ||
| 504 | - continue; | ||
| 505 | - } | ||
| 506 | - checked += 1; | ||
| 507 | - let size = live | ||
| 508 | - .iter() | ||
| 509 | - .find(|(n, _)| n == name) | ||
| 510 | - .map(|(_, size)| *size) | ||
| 511 | - .unwrap_or_else(|| panic!("{name} is inventoried but never measured")); | ||
| 512 | - assert!( | ||
| 513 | - size <= STACK_BUDGET, | ||
| 514 | - "{name} is {size} bytes, over the {STACK_BUDGET}-byte by-value \ | ||
| 515 | - stack budget ({:.2}x). It is returned by value from {path}, so \ | ||
| 516 | - every caller pays it on its own stack, and the constructors \ | ||
| 517 | - nest -- one value's size is the multiplier, not the cost. \ | ||
| 518 | - Box the large field (this crate did exactly that for \ | ||
| 519 | - Ac3Decoder's inline decode::Core) or hand back a reference.", | ||
| 520 | - size as f64 / STACK_BUDGET as f64 | ||
| 521 | - ); | ||
| 522 | - } | ||
| 523 | - assert!( | ||
| 524 | - checked >= 10, | ||
| 525 | - "only {checked} rows were bound-checked; the budget must apply to \ | ||
| 526 | - every type a caller can be made to hold by value" | ||
| 527 | - ); | ||
| 528 | - // The other half of the derivation, asserted so it cannot rot: the | ||
| 529 | - // worst a caller can owe is DEEPEST_CHAIN x the worst public return. | ||
| 530 | - let worst = live | ||
| 531 | - .iter() | ||
| 532 | - .filter(|(n, _)| { | ||
| 533 | - BY_VALUE_TYPES | ||
| 534 | - .iter() | ||
| 535 | - .any(|(row, _, public, _)| row == n && *public) | ||
| 536 | - }) | ||
| 537 | - .map(|(_, size)| *size) | ||
| 538 | - .max() | ||
| 539 | - .expect("at least one public row"); | ||
| 540 | - assert!( | ||
| 541 | - DEEPEST_PUBLIC_CHAIN * worst * 8 <= 2 * 1024 * 1024, | ||
| 542 | - "the deepest public chain ({DEEPEST_PUBLIC_CHAIN}) times the worst \ | ||
| 543 | - public by-value return ({worst} B) is {} B, over an eighth of the \ | ||
| 544 | - 2101248-byte stack an unconfigured caller hands this crate; \ | ||
| 545 | - re-derive STACK_BUDGET", | ||
| 546 | - DEEPEST_PUBLIC_CHAIN * worst | ||
| 547 | - ); | ||
| 548 | - } | ||
| 549 | - | ||
| 550 | - /// The crate-private decode state stays BEHIND A BOX. | ||
| 551 | - /// | ||
| 552 | - /// The budget does not apply to `Core` because no `pub fn` returns it, so | ||
| 553 | - /// bounding it would calibrate the number to something no caller can | ||
| 554 | - /// reach. What keeps its 16,896 bytes of coefficient planes off every | ||
| 555 | - /// caller's stack is that the four fields holding them are `Box`es, and | ||
| 556 | - /// THIS is the pin for that -- a source scan over the four declarations | ||
| 557 | - /// plus the four `Box::new`s in `Core::new`. | ||
| 558 | - /// | ||
| 559 | - /// It earned its place during the layout fix: `exps`, `bap` and `delay` | ||
| 560 | - /// are `[[T; COEFFS]; CHANNELS]`-shaped planes at 1,792 / 1,792 / 6,144 | ||
| 561 | - /// bytes and `coeffs` is 7,168 -- 16,896 of a 19,728-byte `Core` -- and | ||
| 562 | - /// `Core` sits inline in the `Ac3Decoder` that `Ac3Decoder::new` hands a | ||
| 563 | - /// caller BY VALUE. Unboxing any of the four puts the stack cost straight | ||
| 564 | - /// back. | ||
| 565 | - #[test] | ||
| 566 | - fn the_crate_private_core_stays_behind_a_box() { | ||
| 567 | - const PINS: &[(&str, &str)] = &[ | ||
| 568 | - ( | ||
| 569 | - "decode.rs::Core::exps", | ||
| 570 | - "exps: Box<[[u8; COEFFS]; CHANNELS]>", | ||
| 571 | - ), | ||
| 572 | - ("decode.rs::Core::bap", "bap: Box<[[u8; COEFFS]; CHANNELS]>"), | ||
| 573 | - ( | ||
| 574 | - "decode.rs::Core::coeffs", | ||
| 575 | - "coeffs: Box<[[f32; COEFFS]; CHANNELS]>", | ||
| 576 | - ), | ||
| 577 | - ( | ||
| 578 | - "decode.rs::Core::delay", | ||
| 579 | - "delay: Box<[[f32; COEFFS]; MAX_FBW + 1]>", | ||
| 580 | - ), | ||
| 581 | - ( | ||
| 582 | - "decode.rs::Core::new::exps", | ||
| 583 | - "exps: Box::new([[0; COEFFS]; CHANNELS])", | ||
| 584 | - ), | ||
| 585 | - ( | ||
| 586 | - "decode.rs::Core::new::bap", | ||
| 587 | - "bap: Box::new([[0; COEFFS]; CHANNELS])", | ||
| 588 | - ), | ||
| 589 | - ( | ||
| 590 | - "decode.rs::Core::new::coeffs", | ||
| 591 | - "coeffs: Box::new([[0.0; COEFFS]; CHANNELS])", | ||
| 592 | - ), | ||
| 593 | - ( | ||
| 594 | - "decode.rs::Core::new::delay", | ||
| 595 | - "delay: Box::new([[0.0; COEFFS]; MAX_FBW + 1])", | ||
| 596 | - ), | ||
| 597 | - ]; | ||
| 598 | - const UNBOXED: &[(&str, &str)] = &[ | ||
| 599 | - ("decode.rs::Core::exps", "exps: [[u8; COEFFS]; CHANNELS],"), | ||
| 600 | - ("decode.rs::Core::bap", "bap: [[u8; COEFFS]; CHANNELS],"), | ||
| 601 | - ( | ||
| 602 | - "decode.rs::Core::coeffs", | ||
| 603 | - "coeffs: [[f32; COEFFS]; CHANNELS],", | ||
| 604 | - ), | ||
| 605 | - ( | ||
| 606 | - "decode.rs::Core::delay", | ||
| 607 | - "delay: [[f32; COEFFS]; MAX_FBW + 1],", | ||
| 608 | - ), | ||
| 609 | - ]; | ||
| 610 | - let decode = include_str!("decode.rs"); | ||
| 611 | - for (where_, spelling) in PINS { | ||
| 612 | - assert!( | ||
| 613 | - decode.contains(spelling), | ||
| 614 | - "{where_} is no longer declared `{spelling}`. An inline \ | ||
| 615 | - coefficient plane there puts its 16896 bytes back inside \ | ||
| 616 | - decode::Core, which sits inline in the Ac3Decoder that \ | ||
| 617 | - Ac3Decoder::new returns BY VALUE -- that is how Ac3Decoder was \ | ||
| 618 | - 20024 bytes, 2.44x over the by-value budget.", | ||
| 619 | - ); | ||
| 620 | - } | ||
| 621 | - // And the negative control: the unboxed spellings must be ABSENT, or | ||
| 622 | - // the scan above would be matching a doc comment or a dead branch | ||
| 623 | - // rather than the live declaration. | ||
| 624 | - for (where_, unboxed) in UNBOXED { | ||
| 625 | - assert!( | ||
| 626 | - !decode.contains(unboxed), | ||
| 627 | - "{where_} is declared `{unboxed}`, unboxed. The box pin above \ | ||
| 628 | - is not matching the live declaration, or the plane is inline \ | ||
| 629 | - again and every Ac3Decoder::new caller pays 16896 bytes.", | ||
| 630 | - ); | ||
| 631 | - } | ||
| 632 | - } | ||
| 633 | - | ||
| 634 | - /// CAPABILITY: really construct the heavy types on a tight stack, so a | ||
| 635 | - /// regression ABORTS THE PROCESS instead of costing invisible margin. | ||
| 636 | - /// | ||
| 637 | - /// Arm 1 is the two-deep `Ac3Decoder` constructor nest -- the crate's | ||
| 638 | - /// largest by-value return, and the type this lane's layout fix took from | ||
| 639 | - /// 20,024 to 3,160 bytes. Arm 2 is `Ac3Encoder::new`, the second-closest | ||
| 640 | - /// row to the budget at 34.0% of it. | ||
| 641 | - /// | ||
| 642 | - /// Both arms assert a REAL property of what came back, not merely that the | ||
| 643 | - /// thread survived: a fresh `Ac3Decoder` has no `frame_info()` before any | ||
| 644 | - /// syncframe, and one built with explicit options hands those exact options | ||
| 645 | - /// back through `options_mut()`. A constructor that quietly dropped its | ||
| 646 | - /// argument would red here rather than pass on a stack measurement alone. | ||
| 647 | - /// | ||
| 648 | - /// Measured stack need, **debug** build, one process per point so a | ||
| 649 | - /// stack-overflow abort cannot truncate the sweep: | ||
| 650 | - /// | ||
| 651 | - /// | `EC_AC3_TIGHT_STACK_BYTES` | result | | ||
| 652 | - /// |---|---| | ||
| 653 | - /// | 1048576 (1 MiB) | **ok** | | ||
| 654 | - /// | 524288 | **ok** | | ||
| 655 | - /// | 262144 | **ok** | | ||
| 656 | - /// | 131072 | **ok** | | ||
| 657 | - /// | 98304 | **ok** | | ||
| 658 | - /// | 86016 | **ok** | | ||
| 659 | - /// | 81920 | **ok** | | ||
| 660 | - /// | 77824 | overflow | | ||
| 661 | - /// | 65536 | overflow | | ||
| 662 | - /// | 32768 | overflow | | ||
| 663 | - /// | 24576 | overflow | | ||
| 664 | - /// | ||
| 665 | - /// The deepest measured need is therefore between 77,824 and 81,920 | ||
| 666 | - /// bytes, and the gate sits at 1 MiB -- **12.8x** that, and half of what an | ||
| 667 | - /// unconfigured caller hands this crate. The ~80 KiB is dominated by | ||
| 668 | - /// `Ac3Encoder::new`'s own working frames (a 512-float window, an | ||
| 669 | - /// `Mdct::new(512)` plan and a per-`COEFFS` IMDCT basis sweep), not by the | ||
| 670 | - /// by-value return slots this module bounds; that is exactly the residual | ||
| 671 | - /// `size_of` cannot predict, and why the arm constructs rather than | ||
| 672 | - /// computing. | ||
| 673 | - /// | ||
| 674 | - /// `EC_AC3_TIGHT_STACK_BYTES` overrides the size, which is how the | ||
| 675 | - /// threshold is swept. | ||
| 676 | - #[test] | ||
| 677 | - fn the_deepest_by_value_constructors_fit_on_a_tight_stack() { | ||
| 678 | - let stack: usize = std::env::var("EC_AC3_TIGHT_STACK_BYTES") | ||
| 679 | - .ok() | ||
| 680 | - .and_then(|v| v.parse().ok()) | ||
| 681 | - .unwrap_or(TIGHT_STACK); | ||
| 682 | - let config = EncoderConfig { | ||
| 683 | - sample_rate: 48_000, | ||
| 684 | - channels: 2, | ||
| 685 | - bitrate_kbps: 192, | ||
| 686 | - }; | ||
| 687 | - let handle = std::thread::Builder::new() | ||
| 688 | - .stack_size(stack) | ||
| 689 | - .spawn(move || { | ||
| 690 | - // Arm 1: the two-deep `Ac3Decoder` constructor nest, the | ||
| 691 | - // crate's largest by-value return. | ||
| 692 | - let mut plain = Ac3Decoder::new(); | ||
| 693 | - let fresh_has_no_frame_info = plain.frame_info().is_none(); | ||
| 694 | - let plain_options = *plain.options_mut(); | ||
| 695 | - // A decoder built with explicit options must keep exactly | ||
| 696 | - // those options, including a non-default downmix. | ||
| 697 | - let mut configured = Ac3Decoder::with_options(Options { | ||
| 698 | - drc_scale: 0.25, | ||
| 699 | - downmix: Downmix::Stereo, | ||
| 700 | - dither: false, | ||
| 701 | - }); | ||
| 702 | - let kept = *configured.options_mut(); | ||
| 703 | - drop(plain); | ||
| 704 | - drop(configured); | ||
| 705 | - // Arm 2: `Ac3Encoder::new`, the second-closest row to the budget. | ||
| 706 | - let encoder = Ac3Encoder::new(config).expect("Ac3Encoder::new"); | ||
| 707 | - let delay = encoder.encoder_delay(); | ||
| 708 | - let stats = encoder.stats(); | ||
| 709 | - (fresh_has_no_frame_info, plain_options, kept, delay, stats) | ||
| 710 | - }) | ||
| 711 | - .expect("spawn tight-stack thread"); | ||
| 712 | - let (fresh_has_no_frame_info, plain_options, kept, delay, stats) = | ||
| 713 | - handle.join().unwrap_or_else(|_| { | ||
| 714 | - panic!( | ||
| 715 | - "a by-value constructor overflowed a {stack}-byte stack; the \ | ||
| 716 | - old 20024-byte Ac3Decoder is what that costs" | ||
| 717 | - ) | ||
| 718 | - }); | ||
| 719 | - assert!( | ||
| 720 | - fresh_has_no_frame_info, | ||
| 721 | - "a freshly constructed Ac3Decoder already reported a frame_info(); \ | ||
| 722 | - decode_frame is the only thing that may set one" | ||
| 723 | - ); | ||
| 724 | - assert_eq!( | ||
| 725 | - plain_options, | ||
| 726 | - Options::default(), | ||
| 727 | - "Ac3Decoder::new did not give back the default Options" | ||
| 728 | - ); | ||
| 729 | - assert_eq!( | ||
| 730 | - kept, | ||
| 731 | - Options { | ||
| 732 | - drc_scale: 0.25, | ||
| 733 | - downmix: Downmix::Stereo, | ||
| 734 | - dither: false, | ||
| 735 | - }, | ||
| 736 | - "Ac3Decoder::with_options did not keep the options it was handed" | ||
| 737 | - ); | ||
| 738 | - assert!( | ||
| 739 | - delay > 0, | ||
| 740 | - "Ac3Encoder::encoder_delay reported no priming samples" | ||
| 741 | - ); | ||
| 742 | - assert_eq!( | ||
| 743 | - stats, | ||
| 744 | - crate::encode::EncodeStats::default(), | ||
| 745 | - "a fresh Ac3Encoder reported non-zero coding stats" | ||
| 746 | - ); | ||
| 747 | - eprintln!( | ||
| 748 | - "TIGHTSTACK {stack} bytes: Ac3Decoder={} Ac3Encoder={} bytes, both \ | ||
| 749 | - constructors returned and both options paths round-tripped", | ||
| 750 | - std::mem::size_of::<Ac3Decoder>(), | ||
| 751 | - std::mem::size_of::<Ac3Encoder>(), | ||
| 752 | - ); | ||
| 753 | - } | ||
| 754 | - | ||
| 755 | - /// The sweep's teeth against a NEW by-value return: re-derive the set from | ||
| 756 | - /// the crate source and require every name to be inventoried. | ||
| 757 | - /// | ||
| 758 | - /// Without this the inventory is a list of what someone remembered to | ||
| 759 | - /// measure, and a lane that adds `pub fn make() -> HugeThing` where | ||
| 760 | - /// `HugeThing` is 200 KB of inline tables passes every other test here. | ||
| 761 | - #[test] | ||
| 762 | - fn every_by_value_public_return_is_in_the_inventory() { | ||
| 763 | - let mut found: Vec<(String, String)> = Vec::new(); | ||
| 764 | - for (file, src) in FILES { | ||
| 765 | - for (n, line) in src.lines().enumerate() { | ||
| 766 | - if let Some(name) = by_value_return_name(line) { | ||
| 767 | - found.push((name, format!("{file}:{}", n + 1))); | ||
| 768 | - } | ||
| 769 | - } | ||
| 770 | - } | ||
| 771 | - found.sort(); | ||
| 772 | - found.dedup(); | ||
| 773 | - assert!( | ||
| 774 | - found.len() > 5, | ||
| 775 | - "the by-value return scan found {} names across {} files, which is \ | ||
| 776 | - too few to be a real sweep -- the matcher, not the crate, is broken", | ||
| 777 | - found.len(), | ||
| 778 | - FILES.len() | ||
| 779 | - ); | ||
| 780 | - eprintln!("BY-VALUE PUBLIC RETURNS FOUND: {found:?}"); | ||
| 781 | - | ||
| 782 | - let mut missing = Vec::new(); | ||
| 783 | - for (name, site) in &found { | ||
| 784 | - if !BY_VALUE_TYPES.iter().any(|(n, _, _, _)| n == name) { | ||
| 785 | - missing.push(format!("{name} ({site})")); | ||
| 786 | - } | ||
| 787 | - } | ||
| 788 | - assert!( | ||
| 789 | - missing.is_empty(), | ||
| 790 | - "these types are returned BY VALUE from a public fn and are not in \ | ||
| 791 | - the inventory: {}. Either they are thin enough not to be a stack \ | ||
| 792 | - cost -- say so by adding a row with its measured size -- or they \ | ||
| 793 | - are the next instance of the class this module exists for.", | ||
| 794 | - missing.join(", ") | ||
| 795 | - ); | ||
| 796 | - } | ||
| 797 | - | ||
| 798 | - /// The control for the scan above, on synthetic text rather than by | ||
| 799 | - /// trusting the live tree to happen to contain a case. | ||
| 800 | - /// | ||
| 801 | - /// If the matcher silently stopped recognising a shape, the sweep would | ||
| 802 | - /// pass everything and this would still be asserting nothing. So: every | ||
| 803 | - /// by-value spelling the crate uses must yield its type name, and every | ||
| 804 | - /// pointer/Vec/primitive/`Self` spelling must yield nothing. | ||
| 805 | - #[test] | ||
| 806 | - fn the_inventory_scan_is_not_vacuous() { | ||
| 807 | - for synthetic in [ | ||
| 808 | - "pub fn zz_a() -> ZzNotInventoried { todo!() }", | ||
| 809 | - "pub fn zz_b() -> Result<ZzNotInventoried, Error> { todo!() }", | ||
| 810 | - "pub fn zz_c() -> Result<ZzNotInventoried> { todo!() }", | ||
| 811 | - "pub fn zz_d() -> Option<ZzNotInventoried> { todo!() }", | ||
| 812 | - "pub fn zz_e() -> ZzNotInventoried<'a> { todo!() }", | ||
| 813 | - ] { | ||
| 814 | - let name = by_value_return_name(synthetic) | ||
| 815 | - .unwrap_or_else(|| panic!("the matcher does not recognise `{synthetic}`")); | ||
| 816 | - assert_eq!( | ||
| 817 | - name, "ZzNotInventoried", | ||
| 818 | - "the matcher mangled `{synthetic}` into `{name}`, so the sweep \ | ||
| 819 | - cannot see a new by-value return and its green is vacuous" | ||
| 820 | - ); | ||
| 821 | - assert!( | ||
| 822 | - !BY_VALUE_TYPES.iter().any(|(n, _, _, _)| *n == name), | ||
| 823 | - "the synthetic control name is in the inventory, so the control \ | ||
| 824 | - proves nothing" | ||
| 825 | - ); | ||
| 826 | - } | ||
| 827 | - for thin in [ | ||
| 828 | - "pub fn zz_t() -> Box<Decoder> { todo!() }", | ||
| 829 | - "pub fn zz_u() -> Result<Vec<u8>, Error> { todo!() }", | ||
| 830 | - "pub fn zz_v() -> Option<&Path> { todo!() }", | ||
| 831 | - "pub fn zz_w() -> usize { todo!() }", | ||
| 832 | - "pub fn zz_x() -> Self { todo!() }", | ||
| 833 | - "pub fn zz_y() -> Result<Arc<Decoder>, Error> { todo!() }", | ||
| 834 | - "pub fn zz_z() { todo!() }", | ||
| 835 | - "fn zz_private() -> ZzNotInventoried { todo!() }", | ||
| 836 | - ] { | ||
| 837 | - assert_eq!( | ||
| 838 | - by_value_return_name(thin), | ||
| 839 | - None, | ||
| 840 | - "`{thin}` is a pointer, a Vec, a primitive, a `Self` the rows \ | ||
| 841 | - above already cover, or not a `pub fn` -- the matcher must not \ | ||
| 842 | - read it as an uninventoried by-value return" | ||
| 843 | - ); | ||
| 844 | - } | ||
| 845 | - } | ||
| 846 | - | ||
| 847 | - /// The stack mapping containing `addr` in `/proc/self/task/<tid>/maps`. | ||
| 848 | - /// | ||
| 849 | - /// The returned size is a LOWER BOUND, never an exact count. Linux MERGES | ||
| 850 | - /// adjacent VMAs that share protections, and a merged region is | ||
| 851 | - /// indistinguishable from a single one in the maps file. A lower bound is | ||
| 852 | - /// what the budget's reasoning needs: the claim is "no caller gets less | ||
| 853 | - /// than 2 MiB", and `size >= 2 MiB` is exactly that, whether the region is | ||
| 854 | - /// one mapping or three. | ||
| 855 | - /// | ||
| 856 | - /// The third field is whether the mapping is writable. Merging only joins | ||
| 857 | - /// VMAs whose protections match, so a merged thread stack is still | ||
| 858 | - /// writable. Its size can grow without bound, which is why the tests check | ||
| 859 | - /// this flag and never an upper bound on the size. | ||
| 860 | - fn stack_region(tid: u32, addr: usize) -> Option<(usize, usize, bool)> { | ||
| 861 | - let maps = std::fs::read_to_string(format!("/proc/self/task/{tid}/maps")).ok()?; | ||
| 862 | - for line in maps.lines() { | ||
| 863 | - let (range, perms) = line.split_once(' ')?; | ||
| 864 | - let (lo, hi) = range.split_once('-')?; | ||
| 865 | - let (lo, hi) = ( | ||
| 866 | - usize::from_str_radix(lo, 16).ok()?, | ||
| 867 | - usize::from_str_radix(hi, 16).ok()?, | ||
| 868 | - ); | ||
| 869 | - if addr >= lo && addr < hi { | ||
| 870 | - // `perms` is `rwxp`-style: the second character is write. | ||
| 871 | - let writable = perms.as_bytes().get(1) == Some(&b'w'); | ||
| 872 | - return Some((lo, hi, writable)); | ||
| 873 | - } | ||
| 874 | - } | ||
| 875 | - None | ||
| 876 | - } | ||
| 877 | - | ||
| 878 | - /// What a thread's stack ACTUALLY is, read from | ||
| 879 | - /// `/proc/self/task/<tid>/maps` rather than assumed from a default. | ||
| 880 | - /// | ||
| 881 | - /// The number the budget's reasoning rests on, measured two ways: | ||
| 882 | - /// | ||
| 883 | - /// * a thread spawned with an EXPLICIT size gets AT LEAST that size -- | ||
| 884 | - /// the control that says the parse finds stacks at all, and the shape | ||
| 885 | - /// [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] relies on; | ||
| 886 | - /// * the DEFAULT -- no `stack_size`, i.e. what a library consumer's | ||
| 887 | - /// `std::thread::spawn` gets, and what libtest gives a test thread when | ||
| 888 | - /// `RUST_MIN_STACK` is unset -- is at least 2 MiB. | ||
| 889 | - /// | ||
| 890 | - /// Both are floors, because [`stack_region`] can only report a lower bound. | ||
| 891 | - /// That is the right direction: the budget's claim is that no caller gets | ||
| 892 | - /// LESS than 2 MiB, and a floor is what proves it. | ||
| 893 | - #[test] | ||
| 894 | - fn test_threads_get_the_stack_they_are_given() { | ||
| 895 | - const EXPLICIT: usize = 1024 * 1024; | ||
| 896 | - let handle = std::thread::Builder::new() | ||
| 897 | - .stack_size(EXPLICIT) | ||
| 898 | - .spawn(|| { | ||
| 899 | - let tid = std::process::id(); | ||
| 900 | - let marker = 0u8; | ||
| 901 | - let here = &marker as *const u8 as usize; | ||
| 902 | - let (lo, hi, rw) = | ||
| 903 | - stack_region(tid, here).expect("this thread's own stack is in its maps"); | ||
| 904 | - (lo, hi, rw) | ||
| 905 | - }) | ||
| 906 | - .expect("spawn"); | ||
| 907 | - let (lo, hi, rw) = handle.join().expect("the probe thread returned"); | ||
| 908 | - let size = hi - lo; | ||
| 909 | - assert!( | ||
| 910 | - size >= EXPLICIT, | ||
| 911 | - "a thread spawned with stack_size({EXPLICIT}) has a {size}-byte \ | ||
| 912 | - stack mapping; the runtime gave it less than it was promised, so \ | ||
| 913 | - the maps parse is finding the wrong region" | ||
| 914 | - ); | ||
| 915 | - assert!( | ||
| 916 | - rw, | ||
| 917 | - "the mapping holding an explicitly-1-MiB thread's frame is not \ | ||
| 918 | - writable -- a thread stack is read-write, so the maps parse found \ | ||
| 919 | - the wrong region" | ||
| 920 | - ); | ||
| 921 | - | ||
| 922 | - let tid = std::process::id(); | ||
| 923 | - let marker = 0u8; | ||
| 924 | - let here = &marker as *const u8 as usize; | ||
| 925 | - let (lo, hi, rw) = | ||
| 926 | - stack_region(tid, here).expect("this test thread's stack is in its maps"); | ||
| 927 | - let size = hi - lo; | ||
| 928 | - assert!( | ||
| 929 | - rw, | ||
| 930 | - "a default test thread's stack mapping is not writable -- the maps \ | ||
| 931 | - parse found the wrong region" | ||
| 932 | - ); | ||
| 933 | - assert!( | ||
| 934 | - size >= 2 * 1024 * 1024, | ||
| 935 | - "a default test thread's stack measured {size} bytes, under the \ | ||
| 936 | - 2 MiB floor the by-value budget is derived from; the smallest \ | ||
| 937 | - stack a caller can hand this crate just got smaller and the bound \ | ||
| 938 | - needs re-deriving" | ||
| 939 | - ); | ||
| 940 | - eprintln!( | ||
| 941 | - "TESTTHREADSTACK default tid={tid} region=[{lo:x},{hi:x}) size>={size} \ | ||
| 942 | - (2101248 measured exactly with the repo cap lifted, 67112960 with it)" | ||
| 943 | - ); | ||
| 944 | - } | ||
| 945 | -} | ||
crates/ec-ac3/src/transform.rsmodified+0 -6
| @@ -91,12 +91,6 @@ impl Imdct { | |||
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | - /// Drop the overlap-add tail; a seek makes it belong to frames that were | ||
| 95 | - /// never decoded. | ||
| 96 | - pub fn reset(delay: &mut [f32]) { | ||
| 97 | - delay.fill(0.0); | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | fn long_transform(&mut self, coeffs: &[f32]) { | 94 | fn long_transform(&mut self, coeffs: &[f32]) { |
| 101 | // Step 2: pre-IFFT complex multiply. | 95 | // Step 2: pre-IFFT complex multiply. |
| 102 | for k in 0..128 { | 96 | for k in 0..128 { |
crates/ec-ac3/tests/it/decode_matrix.rsdeleted+0 -309
| @@ -1,309 +0,0 @@ | |||
| 1 | -//! Fixture matrix: every generated AC-3 and E-AC-3 fixture decoded and | ||
| 2 | -//! compared against ffmpeg, plus the header surface a container reads and the | ||
| 3 | -//! no-panic contract on damaged input. | ||
| 4 | -//! | ||
| 5 | - | ||
| 6 | -use std::path::Path; | ||
| 7 | - | ||
| 8 | -use ec_ac3::{Ac3Decoder, Downmix, Options, Syntax, bsi, eac3, syncinfo}; | ||
| 9 | - | ||
| 10 | -/// Per-channel correlation floor (rubric: audio-ac3 MUST). | ||
| 11 | -const MIN_CORR: f64 = 0.999; | ||
| 12 | -/// RMS delta ceiling on the fixture matrix, where both decoders see the same | ||
| 13 | -/// synthetic material. | ||
| 14 | -const MAX_RMS: f64 = 1e-3; | ||
| 15 | - | ||
| 16 | -/// ffmpeg's decode of `path` as interleaved `f32`. | ||
| 17 | -fn reference(path: &Path) -> Vec<f32> { | ||
| 18 | - let out = ec_testkit::ffmpeg() | ||
| 19 | - .args(["-v", "error", "-i"]) | ||
| 20 | - .arg(path) | ||
| 21 | - .args(["-f", "f32le", "-"]) | ||
| 22 | - .output() | ||
| 23 | - .expect("ffmpeg"); | ||
| 24 | - out.stdout | ||
| 25 | - .as_chunks::<4>().0.iter() | ||
| 26 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 27 | - .collect() | ||
| 28 | -} | ||
| 29 | - | ||
| 30 | -/// Our decode of a raw elementary stream, and the channel count. | ||
| 31 | -fn decode(path: &Path, options: Options) -> (Vec<f32>, usize) { | ||
| 32 | - let data = std::fs::read(path).expect("fixture"); | ||
| 33 | - let mut decoder = Ac3Decoder::with_options(options); | ||
| 34 | - let (mut out, mut channels, mut pos) = (Vec::new(), 0, 0usize); | ||
| 35 | - while pos + 6 <= data.len() { | ||
| 36 | - if data[pos] != 0x0B || data[pos + 1] != 0x77 { | ||
| 37 | - pos += 1; | ||
| 38 | - continue; | ||
| 39 | - } | ||
| 40 | - let Ok(size) = ec_ac3::frame_size(&data[pos..]) else { | ||
| 41 | - break; | ||
| 42 | - }; | ||
| 43 | - if pos + size > data.len() { | ||
| 44 | - break; | ||
| 45 | - } | ||
| 46 | - let frame = decoder | ||
| 47 | - .decode_frame(&data[pos..pos + size]) | ||
| 48 | - .unwrap_or_else(|e| panic!("{}: {e}", path.display())); | ||
| 49 | - channels = frame.channels(); | ||
| 50 | - out.extend( | ||
| 51 | - frame.data[0] | ||
| 52 | - .as_chunks::<4>().0.iter() | ||
| 53 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])), | ||
| 54 | - ); | ||
| 55 | - pos += size; | ||
| 56 | - } | ||
| 57 | - (out, channels) | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -fn correlation(a: &[f32], b: &[f32]) -> (f64, f64) { | ||
| 61 | - let n = a.len().min(b.len()); | ||
| 62 | - let (mut sa, mut sb, mut saa, mut sbb, mut sab, mut sd) = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | ||
| 63 | - for i in 0..n { | ||
| 64 | - let (x, y) = (f64::from(a[i]), f64::from(b[i])); | ||
| 65 | - sa += x; | ||
| 66 | - sb += y; | ||
| 67 | - saa += x * x; | ||
| 68 | - sbb += y * y; | ||
| 69 | - sab += x * y; | ||
| 70 | - sd += (x - y) * (x - y); | ||
| 71 | - } | ||
| 72 | - let n = n as f64; | ||
| 73 | - let cov = sab / n - (sa / n) * (sb / n); | ||
| 74 | - let va = saa / n - (sa / n).powi(2); | ||
| 75 | - let vb = sbb / n - (sb / n).powi(2); | ||
| 76 | - let corr = if va <= 0.0 || vb <= 0.0 { | ||
| 77 | - 1.0 | ||
| 78 | - } else { | ||
| 79 | - cov / (va * vb).sqrt() | ||
| 80 | - }; | ||
| 81 | - (corr, (sd / n).sqrt()) | ||
| 82 | -} | ||
| 83 | - | ||
| 84 | -#[test] | ||
| 85 | -fn fixture_matrix_matches_ffmpeg() { | ||
| 86 | - let mut checked = 0; | ||
| 87 | - for entry in std::fs::read_dir(ec_testkit::root().join("audio")).expect("audio fixtures") { | ||
| 88 | - let path = entry.expect("entry").path(); | ||
| 89 | - let name = path.file_name().unwrap_or_default().to_string_lossy(); | ||
| 90 | - if !(name.starts_with("ac3-") || name.starts_with("eac3-")) { | ||
| 91 | - continue; | ||
| 92 | - } | ||
| 93 | - // Dither is "any reasonably random sequence" (§7.3.4), so two | ||
| 94 | - // conformant decoders differ by exactly that noise. Comparing with it | ||
| 95 | - // off is what isolates everything else; the with-dither run below | ||
| 96 | - // bounds how much noise it adds. | ||
| 97 | - let options = Options { | ||
| 98 | - dither: false, | ||
| 99 | - ..Options::default() | ||
| 100 | - }; | ||
| 101 | - let (ours, channels) = decode(&path, options); | ||
| 102 | - let theirs = reference(&path); | ||
| 103 | - assert!(channels > 0, "{name}: no channels"); | ||
| 104 | - assert_eq!( | ||
| 105 | - ours.len(), | ||
| 106 | - theirs.len(), | ||
| 107 | - "{name}: {} samples vs ffmpeg's {}", | ||
| 108 | - ours.len(), | ||
| 109 | - theirs.len() | ||
| 110 | - ); | ||
| 111 | - for ch in 0..channels { | ||
| 112 | - let a: Vec<f32> = ours[ch..].iter().step_by(channels).copied().collect(); | ||
| 113 | - let b: Vec<f32> = theirs[ch..].iter().step_by(channels).copied().collect(); | ||
| 114 | - let (corr, rms) = correlation(&a, &b); | ||
| 115 | - assert!(corr >= MIN_CORR, "{name} ch{ch}: correlation {corr:.6}"); | ||
| 116 | - assert!(rms <= MAX_RMS, "{name} ch{ch}: RMS delta {rms:.8}"); | ||
| 117 | - } | ||
| 118 | - checked += 1; | ||
| 119 | - } | ||
| 120 | - assert!(checked >= 12, "only {checked} fixtures checked"); | ||
| 121 | -} | ||
| 122 | - | ||
| 123 | -#[test] | ||
| 124 | -fn dither_only_adds_noise_below_the_signal() { | ||
| 125 | - let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); | ||
| 126 | - let (with, channels) = decode(&path, Options::default()); | ||
| 127 | - let (without, _) = decode( | ||
| 128 | - &path, | ||
| 129 | - Options { | ||
| 130 | - dither: false, | ||
| 131 | - ..Options::default() | ||
| 132 | - }, | ||
| 133 | - ); | ||
| 134 | - assert_eq!(with.len(), without.len()); | ||
| 135 | - let (corr, rms) = correlation(&with, &without); | ||
| 136 | - assert!(channels == 6 && corr > 0.999, "correlation {corr:.6}"); | ||
| 137 | - assert!(rms < 1e-3, "dither RMS {rms:.8}"); | ||
| 138 | -} | ||
| 139 | - | ||
| 140 | -#[test] | ||
| 141 | -fn headers_state_what_the_container_needs() { | ||
| 142 | - let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); | ||
| 143 | - let data = std::fs::read(&path).expect("fixture"); | ||
| 144 | - // The exact call shape a container makes: syncinfo from the frame start, | ||
| 145 | - // bsi from five bytes in. | ||
| 146 | - let sync = syncinfo::parse(&data).expect("syncinfo"); | ||
| 147 | - assert_eq!(sync.sample_rate, 48_000); | ||
| 148 | - assert_eq!(sync.frame_size % 2, 0); | ||
| 149 | - let bsi = bsi::parse(&data[5..]).expect("bsi"); | ||
| 150 | - assert_eq!(bsi.nfchans, 5); | ||
| 151 | - assert!(bsi.lfeon); | ||
| 152 | - assert_eq!(bsi.channels, 6); | ||
| 153 | - assert!((1..=31).contains(&bsi.dialnorm)); | ||
| 154 | - | ||
| 155 | - let eac3_path = ec_testkit::fixture("audio/eac3-5.1-48000.eac3"); | ||
| 156 | - let data = std::fs::read(&eac3_path).expect("fixture"); | ||
| 157 | - let hdr = eac3::bsi::parse(&data[2..]).expect("eac3 bsi"); | ||
| 158 | - assert_eq!(hdr.sample_rate, 48_000); | ||
| 159 | - assert_eq!(hdr.nfchans, 5); | ||
| 160 | - assert!(hdr.bsi.lfeon); | ||
| 161 | - assert_eq!( | ||
| 162 | - hdr.frame_size, | ||
| 163 | - ec_ac3::frame_size(&data).expect("frame size") | ||
| 164 | - ); | ||
| 165 | -} | ||
| 166 | - | ||
| 167 | -#[test] | ||
| 168 | -fn frame_info_surfaces_the_metadata_the_rubric_asks_for() { | ||
| 169 | - let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); | ||
| 170 | - let data = std::fs::read(&path).expect("fixture"); | ||
| 171 | - let size = ec_ac3::frame_size(&data).expect("frame size"); | ||
| 172 | - let mut decoder = Ac3Decoder::new(); | ||
| 173 | - decoder.decode_frame(&data[..size]).expect("decode"); | ||
| 174 | - let info = decoder.frame_info().expect("frame info"); | ||
| 175 | - assert_eq!(info.syntax, Syntax::Ac3); | ||
| 176 | - assert_eq!(info.sample_rate, 48_000); | ||
| 177 | - assert!((1..=31).contains(&info.dialnorm)); | ||
| 178 | - // ffmpeg's encoder writes cmixlev 1 (-4.5 dB) and surmixlev 1 (-6 dB). | ||
| 179 | - assert_eq!(info.center_mix_level, Some(0.595)); | ||
| 180 | - assert_eq!(info.surround_mix_level, Some(0.5)); | ||
| 181 | - assert_eq!(info.samples, 1536); | ||
| 182 | -} | ||
| 183 | - | ||
| 184 | -#[test] | ||
| 185 | -fn stereo_downmix_folds_five_one_without_clipping() { | ||
| 186 | - let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); | ||
| 187 | - let (stereo, channels) = decode( | ||
| 188 | - &path, | ||
| 189 | - Options { | ||
| 190 | - downmix: Downmix::Stereo, | ||
| 191 | - ..Options::default() | ||
| 192 | - }, | ||
| 193 | - ); | ||
| 194 | - assert_eq!(channels, 2); | ||
| 195 | - let (native, _) = decode(&path, Options::default()); | ||
| 196 | - assert_eq!(stereo.len() * 3, native.len()); | ||
| 197 | - assert!(stereo.iter().all(|v| v.abs() <= 1.0), "downmix clipped"); | ||
| 198 | - assert!(stereo.iter().any(|v| v.abs() > 0.01), "downmix is silent"); | ||
| 199 | - | ||
| 200 | - let (mono, channels) = decode( | ||
| 201 | - &path, | ||
| 202 | - Options { | ||
| 203 | - downmix: Downmix::Mono, | ||
| 204 | - ..Options::default() | ||
| 205 | - }, | ||
| 206 | - ); | ||
| 207 | - assert_eq!(channels, 1); | ||
| 208 | - assert_eq!(mono.len() * 6, native.len()); | ||
| 209 | -} | ||
| 210 | - | ||
| 211 | -#[test] | ||
| 212 | -fn damaged_input_never_panics() { | ||
| 213 | - let path = ec_testkit::fixture("audio/ac3-stereo-48000.ac3"); | ||
| 214 | - let data = std::fs::read(&path).expect("fixture"); | ||
| 215 | - let size = ec_ac3::frame_size(&data).expect("frame size"); | ||
| 216 | - let frame = &data[..size]; | ||
| 217 | - let mut decoder = Ac3Decoder::new(); | ||
| 218 | - | ||
| 219 | - // Every truncation. | ||
| 220 | - for cut in 0..frame.len() { | ||
| 221 | - let _ = decoder.decode_frame(&frame[..cut]); | ||
| 222 | - } | ||
| 223 | - // Every single-byte corruption at a stride that still hits every field | ||
| 224 | - // class: header, side information, exponents, mantissas. | ||
| 225 | - for pos in (0..frame.len()).step_by(7) { | ||
| 226 | - let mut broken = frame.to_vec(); | ||
| 227 | - broken[pos] ^= 0xA5; | ||
| 228 | - let _ = decoder.decode_frame(&broken); | ||
| 229 | - } | ||
| 230 | - // Garbage that happens to start with a sync word. | ||
| 231 | - let mut noise = vec![0x0B, 0x77]; | ||
| 232 | - let mut state = 12345u32; | ||
| 233 | - for _ in 0..4096 { | ||
| 234 | - state = state.wrapping_mul(1_103_515_245).wrapping_add(12345); | ||
| 235 | - noise.push((state >> 16) as u8); | ||
| 236 | - } | ||
| 237 | - let _ = decoder.decode_frame(&noise); | ||
| 238 | -} | ||
| 239 | - | ||
| 240 | -/// A packet that carries a second frame after the first — the shape a | ||
| 241 | -/// Matroska block for 7.1 DD+ really has (independent substream plus its | ||
| 242 | -/// dependent) — must not decode to the first frame's samples in silence: | ||
| 243 | -/// the tail is stream, and dropping it loses the extension channels without | ||
| 244 | -/// a word. Built from two real frames of the fixture: the tail as it stands | ||
| 245 | -/// (another independent frame) is refused as a second syncframe, and the | ||
| 246 | -/// same packet with the tail's stream-type bits flipped to `dependent` is | ||
| 247 | -/// refused as the dependent substream it then claims to be. The AC-3 path | ||
| 248 | -/// answers the same way for an AC-3 tail. | ||
| 249 | -#[test] | ||
| 250 | -fn a_concatenated_tail_is_refused_by_name_not_dropped() { | ||
| 251 | - for name in ["ac3-5.1-48000.ac3", "eac3-5.1-48000.eac3"] { | ||
| 252 | - let data = std::fs::read(ec_testkit::fixture(&format!("audio/{name}"))).expect("fixture"); | ||
| 253 | - let first = ec_ac3::frame_size(&data).expect("first frame size"); | ||
| 254 | - let second = ec_ac3::frame_size(&data[first..]).expect("second frame size"); | ||
| 255 | - let mut packet = data[..first].to_vec(); | ||
| 256 | - packet.extend_from_slice(&data[first..first + second]); | ||
| 257 | - | ||
| 258 | - let mut dec = Ac3Decoder::new(); | ||
| 259 | - let err = dec | ||
| 260 | - .decode_frame(&packet) | ||
| 261 | - .expect_err("{name}: the tail is stream, not padding"); | ||
| 262 | - let text = err.to_string(); | ||
| 263 | - eprintln!("{name}: {text}"); | ||
| 264 | - assert!( | ||
| 265 | - text.contains("second syncframe"), | ||
| 266 | - "{name}: the independent tail must name itself: {text}" | ||
| 267 | - ); | ||
| 268 | - if name.starts_with("eac3") { | ||
| 269 | - // Flip the tail's stream-type (bits 16..18 of a frame: the top | ||
| 270 | - // two bits of byte 2) to `dependent`. The packet is then the | ||
| 271 | - // shape a 7.1 DD+ block carries, and the refusal names the | ||
| 272 | - // dependent substream. | ||
| 273 | - let mut dep_packet = packet.clone(); | ||
| 274 | - dep_packet[first + 2] = (dep_packet[first + 2] & 0x3F) | 0x40; | ||
| 275 | - let err = dec | ||
| 276 | - .decode_frame(&dep_packet) | ||
| 277 | - .expect_err("the dependent tail is stream"); | ||
| 278 | - let text = err.to_string(); | ||
| 279 | - eprintln!("{name} (tail flipped to dependent): {text}"); | ||
| 280 | - assert!( | ||
| 281 | - text.contains("dependent substream"), | ||
| 282 | - "the dependent tail must name itself: {text}" | ||
| 283 | - ); | ||
| 284 | - } | ||
| 285 | - } | ||
| 286 | -} | ||
| 287 | - | ||
| 288 | -/// The spec's own allowance: a container may pad a block around a frame, and | ||
| 289 | -/// padding that is not itself a syncframe decodes exactly like the bare | ||
| 290 | -/// frame — sample for sample, whatever its length. | ||
| 291 | -#[test] | ||
| 292 | -fn padding_that_is_not_a_syncframe_still_decodes() { | ||
| 293 | - let path = ec_testkit::fixture("audio/ac3-5.1-48000.ac3"); | ||
| 294 | - let data = std::fs::read(&path).expect("fixture"); | ||
| 295 | - let first = ec_ac3::frame_size(&data).expect("frame size"); | ||
| 296 | - let frame = &data[..first]; | ||
| 297 | - let mut dec = Ac3Decoder::new(); | ||
| 298 | - let bare = dec.decode_frame(frame).expect("bare frame"); | ||
| 299 | - for pad in [1usize, 6, 64, 1024] { | ||
| 300 | - let mut padded = frame.to_vec(); | ||
| 301 | - padded.resize(first + pad, 0x00); | ||
| 302 | - let mut dec = Ac3Decoder::new(); | ||
| 303 | - let got = dec.decode_frame(&padded).expect("padded frame decodes"); | ||
| 304 | - assert!( | ||
| 305 | - got.data[0].iter().eq(bare.data[0].iter()), | ||
| 306 | - "pad of {pad} bytes changed the audio" | ||
| 307 | - ); | ||
| 308 | - } | ||
| 309 | -} | ||
crates/ec-ac3/tests/it/dependent.rsdeleted+0 -250
| @@ -1,250 +0,0 @@ | |||
| 1 | -//! E-AC-3 dependent substreams, checked against ffmpeg's own decode of the same | ||
| 2 | -//! spliced stream: its channel placement (the replace-or-add rule of Table E2.5) | ||
| 3 | -//! and its channel order, which ffprobe names in `channel_layout`. | ||
| 4 | -//! | ||
| 5 | - | ||
| 6 | -use std::path::Path; | ||
| 7 | - | ||
| 8 | -use ec_ac3::{Ac3Decoder, Error, Options, eac3, frame_size}; | ||
| 9 | -use ec_core::{ChannelLayout, ChannelPosition}; | ||
| 10 | - | ||
| 11 | -/// Per-channel correlation floor and RMS ceiling, as in `decode_matrix.rs`. | ||
| 12 | -const MIN_CORR: f64 = 0.999; | ||
| 13 | -const MAX_RMS: f64 = 1e-3; | ||
| 14 | - | ||
| 15 | -/// ffprobe's `channel_layout` name for the first audio stream of `path`. | ||
| 16 | -fn ffprobe_layout(path: &Path) -> String { | ||
| 17 | - let out = ec_testkit::ffprobe() | ||
| 18 | - .args(["-v", "error", "-f", "eac3", "-select_streams", "a:0"]) | ||
| 19 | - .args(["-show_entries", "stream=channel_layout", "-of", "csv=p=0"]) | ||
| 20 | - .arg(path) | ||
| 21 | - .output() | ||
| 22 | - .expect("ffprobe"); | ||
| 23 | - String::from_utf8_lossy(&out.stdout).trim().to_owned() | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -/// ffmpeg's decode of `path` as interleaved `f32`, in ffmpeg's channel order. | ||
| 27 | -fn reference(path: &Path, channels: usize) -> Vec<Vec<f32>> { | ||
| 28 | - let out = ec_testkit::ffmpeg() | ||
| 29 | - .args(["-v", "error", "-f", "eac3", "-i"]) | ||
| 30 | - .arg(path) | ||
| 31 | - .args(["-f", "f32le", "-"]) | ||
| 32 | - .output() | ||
| 33 | - .expect("ffmpeg"); | ||
| 34 | - let all: Vec<f32> = out | ||
| 35 | - .stdout | ||
| 36 | - .as_chunks::<4>() | ||
| 37 | - .0 | ||
| 38 | - .iter() | ||
| 39 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 40 | - .collect(); | ||
| 41 | - (0..channels) | ||
| 42 | - .map(|ch| all[ch..].iter().step_by(channels).copied().collect()) | ||
| 43 | - .collect() | ||
| 44 | -} | ||
| 45 | - | ||
| 46 | -/// Split a raw E-AC-3 stream into packets: an independent syncframe and the | ||
| 47 | -/// dependent substreams that follow it. | ||
| 48 | -fn packets(data: &[u8]) -> Vec<&[u8]> { | ||
| 49 | - let mut starts = Vec::new(); | ||
| 50 | - let mut pos = 0; | ||
| 51 | - while pos + 6 <= data.len() { | ||
| 52 | - let Ok(size) = frame_size(&data[pos..]) else { | ||
| 53 | - break; | ||
| 54 | - }; | ||
| 55 | - let independent = eac3::bsi::parse(&data[pos + 2..]) | ||
| 56 | - .is_ok_and(|h| h.strmtyp == eac3::StreamType::Independent); | ||
| 57 | - if independent { | ||
| 58 | - starts.push(pos); | ||
| 59 | - } | ||
| 60 | - pos += size; | ||
| 61 | - } | ||
| 62 | - starts | ||
| 63 | - .iter() | ||
| 64 | - .enumerate() | ||
| 65 | - .map(|(i, &s)| &data[s..starts.get(i + 1).copied().unwrap_or(data.len())]) | ||
| 66 | - .collect() | ||
| 67 | -} | ||
| 68 | - | ||
| 69 | -/// Our decode of every packet: interleaved samples, channels and the layout. | ||
| 70 | -fn decode(data: &[u8]) -> (Vec<f32>, usize, ChannelLayout) { | ||
| 71 | - let mut decoder = Ac3Decoder::with_options(Options { | ||
| 72 | - dither: false, | ||
| 73 | - ..Options::default() | ||
| 74 | - }); | ||
| 75 | - let (mut out, mut channels, mut layout) = (Vec::new(), 0, ChannelLayout::Mono); | ||
| 76 | - for packet in packets(data) { | ||
| 77 | - let frame = decoder | ||
| 78 | - .decode_frame(packet) | ||
| 79 | - .unwrap_or_else(|e| panic!("packet decode: {e}")); | ||
| 80 | - channels = frame.channels(); | ||
| 81 | - layout = frame.layout.clone(); | ||
| 82 | - out.extend( | ||
| 83 | - frame.data[0] | ||
| 84 | - .as_chunks::<4>() | ||
| 85 | - .0 | ||
| 86 | - .iter() | ||
| 87 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])), | ||
| 88 | - ); | ||
| 89 | - } | ||
| 90 | - (out, channels, layout) | ||
| 91 | -} | ||
| 92 | - | ||
| 93 | -fn correlation(a: &[f32], b: &[f32]) -> (f64, f64, f64) { | ||
| 94 | - let n = a.len().min(b.len()); | ||
| 95 | - let (mut sa, mut sb, mut saa, mut sbb, mut sab, mut sd) = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | ||
| 96 | - let mut max_abs = 0.0f64; | ||
| 97 | - for i in 0..n { | ||
| 98 | - let (x, y) = (f64::from(a[i]), f64::from(b[i])); | ||
| 99 | - sa += x; | ||
| 100 | - sb += y; | ||
| 101 | - saa += x * x; | ||
| 102 | - sbb += y * y; | ||
| 103 | - sab += x * y; | ||
| 104 | - sd += (x - y) * (x - y); | ||
| 105 | - max_abs = max_abs.max((x - y).abs()); | ||
| 106 | - } | ||
| 107 | - let n = n as f64; | ||
| 108 | - let cov = sab / n - (sa / n) * (sb / n); | ||
| 109 | - let va = saa / n - (sa / n).powi(2); | ||
| 110 | - let vb = sbb / n - (sb / n).powi(2); | ||
| 111 | - let corr = if va <= 0.0 || vb <= 0.0 { | ||
| 112 | - 1.0 | ||
| 113 | - } else { | ||
| 114 | - cov / (va * vb).sqrt() | ||
| 115 | - }; | ||
| 116 | - (corr, (sd / n).sqrt(), max_abs) | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | -/// The per-channel comparison of our decode of `name` against ffmpeg's decode of | ||
| 120 | -/// the same file. The layout name is ffprobe's, so a wrong channel order fails | ||
| 121 | -/// here even when every channel holds the right signal. | ||
| 122 | -/// | ||
| 123 | -/// With `side_from_core`, channels 6 and 7 (the core's Ls and Rs in a 7.1 layout) | ||
| 124 | -/// are compared against ffmpeg's decode of the 5.1 source instead. ffmpeg 8.1 | ||
| 125 | -/// does not place them correctly once a dependent substream is appended to a | ||
| 126 | -/// core with a side pair: its side-left slot is silent and its side-right slot | ||
| 127 | -/// repeats the dependent's left channel. The core decode is ffmpeg's own | ||
| 128 | -/// unchanged 5.1 path, so it is the reference that ffmpeg itself gets right. | ||
| 129 | -fn check_against_ffmpeg(name: &str, ffprobe_name: &str, layout: &ChannelLayout, side_from_core: bool) { | ||
| 130 | - let stream = ec_testkit::fixture(&format!("audio/{name}")); | ||
| 131 | - let core_side = side_from_core.then(|| reference(&ec_testkit::fixture("audio/ac3dep-src-5.1.eac3"), 6)); | ||
| 132 | - assert_eq!(ffprobe_layout(&stream), ffprobe_name, "{name}: ffprobe channel_layout"); | ||
| 133 | - let data = std::fs::read(&stream).expect("fixture"); | ||
| 134 | - let (ours, channels, ours_layout) = decode(&data); | ||
| 135 | - assert_eq!(&ours_layout, layout, "{name}: layout"); | ||
| 136 | - assert_eq!(channels, layout.channel_count(), "{name}: channels"); | ||
| 137 | - | ||
| 138 | - let theirs = reference(&stream, channels); | ||
| 139 | - let frames = ours.len() / channels; | ||
| 140 | - assert_eq!(frames, theirs[0].len(), "{name}: frame count vs ffmpeg"); | ||
| 141 | - | ||
| 142 | - println!("{name} ({ffprobe_name}): per-channel correlation / RMS delta / max abs error"); | ||
| 143 | - for (ch, from_ffmpeg) in theirs.iter().enumerate() { | ||
| 144 | - let (expect, note) = match (&core_side, ch) { | ||
| 145 | - (Some(c), 6) => (&c[4], " (core Ls, from the 5.1 decode)"), | ||
| 146 | - (Some(c), 7) => (&c[5], " (core Rs, from the 5.1 decode)"), | ||
| 147 | - _ => (from_ffmpeg, ""), | ||
| 148 | - }; | ||
| 149 | - let a: Vec<f32> = ours[ch..].iter().step_by(channels).copied().collect(); | ||
| 150 | - let (corr, rms, max_abs) = correlation(&a, expect); | ||
| 151 | - println!(" ch{ch}: {corr:.6} / {rms:.3e} / {max_abs:.3e}{note}"); | ||
| 152 | - assert!(corr >= MIN_CORR, "{name} ch{ch}: correlation {corr:.6}"); | ||
| 153 | - assert!(rms <= MAX_RMS, "{name} ch{ch}: RMS delta {rms:.8}"); | ||
| 154 | - } | ||
| 155 | -} | ||
| 156 | - | ||
| 157 | -#[test] | ||
| 158 | -fn seven_one_matches_ffmpeg() { | ||
| 159 | - // Lrs/Rrs (BL/BR) are added to the core's side pair: 8 channels in 7.1 order. | ||
| 160 | - check_against_ffmpeg("ac3dep-7.1-48000.eac3", "7.1", &ChannelLayout::Surround7_1, true); | ||
| 161 | -} | ||
| 162 | - | ||
| 163 | -#[test] | ||
| 164 | -fn seven_one_wide_matches_ffmpeg() { | ||
| 165 | - // Lc/Rc (FLC/FRC) are added; canonical order puts them before the side pair. | ||
| 166 | - let wide = ChannelLayout::Custom(vec![ | ||
| 167 | - ChannelPosition::FrontLeft, | ||
| 168 | - ChannelPosition::FrontRight, | ||
| 169 | - ChannelPosition::FrontCenter, | ||
| 170 | - ChannelPosition::Lfe, | ||
| 171 | - ChannelPosition::FrontLeftOfCenter, | ||
| 172 | - ChannelPosition::FrontRightOfCenter, | ||
| 173 | - ChannelPosition::SideLeft, | ||
| 174 | - ChannelPosition::SideRight, | ||
| 175 | - ]); | ||
| 176 | - check_against_ffmpeg("ac3dep-7.1wide-48000.eac3", "7.1(wide-side)", &wide, true); | ||
| 177 | -} | ||
| 178 | - | ||
| 179 | -#[test] | ||
| 180 | -fn side_pair_replacement_matches_ffmpeg() { | ||
| 181 | - // Ls/Rs replace the core's side pair: 6 channels, not 8. | ||
| 182 | - let side = ChannelLayout::Custom(vec![ | ||
| 183 | - ChannelPosition::FrontLeft, | ||
| 184 | - ChannelPosition::FrontRight, | ||
| 185 | - ChannelPosition::FrontCenter, | ||
| 186 | - ChannelPosition::Lfe, | ||
| 187 | - ChannelPosition::SideLeft, | ||
| 188 | - ChannelPosition::SideRight, | ||
| 189 | - ]); | ||
| 190 | - check_against_ffmpeg("ac3dep-repl-48000.eac3", "5.1(side)", &side, false); | ||
| 191 | -} | ||
| 192 | - | ||
| 193 | -#[test] | ||
| 194 | -fn side_pair_replacement_carries_the_dependent_signal() { | ||
| 195 | - // The replaced pair is the dependent stereo source (880 Hz and 1320 Hz | ||
| 196 | - // sines), not the core's: compare the side channels with ffmpeg's decode | ||
| 197 | - // of that source on its own. | ||
| 198 | - let repl = ec_testkit::fixture("audio/ac3dep-repl-48000.eac3"); | ||
| 199 | - let src20 = ec_testkit::fixture("audio/ac3dep-src-2.0.eac3"); | ||
| 200 | - let data = std::fs::read(&repl).expect("fixture"); | ||
| 201 | - let (ours, channels, _) = decode(&data); | ||
| 202 | - assert_eq!(channels, 6, "replacement keeps the 5.1 channel count"); | ||
| 203 | - let source = reference(&src20, 2); | ||
| 204 | - for (side, src) in [(4usize, 0usize), (5, 1)] { | ||
| 205 | - let a: Vec<f32> = ours[side..].iter().step_by(channels).copied().collect(); | ||
| 206 | - let (corr, rms, _) = correlation(&a, &source[src]); | ||
| 207 | - println!("side channel {side} vs dependent source ch{src}: {corr:.6} / {rms:.3e}"); | ||
| 208 | - assert!(corr >= MIN_CORR, "side ch{side}: correlation {corr:.6} against the dependent source"); | ||
| 209 | - } | ||
| 210 | -} | ||
| 211 | - | ||
| 212 | -#[test] | ||
| 213 | -fn dependent_without_an_independent_is_named_not_decoded() { | ||
| 214 | - let stream = ec_testkit::fixture("audio/ac3dep-7.1-48000.eac3"); | ||
| 215 | - let data = std::fs::read(&stream).expect("fixture"); | ||
| 216 | - let packet = packets(&data)[0]; | ||
| 217 | - // The dependent frame alone, as a first substream. | ||
| 218 | - let size = frame_size(packet).expect("frame size"); | ||
| 219 | - let dep = &packet[size..]; | ||
| 220 | - let mut decoder = Ac3Decoder::new(); | ||
| 221 | - assert!(matches!( | ||
| 222 | - decoder.decode_frame(dep), | ||
| 223 | - Err(Error::Unsupported { .. }) | ||
| 224 | - )); | ||
| 225 | -} | ||
| 226 | - | ||
| 227 | -#[test] | ||
| 228 | -fn truncated_dependent_substream_is_an_error_not_a_panic() { | ||
| 229 | - let stream = ec_testkit::fixture("audio/ac3dep-7.1-48000.eac3"); | ||
| 230 | - let data = std::fs::read(&stream).expect("fixture"); | ||
| 231 | - let packet = packets(&data)[0]; | ||
| 232 | - for cut in [1, 2, 8, 100, 500] { | ||
| 233 | - let mut decoder = Ac3Decoder::new(); | ||
| 234 | - assert!(decoder.decode_frame(&packet[..packet.len() - cut]).is_err()); | ||
| 235 | - } | ||
| 236 | -} | ||
| 237 | - | ||
| 238 | -#[test] | ||
| 239 | -fn a_second_independent_substream_in_the_packet_is_still_refused() { | ||
| 240 | - let src20 = ec_testkit::fixture("audio/ac3dep-src-2.0.eac3"); | ||
| 241 | - let data = std::fs::read(&src20).expect("fixture"); | ||
| 242 | - let first = packets(&data)[0]; | ||
| 243 | - let mut two = first.to_vec(); | ||
| 244 | - two.extend_from_slice(first); | ||
| 245 | - let mut decoder = Ac3Decoder::new(); | ||
| 246 | - assert!(matches!( | ||
| 247 | - decoder.decode_frame(&two), | ||
| 248 | - Err(Error::Unsupported { .. }) | ||
| 249 | - )); | ||
| 250 | -} | ||
crates/ec-ac3/tests/it/encode_matrix.rsdeleted+0 -397
| @@ -1,397 +0,0 @@ | |||
| 1 | -//! Encoder coverage: frames our own decoder round-trips, and that ffmpeg | ||
| 2 | -//! synthetic signals and on the real 16-bit fixtures, at every rate and | ||
| 3 | -//! layout the encoder offers. | ||
| 4 | - | ||
| 5 | -use std::path::Path; | ||
| 6 | - | ||
| 7 | -use ec_ac3::{Ac3Decoder, Ac3Encoder, EncoderConfig}; | ||
| 8 | - | ||
| 9 | -/// 440 Hz tone for 1 s, then 0.5 s of silence, interleaved across `channels`. | ||
| 10 | -fn tone_then_silence(sample_rate: u32, channels: usize) -> Vec<f32> { | ||
| 11 | - let tone_samples = sample_rate as usize; | ||
| 12 | - let silence_samples = sample_rate as usize / 2; | ||
| 13 | - let mut out = Vec::with_capacity((tone_samples + silence_samples) * channels); | ||
| 14 | - for n in 0..tone_samples { | ||
| 15 | - let t = n as f32 / sample_rate as f32; | ||
| 16 | - let v = 0.5 * (2.0 * std::f32::consts::PI * 440.0 * t).sin(); | ||
| 17 | - for _ in 0..channels { | ||
| 18 | - out.push(v); | ||
| 19 | - } | ||
| 20 | - } | ||
| 21 | - out.extend(std::iter::repeat_n(0.0f32, silence_samples * channels)); | ||
| 22 | - out | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -fn correlation(a: &[f32], b: &[f32]) -> f64 { | ||
| 26 | - let n = a.len().min(b.len()); | ||
| 27 | - if n == 0 { | ||
| 28 | - return 0.0; | ||
| 29 | - } | ||
| 30 | - let (mut sa, mut sb, mut saa, mut sbb, mut sab) = (0.0, 0.0, 0.0, 0.0, 0.0); | ||
| 31 | - for i in 0..n { | ||
| 32 | - let (x, y) = (f64::from(a[i]), f64::from(b[i])); | ||
| 33 | - sa += x; | ||
| 34 | - sb += y; | ||
| 35 | - saa += x * x; | ||
| 36 | - sbb += y * y; | ||
| 37 | - sab += x * y; | ||
| 38 | - } | ||
| 39 | - let n = n as f64; | ||
| 40 | - let cov = sab / n - (sa / n) * (sb / n); | ||
| 41 | - let va = (saa / n - (sa / n).powi(2)).max(0.0); | ||
| 42 | - let vb = (sbb / n - (sb / n).powi(2)).max(0.0); | ||
| 43 | - if va <= 0.0 || vb <= 0.0 { | ||
| 44 | - return 1.0; // both flat (silence): trivially aligned | ||
| 45 | - } | ||
| 46 | - cov / (va.sqrt() * vb.sqrt()) | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -/// Encoder priming, `Ac3Encoder::encoder_delay`: the decoded stream starts | ||
| 50 | -/// with this many samples of silence per channel. | ||
| 51 | -const DELAY: usize = 256; | ||
| 52 | - | ||
| 53 | -/// Lag-searched correlation on one channel after the priming is dropped, | ||
| 54 | -/// +/- 64 samples of slack: a bug that shifts the audio by a block shows up | ||
| 55 | -/// as ~0 here, where an unbounded search on a periodic signal would hide it. | ||
| 56 | -fn best_lag_correlation(a: &[f32], b: &[f32]) -> f64 { | ||
| 57 | - let b = &b[DELAY.min(b.len())..]; | ||
| 58 | - let mut best = -1.0f64; | ||
| 59 | - for lag in -64i32..=64 { | ||
| 60 | - let (sa, sb): (&[f32], &[f32]) = if lag >= 0 { | ||
| 61 | - (&a[lag as usize..], b) | ||
| 62 | - } else { | ||
| 63 | - (a, &b[(-lag) as usize..]) | ||
| 64 | - }; | ||
| 65 | - best = best.max(correlation(sa, sb)); | ||
| 66 | - } | ||
| 67 | - best | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -/// Deinterleave channel `ch` of `channels`. | ||
| 71 | -fn take_channel(interleaved: &[f32], channels: usize, ch: usize) -> Vec<f32> { | ||
| 72 | - interleaved | ||
| 73 | - .iter() | ||
| 74 | - .skip(ch) | ||
| 75 | - .step_by(channels) | ||
| 76 | - .copied() | ||
| 77 | - .collect() | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -fn read_wav(path: &Path) -> (Vec<f32>, u32, usize) { | ||
| 81 | - let out = ec_testkit::ffmpeg() | ||
| 82 | - .args(["-v", "error", "-i"]) | ||
| 83 | - .arg(path) | ||
| 84 | - .args(["-f", "f32le", "-"]) | ||
| 85 | - .output() | ||
| 86 | - .expect("ffmpeg"); | ||
| 87 | - assert!(out.status.success(), "ffmpeg cannot read {}", path.display()); | ||
| 88 | - let samples = out | ||
| 89 | - .stdout | ||
| 90 | - .as_chunks::<4>().0.iter() | ||
| 91 | - .map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])) | ||
| 92 | - .collect(); | ||
| 93 | - let probe = ffprobe(path, "channels,sample_rate"); | ||
| 94 | - let field = |key: &str| probe_field(&probe, key).and_then(|v| v.parse::<u32>().ok()); | ||
| 95 | - (samples, field("sample_rate").unwrap(), field("channels").unwrap() as usize) | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -fn ffprobe(path: &Path, entries: &str) -> String { | ||
| 99 | - let out = ec_testkit::ffprobe() | ||
| 100 | - .args(["-v", "error", "-select_streams", "a:0", "-show_entries"]) | ||
| 101 | - .arg(format!("stream={entries}")) | ||
| 102 | - .args(["-of", "default=noprint_wrappers=1"]) | ||
| 103 | - .arg(path) | ||
| 104 | - .output() | ||
| 105 | - .expect("ffprobe"); | ||
| 106 | - String::from_utf8_lossy(&out.stdout).into_owned() | ||
| 107 | -} | ||
| 108 | - | ||
| 109 | -fn probe_field(text: &str, key: &str) -> Option<String> { | ||
| 110 | - text.lines() | ||
| 111 | - .find_map(|l| l.strip_prefix(key)?.strip_prefix('=')) | ||
| 112 | - .map(|v| v.trim().to_owned()) | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -/// ffmpeg's decode of an AC-3 file, asserting it voiced no complaint. | ||
| 116 | -fn oracle_decode(path: &Path) -> Vec<f32> { | ||
| 117 | - let out = ec_testkit::ffmpeg() | ||
| 118 | - .args(["-v", "warning", "-i"]) | ||
| 119 | - .arg(path) | ||
| 120 | - .args(["-f", "f32le", "-"]) | ||
| 121 | - .output() | ||
| 122 | - .expect("ffmpeg"); | ||
| 123 | - let stderr = String::from_utf8_lossy(&out.stderr); | ||
| 124 | - let complaint = stderr | ||
| 125 | - .lines() | ||
| 126 | - .any(|l| ["error", "invalid", "crc"].iter().any(|k| l.to_ascii_lowercase().contains(k))); | ||
| 127 | - assert!(!complaint, "ffmpeg complained about {}:\n{stderr}", path.display()); | ||
| 128 | - out.stdout | ||
| 129 | - .as_chunks::<4>().0.iter() | ||
| 130 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 131 | - .collect() | ||
| 132 | -} | ||
| 133 | - | ||
| 134 | -fn encode_with_stats(config: EncoderConfig, pcm: &[f32]) -> (Vec<u8>, ec_ac3::EncodeStats) { | ||
| 135 | - let mut enc = Ac3Encoder::new(config).unwrap(); | ||
| 136 | - enc.push_pcm_f32(pcm).unwrap(); | ||
| 137 | - enc.finish(); | ||
| 138 | - let mut out = Vec::new(); | ||
| 139 | - loop { | ||
| 140 | - match enc.next_packet() { | ||
| 141 | - Ok(frame) => out.extend_from_slice(&frame), | ||
| 142 | - Err(e) if e.is_eof() => break, | ||
| 143 | - Err(e) => panic!("{e}"), | ||
| 144 | - } | ||
| 145 | - } | ||
| 146 | - (out, enc.stats()) | ||
| 147 | -} | ||
| 148 | - | ||
| 149 | -fn encode(config: EncoderConfig, pcm: &[f32]) -> Vec<u8> { | ||
| 150 | - encode_with_stats(config, pcm).0 | ||
| 151 | -} | ||
| 152 | - | ||
| 153 | -/// Worst per-channel lag-searched correlation between `want` and `got`. | ||
| 154 | -fn worst_corr(want: &[f32], got: &[f32], channels: usize) -> f64 { | ||
| 155 | - (0..channels) | ||
| 156 | - .map(|ch| best_lag_correlation(&take_channel(want, channels, ch), &take_channel(got, channels, ch))) | ||
| 157 | - .fold(1.0, f64::min) | ||
| 158 | -} | ||
| 159 | - | ||
| 160 | -/// [`worst_corr`] over the full-bandwidth channels only: the LFE (family slot | ||
| 161 | -/// 3 of six) is band-limited to 7 bins (~660 Hz at 48 kHz) by the standard, | ||
| 162 | -/// so a fixture whose LFE carries full-band content can never correlate with | ||
| 163 | -/// it; that channel is gated on our decoder agreeing with the oracle instead. | ||
| 164 | -fn worst_fbw_corr(want: &[f32], got: &[f32], channels: usize) -> f64 { | ||
| 165 | - (0..channels) | ||
| 166 | - .filter(|&ch| !(channels == 6 && ch == 3)) | ||
| 167 | - .map(|ch| best_lag_correlation(&take_channel(want, channels, ch), &take_channel(got, channels, ch))) | ||
| 168 | - .fold(1.0, f64::min) | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -/// Deterministic white noise, `len` interleaved samples. | ||
| 172 | -fn noise(len: usize, seed: &mut u64) -> Vec<f32> { | ||
| 173 | - (0..len) | ||
| 174 | - .map(|_| { | ||
| 175 | - *seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); | ||
| 176 | - ((*seed >> 40) as f32 / (1u64 << 24) as f32) * 2.0 - 1.0 | ||
| 177 | - }) | ||
| 178 | - .collect() | ||
| 179 | -} | ||
| 180 | - | ||
| 181 | -fn decode_all(data: &[u8], channels: usize) -> Vec<f32> { | ||
| 182 | - let mut decoder = Ac3Decoder::new(); | ||
| 183 | - let mut out = Vec::new(); | ||
| 184 | - let mut pos = 0; | ||
| 185 | - while pos + 6 <= data.len() { | ||
| 186 | - let size = ec_ac3::frame_size(&data[pos..]).unwrap(); | ||
| 187 | - assert!(pos + size <= data.len(), "frame overruns the stream"); | ||
| 188 | - let frame = decoder | ||
| 189 | - .decode_frame(&data[pos..pos + size]) | ||
| 190 | - .unwrap_or_else(|e| panic!("frame at byte {pos}: {e}")); | ||
| 191 | - assert_eq!(frame.samples, 1536); | ||
| 192 | - assert_eq!(frame.channels(), channels); | ||
| 193 | - out.extend( | ||
| 194 | - frame.data[0] | ||
| 195 | - .as_chunks::<4>().0.iter() | ||
| 196 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])), | ||
| 197 | - ); | ||
| 198 | - pos += size; | ||
| 199 | - } | ||
| 200 | - out | ||
| 201 | -} | ||
| 202 | - | ||
| 203 | -#[test] | ||
| 204 | -fn silence_and_tone_frames_decode_in_our_decoder() { | ||
| 205 | - for &(sample_rate, channels) in &[(48_000u32, 1u16), (48_000, 2), (48_000, 6), (44_100, 2)] { | ||
| 206 | - let config = EncoderConfig { | ||
| 207 | - sample_rate, | ||
| 208 | - channels, | ||
| 209 | - bitrate_kbps: if channels >= 5 { 384 } else { 192 }, | ||
| 210 | - }; | ||
| 211 | - let pcm = tone_then_silence(sample_rate, channels as usize); | ||
| 212 | - let data = encode(config, &pcm); | ||
| 213 | - assert!(!data.is_empty(), "{sample_rate} Hz {channels}ch: no frames"); | ||
| 214 | - let decoded = decode_all(&data, channels as usize); | ||
| 215 | - assert!(!decoded.is_empty()); | ||
| 216 | - let corr = worst_corr(&pcm, &decoded, channels as usize); | ||
| 217 | - assert!(corr >= 0.95, "{sample_rate} Hz {channels}ch: corr {corr}"); | ||
| 218 | - } | ||
| 219 | -} | ||
| 220 | - | ||
| 221 | -#[test] | ||
| 222 | -fn oracle_accepts_our_frames() { | ||
| 223 | - let config = EncoderConfig { | ||
| 224 | - sample_rate: 48_000, | ||
| 225 | - channels: 2, | ||
| 226 | - bitrate_kbps: 192, | ||
| 227 | - }; | ||
| 228 | - let pcm = tone_then_silence(48_000, 2); | ||
| 229 | - let data = encode(config, &pcm); | ||
| 230 | - let dir = std::env::temp_dir(); | ||
| 231 | - let path = dir.join("ec_ac3_encode_matrix_oracle.ac3"); | ||
| 232 | - std::fs::write(&path, &data).unwrap(); | ||
| 233 | - | ||
| 234 | - let out = ec_testkit::ffmpeg() | ||
| 235 | - .args(["-v", "warning", "-i"]) | ||
| 236 | - .arg(&path) | ||
| 237 | - .args(["-f", "f32le", "-"]) | ||
| 238 | - .output() | ||
| 239 | - .expect("ffmpeg"); | ||
| 240 | - let stderr = String::from_utf8_lossy(&out.stderr); | ||
| 241 | - let complaint = stderr | ||
| 242 | - .lines() | ||
| 243 | - .any(|l| ["error", "invalid", "crc"].iter().any(|k| l.to_ascii_lowercase().contains(k))); | ||
| 244 | - assert!( | ||
| 245 | - !complaint, | ||
| 246 | - "ffmpeg complained about our frames:\n{stderr}" | ||
| 247 | - ); | ||
| 248 | - | ||
| 249 | - let decoded: Vec<f32> = out | ||
| 250 | - .stdout | ||
| 251 | - .as_chunks::<4>().0.iter() | ||
| 252 | - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 253 | - .collect(); | ||
| 254 | - for ch in 0..2 { | ||
| 255 | - let want = take_channel(&pcm, 2, ch); | ||
| 256 | - let got = take_channel(&decoded, 2, ch); | ||
| 257 | - let corr = best_lag_correlation(&want, &got); | ||
| 258 | - assert!(corr >= 0.95, "oracle channel {ch} corr {corr}"); | ||
| 259 | - } | ||
| 260 | - | ||
| 261 | - let _ = std::fs::remove_file(Path::new(&path)); | ||
| 262 | -} | ||
| 263 | - | ||
| 264 | - | ||
| 265 | -/// The full fixture matrix: every wav16 fixture at its layout's bit rate, | ||
| 266 | -/// through our decoder and the oracle, with ffprobe agreeing on what was | ||
| 267 | -/// asked for. Prints the per-file numbers and the stereo strategy shares. | ||
| 268 | -#[test] | ||
| 269 | -fn real_fixtures_round_trip_through_our_decoder_and_the_oracle() { | ||
| 270 | - let root = ec_testkit::root().join("audio"); | ||
| 271 | - let mut failures = Vec::new(); | ||
| 272 | - for layout in ["mono", "stereo", "5.1"] { | ||
| 273 | - for rate in [48_000u32, 44_100] { | ||
| 274 | - let path = root.join(format!("wav16-{layout}-{rate}.wav")); | ||
| 275 | - let (pcm, sample_rate, channels) = read_wav(&path); | ||
| 276 | - assert_eq!(sample_rate, rate); | ||
| 277 | - let bitrate_kbps = match channels { 1 => 96, 2 => 192, _ => 448 }; | ||
| 278 | - let config = EncoderConfig { sample_rate, channels: channels as u16, bitrate_kbps }; | ||
| 279 | - let (data, stats) = encode_with_stats(config, &pcm); | ||
| 280 | - let frame = ec_ac3::frame_size(&data).unwrap(); | ||
| 281 | - assert_eq!(data.len() % frame, 0, "{layout} {rate}: frames are not all {frame} bytes"); | ||
| 282 | - | ||
| 283 | - let decoded = decode_all(&data, channels); | ||
| 284 | - let ours = worst_fbw_corr(&pcm, &decoded, channels); | ||
| 285 | - let out = std::env::temp_dir().join(format!("ec_ac3_encode_matrix_{layout}_{rate}.ac3")); | ||
| 286 | - std::fs::write(&out, &data).unwrap(); | ||
| 287 | - let oracle_pcm = oracle_decode(&out); | ||
| 288 | - let oracle = worst_fbw_corr(&pcm, &oracle_pcm, channels); | ||
| 289 | - if channels == 6 { | ||
| 290 | - let lfe = correlation(&take_channel(&decoded, 6, 3), &take_channel(&oracle_pcm, 6, 3)); | ||
| 291 | - assert!(lfe >= 0.99, "{layout} {rate}: LFE ours vs oracle corr {lfe}"); | ||
| 292 | - } | ||
| 293 | - let probe = ffprobe(&out, "channels,channel_layout,sample_rate,bit_rate"); | ||
| 294 | - let _ = std::fs::remove_file(&out); | ||
| 295 | - | ||
| 296 | - let total = (stats.d15 + stats.d25 + stats.d45 + stats.reuse) as f64; | ||
| 297 | - let share = |n: u64| n as f64 / total * 100.0; | ||
| 298 | - eprintln!( | ||
| 299 | - "{layout} {rate}: {} frames, ours {ours:.4} oracle {oracle:.4}, csnroffst mean {:.1}, fill {:.1}%, blksw {}, D15 {:.1}% D25 {:.1}% D45 {:.1}% REUSE {:.1}%", | ||
| 300 | - stats.frames, | ||
| 301 | - stats.csnroffst_sum as f64 / stats.frames as f64, | ||
| 302 | - stats.bits_used as f64 / stats.bits_budget as f64 * 100.0, | ||
| 303 | - stats.blksw_blocks, | ||
| 304 | - share(stats.d15), share(stats.d25), share(stats.d45), share(stats.reuse), | ||
| 305 | - ); | ||
| 306 | - if ours < 0.99 || oracle < 0.99 { | ||
| 307 | - failures.push(format!("{layout} {rate}: ours {ours:.4} oracle {oracle:.4}")); | ||
| 308 | - } | ||
| 309 | - assert!(stats.bits_used * 10 > stats.bits_budget * 9, "{layout} {rate}: rate loop left bits unused: {stats:?}"); | ||
| 310 | - let expect_layout = match channels { 1 => "mono", 2 => "stereo", _ => "5.1" }; | ||
| 311 | - assert_eq!(probe_field(&probe, "channels").as_deref(), Some(channels.to_string().as_str()), "{probe}"); | ||
| 312 | - assert!(probe_field(&probe, "channel_layout").is_some_and(|l| l.starts_with(expect_layout)), "{probe}"); | ||
| 313 | - assert_eq!(probe_field(&probe, "sample_rate").as_deref(), Some(rate.to_string().as_str()), "{probe}"); | ||
| 314 | - assert_eq!(probe_field(&probe, "bit_rate").as_deref(), Some((bitrate_kbps * 1000).to_string().as_str()), "{probe}"); | ||
| 315 | - } | ||
| 316 | - } | ||
| 317 | - assert!(failures.is_empty(), "corr < 0.99:\n{}", failures.join("\n")); | ||
| 318 | -} | ||
| 319 | - | ||
| 320 | -/// A train of sharp attacks (decaying 2 kHz bursts, 25 per second) over a | ||
| 321 | -/// quiet noise floor: every attack is a block switch, and the stream still | ||
| 322 | -/// round-trips through both decoders. | ||
| 323 | -#[test] | ||
| 324 | -fn click_train_switches_blocks_and_still_round_trips() { | ||
| 325 | - let channels = 2; | ||
| 326 | - let mut pcm = noise(48_000 * channels, &mut 11u64); | ||
| 327 | - for v in &mut pcm { | ||
| 328 | - *v *= 0.01; | ||
| 329 | - } | ||
| 330 | - for n in (500..48_000).step_by(1900) { | ||
| 331 | - for i in 0..200 { | ||
| 332 | - let v = 0.8 * (-(i as f32) / 40.0).exp() * (i as f32 * 2.0 * std::f32::consts::PI * 2000.0 / 48_000.0).sin(); | ||
| 333 | - for ch in 0..channels { | ||
| 334 | - pcm[(n + i) * channels + ch] += v; | ||
| 335 | - } | ||
| 336 | - } | ||
| 337 | - } | ||
| 338 | - let config = EncoderConfig { sample_rate: 48_000, channels: 2, bitrate_kbps: 192 }; | ||
| 339 | - let (data, stats) = encode_with_stats(config, &pcm); | ||
| 340 | - assert!(stats.blksw_blocks >= 20, "{stats:?}"); | ||
| 341 | - let corr = worst_corr(&pcm, &decode_all(&data, channels), channels); | ||
| 342 | - eprintln!("click train: ours {corr:.4}, {stats:?}"); | ||
| 343 | - assert!(corr >= 0.95, "click train corr {corr}"); | ||
| 344 | - let out = std::env::temp_dir().join("ec_ac3_encode_matrix_clicks.ac3"); | ||
| 345 | - std::fs::write(&out, &data).unwrap(); | ||
| 346 | - let corr = worst_corr(&pcm, &oracle_decode(&out), channels); | ||
| 347 | - let _ = std::fs::remove_file(&out); | ||
| 348 | - eprintln!("click train: oracle {corr:.4}"); | ||
| 349 | - assert!(corr >= 0.95, "click train oracle corr {corr}"); | ||
| 350 | -} | ||
| 351 | - | ||
| 352 | -#[test] | ||
| 353 | -fn tone_at_32khz_round_trips() { | ||
| 354 | - let rate = 32_000; | ||
| 355 | - let pcm: Vec<f32> = (0..rate as usize * 2) | ||
| 356 | - .flat_map(|n| { | ||
| 357 | - let t = n as f32 / rate as f32; | ||
| 358 | - let v = 0.5 * (2.0 * std::f32::consts::PI * 440.0 * t).sin(); | ||
| 359 | - [v, 0.5 * v] | ||
| 360 | - }) | ||
| 361 | - .collect(); | ||
| 362 | - let config = EncoderConfig { sample_rate: rate, channels: 2, bitrate_kbps: 96 }; | ||
| 363 | - let data = encode(config, &pcm); | ||
| 364 | - let corr = worst_corr(&pcm, &decode_all(&data, 2), 2); | ||
| 365 | - assert!(corr >= 0.99, "32 kHz ours corr {corr}"); | ||
| 366 | - let out = std::env::temp_dir().join("ec_ac3_encode_matrix_32k.ac3"); | ||
| 367 | - std::fs::write(&out, &data).unwrap(); | ||
| 368 | - let corr = worst_corr(&pcm, &oracle_decode(&out), 2); | ||
| 369 | - let probe = ffprobe(&out, "sample_rate,bit_rate"); | ||
| 370 | - let _ = std::fs::remove_file(&out); | ||
| 371 | - assert!(corr >= 0.99, "32 kHz oracle corr {corr}"); | ||
| 372 | - assert_eq!(probe_field(&probe, "sample_rate").as_deref(), Some("32000"), "{probe}"); | ||
| 373 | - assert_eq!(probe_field(&probe, "bit_rate").as_deref(), Some("96000"), "{probe}"); | ||
| 374 | -} | ||
| 375 | - | ||
| 376 | -/// 200 random (rate, channels, bit rate) configurations, two frames of | ||
| 377 | -/// noise each: nothing panics and our decoder takes every frame. | ||
| 378 | -#[test] | ||
| 379 | -fn random_configs_never_panic_and_always_decode() { | ||
| 380 | - let (mut seed, mut noise_seed) = (99u64, 7u64); | ||
| 381 | - let mut next = |n: u64| { | ||
| 382 | - seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); | ||
| 383 | - (seed >> 33) % n | ||
| 384 | - }; | ||
| 385 | - for _ in 0..200 { | ||
| 386 | - let sample_rate = ec_ac3::tables::SAMPLE_RATE[next(3) as usize]; | ||
| 387 | - let channels = next(6) as u16 + 1; | ||
| 388 | - let bitrate_kbps = ec_ac3::tables::BIT_RATE_KBPS[next(ec_ac3::tables::BIT_RATE_KBPS.len() as u64) as usize]; | ||
| 389 | - let config = EncoderConfig { sample_rate, channels, bitrate_kbps }; | ||
| 390 | - let pcm = noise(1536 * 2 * channels as usize, &mut noise_seed); | ||
| 391 | - let data = encode(config, &pcm); | ||
| 392 | - let decoded = decode_all(&data, channels as usize); | ||
| 393 | - assert!(decoded.len() >= pcm.len() + 256, "{config:?}: {} of {} samples", decoded.len(), pcm.len()); | ||
| 394 | - } | ||
| 395 | -} | ||
| 396 | - | ||
| 397 | - | ||
crates/ec-ac3/tests/it/main.rsmodified+0 -3
| @@ -1,9 +1,6 @@ | |||
| 1 | //! One integration-test binary for ec-ac3; each module is one former `tests/*.rs` file. | 1 | //! One integration-test binary for ec-ac3; each module is one former `tests/*.rs` file. |
| 2 | #![forbid(unsafe_code)] | 2 | #![forbid(unsafe_code)] |
| 3 | 3 | ||
| 4 | -mod decode_matrix; | ||
| 5 | -mod dependent; | ||
| 6 | -mod encode_matrix; | ||
| 7 | mod ffmpeg_parity; | 4 | mod ffmpeg_parity; |
| 8 | mod packet_walk; | 5 | mod packet_walk; |
| 9 | mod real_library; | 6 | mod real_library; |
crates/ec-dts/devscripts/cmp_all.shdeleted+0 -23
| @@ -1,23 +0,0 @@ | |||
| 1 | -#!/usr/bin/env bash | ||
| 2 | -# Decode each FATE sample with ec-dts and ffmpeg (-flags +bitexact, integer | ||
| 3 | -# path) and compare. Needs the dec example built (release). | ||
| 4 | -set -u | ||
| 5 | -d=${1:-${EC_FIXTURES:-$HOME/fixtures}/open/fate/dts} | ||
| 6 | -FF=${EC_FFMPEG:-$HOME/.cache/ec-ffmpeg/ffmpeg} | ||
| 7 | -FP=$(dirname "$FF")/ffprobe | ||
| 8 | -dec=${CARGO_TARGET_DIR:-target}/release/examples/dec | ||
| 9 | -here=$(cd "$(dirname "$0")" && pwd) | ||
| 10 | -out=${TMPDIR:-/tmp}/dtscmp | ||
| 11 | -mkdir -p "$out" | ||
| 12 | -for f in "$d"/*; do | ||
| 13 | - b=$(basename "$f") | ||
| 14 | - case "$b" in *.f32|*.pcm) continue;; esac | ||
| 15 | - echo "== $b" | ||
| 16 | - "$dec" "$f" "$out/$b.ours" 2>&1 | tail -3 | ||
| 17 | - co="-core_only 1"; case "$b" in xch*|dts_es*|x96*) co="";; esac | ||
| 18 | - "$FF" -v error -y -flags +bitexact $co -i "$f" -f s32le "$out/$b.ref" 2>&1 | tail -2 | ||
| 19 | - nch=$(ffprobe -v error -show_entries stream=channels -of csv=p=0 "$f") | ||
| 20 | - perm=""; [ "$nch" = 7 ] && perm="0,1,2,3,6,4,5" | ||
| 21 | - skip=0; case "$b" in x96*) skip=2048;; *.dtshd) skip=1024;; esac | ||
| 22 | - python3 "$here/compare.py" "$out/$b.ours" "$out/$b.ref" "$nch" s32 "$perm" "$skip" | head -${LINES_MAX:-12} | ||
| 23 | -done | ||
crates/ec-dts/devscripts/cmp_float.shdeleted+0 -22
| @@ -1,22 +0,0 @@ | |||
| 1 | -#!/usr/bin/env bash | ||
| 2 | -# Compare ec-dts against ffmpeg's default (floating point) decoder path. | ||
| 3 | -set -u | ||
| 4 | -d=${1:-${EC_FIXTURES:-$HOME/fixtures}/open/fate/dts} | ||
| 5 | -FF=${EC_FFMPEG:-$HOME/.cache/ec-ffmpeg/ffmpeg} | ||
| 6 | -FP=$(dirname "$FF")/ffprobe | ||
| 7 | -dec=${CARGO_TARGET_DIR:-target}/release/examples/dec | ||
| 8 | -here=$(cd "$(dirname "$0")" && pwd) | ||
| 9 | -out=${TMPDIR:-/tmp}/dtscmpf | ||
| 10 | -mkdir -p "$out" | ||
| 11 | -for f in "$d"/*.dtshd "$d"/dts_es.dts "$here"/../fixtures/*.dts; do | ||
| 12 | - b=$(basename "$f") | ||
| 13 | - case "$b" in xll*|xbr*) continue;; esac | ||
| 14 | - co="-core_only 1"; case "$b" in xch*|dts_es*|x96*|*.dts) co="";; esac | ||
| 15 | - "$dec" "$f" "$out/$b.ours" 2>/dev/null | ||
| 16 | - "$FF" -v error -y $co -i "$f" -f f32le "$out/$b.ref" 2>&1 | tail -2 | ||
| 17 | - nch=$(ffprobe -v error -show_entries stream=channels -of csv=p=0 "$f") | ||
| 18 | - perm=""; [ "$nch" = 7 ] && perm="0,1,2,3,6,4,5" | ||
| 19 | - skip=0; case "$b" in x96*) skip=2048;; *.dtshd) skip=1024;; esac | ||
| 20 | - echo "== $b" | ||
| 21 | - python3 "$here/compare.py" "$out/$b.ours" "$out/$b.ref" "$nch" f32 "$perm" "$skip" | sed -n 2p | ||
| 22 | -done | ||
crates/ec-dts/devscripts/compare.pydeleted+0 -44
| @@ -1,44 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -"""Compare ec-dts output (f32le, interleaved, 24-bit scaled by 2^-23) against | ||
| 3 | -an ffmpeg decode (s32le or f32le, interleaved). | ||
| 4 | - | ||
| 5 | -usage: compare.py ours.f32 ref.raw nch kind [perm [skip]] | ||
| 6 | - kind: s32 (ffmpeg -flags +bitexact, 24-bit << 8) or f32 (ffmpeg default float) | ||
| 7 | - perm: comma list, for each reference channel the index of our channel | ||
| 8 | - skip: samples per channel ours leads the reference by (ffmpeg trims the | ||
| 9 | - start of .dtshd files by 1024) | ||
| 10 | -Exit status 0 when every sample is identical. | ||
| 11 | -""" | ||
| 12 | -import sys | ||
| 13 | -from array import array | ||
| 14 | - | ||
| 15 | -nch = int(sys.argv[3]) | ||
| 16 | -kind = sys.argv[4] | ||
| 17 | -perm = [int(x) for x in sys.argv[5].split(",")] if len(sys.argv) > 5 and sys.argv[5] else list(range(nch)) | ||
| 18 | -ours = array("f") | ||
| 19 | -with open(sys.argv[1], "rb") as f: | ||
| 20 | - ours.frombytes(f.read()) | ||
| 21 | -ref = array("i" if kind == "s32" else "f") | ||
| 22 | -with open(sys.argv[2], "rb") as f: | ||
| 23 | - ref.frombytes(f.read()) | ||
| 24 | -skip = int(sys.argv[6]) if len(sys.argv) > 6 else 0 | ||
| 25 | -ours = ours[skip * nch:] | ||
| 26 | -n = len(ours) // nch | ||
| 27 | -m = len(ref) // nch | ||
| 28 | -k = min(n, m) | ||
| 29 | -mx = [0] * nch | ||
| 30 | -nz = [0] * nch | ||
| 31 | -for i in range(k): | ||
| 32 | - for c in range(nch): | ||
| 33 | - o = round(ours[i * nch + perm[c]] * 8388608.0) | ||
| 34 | - r = ref[i * nch + c] | ||
| 35 | - r = (r >> 8) if kind == "s32" else round(r * 8388608.0) | ||
| 36 | - d = abs(o - r) | ||
| 37 | - if d: | ||
| 38 | - nz[c] += 1 | ||
| 39 | - if d > mx[c]: | ||
| 40 | - mx[c] = d | ||
| 41 | -print(f"samples/ch ours={n} ref={m} compared={k} ch={nch}") | ||
| 42 | -print(f"max abs diff (24-bit LSB) = {max(mx)}; mismatching samples = {sum(nz)} of {k * nch}") | ||
| 43 | -print(" per channel max:", mx, "nonzero:", nz) | ||
| 44 | -sys.exit(0 if max(mx) == 0 and abs(n - m) < 1 else 1) | ||
crates/ec-dts/examples/dec.rsdeleted+0 -64
| @@ -1,64 +0,0 @@ | |||
| 1 | -//! Decode a raw DTS stream (or the STRMDATA of a `.dtshd` file) to | ||
| 2 | -//! interleaved `f32le` on stdout. Dev tool for comparing against ffmpeg. | ||
| 3 | -//! | ||
| 4 | -//! `dec <file> [out.f32]`; frames are split with `ec_dts::frame_size`. | ||
| 5 | - | ||
| 6 | -use ec_dts::DtsDecoder; | ||
| 7 | -use std::io::Write; | ||
| 8 | - | ||
| 9 | -fn strmdata(buf: &[u8]) -> &[u8] { | ||
| 10 | - if !buf.starts_with(b"DTSHDHDR") { | ||
| 11 | - return buf; | ||
| 12 | - } | ||
| 13 | - let mut p = 0; | ||
| 14 | - while p + 16 <= buf.len() { | ||
| 15 | - let tag = &buf[p..p + 8]; | ||
| 16 | - let size = u64::from_be_bytes(buf[p + 8..p + 16].try_into().unwrap()) as usize; | ||
| 17 | - if tag == b"STRMDATA" { | ||
| 18 | - return &buf[p + 16..(p + 16 + size).min(buf.len())]; | ||
| 19 | - } | ||
| 20 | - p += 16 + size; | ||
| 21 | - } | ||
| 22 | - buf | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -fn main() { | ||
| 26 | - let args: Vec<String> = std::env::args().collect(); | ||
| 27 | - let data = std::fs::read(&args[1]).unwrap(); | ||
| 28 | - let data = strmdata(&data); | ||
| 29 | - let mut dec = DtsDecoder::new(); | ||
| 30 | - let mut out: Box<dyn Write> = match args.get(2) { | ||
| 31 | - Some(p) => Box::new(std::io::BufWriter::new(std::fs::File::create(p).unwrap())), | ||
| 32 | - None => Box::new(std::io::sink()), | ||
| 33 | - }; | ||
| 34 | - let mut pos = 0; | ||
| 35 | - let mut frames = 0; | ||
| 36 | - let mut errors = 0; | ||
| 37 | - while pos + 4 < data.len() { | ||
| 38 | - let Some((s, _)) = ec_dts::find_sync(&data[pos..]) else { break }; | ||
| 39 | - pos += s; | ||
| 40 | - let hdr = match ec_dts::parse_frame_header(&data[pos..]) { | ||
| 41 | - Ok(h) => h, | ||
| 42 | - Err(_) => { | ||
| 43 | - pos += 1; | ||
| 44 | - continue; | ||
| 45 | - } | ||
| 46 | - }; | ||
| 47 | - // The frame plus whatever follows up to the next core sync word. | ||
| 48 | - let end = ec_dts::find_sync(&data[pos + hdr.stream_frame_size.min(data.len() - pos)..]) | ||
| 49 | - .map(|(o, _)| pos + hdr.stream_frame_size + o) | ||
| 50 | - .unwrap_or(data.len()); | ||
| 51 | - match dec.decode_frame(&data[pos..end]) { | ||
| 52 | - Ok(f) => { | ||
| 53 | - frames += 1; | ||
| 54 | - out.write_all(&f.data[0]).unwrap(); | ||
| 55 | - } | ||
| 56 | - Err(e) => { | ||
| 57 | - errors += 1; | ||
| 58 | - eprintln!("frame at {pos}: {e}"); | ||
| 59 | - } | ||
| 60 | - } | ||
| 61 | - pos = end; | ||
| 62 | - } | ||
| 63 | - eprintln!("frames={frames} errors={errors} info={:?}", dec.frame_info().map(|i| (i.sample_rate, i.header.channels, i.extensions, i.xll))); | ||
| 64 | -} | ||
crates/ec-dts/gen_dts_tables.pymodified+7 -41
| @@ -7,17 +7,11 @@ https://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.06.01_60/ts_102114v | |||
| 7 | 7 | ||
| 8 | Usage: | 8 | Usage: |
| 9 | pdftotext -layout ts_102114v010601p.pdf ts102114.txt | 9 | pdftotext -layout ts_102114v010601p.pdf ts102114.txt |
| 10 | - python3 -I crates/ec-dts/gen_dts_tables.py ts102114.txt \ | 10 | + python3 -I tools/gen_dts_tables.py ts102114.txt crates/ec-dts/src/tables_data.rs |
| 11 | - crates/ec-dts/src/tables_data.rs crates/ec-dts/tests/spec_ts102114_tables.txt | ||
| 12 | 11 | ||
| 13 | The spec text (decimal commas, "1 926" style thousands separators) is parsed | 12 | The spec text (decimal commas, "1 926" style thousands separators) is parsed |
| 14 | -here; nothing is read from any other decoder. Two files are written: | 13 | +here; nothing is read from any other decoder. One file is written: |
| 15 | - | 14 | +tables_data.rs, the Rust statics, after the conversions listed below. |
| 16 | -* tables_data.rs: the Rust statics, after the conversions listed below. | ||
| 17 | -* spec_ts102114_tables.txt: the raw numbers exactly as the spec prints them | ||
| 18 | - (one line per table, with clause references). tests/spec_tables.rs applies | ||
| 19 | - the same conversions independently in Rust and asserts equality with the | ||
| 20 | - statics, so the committed numbers are checked against the committed text. | ||
| 21 | 15 | ||
| 22 | Clauses used (all normative): | 16 | Clauses used (all normative): |
| 23 | Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS | 17 | Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS |
| @@ -28,7 +22,6 @@ Clauses used (all normative): | |||
| 28 | A12..E12, A4..D4) -> HUFF_SRC | 22 | A12..E12, A4..D4) -> HUFF_SRC |
| 29 | D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 | 23 | D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 |
| 30 | D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 | 24 | D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 |
| 31 | - D.11 Downmix scale factor look-up (DmixTable) -> DMIXTABLE | ||
| 32 | 25 | ||
| 33 | Conversions (implementation layout choices, not spec content): | 26 | Conversions (implementation layout choices, not spec content): |
| 34 | * invalid entries -> 0; tables are padded to their power-of-two length with 0. | 27 | * invalid entries -> 0; tables are padded to their power-of-two length with 0. |
| @@ -43,7 +36,6 @@ Conversions (implementation layout choices, not spec content): | |||
| 43 | k = 4q+p -> index [q, 128+q, 255-q, 127-q][p]. | 36 | k = 4q+p -> index [q, 128+q, 255-q, 127-q][p]. |
| 44 | * FIR_64: round-half-up(coef * 2^29), sign negated unless (index/32) % 4 == 0 | 37 | * FIR_64: round-half-up(coef * 2^29), sign negated unless (index/32) % 4 == 0 |
| 45 | (QMF cosine modulation sign), index 0-based (spec "Coef #" is 1-based). | 38 | (QMF cosine modulation sign), index 0-based (spec "Coef #" is 1-based). |
| 46 | - * DMIXTABLE: a leading 0 then the 241 DmixTable entries. | ||
| 47 | """ | 39 | """ |
| 48 | import re | 40 | import re |
| 49 | import sys | 41 | import sys |
| @@ -55,7 +47,7 @@ def D(s): | |||
| 55 | 47 | ||
| 56 | 48 | ||
| 57 | def main(): | 49 | def main(): |
| 58 | - spec_path, out_rs, out_spec = sys.argv[1:4] | 50 | + spec_path, out_rs = sys.argv[1:3] |
| 59 | with open(spec_path, encoding='utf-8') as f: | 51 | with open(spec_path, encoding='utf-8') as f: |
| 60 | L = f.read().split('\n') | 52 | L = f.read().split('\n') |
| 61 | assert any('V1.6.1 (2019-08)' in l for l in L[:3000]), 'spec is not V1.6.1' | 53 | assert any('V1.6.1 (2019-08)' in l for l in L[:3000]), 'spec is not V1.6.1' |
| @@ -73,7 +65,7 @@ def main(): | |||
| 73 | ('d21', r'^D\.2\.1 '), ('d22', r'^D\.2\.2 '), ('d3', r'^D\.3 '), | 65 | ('d21', r'^D\.2\.1 '), ('d22', r'^D\.2\.2 '), ('d3', r'^D\.3 '), |
| 74 | ('d4', r'^D\.4 '), ('d5', r'^D\.5 '), ('d6', r'^D\.6 '), | 66 | ('d4', r'^D\.4 '), ('d5', r'^D\.5 '), ('d6', r'^D\.6 '), |
| 75 | ('d7', r'^D\.7 '), ('d8', r'^D\.8 '), ('d9', r'^D\.9 '), | 67 | ('d7', r'^D\.7 '), ('d8', r'^D\.8 '), ('d9', r'^D\.9 '), |
| 76 | - ('d10', r'^D\.10 '), ('d11x', r'^D\.11 ')]: | 68 | + ('d10', r'^D\.10 ')]: |
| 77 | s[key] = find(pat, a_d) | 69 | s[key] = find(pat, a_d) |
| 78 | 70 | ||
| 79 | raw = [] # (name, clause, [strings]) | 71 | raw = [] # (name, clause, [strings]) |
| @@ -242,28 +234,6 @@ def main(): | |||
| 242 | assert sorted(fir) == list(range(1, 1025)) | 234 | assert sorted(fir) == list(range(1, 1025)) |
| 243 | raw.append(('FIR_64', 'D.9', [fir[i] for i in range(1, 1025)])) | 235 | raw.append(('FIR_64', 'D.9', [fir[i] for i in range(1, 1025)])) |
| 244 | 236 | ||
| 245 | - # ---- D.11 downmix look-up | ||
| 246 | - dm = {} | ||
| 247 | - for l in L[s['d11x']:]: | ||
| 248 | - m = re.match(r'^\s+(\d+)\s+(-?[\d,]+)\s+([\d,]+)\s+(\d+)\s+(\d+|N/A)\s+(\d+|N/A)\s*$', l) | ||
| 249 | - if m: | ||
| 250 | - dm[int(m.group(1))] = m.group(4) | ||
| 251 | - assert sorted(dm) == list(range(241)), len(dm) | ||
| 252 | - raw.append(('DMIXTABLE', 'D.11 (DmixTable column)', [dm[i] for i in range(241)])) | ||
| 253 | - | ||
| 254 | - # ---- write the raw spec numbers | ||
| 255 | - with open(out_spec, 'w') as f: | ||
| 256 | - f.write('# Numbers exactly as printed in ETSI TS 102 114 V1.6.1 (2019-08), Annex D / clause 5.\n') | ||
| 257 | - f.write('# Written by crates/ec-dts/gen_dts_tables.py; decimal commas written as points.\n') | ||
| 258 | - f.write('# table NAME | clause | values... (invalid entries kept as the word "invalid")\n') | ||
| 259 | - f.write('# huff TABLE | clause | level:length:code ... (code = value of the code word)\n') | ||
| 260 | - for name, cl, vals in raw: | ||
| 261 | - f.write('table %s | %s | %s\n' % (name, cl, ' '.join(vals))) | ||
| 262 | - for tname, e in huff_raw: | ||
| 263 | - tn, _, note = tname.partition(' ') | ||
| 264 | - f.write('huff %s | D.5%s | %s\n' % (tn, ' ' + note if note else '', | ||
| 265 | - ' '.join('%d:%d:%d' % x for x in e))) | ||
| 266 | - | ||
| 267 | # ---- convert and write the Rust file | 237 | # ---- convert and write the Rust file |
| 268 | out = [] | 238 | out = [] |
| 269 | 239 | ||
| @@ -281,11 +251,9 @@ def main(): | |||
| 281 | R = {n: v for n, _, v in raw} | 251 | R = {n: v for n, _, v in raw} |
| 282 | out.append('//! Constant tables for DTS Coherent Acoustics (ETSI TS 102 114).') | 252 | out.append('//! Constant tables for DTS Coherent Acoustics (ETSI TS 102 114).') |
| 283 | out.append('//!') | 253 | out.append('//!') |
| 284 | - out.append('//! GENERATED by crates/ec-dts/gen_dts_tables.py from the numeric tables of') | 254 | + out.append('//! GENERATED by tools/gen_dts_tables.py from the numeric tables of') |
| 285 | out.append('//! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on') | 255 | out.append('//! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on') |
| 286 | - out.append('//! it. The raw printed numbers are committed in') | 256 | + out.append('//! it. Do not edit by hand.') |
| 287 | - out.append('//! tests/spec_ts102114_tables.txt and tests/spec_tables.rs checks every') | ||
| 288 | - out.append('//! table here against them. Do not edit by hand.') | ||
| 289 | out.append('//!') | 257 | out.append('//!') |
| 290 | out.append('//! The tables the standard does not print numerically (ADPCM and') | 258 | out.append('//! The tables the standard does not print numerically (ADPCM and') |
| 291 | out.append('//! high-frequency VQ codebooks, which it says are too large to include) or') | 259 | out.append('//! high-frequency VQ codebooks, which it says are too large to include) or') |
| @@ -318,8 +286,6 @@ def main(): | |||
| 318 | out.append(' ' + ', '.join(lfe[perm[j]] for j in range(k, k + 4)) + ',') | 286 | out.append(' ' + ', '.join(lfe[perm[j]] for j in range(k, k + 4)) + ',') |
| 319 | out.append('];') | 287 | out.append('];') |
| 320 | out.append('') | 288 | out.append('') |
| 321 | - emit('DMIXTABLE', 'u16', [0] + [int(dm[i]) for i in range(241)], | ||
| 322 | - 'Downmix scale factors, ETSI TS 102 114 D.11 (DmixTable, preceded by a 0 entry).') | ||
| 323 | out.append('/// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114') | 289 | out.append('/// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114') |
| 324 | out.append('/// D.5: quantizer index books (10 books x group), bit allocation (5 x 12),') | 290 | out.append('/// D.5: quantizer index books (10 books x group), bit allocation (5 x 12),') |
| 325 | out.append('/// scale factors (5 x 129), transition mode (4 x 4).') | 291 | out.append('/// scale factors (5 x 129), transition mode (4 x 4).') |
crates/ec-dts/src/lib.rsmodified+5 -9
| @@ -28,10 +28,10 @@ | |||
| 28 | //! [`Error::Corrupt`] and a construct this build does not implement is | 28 | //! [`Error::Corrupt`] and a construct this build does not implement is |
| 29 | //! [`Error::Unsupported`] naming what and why. No input panics. | 29 | //! [`Error::Unsupported`] naming what and why. No input panics. |
| 30 | //! | 30 | //! |
| 31 | -//! The constant tables in [`tables_data`] are generated by | 31 | +//! The constant tables in `tables_data.rs` are generated by |
| 32 | //! `crates/ec-dts/gen_dts_tables.py` from the numeric tables printed in ETSI TS 102 114 | 32 | //! `crates/ec-dts/gen_dts_tables.py` from the numeric tables printed in ETSI TS 102 114 |
| 33 | -//! V1.6.1 and checked against them by `tests/spec_tables.rs`; the few tables | 33 | +//! V1.6.1; the few tables the standard does not print usably are in |
| 34 | -//! the standard does not print usably are in `tables_residual.rs`. | 34 | +//! `tables_residual.rs`. |
| 35 | 35 | ||
| 36 | #![forbid(unsafe_code)] | 36 | #![forbid(unsafe_code)] |
| 37 | #![warn(missing_docs)] | 37 | #![warn(missing_docs)] |
| @@ -46,14 +46,10 @@ mod header; | |||
| 46 | mod huff; | 46 | mod huff; |
| 47 | mod math; | 47 | mod math; |
| 48 | #[allow(missing_docs, clippy::excessive_precision)] | 48 | #[allow(missing_docs, clippy::excessive_precision)] |
| 49 | -pub mod tables_data; | 49 | +mod tables_data; |
| 50 | mod tables_residual; | 50 | mod tables_residual; |
| 51 | 51 | ||
| 52 | pub use crate::core::Extensions; | 52 | pub use crate::core::Extensions; |
| 53 | pub use decoder::{DtsDecoder, FrameInfo, Options}; | 53 | pub use decoder::{DtsDecoder, FrameInfo, Options}; |
| 54 | pub use ec_core::Error; | 54 | pub use ec_core::Error; |
| 55 | -pub use header::{ | 55 | +pub use header::{find_sync, frame_size, parse_frame_header, FrameHeader, StreamFormat}; |
| 56 | - find_sync, frame_size, parse_frame_header, to_canonical, FrameHeader, StreamFormat, | ||
| 57 | - BIT_RATES, CHANNELS, PCM_RESOLUTION, SAMPLE_RATES, SYNC_CORE, SYNC_CORE_14_BE, | ||
| 58 | - SYNC_CORE_14_LE, SYNC_CORE_LE, SYNC_EXSS, | ||
| 59 | -}; | ||
crates/ec-dts/src/tables_data.rsmodified+1 -28
| @@ -2,9 +2,7 @@ | |||
| 2 | //! | 2 | //! |
| 3 | //! GENERATED by crates/ec-dts/gen_dts_tables.py from the numeric tables of | 3 | //! GENERATED by crates/ec-dts/gen_dts_tables.py from the numeric tables of |
| 4 | //! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on | 4 | //! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on |
| 5 | -//! it. The raw printed numbers are committed in | 5 | +//! it. Do not edit by hand. |
| 6 | -//! tests/spec_ts102114_tables.txt and tests/spec_tables.rs checks every | ||
| 7 | -//! table here against them. Do not edit by hand. | ||
| 8 | //! | 6 | //! |
| 9 | //! The tables the standard does not print numerically (ADPCM and | 7 | //! The tables the standard does not print numerically (ADPCM and |
| 10 | //! high-frequency VQ codebooks, which it says are too large to include) or | 8 | //! high-frequency VQ codebooks, which it says are too large to include) or |
| @@ -265,31 +263,6 @@ pub static LFE_FIR_128: [f32; 256] = [ | |||
| 265 | 1.724460535e-02, 4.796448052e-01, 4.850307405e-01, 1.805862412e-02, | 263 | 1.724460535e-02, 4.796448052e-01, 4.850307405e-01, 1.805862412e-02, |
| 266 | ]; | 264 | ]; |
| 267 | 265 | ||
| 268 | -/// Downmix scale factors, ETSI TS 102 114 D.11 (DmixTable, preceded by a 0 entry). | ||
| 269 | -pub static DMIXTABLE: [u16; 242] = [ | ||
| 270 | - 0, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, | ||
| 271 | - 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 116, | ||
| 272 | - 123, 130, 138, 146, 155, 164, 174, 184, 195, 207, 219, 232, | ||
| 273 | - 246, 260, 276, 292, 309, 328, 347, 368, 389, 413, 437, 463, | ||
| 274 | - 490, 519, 550, 583, 617, 654, 693, 734, 777, 823, 872, 924, | ||
| 275 | - 978, 1036, 1066, 1098, 1130, 1163, 1197, 1232, 1268, 1305, 1343, 1382, | ||
| 276 | - 1422, 1464, 1506, 1550, 1596, 1642, 1690, 1740, 1790, 1843, 1896, 1952, | ||
| 277 | - 2009, 2068, 2128, 2190, 2254, 2320, 2388, 2457, 2529, 2603, 2679, 2757, | ||
| 278 | - 2838, 2920, 3006, 3093, 3184, 3277, 3372, 3471, 3572, 3677, 3784, 3894, | ||
| 279 | - 4008, 4125, 4246, 4370, 4497, 4629, 4764, 4903, 5046, 5193, 5345, 5501, | ||
| 280 | - 5662, 5827, 5912, 5997, 6084, 6172, 6262, 6353, 6445, 6538, 6633, 6729, | ||
| 281 | - 6827, 6925, 7026, 7128, 7231, 7336, 7442, 7550, 7659, 7771, 7883, 7997, | ||
| 282 | - 8113, 8231, 8350, 8471, 8594, 8719, 8845, 8973, 9103, 9235, 9369, 9505, | ||
| 283 | - 9643, 9783, 9924, 10068, 10214, 10362, 10512, 10665, 10819, 10976, 11135, 11297, | ||
| 284 | - 11460, 11627, 11795, 11966, 12139, 12315, 12494, 12675, 12859, 13045, 13234, 13426, | ||
| 285 | - 13621, 13818, 14018, 14222, 14428, 14637, 14849, 15064, 15283, 15504, 15729, 15957, | ||
| 286 | - 16188, 16423, 16661, 16902, 17147, 17396, 17648, 17904, 18164, 18427, 18694, 18965, | ||
| 287 | - 19240, 19519, 19802, 20089, 20380, 20675, 20975, 21279, 21587, 21900, 22218, 22540, | ||
| 288 | - 22867, 23170, 23534, 23875, 24221, 24573, 24929, 25290, 25657, 26029, 26406, 26789, | ||
| 289 | - 27177, 27571, 27970, 28376, 28787, 29205, 29628, 30057, 30493, 30935, 31383, 31838, | ||
| 290 | - 32300, 32768, | ||
| 291 | -]; | ||
| 292 | - | ||
| 293 | /// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114 | 266 | /// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114 |
| 294 | /// D.5: quantizer index books (10 books x group), bit allocation (5 x 12), | 267 | /// D.5: quantizer index books (10 books x group), bit allocation (5 x 12), |
| 295 | /// scale factors (5 x 129), transition mode (4 x 4). | 268 | /// scale factors (5 x 129), transition mode (4 x 4). |
crates/ec-dts/src/tables_residual.rsmodified+2 -0
| @@ -4301,3 +4301,5 @@ pub static LFE_FIR_64: [i32; 256] = [ | |||
| 4301 | 24426, -106412, -437356, 4549871, 4819584, -350658, -139125, 28376, | 4301 | 24426, -106412, -437356, 4549871, 4819584, -350658, -139125, 28376, |
| 4302 | 25721, -116977, -410365, 4641355, 4731293, -381475, -127884, 27038, | 4302 | 25721, -116977, -410365, 4641355, 4731293, -381475, -127884, 27038, |
| 4303 | ]; | 4303 | ]; |
| 4304 | +const _: () = assert!(ADPCM_VB.len() == 16384); | ||
| 4305 | +const _: () = assert!(HIGH_FREQ_VQ.len() == 32768); | ||
crates/ec-dts/tests/fate_vectors.rsdeleted+0 -120
| @@ -1,120 +0,0 @@ | |||
| 1 | -#![allow(clippy::chunks_exact_to_as_chunks, clippy::manual_is_multiple_of)] | ||
| 2 | -//! The public FFmpeg FATE DTS samples (the dcadec conformance suite) against | ||
| 3 | -//! ffmpeg's integer decoder, sample for sample: core 5.1, XCH (6.1), X96 (96 | ||
| 4 | -//! kHz, alone and with XCH), the core inside XBR and XLL (DTS-HD) streams and | ||
| 5 | -//! a DTS-ES elementary stream. | ||
| 6 | -//! | ||
| 7 | - | ||
| 8 | -use std::path::Path; | ||
| 9 | - | ||
| 10 | -use ec_dts::DtsDecoder; | ||
| 11 | - | ||
| 12 | -/// The STRMDATA chunk of a `.dtshd` file, or the whole buffer. | ||
| 13 | -fn strmdata(buf: &[u8]) -> &[u8] { | ||
| 14 | - if !buf.starts_with(b"DTSHDHDR") { | ||
| 15 | - return buf; | ||
| 16 | - } | ||
| 17 | - let mut p = 0; | ||
| 18 | - while p + 16 <= buf.len() { | ||
| 19 | - let size = u64::from_be_bytes(buf[p + 8..p + 16].try_into().unwrap()) as usize; | ||
| 20 | - if &buf[p..p + 8] == b"STRMDATA" { | ||
| 21 | - return &buf[p + 16..(p + 16 + size).min(buf.len())]; | ||
| 22 | - } | ||
| 23 | - p += 16 + size; | ||
| 24 | - } | ||
| 25 | - buf | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -fn decode_ours(data: &[u8]) -> (Vec<i32>, usize, u32) { | ||
| 29 | - let mut dec = DtsDecoder::new(); | ||
| 30 | - let (mut out, mut channels, mut rate) = (Vec::new(), 0, 0); | ||
| 31 | - let mut pos = 0; | ||
| 32 | - while pos + 4 < data.len() { | ||
| 33 | - let Some((s, _)) = ec_dts::find_sync(&data[pos..]) else { | ||
| 34 | - break; | ||
| 35 | - }; | ||
| 36 | - pos += s; | ||
| 37 | - let Ok(h) = ec_dts::parse_frame_header(&data[pos..]) else { | ||
| 38 | - pos += 1; | ||
| 39 | - continue; | ||
| 40 | - }; | ||
| 41 | - let end = ec_dts::find_sync(&data[pos + h.stream_frame_size.min(data.len() - pos)..]) | ||
| 42 | - .map(|(o, _)| pos + h.stream_frame_size + o) | ||
| 43 | - .unwrap_or(data.len()); | ||
| 44 | - let a = dec.decode_frame(&data[pos..end]).expect("decode"); | ||
| 45 | - channels = a.layout.channel_count(); | ||
| 46 | - rate = a.rate; | ||
| 47 | - for c in a.data[0].chunks_exact(4) { | ||
| 48 | - let v = f32::from_le_bytes([c[0], c[1], c[2], c[3]]); | ||
| 49 | - out.push((v as f64 * 8388608.0).round() as i32); | ||
| 50 | - } | ||
| 51 | - pos = end; | ||
| 52 | - } | ||
| 53 | - (out, channels, rate) | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -fn decode_ffmpeg(path: &Path, core_only: bool) -> Vec<i32> { | ||
| 57 | - let mut cmd = ec_testkit::ffmpeg(); | ||
| 58 | - cmd.args(["-v", "error", "-nostdin", "-flags", "+bitexact"]); | ||
| 59 | - if core_only { | ||
| 60 | - cmd.args(["-core_only", "1"]); | ||
| 61 | - } | ||
| 62 | - let out = cmd | ||
| 63 | - .arg("-i") | ||
| 64 | - .arg(path) | ||
| 65 | - .args(["-f", "s32le", "-"]) | ||
| 66 | - .output() | ||
| 67 | - .unwrap(); | ||
| 68 | - assert!( | ||
| 69 | - out.status.success(), | ||
| 70 | - "{}", | ||
| 71 | - String::from_utf8_lossy(&out.stderr) | ||
| 72 | - ); | ||
| 73 | - out.stdout | ||
| 74 | - .chunks_exact(4) | ||
| 75 | - .map(|c| i32::from_le_bytes([c[0], c[1], c[2], c[3]]) >> 8) | ||
| 76 | - .collect() | ||
| 77 | -} | ||
| 78 | - | ||
| 79 | -#[test] | ||
| 80 | -fn fate_vectors_are_bit_exact_against_ffmpeg() { | ||
| 81 | - // (file, ffmpeg -core_only, leading samples ffmpeg trims from .dtshd) | ||
| 82 | - let cases = [ | ||
| 83 | - ("core_51_24_48_768_0.dtshd", true, 1024), | ||
| 84 | - ("core_51_24_48_768_1.dtshd", true, 1024), | ||
| 85 | - ("xch_61_24_48_768.dtshd", false, 1024), | ||
| 86 | - ("x96_51_24_96_1509.dtshd", false, 2048), | ||
| 87 | - ("x96_xch_61_24_96_3840.dtshd", false, 2048), | ||
| 88 | - ("xbr_51_24_48_3840.dtshd", true, 1024), | ||
| 89 | - ("xll_51_24_48_768.dtshd", true, 1024), | ||
| 90 | - ("dts_es.dts", false, 0), | ||
| 91 | - ]; | ||
| 92 | - let mut ran = 0; | ||
| 93 | - for (name, core_only, skip) in cases { | ||
| 94 | - let path = ec_testkit::fixture(&format!("open/fate/dts/{name}")); | ||
| 95 | - let raw = std::fs::read(&path).expect("read fixture"); | ||
| 96 | - let (ours, ch, rate) = decode_ours(strmdata(&raw)); | ||
| 97 | - let reference = decode_ffmpeg(&path, core_only); | ||
| 98 | - // ours is front-to-back; ffmpeg puts the back centre of a 6.1 stream | ||
| 99 | - // before the side surrounds. | ||
| 100 | - let perm: Vec<usize> = if ch == 7 { | ||
| 101 | - vec![0, 1, 2, 3, 6, 4, 5] | ||
| 102 | - } else { | ||
| 103 | - (0..ch).collect() | ||
| 104 | - }; | ||
| 105 | - let ours: Vec<i32> = ours | ||
| 106 | - .chunks_exact(ch) | ||
| 107 | - .skip(skip) | ||
| 108 | - .flat_map(|f| perm.iter().map(|&p| f[p]).collect::<Vec<_>>()) | ||
| 109 | - .collect(); | ||
| 110 | - assert_eq!(ours.len(), reference.len(), "{name}: sample count"); | ||
| 111 | - let bad = ours.iter().zip(&reference).position(|(a, b)| a != b); | ||
| 112 | - assert_eq!(bad, None, "{name}: first mismatch at {bad:?}"); | ||
| 113 | - eprintln!( | ||
| 114 | - "{name}: {ch} ch {rate} Hz {} samples/ch bit-exact", | ||
| 115 | - ours.len() / ch | ||
| 116 | - ); | ||
| 117 | - ran += 1; | ||
| 118 | - } | ||
| 119 | - eprintln!("{ran} FATE vectors compared"); | ||
| 120 | -} | ||
crates/ec-dts/tests/spec_tables.rsdeleted+0 -145
| @@ -1,145 +0,0 @@ | |||
| 1 | -//! The constant tables in `tables_data.rs` against the numbers printed in | ||
| 2 | -//! ETSI TS 102 114 V1.6.1 (2019-08), committed in `spec_ts102114_tables.txt` | ||
| 3 | -//! (written by `crates/ec-dts/gen_dts_tables.py`, with the clause of every table). | ||
| 4 | -//! | ||
| 5 | -//! The conversions from printed number to Rust value are repeated here | ||
| 6 | -//! independently of the generator. | ||
| 7 | - | ||
| 8 | -use ec_dts::tables_data::*; | ||
| 9 | -use std::collections::HashMap; | ||
| 10 | - | ||
| 11 | -const SPEC: &str = include_str!("spec_ts102114_tables.txt"); | ||
| 12 | - | ||
| 13 | -struct Spec { | ||
| 14 | - tables: HashMap<String, Vec<String>>, | ||
| 15 | - huff: HashMap<String, Vec<(i32, u32, u64)>>, | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -fn load() -> Spec { | ||
| 19 | - let mut s = Spec { | ||
| 20 | - tables: HashMap::new(), | ||
| 21 | - huff: HashMap::new(), | ||
| 22 | - }; | ||
| 23 | - for line in SPEC.lines().filter(|l| !l.starts_with('#') && !l.is_empty()) { | ||
| 24 | - let parts: Vec<&str> = line.splitn(3, " | ").collect(); | ||
| 25 | - let head: Vec<&str> = parts[0].split(' ').collect(); | ||
| 26 | - match head[0] { | ||
| 27 | - "table" => { | ||
| 28 | - s.tables.insert( | ||
| 29 | - head[1].to_string(), | ||
| 30 | - parts[2].split(' ').map(str::to_string).collect(), | ||
| 31 | - ); | ||
| 32 | - } | ||
| 33 | - "huff" => { | ||
| 34 | - let e = parts[2] | ||
| 35 | - .split(' ') | ||
| 36 | - .map(|t| { | ||
| 37 | - let v: Vec<&str> = t.split(':').collect(); | ||
| 38 | - (v[0].parse().unwrap(), v[1].parse().unwrap(), v[2].parse().unwrap()) | ||
| 39 | - }) | ||
| 40 | - .collect(); | ||
| 41 | - s.huff.insert(head[1].to_string(), e); | ||
| 42 | - } | ||
| 43 | - other => panic!("unknown record {other}"), | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - s | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -/// Integers with "invalid" read as 0 and zero padding to `n`. | ||
| 50 | -fn ints(v: &[String], n: usize) -> Vec<u32> { | ||
| 51 | - let mut o: Vec<u32> = v | ||
| 52 | - .iter() | ||
| 53 | - .map(|x| if x == "invalid" { 0 } else { x.parse().unwrap() }) | ||
| 54 | - .collect(); | ||
| 55 | - o.resize(n, 0); | ||
| 56 | - o | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -#[test] | ||
| 60 | -fn integer_tables_match_spec() { | ||
| 61 | - let s = load(); | ||
| 62 | - assert_eq!(SCALE_FACTOR_QUANT6.to_vec(), ints(&s.tables["SCALE_FACTOR_QUANT6"], 64)); // D.1.1 | ||
| 63 | - assert_eq!(SCALE_FACTOR_QUANT7.to_vec(), ints(&s.tables["SCALE_FACTOR_QUANT7"], 128)); // D.1.2 | ||
| 64 | - assert_eq!(LOSSY_QUANT.to_vec(), ints(&s.tables["LOSSY_QUANT"], 32)); // D.2.1 | ||
| 65 | - assert_eq!(LOSSLESS_QUANT.to_vec(), ints(&s.tables["LOSSLESS_QUANT"], 32)); // D.2.2 | ||
| 66 | - // Table 5-26: ABITS 0 is 1 here (spec 0), 27..31 invalid. | ||
| 67 | - let mut ql = ints(&s.tables["QUANT_LEVELS"], 32); | ||
| 68 | - ql[0] = 1; | ||
| 69 | - assert_eq!(QUANT_LEVELS.to_vec(), ql); | ||
| 70 | - // Table 5-27: adjustment values x 2^22. | ||
| 71 | - let adj: Vec<u32> = s.tables["SCALE_FACTOR_ADJ"] | ||
| 72 | - .iter() | ||
| 73 | - .map(|x| (x.parse::<f64>().unwrap() * 4194304.0) as u32) | ||
| 74 | - .collect(); | ||
| 75 | - assert_eq!(SCALE_FACTOR_ADJ.to_vec(), adj); | ||
| 76 | - // D.11: DmixTable preceded by a 0 entry. | ||
| 77 | - let mut dm = vec![0u32]; | ||
| 78 | - dm.extend(ints(&s.tables["DMIXTABLE"], 241)); | ||
| 79 | - assert_eq!(DMIXTABLE.iter().map(|&x| x as u32).collect::<Vec<_>>(), dm); | ||
| 80 | -} | ||
| 81 | - | ||
| 82 | -#[test] | ||
| 83 | -fn float_and_fir_tables_match_spec() { | ||
| 84 | - let s = load(); | ||
| 85 | - // D.9: round-half-up(coef * 2^29), cosine modulation sign per 32 taps. | ||
| 86 | - let fir = &s.tables["FIR_64"]; | ||
| 87 | - assert_eq!(fir.len(), 1024); | ||
| 88 | - for (i, t) in fir.iter().enumerate() { | ||
| 89 | - let v = (t.parse::<f64>().unwrap() * 536870912.0 + 0.5).floor() as i32; | ||
| 90 | - let v = if (i / 32) % 4 == 0 { v } else { -v }; | ||
| 91 | - assert_eq!(FIR_64[i], v, "FIR_64[{i}]"); | ||
| 92 | - } | ||
| 93 | - // D.8, 128x column, polyphase order. | ||
| 94 | - let lfe = &s.tables["LFE_FIR_128"]; | ||
| 95 | - assert_eq!(lfe.len(), 512); | ||
| 96 | - for (k, got) in LFE_FIR_128.iter().enumerate() { | ||
| 97 | - let (q, p) = (k / 4, k % 4); | ||
| 98 | - let idx = [q, 128 + q, 255 - q, 127 - q][p]; | ||
| 99 | - let want: f32 = lfe[idx].parse().unwrap(); | ||
| 100 | - assert_eq!(got.to_bits(), want.to_bits(), "LFE_FIR_128[{k}]"); | ||
| 101 | - } | ||
| 102 | -} | ||
| 103 | - | ||
| 104 | -#[test] | ||
| 105 | -fn huffman_books_match_spec() { | ||
| 106 | - let s = load(); | ||
| 107 | - let mut order: Vec<(String, i32)> = Vec::new(); // (table, symbol = level + offset) | ||
| 108 | - for (n, groups, off) in [ | ||
| 109 | - (3, "A", 1), | ||
| 110 | - (5, "ABC", 2), | ||
| 111 | - (7, "ABC", 3), | ||
| 112 | - (9, "ABC", 4), | ||
| 113 | - (13, "ABC", 6), | ||
| 114 | - (17, "ABCDEFG", 8), | ||
| 115 | - (25, "ABCDEFG", 12), | ||
| 116 | - (33, "ABCDEFG", 16), | ||
| 117 | - (65, "ABCDEFG", 32), | ||
| 118 | - (129, "ABCDEFG", 64), | ||
| 119 | - ] { | ||
| 120 | - for g in groups.chars() { | ||
| 121 | - order.push((format!("{g}{n}"), off)); | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - for g in "ABCDE".chars() { | ||
| 125 | - order.push((format!("{g}12"), -1)); // level column is ABITS = symbol + 1 | ||
| 126 | - } | ||
| 127 | - for g in "ABCDE".chars() { | ||
| 128 | - order.push((format!("S{g}129"), 64)); | ||
| 129 | - } | ||
| 130 | - for g in "ABCD".chars() { | ||
| 131 | - order.push((format!("{g}4"), 0)); | ||
| 132 | - } | ||
| 133 | - assert_eq!(s.huff.len(), order.len()); | ||
| 134 | - let mut got: Vec<(u8, u8)> = Vec::new(); | ||
| 135 | - for (name, off) in &order { | ||
| 136 | - let mut e = s.huff[name].clone(); | ||
| 137 | - // a prefix code with no gaps | ||
| 138 | - let kraft: u64 = e.iter().map(|&(_, l, _)| 1u64 << (32 - l)).sum(); | ||
| 139 | - assert_eq!(kraft, 1u64 << 32, "{name} is not a complete prefix code"); | ||
| 140 | - e.sort_by_key(|&(_, l, c)| c << (32 - l)); | ||
| 141 | - got.extend(e.iter().map(|&(lv, l, _)| ((lv + off) as u8, l as u8))); | ||
| 142 | - } | ||
| 143 | - assert_eq!(HUFF_SRC.len(), got.len()); | ||
| 144 | - assert_eq!(HUFF_SRC.to_vec(), got); | ||
| 145 | -} | ||
crates/ec-dts/tests/spec_ts102114_tables.txtdeleted+0 -75
| @@ -1,75 +0,0 @@ | |||
| 1 | -# Numbers exactly as printed in ETSI TS 102 114 V1.6.1 (2019-08), Annex D / clause 5. | ||
| 2 | -# Written by crates/ec-dts/gen_dts_tables.py; decimal commas written as points. | ||
| 3 | -# table NAME | clause | values... (invalid entries kept as the word "invalid") | ||
| 4 | -# huff TABLE | clause | level:length:code ... (code = value of the code word) | ||
| 5 | -table QUANT_LEVELS | Table 5-26 | 0 3 5 7 9 13 17 25 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 | ||
| 6 | -table SCALE_FACTOR_ADJ | Table 5-27 | 1.0000 1.1250 1.2500 1.4375 | ||
| 7 | -table SCALE_FACTOR_QUANT6 | D.1.1 | 1 2 2 3 3 4 6 7 10 12 16 20 26 34 44 56 72 93 120 155 200 257 331 427 550 708 912 1175 1514 1950 2512 3236 4169 5370 6918 8913 11482 14791 19055 24547 31623 40738 52481 67608 87096 112202 144544 186209 239883 309030 398107 512861 660693 851138 1096478 1412538 1819701 2344229 3019952 3890451 5011872 6456542 8317638 invalid | ||
| 8 | -table SCALE_FACTOR_QUANT7 | D.1.2 | 1 1 2 2 2 2 3 3 3 4 4 5 6 7 7 8 10 11 12 14 16 18 20 23 26 30 34 38 44 50 56 64 72 82 93 106 120 136 155 176 200 226 257 292 331 376 427 484 550 624 708 804 912 1035 1175 1334 1514 1718 1950 2213 2512 2851 3236 3673 4169 4732 5370 6095 6918 7852 8913 10116 11482 13032 14791 16788 19055 21627 24547 27861 31623 35892 40738 46238 52481 59566 67608 76736 87096 98855 112202 127350 144544 164059 186209 211349 239883 272270 309030 350752 398107 451856 512861 582103 660693 749894 851138 966051 1096478 1244515 1412538 1603245 1819701 2065380 2344229 2660725 3019952 3427678 3890451 4415704 5011872 5688529 6456542 7328245 8317638 invalid invalid invalid | ||
| 9 | -table LOSSY_QUANT | D.2.1 | 0 6710886 4194304 3355443 2474639 2097152 1761608 1426063 796918 461373 251658 146801 79692 46137 27263 16777 10486 5872 3355 1887 1258 713 336 168 84 42 21 invalid invalid invalid invalid invalid | ||
| 10 | -table LOSSLESS_QUANT | D.2.2 | 0 4194304 2097152 1384120 1048576 696254 524288 348127 262144 131072 65431 33026 16450 8208 4100 2049 1024 512 256 128 64 32 16 8 4 2 1 invalid invalid invalid invalid invalid | ||
| 11 | -table LFE_FIR_128 | D.8 (128 x Interpolation column) | 5.316857100e-04 1.635869100e-04 1.887860900e-04 2.164336300e-04 2.466738200e-04 2.794966000e-04 3.151909600e-04 3.539837500e-04 3.963469100e-04 4.423685900e-04 4.920452500e-04 5.452220800e-04 6.027714100e-04 6.656776500e-04 7.317967800e-04 8.036546600e-04 8.803732300e-04 9.625531400e-04 1.050489840e-03 1.144316160e-03 1.244423330e-03 1.351100280e-03 1.464826870e-03 1.585700080e-03 1.714018640e-03 1.850234690e-03 1.994950230e-03 2.147856400e-03 2.310042500e-03 2.481348810e-03 2.662512240e-03 2.853781920e-03 3.055653300e-03 3.268416510e-03 3.492647550e-03 3.728747140e-03 3.977200480e-03 4.238294900e-03 4.512710030e-03 4.800856580e-03 5.103122910e-03 5.420174920e-03 5.752369300e-03 6.100293250e-03 6.464532110e-03 6.845539900e-03 7.243919190e-03 7.660165890e-03 8.094980380e-03 8.548815730e-03 9.022301060e-03 9.516004470e-03 1.003060210e-02 1.056654565e-02 1.112466771e-02 1.170534454e-02 1.230939943e-02 1.293735672e-02 1.358995494e-02 1.426773332e-02 1.497144438e-02 1.570170000e-02 1.645922661e-02 1.724460535e-02 1.805862412e-02 1.890186779e-02 1.977507770e-02 2.067894675e-02 2.161412500e-02 2.258131653e-02 2.358125709e-02 2.461459488e-02 2.568206564e-02 2.678431384e-02 2.792212367e-02 2.909611352e-02 3.030703776e-02 3.155555204e-02 3.284239396e-02 3.416819125e-02 3.553372994e-02 3.693958372e-02 3.838652745e-02 3.987516090e-02 4.140623659e-02 4.298033938e-02 4.459818453e-02 4.626038298e-02 4.796761274e-02 4.972046614e-02 5.151961371e-02 5.336561054e-02 5.525910854e-02 5.720067024e-02 5.919086933e-02 6.123027951e-02 6.331945211e-02 6.545893103e-02 6.764923781e-02 6.989086419e-02 7.218432426e-02 7.453006506e-02 7.692859322e-02 7.938029617e-02 8.188561350e-02 8.444493264e-02 8.705867827e-02 8.972713351e-02 9.245070815e-02 9.522963315e-02 9.806428105e-02 1.009548605e-01 1.039016470e-01 1.069048345e-01 1.099646092e-01 1.130811572e-01 1.162546203e-01 1.194850579e-01 1.227726117e-01 1.261173040e-01 1.295191795e-01 1.329781860e-01 1.364943385e-01 1.400675476e-01 1.436977387e-01 1.473847479e-01 1.511284113e-01 1.549285650e-01 1.587849557e-01 1.626973301e-01 1.666653752e-01 1.706887931e-01 1.747671962e-01 1.789001823e-01 1.830873191e-01 1.873281151e-01 1.916220933e-01 1.959686577e-01 2.003673166e-01 2.048173845e-01 2.093182206e-01 2.138691545e-01 2.184694260e-01 2.231182903e-01 2.278149277e-01 2.325585187e-01 2.373482138e-01 2.421830446e-01 2.470620573e-01 2.519843280e-01 2.569487989e-01 2.619544268e-01 2.670000792e-01 2.720846236e-01 2.772069275e-01 2.823657692e-01 2.875599265e-01 2.927881181e-01 2.980490029e-01 3.033412695e-01 3.086635172e-01 3.140144050e-01 3.193923831e-01 3.247960210e-01 3.302238286e-01 3.356742859e-01 3.411457539e-01 3.466366828e-01 3.521454632e-01 3.576703668e-01 3.632097244e-01 3.687619269e-01 3.743250966e-01 3.798975349e-01 3.854774535e-01 3.910630047e-01 3.966524303e-01 4.022437930e-01 4.078352153e-01 4.134248793e-01 4.190107882e-01 4.245910645e-01 4.301636219e-01 4.357266724e-01 4.412781000e-01 4.468160272e-01 4.523383081e-01 4.578429461e-01 4.633280039e-01 4.687913656e-01 4.742309451e-01 4.796448052e-01 4.850307405e-01 4.903867543e-01 4.957108200e-01 5.010007620e-01 5.062545538e-01 5.114701390e-01 5.166453719e-01 5.217782855e-01 5.268667936e-01 5.319088101e-01 5.369022489e-01 5.418450832e-01 5.467353463e-01 5.515710115e-01 5.563499928e-01 5.610702634e-01 5.657299161e-01 5.703269839e-01 5.748594403e-01 5.793255568e-01 5.837231875e-01 5.880505443e-01 5.923057795e-01 5.964869261e-01 6.005923152e-01 6.046201587e-01 6.085684896e-01 6.124358177e-01 6.162202954e-01 6.199202538e-01 6.235341430e-01 6.270602942e-01 6.304970384e-01 6.338429451e-01 6.370964646e-01 6.402561665e-01 6.433205605e-01 6.462883353e-01 6.491580606e-01 6.519285440e-01 6.545983553e-01 6.571664810e-01 6.596315503e-01 6.619924903e-01 6.642482877e-01 6.663978696e-01 6.684402227e-01 6.703743935e-01 6.721994877e-01 6.739146709e-01 6.755192280e-01 6.770122051e-01 6.783930659e-01 6.796611548e-01 6.808158755e-01 6.818566918e-01 6.827830076e-01 6.835945249e-01 6.842908263e-01 6.848715544e-01 6.853365302e-01 6.856853962e-01 6.859180331e-01 6.860344410e-01 6.860344410e-01 6.859180331e-01 6.856853962e-01 6.853365302e-01 6.848715544e-01 6.842908263e-01 6.835945249e-01 6.827830076e-01 6.818566918e-01 6.808158755e-01 6.796611548e-01 6.783930659e-01 6.770122051e-01 6.755192280e-01 6.739146709e-01 6.721994877e-01 6.703743935e-01 6.684402227e-01 6.663978696e-01 6.642482877e-01 6.619924903e-01 6.596315503e-01 6.571664810e-01 6.545983553e-01 6.519285440e-01 6.491580606e-01 6.462883353e-01 6.433205605e-01 6.402561665e-01 6.370964646e-01 6.338429451e-01 6.304970384e-01 6.270602942e-01 6.235341430e-01 6.199202538e-01 6.162202954e-01 6.124358177e-01 6.085684896e-01 6.046201587e-01 6.005923152e-01 5.964869261e-01 5.923057795e-01 5.880505443e-01 5.837231875e-01 5.793255568e-01 5.748594403e-01 5.703269839e-01 5.657299161e-01 5.610702634e-01 5.563499928e-01 5.515710115e-01 5.467353463e-01 5.418450832e-01 5.369022489e-01 5.319088101e-01 5.268667936e-01 5.217782855e-01 5.166453719e-01 5.114701390e-01 5.062545538e-01 5.010007620e-01 4.957108200e-01 4.903867543e-01 4.850307405e-01 4.796448052e-01 4.742309451e-01 4.687913656e-01 4.633280039e-01 4.578429461e-01 4.523383081e-01 4.468160272e-01 4.412781000e-01 4.357266724e-01 4.301636219e-01 4.245910645e-01 4.190107882e-01 4.134248793e-01 4.078352153e-01 4.022437930e-01 3.966524303e-01 3.910630047e-01 3.854774535e-01 3.798975349e-01 3.743250966e-01 3.687619269e-01 3.632097244e-01 3.576703668e-01 3.521454632e-01 3.466366828e-01 3.411457539e-01 3.356742859e-01 3.302238286e-01 3.247960210e-01 3.193923831e-01 3.140144050e-01 3.086635172e-01 3.033412695e-01 2.980490029e-01 2.927881181e-01 2.875599265e-01 2.823657692e-01 2.772069275e-01 2.720846236e-01 2.670000792e-01 2.619544268e-01 2.569487989e-01 2.519843280e-01 2.470620573e-01 2.421830446e-01 2.373482138e-01 2.325585187e-01 2.278149277e-01 2.231182903e-01 2.184694260e-01 2.138691545e-01 2.093182206e-01 2.048173845e-01 2.003673166e-01 1.959686577e-01 1.916220933e-01 1.873281151e-01 1.830873191e-01 1.789001823e-01 1.747671962e-01 1.706887931e-01 1.666653752e-01 1.626973301e-01 1.587849557e-01 1.549285650e-01 1.511284113e-01 1.473847479e-01 1.436977387e-01 1.400675476e-01 1.364943385e-01 1.329781860e-01 1.295191795e-01 1.261173040e-01 1.227726117e-01 1.194850579e-01 1.162546203e-01 1.130811572e-01 1.099646092e-01 1.069048345e-01 1.039016470e-01 1.009548605e-01 9.806428105e-02 9.522963315e-02 9.245070815e-02 8.972713351e-02 8.705867827e-02 8.444493264e-02 8.188561350e-02 7.938029617e-02 7.692859322e-02 7.453006506e-02 7.218432426e-02 6.989086419e-02 6.764923781e-02 6.545893103e-02 6.331945211e-02 6.123027951e-02 5.919086933e-02 5.720067024e-02 5.525910854e-02 5.336561054e-02 5.151961371e-02 4.972046614e-02 4.796761274e-02 4.626038298e-02 4.459818453e-02 4.298033938e-02 4.140623659e-02 3.987516090e-02 3.838652745e-02 3.693958372e-02 3.553372994e-02 3.416819125e-02 3.284239396e-02 3.155555204e-02 3.030703776e-02 2.909611352e-02 2.792212367e-02 2.678431384e-02 2.568206564e-02 2.461459488e-02 2.358125709e-02 2.258131653e-02 2.161412500e-02 2.067894675e-02 1.977507770e-02 1.890186779e-02 1.805862412e-02 1.724460535e-02 1.645922661e-02 1.570170000e-02 1.497144438e-02 1.426773332e-02 1.358995494e-02 1.293735672e-02 1.230939943e-02 1.170534454e-02 1.112466771e-02 1.056654565e-02 1.003060210e-02 9.516004470e-03 9.022301060e-03 8.548815730e-03 8.094980380e-03 7.660165890e-03 7.243919190e-03 6.845539900e-03 6.464532110e-03 6.100293250e-03 5.752369300e-03 5.420174920e-03 5.103122910e-03 4.800856580e-03 4.512710030e-03 4.238294900e-03 3.977200480e-03 3.728747140e-03 3.492647550e-03 3.268416510e-03 3.055653300e-03 2.853781920e-03 2.662512240e-03 2.481348810e-03 2.310042500e-03 2.147856400e-03 1.994950230e-03 1.850234690e-03 1.714018640e-03 1.585700080e-03 1.464826870e-03 1.351100280e-03 1.244423330e-03 1.144316160e-03 1.050489840e-03 9.625531400e-04 8.803732300e-04 8.036546600e-04 7.317967800e-04 6.656776500e-04 6.027714100e-04 5.452220800e-04 4.920452500e-04 4.423685900e-04 3.963469100e-04 3.539837500e-04 3.151909600e-04 2.794966000e-04 2.466738200e-04 2.164336300e-04 1.887860900e-04 1.635869100e-04 5.316857100e-04 | ||
| 12 | -table FIR_64 | D.9 | -7.1279389866041690e-8 -7.0950903150874990e-8 -7.9525034321375090e-8 -8.9326871281374790e-8 -9.7483190494874640e-8 -1.0586659510721950e-7 -1.1527363411865760e-7 -1.2523109645615350e-7 -1.3555636137971380e-7 -1.4640931821191640e-7 -1.5787424998123710e-7 -1.6994592926571220e-7 -1.8264184311018150e-7 -1.9600594587757850e-7 -2.1007899706006800e-7 -2.2489759047553620e-7 -2.4050245877923400e-7 -2.5693874615777660e-7 -2.7425370308549580e-7 -2.9249662541757600e-7 -3.1171981968268900e-7 -3.3197864040473180e-7 -3.5333134588843600e-7 -3.7583910465412180e-7 -3.9956628121669190e-7 -4.2458045296159330e-7 -4.5095249563698380e-7 -4.7875659112606760e-7 -5.0807031294631050e-7 -5.3897464223335550e-7 -5.7155423388793000e-7 -6.0589741192019800e-7 -6.4209580087853050e-7 -6.8024432849991400e-7 -7.2044165259013450e-7 -7.6279018172077200e-7 -8.0739610368280600e-7 -8.5436937020293650e-7 -9.0382333224895500e-7 -9.5587472540498280e-7 -1.0106437128213760e-6 -1.0682538906146330e-6 -1.1288323637155430e-6 -1.1925097184646100e-6 -1.2594193438633260e-6 -1.3296974052300520e-6 -1.4034829433780260e-6 -1.4809178634979940e-6 -1.5621465913980060e-6 -1.6473160377545360e-6 -1.7365751553971340e-6 -1.8300749104526120e-6 -1.9279680902322050e-6 -2.0304092660990760e-6 -2.1375541686662320e-6 -2.2495596253776460e-6 -2.3665828120950560e-6 -2.4887811970856540e-6 -2.6163120571644820e-6 -2.7493324266391140e-6 -2.8879984579501380e-6 -3.0324653639203880e-6 -3.1828867865974640e-6 -3.3394147240855820e-6 -3.5021985520037540e-6 -3.6713849262294680e-6 -3.8471166218015830e-6 -4.0295324657699800e-6 -4.2187670209852250e-6 -4.4149505043312320e-6 -4.6182073040543900e-6 -4.8286558658894680e-6 -5.0464076705003400e-6 -5.2715671455405850e-6 -5.5042307535458100e-6 -5.7444868785028750e-6 -5.9924142424804800e-6 -6.2480817863072800e-6 -6.5115476278604000e-6 -6.7828589565804950e-6 -7.0620507545154100e-6 -7.3491456697144900e-6 -7.6441525098592000e-6 -7.9470661364365490e-6 -8.2578666429227760e-6 -8.5765192154768100e-6 -8.9029718900122000e-6 -9.2371554195468400e-6 -9.5789825988253100e-6 -9.9283481667264540e-6 -1.0285127334608450e-5 -1.0649175634328590e-5 -1.1020327046334650e-5 -1.1398393880881060e-5 -1.1783166036693560e-5 -1.2174410889256530e-5 -1.2571871574469220e-5 -1.2975266858030310e-5 -1.3384289978242060e-5 -1.3798608540965960e-5 -1.4217863365843780e-5 -1.4641668383496450e-5 -1.5069609527679710e-5 -1.5501244597782600e-5 -1.5936101341640500e-5 -1.6373677426466900e-5 -1.6813441716539560e-5 -1.7254834143068570e-5 -1.7697261563607500e-5 -1.8140097714618200e-5 -1.8582686308483550e-5 -1.9024340970099240e-5 -1.9464340744880170e-5 -1.9901930030141080e-5 -2.0336321557464510e-5 -2.0766696417773940e-5 -2.1192201630574280e-5 -2.1611950084231910e-5 -2.2025021652894630e-5 -2.2430463239517170e-5 -2.2827288605503470e-5 -2.3214478371918170e-5 -2.3590980216497750e-5 -2.3955708939763280e-5 -2.4307547722489910e-5 -2.4645348200903720e-5 -2.4967930863542620e-5 -2.5274085082324960e-5 2.5562569399199020e-5 2.5832111724562040e-5 2.6081413415833200e-5 2.6309149390520640e-5 2.6513966535124460e-5 2.6694483850464800e-5 2.6849297239997120e-5 2.6976979753245170e-5 2.7076082153012070e-5 2.7145133103663890e-5 2.7182642746157720e-5 2.7187102980536760e-5 2.7156990105794550e-5 2.7090765064735940e-5 2.6986876191054700e-5 2.6843759539035120e-5 2.6659843389908530e-5 2.6433548592482960e-5 2.6163291550639320e-5 2.5847484577439320e-5 2.5484540698002960e-5 2.5072874052447260e-5 2.4610903957661350e-5 2.4097055300584120e-5 2.3529763128539150e-5 2.2907473117403740e-5 2.2228647280994560e-5 2.1491764461832140e-5 2.0695325418576370e-5 1.9837853265502040e-5 1.8917898053528080e-5 1.7934037335534700e-5 1.6884884022311310e-5 1.5769086921577900e-5 1.4585334740507920e-5 1.3332356590263080e-5 1.2008929083235120e-5 1.0613876973541650e-5 9.1460801506922300e-6 7.6044740757265500e-6 5.9880523825897000e-6 4.2958677847708840e-6 2.5270494199802070e-6 6.8080315386959900e-7 -1.2435990827839660e-6 -3.2468187066945930e-6 -5.3294268968052800e-6 -7.4919036559427900e-6 -9.7346407524871100e-6 -1.2057941408635810e-5 -1.4462010500550970e-5 -1.6946953848107710e-5 -1.9512772389215240e-5 -2.2159361597292710e-5 -2.4886504491416160e-5 -2.7693871041862060e-5 -3.0581012081916960e-5 -3.3547358765259040e-5 -3.6592216716540970e-5 -3.9714765485539260e-5 -4.2914052387856640e-5 -4.6188991961724560e-5 -4.9538360176954340e-5 -5.2960794000140600e-5 -5.6454787620185350e-5 -6.0018691972791050e-5 -6.3650708053788550e-5 -6.7348886525882700e-5 -7.1111125753722860e-5 -7.4935171411178040e-5 -7.8818609806320000e-5 -8.2758867628623800e-5 -8.6753213062403400e-5 -9.0798755482139240e-5 -9.4892437636254000e-5 -9.9031035415475500e-5 -1.0321116057304920e-4 -1.0742926070674010e-4 -1.1168161614264270e-4 -1.1596433966772030e-4 -1.2027337376184880e-4 -1.2460449089034750e-4 -1.2895330270761850e-4 -1.3331525983885840e-4 -1.3768563787408340e-4 -1.4205953760578120e-4 -1.4643190426323540e-4 -1.5079752791692290e-4 -1.5515103314094370e-4 -1.5948687909058970e-4 -1.6379937154642740e-4 -1.6808266356446820e-4 -1.7233075773584680e-4 -1.7653750646560020e-4 -1.8069661584612290e-4 -1.8480164638953740e-4 -1.8884602526638050e-4 -1.9282304696531290e-4 -1.9672587556804270e-4 -2.0054754547108610e-4 -2.0428097498957360e-4 -2.0791896735659270e-4 -2.1145421910491280e-4 -2.1487932080488700e-4 -2.1818676491655660e-4 -2.2136894706917190e-4 -2.2441818635854840e-4 -2.2732672676686290e-4 -2.3008674810081220e-4 -2.3269036653525150e-4 -2.3512963563507800e-4 -2.3739654799291240e-4 -2.3948307023621970e-4 -2.4138114593372380e-4 -2.4308272452941820e-4 -2.4457975717687980e-4 -2.4586407616017000e-4 -2.4692741569938220e-4 -2.4776199025177680e-4 -2.4836046092637280e-4 -2.4871461830381660e-4 -2.4881540457247040e-4 -2.4865471770248810e-4 -2.4822543333608940e-4 -2.4752008219951220e-4 -2.4653081794176570e-4 -2.4525003217524440e-4 -2.4367037437341020e-4 2.4178457457919800e-4 2.3958543985834340e-4 2.3706595356421380e-4 2.3421928008696620e-4 2.3103877007019660e-4 2.2751796132972940e-4 2.2365059385031200e-4 2.1943061159567880e-4 2.1485218733324290e-4 2.0990972538755550e-4 2.0459789739171640e-4 1.9891164424316180e-4 1.9284618337957900e-4 1.8639701070854740e-4 1.7955993578371750e-4 1.7233108395155490e-4 1.6470690840351980e-4 1.5668419239382670e-4 1.4826008597798460e-4 1.3943210818407590e-4 1.3019815804235450e-4 1.2055651618705740e-4 1.1050586906665980e-4 1.0004531116378850e-4 8.9174369623037550e-5 7.7893006105444910e-5 6.6201632959158800e-5 5.4101115008963200e-5 4.1592792755171040e-5 2.8678484003389880e-5 1.5360496520469550e-5 1.6416297019304470e-6 -1.2474801400564880e-5 -2.6984964757674160e-5 -4.1884506316022560e-5 -5.7168548169515050e-5 -7.2831653374563650e-5 -8.8867825335203200e-5 -1.0527052946041040e-4 -1.2203269185287530e-4 -1.3914664880465400e-4 -1.5660414556657680e-4 -1.7439635977956720e-4 -1.9251390142613000e-4 -2.1094678833176480e-4 -2.2968444457655940e-4 -2.4871569004884240e-4 -2.6802874127778880e-4 -2.8761124019708440e-4 -3.0745025297166030e-4 -3.2753221542219500e-4 -3.4784293347385130e-4 -3.6836764760397900e-4 -3.8909103335715320e-4 -4.0999714822829530e-4 -4.3106943097409840e-4 -4.5229073958127750e-4 -4.7364335350426610e-4 -4.9510898492628230e-4 -5.1666877822680600e-4 -5.3830328700499900e-4 -5.5999247625413450e-4 -5.8171579317559550e-4 -6.0345216810040500e-4 -6.2517996394886800e-4 -6.4687697763330650e-4 -6.6852052145861900e-4 -6.9008742526480550e-4 -7.1155400216196750e-4 -7.3289605035434600e-4 -7.5408892753413600e-4 -7.7510755325530950e-4 -7.9592638676398950e-4 -8.1651942936660300e-4 -8.3686029869896850e-4 -8.5692223230171550e-4 -8.7667809201044900e-4 -8.9610036547340950e-4 -9.1516119514986000e-4 -9.3383238324995840e-4 -9.5208547141354700e-4 -9.6989174214394400e-4 -9.8722217067251400e-4 -1.0040474297445790e-3 -1.0203380430448350e-3 -1.0360643900964910e-3 -1.0511966606168980e-3 -1.0657048556038330e-3 -1.0795588568782010e-3 -1.0927284332850520e-3 -1.1051833075734240e-3 -1.1168931605293980e-3 -1.1278276550234160e-3 -1.1379564405661050e-3 -1.1472492294891640e-3 -1.1556758000499310e-3 -1.1632059885511800e-3 -1.1698096960154200e-3 -1.1754570428998680e-3 -1.1801183720212010e-3 -1.1837641581852870e-3 -1.1863650153060240e-3 -1.1878919433902330e-3 -1.1883163316843900e-3 -1.1876097809178440e-3 -1.1857441072376680e-3 -1.1826916065321440e-3 -1.1784250628415020e-3 -1.1729176690707690e-3 -1.1661430294353880e-3 -1.1580752925519680e-3 -1.1486891568700730e-3 -1.1379598570807350e-3 -1.1258631690530700e-3 -1.1123755320313420e-3 -1.0974740543942100e-3 -1.0811365181610850e-3 -1.0633413819325920e-3 -1.0440678410743190e-3 -1.0232958338441730e-3 -1.0010061160103870e-3 -9.7718026613602800e-4 -9.5180072722007060e-4 -9.2485080945546600e-4 -8.9631470926558100e-4 -8.6617751390929650e-4 -8.3442528375666700e-4 -8.0104505655578600e-4 7.6602485902806300e-4 7.2935371157849700e-4 6.9102172032639350e-4 6.5102007948960100e-4 6.0934103180698750e-4 5.6597787244591100e-4 5.2092507454409450e-4 4.7417829303612970e-4 4.2573432329476060e-4 3.7559110239316400e-4 3.2374777823389440e-4 2.7020471361387040e-4 2.1496350652513040e-4 1.5802699163104190e-4 9.9399252442146460e-5 3.9085623279149610e-5 -2.2907279717153710e-5 -8.6571556658577800e-5 -1.5189801251884410e-4 -2.1887615668780720e-4 -2.8749420455512610e-4 -3.5773907519488100e-4 -4.2959633884346400e-4 -5.0305021853266900e-4 -5.7808367853976800e-4 -6.5467842279709950e-4 -7.3281477145293300e-4 -8.1247166091487090e-4 -8.9362676824381250e-4 -9.7625651350435400e-4 -1.0603359870796300e-3 -1.1458389497708370e-3 -1.2327379076720450e-3 -1.3210041125919850e-3 -1.4106074964587530e-3 -1.5015166759080980e-3 -1.5936991188210680e-3 -1.6871211446584360e-3 -1.7817477652804130e-3 -1.8775426862784720e-3 -1.9744684954557180e-3 -2.0724866717198650e-3 -2.1715575922482770e-3 -2.2716405301701940e-3 -2.3726935964105480e-3 -2.4746737418493600e-3 -2.5775368629845300e-3 -2.6812378156433060e-3 -2.7857306109716460e-3 -2.8909684129992950e-3 -2.9969032890820140e-3 -3.1034862132032660e-3 -3.2106673881690480e-3 -3.3183962566563890e-3 -3.4266214220855450e-3 -3.5352906520539890e-3 -3.6443510330122110e-3 -3.7537489709635930e-3 -3.8634300521859240e-3 -3.9733390588103910e-3 -4.0834204508378470e-3 -4.1936183686073460e-3 -4.3038762050876900e-3 -4.4141366059086620e-3 -4.5243418977567100e-3 -4.6344341075783170e-3 -4.7443549566589130e-3 -4.8540458565358850e-3 -4.9634478250060780e-3 -5.0725014978718950e-3 -5.1811474713480250e-3 -5.2893263173827950e-3 -5.3969785783205650e-3 -5.5040447592375600e-3 -5.6104651646665850e-3 -5.7161799140263450e-3 -5.8211294443412250e-3 -5.9252545216101900e-3 -6.0284959882028950e-3 -6.1307947602360250e-3 -6.2320920224565700e-3 -6.3323292492425800e-3 -6.4314484717364400e-3 -6.5293922762311450e-3 -6.6261035015351700e-3 -6.7215252466922100e-3 -6.8156013434509950e-3 -6.9082763630156450e-3 -6.9994952920827200e-3 -7.0892035490577050e-3 -7.1773476647806300e-3 -7.2638752839566550e-3 -7.3487345159041400e-3 -7.4318739341000500e-3 -7.5132432154309250e-3 -7.5927931627681400e-3 -7.6704755623721500e-3 -7.7462431738117650e-3 -7.8200496507836000e-3 -7.8918495587816850e-3 -7.9615988430090790e-3 -8.0292548409052500e-3 -8.0947760898363200e-3 -8.1581223027535600e-3 -8.2192540249893810e-3 -8.2781326752680240e-3 -8.3347217911436610e-3 -8.3889870206274740e-3 -8.4408946925453690e-3 -8.4904118087845760e-3 -8.5375073033623590e-3 -8.5821520672029750e-3 -8.6243182341614300e-3 -8.6639791627160300e-3 -8.7011097471794110e-3 -8.7356864659172800e-3 -8.7676881309490440e-3 -8.7970958152554810e-3 -8.8238905039462850e-3 -8.8480531477483150e-3 -8.8695681885783190e-3 -8.8884235927356400e-3 -8.9046080555685600e-3 -8.9181109318560050e-3 -8.9289234995380550e-3 -8.9370390010903460e-3 -8.9424522900292110e-3 -8.9451598223763610e-3 8.9451598223763610e-3 8.9424522900292110e-3 8.9370390010903460e-3 8.9289234995380550e-3 8.9181109318560050e-3 8.9046080555685600e-3 8.8884235927356400e-3 8.8695681885783190e-3 8.8480531477483150e-3 8.8238905039462850e-3 8.7970958152554810e-3 8.7676881309490440e-3 8.7356864659172800e-3 8.7011097471794110e-3 8.6639791627160300e-3 8.6243182341614300e-3 8.5821520672029750e-3 8.5375073033623590e-3 8.4904118087845760e-3 8.4408946925453690e-3 8.3889870206274740e-3 8.3347217911436610e-3 8.2781326752680240e-3 8.2192540249893810e-3 8.1581223027535600e-3 8.0947760898363200e-3 8.0292548409052500e-3 7.9615988430090790e-3 7.8918495587816850e-3 7.8200496507836000e-3 7.7462431738117650e-3 7.6704755623721500e-3 7.5927931627681400e-3 7.5132432154309250e-3 7.4318739341000500e-3 7.3487345159041400e-3 7.2638752839566550e-3 7.1773476647806300e-3 7.0892035490577050e-3 6.9994952920827200e-3 6.9082763630156450e-3 6.8156013434509950e-3 6.7215252466922100e-3 6.6261035015351700e-3 6.5293922762311450e-3 6.4314484717364400e-3 6.3323292492425800e-3 6.2320920224565700e-3 6.1307947602360250e-3 6.0284959882028950e-3 5.9252545216101900e-3 5.8211294443412250e-3 5.7161799140263450e-3 5.6104651646665850e-3 5.5040447592375600e-3 5.3969785783205650e-3 5.2893263173827950e-3 5.1811474713480250e-3 5.0725014978718950e-3 4.9634478250060780e-3 4.8540458565358850e-3 4.7443549566589130e-3 4.6344341075783170e-3 4.5243418977567100e-3 4.4141366059086620e-3 4.3038762050876900e-3 4.1936183686073460e-3 4.0834204508378470e-3 3.9733390588103910e-3 3.8634300521859240e-3 3.7537489709635930e-3 3.6443510330122110e-3 3.5352906520539890e-3 3.4266214220855450e-3 3.3183962566563890e-3 3.2106673881690480e-3 3.1034862132032660e-3 2.9969032890820140e-3 2.8909684129992950e-3 2.7857306109716460e-3 2.6812378156433060e-3 2.5775368629845300e-3 2.4746737418493600e-3 2.3726935964105480e-3 2.2716405301701940e-3 2.1715575922482770e-3 2.0724866717198650e-3 1.9744684954557180e-3 1.8775426862784720e-3 1.7817477652804130e-3 1.6871211446584360e-3 1.5936991188210680e-3 1.5015166759080980e-3 1.4106074964587530e-3 1.3210041125919850e-3 1.2327379076720450e-3 1.1458389497708370e-3 1.0603359870796300e-3 9.7625651350435400e-4 8.9362676824381250e-4 8.1247166091487090e-4 7.3281477145293300e-4 6.5467842279709950e-4 5.7808367853976800e-4 5.0305021853266900e-4 4.2959633884346400e-4 3.5773907519488100e-4 2.8749420455512610e-4 2.1887615668780720e-4 1.5189801251884410e-4 8.6571556658577800e-5 2.2907279717153710e-5 -3.9085623279149610e-5 -9.9399252442146460e-5 -1.5802699163104190e-4 -2.1496350652513040e-4 -2.7020471361387040e-4 -3.2374777823389440e-4 -3.7559110239316400e-4 -4.2573432329476060e-4 -4.7417829303612970e-4 -5.2092507454409450e-4 -5.6597787244591100e-4 -6.0934103180698750e-4 -6.5102007948960100e-4 -6.9102172032639350e-4 -7.2935371157849700e-4 -7.6602485902806300e-4 8.0104505655578600e-4 8.3442528375666700e-4 8.6617751390929650e-4 8.9631470926558100e-4 9.2485080945546600e-4 9.5180072722007060e-4 9.7718026613602800e-4 1.0010061160103870e-3 1.0232958338441730e-3 1.0440678410743190e-3 1.0633413819325920e-3 1.0811365181610850e-3 1.0974740543942100e-3 1.1123755320313420e-3 1.1258631690530700e-3 1.1379598570807350e-3 1.1486891568700730e-3 1.1580752925519680e-3 1.1661430294353880e-3 1.1729176690707690e-3 1.1784250628415020e-3 1.1826916065321440e-3 1.1857441072376680e-3 1.1876097809178440e-3 1.1883163316843900e-3 1.1878919433902330e-3 1.1863650153060240e-3 1.1837641581852870e-3 1.1801183720212010e-3 1.1754570428998680e-3 1.1698096960154200e-3 1.1632059885511800e-3 1.1556758000499310e-3 1.1472492294891640e-3 1.1379564405661050e-3 1.1278276550234160e-3 1.1168931605293980e-3 1.1051833075734240e-3 1.0927284332850520e-3 1.0795588568782010e-3 1.0657048556038330e-3 1.0511966606168980e-3 1.0360643900964910e-3 1.0203380430448350e-3 1.0040474297445790e-3 9.8722217067251400e-4 9.6989174214394400e-4 9.5208547141354700e-4 9.3383238324995840e-4 9.1516119514986000e-4 8.9610036547340950e-4 8.7667809201044900e-4 8.5692223230171550e-4 8.3686029869896850e-4 8.1651942936660300e-4 7.9592638676398950e-4 7.7510755325530950e-4 7.5408892753413600e-4 7.3289605035434600e-4 7.1155400216196750e-4 6.9008742526480550e-4 6.6852052145861900e-4 6.4687697763330650e-4 6.2517996394886800e-4 6.0345216810040500e-4 5.8171579317559550e-4 5.5999247625413450e-4 5.3830328700499900e-4 5.1666877822680600e-4 4.9510898492628230e-4 4.7364335350426610e-4 4.5229073958127750e-4 4.3106943097409840e-4 4.0999714822829530e-4 3.8909103335715320e-4 3.6836764760397900e-4 3.4784293347385130e-4 3.2753221542219500e-4 3.0745025297166030e-4 2.8761124019708440e-4 2.6802874127778880e-4 2.4871569004884240e-4 2.2968444457655940e-4 2.1094678833176480e-4 1.9251390142613000e-4 1.7439635977956720e-4 1.5660414556657680e-4 1.3914664880465400e-4 1.2203269185287530e-4 1.0527052946041040e-4 8.8867825335203200e-5 7.2831653374563650e-5 5.7168548169515050e-5 4.1884506316022560e-5 2.6984964757674160e-5 1.2474801400564880e-5 -1.6416297019304470e-6 -1.5360496520469550e-5 -2.8678484003389880e-5 -4.1592792755171040e-5 -5.4101115008963200e-5 -6.6201632959158800e-5 -7.7893006105444910e-5 -8.9174369623037550e-5 -1.0004531116378850e-4 -1.1050586906665980e-4 -1.2055651618705740e-4 -1.3019815804235450e-4 -1.3943210818407590e-4 -1.4826008597798460e-4 -1.5668419239382670e-4 -1.6470690840351980e-4 -1.7233108395155490e-4 -1.7955993578371750e-4 -1.8639701070854740e-4 -1.9284618337957900e-4 -1.9891164424316180e-4 -2.0459789739171640e-4 -2.0990972538755550e-4 -2.1485218733324290e-4 -2.1943061159567880e-4 -2.2365059385031200e-4 -2.2751796132972940e-4 -2.3103877007019660e-4 -2.3421928008696620e-4 -2.3706595356421380e-4 -2.3958543985834340e-4 -2.4178457457919800e-4 2.4367037437341020e-4 2.4525003217524440e-4 2.4653081794176570e-4 2.4752008219951220e-4 2.4822543333608940e-4 2.4865471770248810e-4 2.4881540457247040e-4 2.4871461830381660e-4 2.4836046092637280e-4 2.4776199025177680e-4 2.4692741569938220e-4 2.4586407616017000e-4 2.4457975717687980e-4 2.4308272452941820e-4 2.4138114593372380e-4 2.3948307023621970e-4 2.3739654799291240e-4 2.3512963563507800e-4 2.3269036653525150e-4 2.3008674810081220e-4 2.2732672676686290e-4 2.2441818635854840e-4 2.2136894706917190e-4 2.1818676491655660e-4 2.1487932080488700e-4 2.1145421910491280e-4 2.0791896735659270e-4 2.0428097498957360e-4 2.0054754547108610e-4 1.9672587556804270e-4 1.9282304696531290e-4 1.8884602526638050e-4 1.8480164638953740e-4 1.8069661584612290e-4 1.7653750646560020e-4 1.7233075773584680e-4 1.6808266356446820e-4 1.6379937154642740e-4 1.5948687909058970e-4 1.5515103314094370e-4 1.5079752791692290e-4 1.4643190426323540e-4 1.4205953760578120e-4 1.3768563787408340e-4 1.3331525983885840e-4 1.2895330270761850e-4 1.2460449089034750e-4 1.2027337376184880e-4 1.1596433966772030e-4 1.1168161614264270e-4 1.0742926070674010e-4 1.0321116057304920e-4 9.9031035415475500e-5 9.4892437636254000e-5 9.0798755482139240e-5 8.6753213062403400e-5 8.2758867628623800e-5 7.8818609806320000e-5 7.4935171411178040e-5 7.1111125753722860e-5 6.7348886525882700e-5 6.3650708053788550e-5 6.0018691972791050e-5 5.6454787620185350e-5 5.2960794000140600e-5 4.9538360176954340e-5 4.6188991961724560e-5 4.2914052387856640e-5 3.9714765485539260e-5 3.6592216716540970e-5 3.3547358765259040e-5 3.0581012081916960e-5 2.7693871041862060e-5 2.4886504491416160e-5 2.2159361597292710e-5 1.9512772389215240e-5 1.6946953848107710e-5 1.4462010500550970e-5 1.2057941408635810e-5 9.7346407524871100e-6 7.4919036559427900e-6 5.3294268968052800e-6 3.2468187066945930e-6 1.2435990827839660e-6 -6.8080315386959900e-7 -2.5270494199802070e-6 -4.2958677847708840e-6 -5.9880523825897000e-6 -7.6044740757265500e-6 -9.1460801506922300e-6 -1.0613876973541650e-5 -1.2008929083235120e-5 -1.3332356590263080e-5 -1.4585334740507920e-5 -1.5769086921577900e-5 -1.6884884022311310e-5 -1.7934037335534700e-5 -1.8917898053528080e-5 -1.9837853265502040e-5 -2.0695325418576370e-5 -2.1491764461832140e-5 -2.2228647280994560e-5 -2.2907473117403740e-5 -2.3529763128539150e-5 -2.4097055300584120e-5 -2.4610903957661350e-5 -2.5072874052447260e-5 -2.5484540698002960e-5 -2.5847484577439320e-5 -2.6163291550639320e-5 -2.6433548592482960e-5 -2.6659843389908530e-5 -2.6843759539035120e-5 -2.6986876191054700e-5 -2.7090765064735940e-5 -2.7156990105794550e-5 -2.7187102980536760e-5 -2.7182642746157720e-5 -2.7145133103663890e-5 -2.7076082153012070e-5 -2.6976979753245170e-5 -2.6849297239997120e-5 -2.6694483850464800e-5 -2.6513966535124460e-5 -2.6309149390520640e-5 -2.6081413415833200e-5 -2.5832111724562040e-5 -2.5562569399199020e-5 2.5274085082324960e-5 2.4967930863542620e-5 2.4645348200903720e-5 2.4307547722489910e-5 2.3955708939763280e-5 2.3590980216497750e-5 2.3214478371918170e-5 2.2827288605503470e-5 2.2430463239517170e-5 2.2025021652894630e-5 2.1611950084231910e-5 2.1192201630574280e-5 2.0766696417773940e-5 2.0336321557464510e-5 1.9901930030141080e-5 1.9464340744880170e-5 1.9024340970099240e-5 1.8582686308483550e-5 1.8140097714618200e-5 1.7697261563607500e-5 1.7254834143068570e-5 1.6813441716539560e-5 1.6373677426466900e-5 1.5936101341640500e-5 1.5501244597782600e-5 1.5069609527679710e-5 1.4641668383496450e-5 1.4217863365843780e-5 1.3798608540965960e-5 1.3384289978242060e-5 1.2975266858030310e-5 1.2571871574469220e-5 1.2174410889256530e-5 1.1783166036693560e-5 1.1398393880881060e-5 1.1020327046334650e-5 1.0649175634328590e-5 1.0285127334608450e-5 9.9283481667264540e-6 9.5789825988253100e-6 9.2371554195468400e-6 8.9029718900122000e-6 8.5765192154768100e-6 8.2578666429227760e-6 7.9470661364365490e-6 7.6441525098592000e-6 7.3491456697144900e-6 7.0620507545154100e-6 6.7828589565804950e-6 6.5115476278604000e-6 6.2480817863072800e-6 5.9924142424804800e-6 5.7444868785028750e-6 5.5042307535458100e-6 5.2715671455405850e-6 5.0464076705003400e-6 4.8286558658894680e-6 4.6182073040543900e-6 4.4149505043312320e-6 4.2187670209852250e-6 4.0295324657699800e-6 3.8471166218015830e-6 3.6713849262294680e-6 3.5021985520037540e-6 3.3394147240855820e-6 3.1828867865974640e-6 3.0324653639203880e-6 2.8879984579501380e-6 2.7493324266391140e-6 2.6163120571644820e-6 2.4887811970856540e-6 2.3665828120950560e-6 2.2495596253776460e-6 2.1375541686662320e-6 2.0304092660990760e-6 1.9279680902322050e-6 1.8300749104526120e-6 1.7365751553971340e-6 1.6473160377545360e-6 1.5621465913980060e-6 1.4809178634979940e-6 1.4034829433780260e-6 1.3296974052300520e-6 1.2594193438633260e-6 1.1925097184646100e-6 1.1288323637155430e-6 1.0682538906146330e-6 1.0106437128213760e-6 9.5587472540498280e-7 9.0382333224895500e-7 8.5436937020293650e-7 8.0739610368280600e-7 7.6279018172077200e-7 7.2044165259013450e-7 6.8024432849991400e-7 6.4209580087853050e-7 6.0589741192019800e-7 5.7155423388793000e-7 5.3897464223335550e-7 5.0807031294631050e-7 4.7875659112606760e-7 4.5095249563698380e-7 4.2458045296159330e-7 3.9956628121669190e-7 3.7583910465412180e-7 3.5333134588843600e-7 3.3197864040473180e-7 3.1171981968268900e-7 2.9249662541757600e-7 2.7425370308549580e-7 2.5693874615777660e-7 2.4050245877923400e-7 2.2489759047553620e-7 2.1007899706006800e-7 1.9600594587757850e-7 1.8264184311018150e-7 1.6994592926571220e-7 1.5787424998123710e-7 1.4640931821191640e-7 1.3555636137971380e-7 1.2523109645615350e-7 1.1527363411865760e-7 1.0586659510721950e-7 9.7483190494874640e-8 8.9326871281374790e-8 7.9525034321375090e-8 7.0950903150874990e-8 7.1279389866041690e-8 | ||
| 13 | -table DMIXTABLE | D.11 (DmixTable column) | 33 35 37 39 41 44 46 49 52 55 58 62 65 69 73 78 82 87 92 98 104 110 116 123 130 138 146 155 164 174 184 195 207 219 232 246 260 276 292 309 328 347 368 389 413 437 463 490 519 550 583 617 654 693 734 777 823 872 924 978 1036 1066 1098 1130 1163 1197 1232 1268 1305 1343 1382 1422 1464 1506 1550 1596 1642 1690 1740 1790 1843 1896 1952 2009 2068 2128 2190 2254 2320 2388 2457 2529 2603 2679 2757 2838 2920 3006 3093 3184 3277 3372 3471 3572 3677 3784 3894 4008 4125 4246 4370 4497 4629 4764 4903 5046 5193 5345 5501 5662 5827 5912 5997 6084 6172 6262 6353 6445 6538 6633 6729 6827 6925 7026 7128 7231 7336 7442 7550 7659 7771 7883 7997 8113 8231 8350 8471 8594 8719 8845 8973 9103 9235 9369 9505 9643 9783 9924 10068 10214 10362 10512 10665 10819 10976 11135 11297 11460 11627 11795 11966 12139 12315 12494 12675 12859 13045 13234 13426 13621 13818 14018 14222 14428 14637 14849 15064 15283 15504 15729 15957 16188 16423 16661 16902 17147 17396 17648 17904 18164 18427 18694 18965 19240 19519 19802 20089 20380 20675 20975 21279 21587 21900 22218 22540 22867 23170 23534 23875 24221 24573 24929 25290 25657 26029 26406 26789 27177 27571 27970 28376 28787 29205 29628 30057 30493 30935 31383 31838 32300 32768 | ||
| 14 | -huff A3 | D.5 | 0:1:0 1:2:2 -1:2:3 | ||
| 15 | -huff A5 | D.5 | 0:1:0 1:2:2 -1:3:6 2:4:14 -2:4:15 | ||
| 16 | -huff B5 | D.5 | 0:2:2 1:2:0 -1:2:1 2:3:6 -2:3:7 | ||
| 17 | -huff C5 | D.5 | 0:1:0 1:3:4 -1:3:5 2:3:6 -2:3:7 | ||
| 18 | -huff A7 | D.5 | 0:1:0 1:3:6 -1:3:5 2:3:4 -2:4:14 3:5:31 -3:5:30 | ||
| 19 | -huff B7 | D.5 | 0:2:3 1:2:1 -1:2:0 2:3:4 -2:4:11 3:5:21 -3:5:20 | ||
| 20 | -huff C7 | D.5 | 0:2:3 1:2:2 -1:2:1 2:4:3 -2:4:2 3:4:1 -3:4:0 | ||
| 21 | -huff A9 | D.5 | 0:1:0 1:3:7 -1:3:5 2:4:13 -2:4:9 3:4:8 -3:5:25 4:6:49 -4:6:48 | ||
| 22 | -huff B9 | D.5 | 0:2:2 1:2:0 -1:3:7 2:3:3 -2:3:2 3:5:27 -3:5:26 4:5:25 -4:5:24 | ||
| 23 | -huff C9 | D.5 | 0:2:2 1:2:0 -1:3:7 2:3:6 -2:3:2 3:4:6 -3:5:15 4:6:29 -4:6:28 | ||
| 24 | -huff A13 | D.5 | 0:1:0 1:3:4 -1:4:15 2:4:13 -2:4:12 3:4:10 -3:5:29 4:5:22 -4:6:57 5:6:47 -5:6:46 6:7:113 -6:7:112 | ||
| 25 | -huff B13 | D.5 | 0:2:0 1:3:6 -1:3:5 2:3:2 -2:4:15 3:4:9 -3:4:7 4:4:6 -4:5:29 5:5:17 -5:5:16 6:6:57 -6:6:56 | ||
| 26 | -huff C13 | D.5 | 0:3:5 1:3:4 -1:3:3 2:3:2 -2:3:0 3:4:15 -3:4:14 4:4:12 -4:4:3 5:5:27 -5:5:26 6:5:5 -6:5:4 | ||
| 27 | -huff A17 | D.5 | 0:2:1 1:3:7 -1:3:6 2:3:4 -2:3:1 3:4:11 -3:4:10 4:4:0 -4:5:3 5:6:4 -5:7:11 6:8:20 -6:9:43 7:10:84 -7:11:171 8:12:341 -8:12:340 | ||
| 28 | -huff B17 | D.5 | 0:2:0 1:3:6 -1:3:5 2:3:2 -2:4:15 3:4:9 -3:4:8 4:5:29 -4:5:28 5:5:14 -5:5:13 6:6:30 -6:6:25 7:6:24 -7:7:63 8:8:125 -8:8:124 | ||
| 29 | -huff C17 | D.5 | 0:3:6 1:3:4 -1:3:3 2:3:0 -2:4:15 3:4:11 -3:4:10 4:4:4 -4:4:3 5:5:29 -5:5:28 6:5:10 -6:5:5 7:5:4 -7:6:23 8:7:45 -8:7:44 | ||
| 30 | -huff D17 | D.5 | 0:1:0 1:3:7 -1:3:6 2:4:11 -2:4:10 3:5:19 -3:5:18 4:6:35 -4:6:34 5:7:67 -5:7:66 6:8:131 -6:8:130 7:9:259 -7:9:258 8:9:257 -8:9:256 | ||
| 31 | -huff E17 | D.5 | 0:1:0 1:3:5 -1:3:4 2:4:12 -2:5:31 3:5:28 -3:5:27 4:6:60 -4:6:59 5:6:53 -5:6:52 6:7:122 -6:7:117 7:8:247 -7:8:246 8:8:233 -8:8:232 | ||
| 32 | -huff F17 | D.5 | 0:3:6 1:3:5 -1:3:4 2:3:2 -2:3:1 3:4:15 -3:4:14 4:4:6 -4:4:1 5:5:14 -5:5:1 6:6:31 -6:6:30 7:6:0 -7:7:3 8:8:5 -8:8:4 | ||
| 33 | -huff G17 | D.5 | 0:2:2 1:3:7 -1:3:6 2:3:1 -2:3:0 3:4:5 -3:4:4 4:5:14 -4:5:13 5:6:30 -5:6:25 6:7:62 -6:7:49 7:8:127 -7:8:126 8:8:97 -8:8:96 | ||
| 34 | -huff A25 | D.5 | 0:3:6 1:3:4 -1:3:3 2:3:1 -2:3:0 3:4:15 -3:4:14 4:4:5 -4:4:4 5:5:22 -5:5:21 6:6:47 -6:6:46 7:7:83 -7:7:82 8:8:163 -8:8:162 9:8:160 -9:9:323 10:10:644 -10:11:1291 11:12:2580 -11:13:5163 12:14:10325 -12:14:10324 | ||
| 35 | -huff B25 | D.5 | 0:3:5 1:3:2 -1:3:1 2:4:15 -2:4:14 3:4:9 -3:4:8 4:4:6 -4:4:1 5:5:26 -5:5:25 6:5:15 -6:5:14 7:6:55 -7:6:54 8:6:49 -8:6:48 9:6:1 -9:6:0 10:7:6 -10:7:5 11:7:4 -11:8:15 12:9:29 -12:9:28 | ||
| 36 | -huff C25 | D.5 | 0:3:1 1:4:15 -1:4:14 2:4:12 -2:4:11 3:4:9 -3:4:8 4:4:6 -4:4:5 5:4:1 -5:4:0 6:5:26 -6:5:21 7:5:15 -7:5:14 8:5:8 -8:6:55 9:6:41 -9:6:40 10:6:18 -10:7:109 11:7:108 -11:7:39 12:8:77 -12:8:76 | ||
| 37 | -huff D25 | D.5 | 0:2:2 1:3:7 -1:3:6 2:3:1 -2:3:0 3:4:5 -3:4:4 4:5:13 -4:5:12 5:6:29 -5:6:28 6:7:62 -6:7:61 7:8:126 -7:8:121 8:9:255 -8:9:254 9:10:483 -9:10:482 10:11:963 -10:11:962 11:12:1923 -11:12:1922 12:12:1921 -12:12:1920 | ||
| 38 | -huff E25 | D.5 | 0:2:3 1:3:3 -1:3:2 2:4:11 -2:4:10 3:4:1 -3:4:0 4:5:17 -4:5:16 5:5:5 -5:5:4 6:6:38 -6:6:37 7:6:14 -7:6:13 8:7:79 -8:7:78 9:7:72 -9:7:31 10:7:25 -10:7:24 11:8:147 -11:8:146 12:8:61 -12:8:60 | ||
| 39 | -huff F25 | D.5 | 0:3:1 1:3:0 -1:4:15 2:4:14 -2:4:13 3:4:11 -3:4:10 4:4:8 -4:4:7 5:4:5 -5:4:4 6:5:24 -6:5:19 7:5:13 -7:5:12 8:6:37 -8:6:36 9:7:102 -9:7:101 10:8:207 -10:8:206 11:8:200 -11:9:403 12:10:805 -12:10:804 | ||
| 40 | -huff G25 | D.5 | 0:2:1 1:3:6 -1:3:5 2:3:0 -2:4:15 3:4:8 -3:4:3 4:5:28 -4:5:19 5:5:4 -5:6:59 6:6:36 -6:6:11 7:7:116 -7:7:75 8:7:21 -8:7:20 9:8:149 -9:8:148 10:9:470 -10:9:469 11:10:943 -11:10:942 12:10:937 -12:10:936 | ||
| 41 | -huff A33 | D.5 | 0:3:2 1:3:1 -1:3:0 2:4:14 -2:4:13 3:4:12 -3:4:11 4:4:9 -4:4:8 5:4:6 -5:5:31 6:5:20 -6:5:15 7:6:61 -7:6:60 8:6:29 -8:6:28 9:7:85 -9:7:84 10:8:174 -10:8:173 11:9:351 -11:9:350 12:10:691 -12:10:690 13:11:1379 -13:11:1378 14:12:2755 -14:12:2754 15:13:5507 -15:13:5506 16:13:5505 -16:13:5504 | ||
| 42 | -huff B33 | D.5 | 0:3:1 1:4:15 -1:4:14 2:4:11 -2:4:10 3:4:8 -3:4:7 4:4:4 -4:4:1 5:5:27 -5:5:26 6:5:19 -6:5:18 7:5:12 -7:5:11 8:5:1 -8:5:0 9:6:50 -9:6:49 10:6:26 -10:6:21 11:7:103 -11:7:102 12:7:96 -12:7:55 13:7:41 -13:7:40 14:8:194 -14:8:109 15:8:108 -15:9:391 16:10:781 -16:10:780 | ||
| 43 | -huff C33 | D.5 | 0:4:13 1:4:11 -1:4:10 2:4:8 -2:4:7 3:4:4 -3:4:3 4:4:2 -4:4:1 5:5:30 -5:5:29 6:5:25 -6:5:24 7:5:19 -7:5:18 8:5:11 -8:5:10 9:5:0 -9:6:63 10:6:62 -10:6:57 11:6:27 -11:6:26 12:6:24 -12:6:3 13:7:113 -13:7:112 14:7:50 -14:7:5 15:7:4 -15:8:103 16:9:205 -16:9:204 | ||
| 44 | -huff D33 | D.5 | 0:2:1 1:3:6 -1:3:5 2:3:0 -2:4:15 3:4:8 -3:4:3 4:5:28 -4:5:19 5:5:4 -5:6:59 6:6:36 -6:6:11 7:7:116 -7:7:75 8:7:21 -8:7:20 9:8:149 -9:8:148 10:9:469 -10:9:468 11:10:941 -11:10:940 12:11:1885 -12:11:1884 13:12:3773 -13:12:3772 14:13:7551 -14:13:7550 15:14:15099 -15:14:15098 16:14:15097 -16:14:15096 | ||
| 45 | -huff E33 | D.5 | 0:2:2 1:3:2 -1:3:1 2:4:12 -2:4:7 3:4:0 -3:5:31 4:5:27 -4:5:26 5:5:3 -5:5:2 6:6:59 -6:6:58 7:6:27 -7:6:26 8:7:123 -8:7:122 9:7:120 -9:7:115 10:7:112 -10:7:51 11:7:49 -11:7:48 12:8:242 -12:8:229 13:8:227 -13:8:226 14:8:101 -14:8:100 15:9:487 -15:9:486 16:9:457 -16:9:456 | ||
| 46 | -huff F33 | D.5 | 0:4:13 1:4:12 -1:4:11 2:4:9 -2:4:8 3:4:7 -3:4:6 4:4:4 -4:4:3 5:4:1 -5:4:0 6:5:30 -6:5:29 7:5:21 -7:5:20 8:5:10 -8:5:5 9:6:63 -9:6:62 10:6:56 -10:6:23 11:6:9 -11:6:8 12:7:45 -12:7:44 13:8:230 -13:8:229 14:9:463 -14:9:462 15:9:456 -15:10:915 16:11:1829 -16:11:1828 | ||
| 47 | -huff G33 | D.5 | 0:3:6 1:3:3 -1:3:2 2:4:15 -2:4:14 3:4:9 -3:4:8 4:4:1 -4:4:0 5:5:22 -5:5:21 6:5:6 -6:5:5 7:6:46 -7:6:41 8:6:14 -8:6:9 9:7:94 -9:7:81 10:7:30 -10:7:17 11:8:191 -11:8:190 12:8:63 -12:8:62 13:8:32 -13:9:323 14:9:321 -14:9:320 15:9:67 -15:9:66 16:10:645 -16:10:644 | ||
| 48 | -huff A65 | D.5 | 0:4:6 1:4:5 -1:4:4 2:4:2 -2:4:1 3:4:0 -3:5:31 4:5:29 -4:5:28 5:5:27 -5:5:26 6:5:24 -6:5:23 7:5:21 -7:5:20 8:5:18 -8:5:17 9:5:14 -9:5:7 10:5:6 -10:6:61 11:6:50 -11:6:45 12:6:38 -12:6:33 13:6:31 -13:6:30 14:7:120 -14:7:103 15:7:89 -15:7:88 16:7:65 -16:7:64 17:8:205 -17:8:204 18:8:157 -18:8:156 19:9:486 -19:9:485 20:9:318 -20:9:317 21:10:975 -21:10:974 22:10:639 -22:10:638 23:11:1939 -23:11:1938 24:11:1936 -24:11:1267 25:11:1264 -25:12:3875 26:12:2532 -26:12:2531 27:13:7749 -27:13:7748 28:13:5061 -28:13:5060 29:14:10133 -29:14:10132 30:15:20269 -30:15:20268 31:16:40543 -31:16:40542 32:16:40541 -32:16:40540 | ||
| 49 | -huff B65 | D.5 | 0:4:4 1:4:2 -1:4:1 2:5:30 -2:5:29 3:5:26 -3:5:25 4:5:23 -4:5:22 5:5:19 -5:5:18 6:5:16 -6:5:15 7:5:12 -7:5:11 8:5:7 -8:5:6 9:6:63 -9:6:62 10:6:56 -10:6:55 11:6:49 -11:6:48 12:6:41 -12:6:40 13:6:34 -13:6:29 14:6:26 -14:6:21 15:6:20 -15:6:3 16:6:0 -16:7:115 17:7:109 -17:7:108 18:7:86 -18:7:85 19:7:70 -19:7:57 20:7:56 -20:7:55 21:7:4 -21:7:3 22:8:229 -22:8:228 23:8:175 -23:8:174 24:8:143 -24:8:142 25:8:108 -25:8:11 26:8:10 -26:8:5 27:9:339 -27:9:338 28:9:336 -28:9:219 29:9:9 -29:9:8 30:10:674 -30:10:437 31:10:436 -31:11:1351 32:12:2701 -32:12:2700 | ||
| 50 | -huff C65 | D.5 | 0:5:28 1:5:25 -1:5:24 2:5:23 -2:5:22 3:5:19 -3:5:18 4:5:16 -4:5:15 5:5:13 -5:5:12 6:5:10 -6:5:9 7:5:7 -7:5:6 8:5:4 -8:5:3 9:5:1 -9:5:0 10:6:62 -10:6:61 11:6:59 -11:6:58 12:6:54 -12:6:53 13:6:43 -13:6:42 14:6:40 -14:6:35 15:6:29 -15:6:28 16:6:17 -16:6:16 17:6:11 -17:6:10 18:6:4 -18:7:127 19:7:121 -19:7:120 20:7:110 -20:7:105 21:7:83 -21:7:82 22:7:68 -22:7:47 23:7:46 -23:7:45 24:7:11 -24:7:10 25:8:252 -25:8:223 26:8:209 -26:8:208 27:8:138 -27:8:89 28:8:88 -28:9:507 29:9:445 -29:9:444 30:9:278 -30:10:1013 31:10:1012 -31:10:559 32:11:1117 -32:11:1116 | ||
| 51 | -huff D65 | D.5 [rows +-31,+-32 completed, see generator] | 0:3:4 1:3:1 -1:3:0 2:4:13 -2:4:12 3:4:7 -3:4:6 4:5:31 -4:5:30 5:5:23 -5:5:22 6:5:11 -6:5:10 7:6:59 -7:6:58 8:6:43 -8:6:42 9:6:19 -9:6:18 10:7:115 -10:7:114 11:7:83 -11:7:82 12:7:35 -12:7:34 13:8:227 -13:8:226 14:8:163 -14:8:162 15:8:160 -15:8:67 16:8:64 -16:9:451 17:9:448 -17:9:323 18:9:132 -18:9:131 19:10:900 -19:10:899 20:10:644 -20:10:267 21:10:261 -21:10:260 22:11:1797 -22:11:1796 23:11:533 -23:11:532 24:12:3605 -24:12:3604 25:12:2582 -25:12:2581 26:13:7215 -26:13:7214 27:13:5167 -27:13:5166 28:13:5160 -28:14:14427 29:14:10323 -29:14:10322 30:15:28853 -30:15:28852 -32:15:28848 32:15:28849 -31:15:28850 31:15:28851 | ||
| 52 | -huff E65 | D.5 | 0:3:4 1:3:0 -1:4:15 2:4:7 -2:4:6 3:5:29 -3:5:28 4:5:23 -4:5:22 5:5:10 -5:5:9 6:5:6 -6:5:5 7:6:54 -7:6:53 8:6:48 -8:6:43 9:6:40 -9:6:23 10:6:16 -10:6:15 11:6:9 -11:6:8 12:7:105 -12:7:104 13:7:100 -13:7:99 14:7:84 -14:7:83 15:7:45 -15:7:44 16:7:29 -16:7:28 17:8:221 -17:8:220 18:8:206 -18:8:205 19:8:202 -19:8:197 20:8:171 -20:8:170 21:8:164 -21:8:71 22:8:69 -22:8:68 23:9:446 -23:9:445 24:9:415 -24:9:414 25:9:408 -25:9:407 26:9:393 -26:9:392 27:9:331 -27:9:330 28:9:141 -28:9:140 29:10:895 -29:10:894 30:10:889 -30:10:888 31:10:819 -31:10:818 32:10:813 -32:10:812 | ||
| 53 | -huff F65 | D.5 | 0:3:6 1:3:3 -1:3:2 2:4:15 -2:4:14 3:4:9 -3:4:8 4:4:1 -4:4:0 5:5:21 -5:5:20 6:5:5 -6:5:4 7:6:45 -7:6:44 8:6:13 -8:6:12 9:7:93 -9:7:92 10:7:29 -10:7:28 11:8:189 -11:8:188 12:8:61 -12:8:60 13:9:381 -13:9:380 14:9:125 -14:9:124 15:10:765 -15:10:764 16:10:252 -16:11:1535 17:11:1532 -17:11:511 18:11:506 -18:12:3069 19:12:3067 -19:12:3066 20:12:1015 -20:12:1014 21:13:6136 -21:13:2043 22:13:2035 -22:13:2034 23:14:12275 -23:14:12274 24:14:4085 -24:14:4084 25:14:4083 -25:14:4082 26:14:4081 -26:14:4080 27:14:4079 -27:14:4078 28:14:4077 -28:14:4076 29:14:4075 -29:14:4074 30:14:4073 -30:14:4072 31:14:4067 -31:14:4066 32:14:4065 -32:14:4064 | ||
| 54 | -huff G65 | D.5 | 0:4:14 1:4:11 -1:4:10 2:4:8 -2:4:6 3:4:4 -3:4:3 4:4:0 -4:5:31 5:5:26 -5:5:25 6:5:18 -6:5:15 7:5:10 -7:5:5 8:5:2 -8:6:61 9:6:54 -9:6:49 10:6:38 -10:6:29 11:6:22 -11:6:9 12:6:6 -12:7:121 13:7:110 -13:7:97 14:7:78 -14:7:57 15:7:46 -15:7:17 16:7:14 -16:8:241 17:8:223 -17:8:222 18:8:159 -18:8:158 19:8:95 -19:8:94 20:8:31 -20:8:30 21:9:480 -21:9:387 22:9:384 -22:9:227 23:9:225 -23:9:224 24:9:65 -24:9:64 25:10:962 -25:10:773 26:10:771 -26:10:770 27:10:452 -27:10:135 28:10:133 -28:10:132 29:11:1927 -29:11:1926 30:11:1545 -30:11:1544 31:11:907 -31:11:906 32:11:269 -32:11:268 | ||
| 55 | -huff A129 | D.5 | 0:4:8 23:8:231 -45:9:36 1:4:10 -23:8:230 46:10:950 -1:4:9 24:8:223 -46:10:945 2:4:0 -24:8:222 47:10:919 -2:5:31 25:8:211 -47:10:918 3:5:24 -25:8:210 48:10:912 -3:5:23 26:8:203 -48:10:887 4:5:12 -26:8:202 49:10:881 -4:5:11 27:8:123 -49:10:880 5:5:5 -27:8:122 50:10:818 -5:5:4 28:8:116 -50:10:817 6:6:60 -28:8:107 51:10:499 -6:6:58 29:8:84 -51:10:498 7:6:54 -29:8:83 52:10:469 -7:6:53 30:8:68 -52:10:468 8:6:45 -30:8:67 53:10:343 -8:6:44 31:8:60 -53:10:342 9:6:28 -31:8:51 54:10:329 -9:6:27 32:8:49 -54:10:328 10:6:19 -32:8:48 55:10:267 -10:6:18 33:8:17 -55:10:266 11:6:14 -33:8:16 56:10:245 -11:6:13 34:9:474 -56:10:244 12:6:6 -34:9:473 57:10:79 -12:6:5 35:9:458 -57:10:78 13:7:122 -35:9:457 58:10:77 -13:7:119 36:9:442 -58:10:76 14:7:113 -36:9:441 59:11:1903 -14:7:112 37:9:411 -59:11:1902 15:7:104 -37:9:410 60:11:1889 -15:7:103 38:9:251 -60:11:1888 16:7:100 -38:9:250 61:11:1827 -16:7:63 39:9:248 -61:11:1826 17:7:60 -39:9:235 62:11:1773 -17:7:59 40:9:213 -62:11:1772 18:7:52 -40:9:212 63:11:1639 -18:7:43 41:9:170 -63:11:1638 19:7:40 -41:9:165 64:11:1633 -19:7:35 42:9:139 -64:11:1632 20:7:32 -42:9:138 -20:7:31 43:9:132 21:7:15 -43:9:123 -21:7:14 44:9:101 22:8:247 -44:9:100 -22:8:246 45:9:37 | ||
| 56 | -huff B129 | D.5 | 0:5:10 23:7:89 -45:9:390 1:5:7 -23:7:88 46:9:388 -1:5:6 24:7:81 -46:9:335 2:5:4 -24:7:80 47:9:329 -2:5:3 25:7:74 -47:9:328 3:5:0 -25:7:73 48:9:269 -3:6:63 26:7:66 -48:9:268 4:6:60 -26:7:61 49:9:215 -4:6:59 27:7:59 -49:9:214 5:6:57 -27:7:58 50:9:184 -5:6:56 28:7:52 -50:9:139 6:6:53 -28:7:47 51:9:29 -6:6:52 29:7:37 -51:9:28 7:6:50 -29:7:36 52:10:934 -7:6:49 30:7:21 -52:10:929 8:6:46 -30:7:20 53:10:779 -8:6:45 31:7:6 -53:10:778 9:6:43 -31:7:5 54:10:668 -9:6:42 32:8:247 -54:10:583 10:6:39 -32:8:246 55:10:582 -10:6:38 33:8:223 -55:10:581 11:6:35 -33:8:222 56:10:371 -11:6:34 34:8:217 -56:10:370 12:6:32 -34:8:216 57:10:276 -12:6:31 35:8:189 -57:11:1871 13:6:28 -35:8:188 58:11:1857 -13:6:27 36:8:166 -58:11:1856 14:6:25 -36:8:165 59:11:1338 -14:6:24 37:8:151 -59:11:1161 15:6:22 -37:8:150 60:11:1160 -15:6:19 38:8:144 -60:11:555 16:6:16 -38:8:135 61:12:3741 -16:6:11 39:8:121 -61:12:3740 17:6:5 -39:8:120 62:12:2678 -17:6:4 40:8:106 -62:12:1109 18:7:125 -40:8:93 63:12:1108 -18:7:124 41:8:71 -63:13:5359 19:7:122 -41:8:70 64:14:10717 -19:7:117 42:8:68 -64:14:10716 20:7:110 -42:8:15 -20:7:109 43:8:9 21:7:103 -43:8:8 -21:7:102 44:9:466 22:7:96 -44:9:465 -22:7:95 45:9:391 | ||
| 57 | -huff C129 | D.5 | 0:6:58 23:7:113 -45:8:100 1:6:55 -23:7:112 46:8:66 -1:6:54 24:7:106 -46:8:65 2:6:52 -24:7:101 47:8:43 -2:6:51 25:7:95 -47:8:42 3:6:49 -25:7:94 48:8:17 -3:6:48 26:7:88 -48:8:16 4:6:46 -26:7:83 49:8:2 -4:6:45 27:7:77 -49:9:501 5:6:43 -27:7:76 50:9:479 -5:6:42 28:7:70 -50:9:478 6:6:40 -28:7:65 51:9:456 -6:6:39 29:7:64 -51:9:403 7:6:37 -29:7:63 52:9:357 -7:6:36 30:7:56 -52:9:356 8:6:34 -30:7:51 53:9:251 -8:6:33 31:7:45 -53:9:250 9:6:30 -31:7:44 54:9:228 -9:6:29 32:7:39 -54:9:135 10:6:27 -32:7:38 55:9:129 -10:6:26 33:7:31 -55:9:128 11:6:24 -33:7:30 56:9:6 -11:6:23 34:7:20 -56:10:1001 12:6:21 -34:7:19 57:10:1000 -12:6:20 35:7:18 -57:10:915 13:6:18 -35:7:9 58:10:805 -13:6:17 36:7:3 -58:10:804 14:6:14 -36:7:2 59:10:458 -14:6:13 37:7:0 -59:10:269 15:6:12 -37:8:251 60:10:268 -15:6:11 38:8:245 -60:10:15 16:6:8 -38:8:244 61:11:1829 -16:6:7 39:8:238 -61:11:1828 17:6:6 -39:8:229 62:11:918 -17:6:5 40:8:215 -62:11:29 18:6:3 -40:8:214 63:11:28 -18:6:2 41:8:200 -63:12:1839 19:7:127 -41:8:179 64:13:3677 -19:7:126 42:8:165 -64:13:3676 20:7:124 -42:8:164 -20:7:123 43:8:143 21:7:121 -43:8:142 -21:7:120 44:8:124 22:7:118 -44:8:115 -22:7:115 45:8:101 | ||
| 58 | -huff D129 | D.5 | 0:4:9 23:8:116 -45:12:851 1:4:6 -23:8:75 46:12:849 -1:4:5 24:8:52 -46:12:848 2:4:2 -24:8:11 47:13:7346 -2:4:1 25:9:501 -47:13:7345 3:5:30 -25:9:500 48:13:6322 -3:5:29 26:9:437 -48:13:5309 4:5:26 -26:9:436 49:13:3773 -4:5:25 27:9:373 -49:13:3772 5:5:22 -27:9:372 50:13:3762 -5:5:21 28:9:277 -50:13:1701 6:5:16 -28:9:276 51:14:14695 -6:5:15 29:9:149 -51:14:14694 7:5:8 -29:9:148 52:14:14688 -7:5:7 30:9:21 -52:14:12647 8:5:0 -30:9:20 53:14:10617 -8:6:63 31:10:917 -53:14:10616 9:6:56 -31:10:916 54:14:10596 -9:6:55 32:10:789 -54:14:7527 10:6:48 -32:10:788 55:14:3401 -10:6:47 33:10:661 -55:14:3400 11:6:40 -33:10:660 56:15:29378 -11:6:35 34:10:469 -56:15:25293 12:6:28 -34:10:468 57:15:21195 -12:6:19 35:10:214 -57:15:21194 13:6:12 -35:10:213 58:15:15053 -13:6:3 36:11:1838 -58:15:15052 14:7:124 -36:11:1837 59:16:58759 -14:7:115 37:11:1582 -59:16:58758 15:7:108 -37:11:1581 60:16:50585 -15:7:99 38:11:1326 -60:16:50584 16:7:92 -38:11:1325 61:16:42399 -16:7:83 39:11:942 -61:16:42398 17:7:68 -39:11:941 62:16:42397 -17:7:59 40:11:431 -62:16:42396 18:7:36 -40:11:430 63:16:42395 -18:7:27 41:12:3679 -63:16:42394 19:7:4 -41:12:3678 64:16:42393 -19:8:251 42:12:3167 -64:16:42392 20:8:228 -42:12:3166 -20:8:219 43:12:3160 21:8:196 -43:12:2655 -21:8:187 44:12:2648 22:8:164 -44:12:1887 -22:8:139 45:12:1880 | ||
| 59 | -huff E129 | D.5 | 0:5:12 23:7:87 -45:11:1059 1:5:11 -23:7:86 46:11:877 -1:5:10 24:7:79 -46:11:876 2:5:9 -24:7:78 47:12:3197 -2:5:8 25:7:68 -47:12:3196 3:5:7 -25:7:67 48:12:2589 -3:5:6 26:7:60 -48:12:2588 4:5:4 -26:7:55 49:12:2117 -4:5:3 27:7:21 -49:12:2116 5:5:2 -27:7:20 50:13:7398 -5:5:1 28:8:230 -50:13:7397 6:5:0 -28:8:229 51:13:6374 -6:6:63 29:8:198 -51:13:6373 7:6:61 -29:8:193 52:13:5158 -7:6:60 30:8:163 -52:13:5157 8:6:59 -30:8:162 53:14:14799 -8:6:58 31:8:139 -53:14:14798 9:6:56 -31:8:138 54:14:12751 -9:6:55 32:8:123 -54:14:12750 10:6:53 -32:8:122 55:14:10318 -10:6:52 33:8:108 -55:14:10313 11:6:51 -33:9:463 56:15:29587 -11:6:50 34:9:457 -56:15:29586 12:6:47 -34:9:456 57:15:29584 -12:6:46 35:9:385 -57:15:25491 13:6:45 -35:9:384 58:15:20625 -13:6:44 36:9:321 -58:15:20624 14:6:42 -36:9:320 59:16:59171 -14:6:41 37:9:266 -59:16:59170 15:6:38 -37:9:265 60:16:50980 -15:6:37 38:9:218 -60:16:41277 16:6:36 -38:10:925 61:16:50981 -16:6:35 39:10:798 -61:16:41278 17:6:32 -39:10:797 62:16:50978 -17:6:31 40:10:646 -62:16:41279 18:6:29 -40:10:645 63:16:50979 -18:6:28 41:10:535 -63:16:50976 19:6:26 -41:10:534 64:16:50977 -19:6:11 42:10:528 -64:16:41276 20:7:125 -42:10:439 -20:7:124 43:11:1848 21:7:109 -43:11:1599 -21:7:108 44:11:1592 22:7:98 -44:11:1295 -22:7:97 45:11:1288 | ||
| 60 | -huff F129 | D.5 | 0:6:56 23:7:125 -45:9:473 1:6:55 -23:7:124 46:9:343 -1:6:54 24:7:123 -46:9:342 2:6:52 -24:7:122 47:9:340 -2:6:51 25:7:120 -47:9:223 3:6:50 -25:7:119 48:9:192 -3:6:49 26:7:116 -48:9:135 4:6:48 -26:7:115 49:9:129 -4:6:47 27:7:114 -49:9:128 5:6:46 -27:7:107 50:9:34 -5:6:45 28:7:84 -50:10:1021 6:6:44 -28:7:75 51:10:951 -6:6:43 29:7:65 -51:10:950 7:6:41 -29:7:64 52:10:944 -7:6:40 30:7:54 -52:10:683 8:6:39 -30:7:49 53:10:445 -8:6:38 31:7:39 -53:10:444 9:6:36 -31:7:38 54:10:269 -9:6:35 32:7:27 -54:10:268 10:6:34 -32:7:26 55:10:71 -10:6:33 33:7:20 -55:10:70 11:6:31 -33:7:11 56:11:2040 -11:6:30 34:7:10 -56:11:1891 12:6:29 -34:7:9 57:11:1364 -12:6:28 35:8:254 -57:11:775 13:6:26 -35:8:253 58:11:774 -13:6:25 36:8:243 -58:11:773 14:6:23 -36:8:242 59:12:4083 -14:6:22 37:8:235 -59:12:4082 15:6:21 -37:8:234 60:12:3780 -15:6:20 38:8:213 -60:12:2731 16:6:18 -38:8:212 61:12:1545 -16:6:17 39:8:149 -61:12:1544 17:6:15 -39:8:148 62:13:7562 -17:6:14 40:8:110 -62:13:5461 18:6:12 -40:8:97 63:13:5460 -18:6:11 41:8:66 -63:14:15127 19:6:9 -41:8:65 64:15:30253 -19:6:8 42:8:43 -64:15:30252 20:6:7 -42:8:42 -20:6:6 43:8:16 21:6:3 -43:9:511 -21:6:2 44:9:505 22:6:1 -44:9:504 -22:6:0 45:9:474 | ||
| 61 | -huff G129 | D.5 | 0:4:0 23:7:11 -45:10:328 1:5:29 -23:7:10 46:10:201 -1:5:28 24:7:8 -46:10:200 2:5:25 -24:8:243 47:10:198 -2:5:24 25:8:240 -47:10:73 3:5:21 -25:8:211 48:11:1942 -3:5:20 26:8:208 -48:11:1929 4:5:17 -26:8:179 49:11:1675 -4:5:16 27:8:176 -49:11:1674 5:5:13 -27:8:147 50:11:1672 -5:5:12 28:8:144 -50:11:1419 6:5:9 -28:8:115 51:11:1165 -6:5:8 29:8:112 -51:11:1164 7:5:5 -29:8:83 52:11:1162 -7:5:4 30:8:80 -52:11:909 8:6:63 -30:8:51 53:11:655 -8:6:62 31:8:48 -53:11:654 9:6:55 -31:8:19 54:11:652 -9:6:54 32:9:484 -54:11:399 10:6:47 -32:9:483 55:11:145 -10:6:46 33:9:421 -55:11:144 11:6:39 -33:9:420 56:12:3886 -11:6:38 34:9:357 -56:12:3857 12:6:31 -34:9:356 57:12:3347 -12:6:30 35:9:293 -57:12:3346 13:6:23 -35:9:292 58:12:2837 -13:6:22 36:9:229 -58:12:2836 14:6:15 -36:9:228 59:12:2327 -14:6:14 37:9:226 -59:12:2326 15:6:7 -37:9:165 60:12:1817 -15:6:6 38:9:162 -60:12:1816 16:7:123 -38:9:101 61:12:1307 -16:7:122 39:9:98 -61:12:1306 17:7:107 -39:9:37 62:12:797 -17:7:106 40:10:970 -62:12:796 18:7:91 -40:10:965 63:13:7775 -18:7:90 41:10:839 -63:13:7774 19:7:75 -41:10:838 64:13:7713 -19:7:74 42:10:711 -64:13:7712 20:7:59 -42:10:710 -20:7:58 43:10:708 21:7:43 -43:10:583 -21:7:42 44:10:580 22:7:27 -44:10:455 -22:7:26 45:10:329 | ||
| 62 | -huff A12 | D.5 | 1:1:0 2:2:2 3:3:6 4:4:14 5:5:30 6:6:62 7:8:255 8:8:254 9:9:507 10:9:506 11:9:505 12:9:504 | ||
| 63 | -huff B12 | D.5 | 1:1:1 2:2:0 3:3:2 4:5:15 5:5:12 6:6:29 7:7:57 8:7:56 9:7:55 10:7:54 11:7:53 12:7:52 | ||
| 64 | -huff C12 | D.5 | 1:2:0 2:3:7 3:3:5 4:3:4 5:3:2 6:4:13 7:4:12 8:4:6 9:5:15 10:6:29 11:7:57 12:7:56 | ||
| 65 | -huff D12 | D.5 | 1:2:3 2:2:2 3:2:0 4:3:2 5:4:6 6:5:14 7:6:30 8:7:62 9:8:126 10:9:254 11:10:511 12:10:510 | ||
| 66 | -huff E12 | D.5 | 1:1:1 2:2:0 3:3:2 4:4:6 5:5:14 6:7:63 7:7:61 8:8:124 9:8:121 10:8:120 11:9:251 12:9:250 | ||
| 67 | -huff SA129 | D.5 | 0:2:1 23:13:1347 -45:14:15062 1:3:6 -23:13:1346 46:14:15061 -1:3:5 24:13:1345 -46:14:15060 2:3:0 -24:13:1344 47:14:15059 -2:4:15 25:14:15103 -47:14:15058 3:4:8 -25:14:15102 48:14:15057 -3:4:3 26:14:15101 -48:14:15056 4:5:28 -26:14:15100 49:14:15055 -4:5:19 27:14:15099 -49:14:15054 5:5:4 -27:14:15098 50:14:15053 -5:6:59 28:14:15097 -50:14:15052 6:6:36 -28:14:15096 51:14:15051 -6:6:11 29:14:15095 -51:14:15050 7:7:75 -29:14:15094 52:14:15049 -7:7:74 30:14:15093 -52:14:15048 8:8:233 -30:14:15092 53:14:15047 -8:8:232 31:14:15091 -53:14:15046 9:8:41 -31:14:15090 54:14:15045 -9:8:40 32:14:15089 -54:14:15044 10:9:87 -32:14:15088 55:14:15043 -10:9:86 33:14:15087 -55:14:15042 11:10:937 -33:14:15086 56:14:15041 -11:10:936 34:14:15085 -56:14:15040 12:11:1877 -34:14:15084 57:14:15039 -12:11:1876 35:14:15083 -57:14:15038 13:11:341 -35:14:15082 58:14:15037 -13:11:340 36:14:15081 -58:14:15036 14:12:686 -36:14:15080 59:14:15035 -14:12:685 37:14:15079 -59:14:15034 15:13:1375 -37:14:15078 60:14:15033 -15:13:1374 38:14:15077 -60:14:15032 16:13:1369 -38:14:15076 61:14:15031 -16:13:1368 39:14:15075 -61:14:15030 17:13:1359 -39:14:15074 62:14:15029 -17:13:1358 40:14:15073 -62:14:15028 18:13:1357 -40:14:15072 63:14:15027 -18:13:1356 41:14:15071 -63:14:15026 19:13:1355 -41:14:15070 64:14:15025 -19:13:1354 42:14:15069 -64:14:15024 20:13:1353 -42:14:15068 -20:13:1352 43:14:15067 21:13:1351 -43:14:15066 -21:13:1350 44:14:15065 22:13:1349 -44:14:15064 -22:13:1348 45:14:15063 | ||
| 68 | -huff SB129 | D.5 | 0:3:3 23:15:4019 -45:15:3974 1:3:2 -23:15:4018 46:15:3973 -1:3:1 24:15:4017 -46:15:3972 2:4:15 -24:15:4016 47:15:3971 -2:4:14 25:15:4015 -47:15:3970 3:4:12 -25:15:4014 48:15:3969 -3:4:11 26:15:4013 -48:15:3968 4:4:10 -26:15:4012 49:15:3967 -4:4:9 27:15:4011 -49:15:3966 5:4:0 -27:15:4010 50:15:3965 -5:5:27 28:15:4009 -50:15:3964 6:5:17 -28:15:4008 51:15:3963 -6:5:16 29:15:4007 -51:15:3962 7:6:53 -29:15:4006 52:15:3961 -7:6:52 30:15:4005 -52:15:3960 8:6:5 -30:15:4004 53:15:3959 -8:6:4 31:15:4003 -53:15:3958 9:7:13 -31:15:4002 54:15:3957 -9:7:12 32:15:4001 -54:15:3956 10:8:29 -32:15:4000 55:15:3955 -10:8:28 33:15:3999 -55:15:3954 11:9:60 -33:15:3998 56:15:3953 -11:10:127 34:15:3997 -56:15:3952 12:11:253 -34:15:3996 57:15:3951 -12:11:252 35:15:3995 -57:15:3950 13:12:491 -35:15:3994 58:15:3949 -13:12:490 36:15:3993 -58:15:3948 14:13:979 -36:15:3992 59:15:3947 -14:13:978 37:15:3991 -59:15:3946 15:14:1955 -37:15:3990 60:15:3945 -15:14:1954 38:15:3989 -60:15:3944 16:14:1953 -38:15:3988 61:15:3943 -16:14:1952 39:15:3987 -61:15:3942 17:15:4031 -39:15:3986 62:15:3941 -17:15:4030 40:15:3985 -62:15:3940 18:15:4029 -40:15:3984 63:15:3939 -18:15:4028 41:15:3983 -63:15:3938 19:15:4027 -41:15:3982 64:15:3937 -19:15:4026 42:15:3981 -64:15:3936 20:15:4025 -42:15:3980 -20:15:4024 43:15:3979 21:15:4023 -43:15:3978 -21:15:4022 44:15:3977 22:15:4021 -44:15:3976 -22:15:4020 45:15:3975 | ||
| 69 | -huff SC129 | D.5 | 0:3:4 23:11:540 -45:15:20982 1:3:1 -23:11:539 46:15:20981 -1:3:0 24:12:3612 -46:15:20980 2:4:13 -24:12:3611 47:15:20979 -2:4:12 25:12:2613 -47:15:20978 3:4:7 -25:12:2612 48:15:20977 -3:4:6 26:12:1077 -48:15:20976 4:5:31 -26:12:1076 49:15:20975 -4:5:30 27:13:7226 -49:15:20974 5:5:23 -27:13:7221 50:15:20973 -5:5:22 28:13:2167 -50:15:20972 6:5:11 -28:13:2166 51:15:20971 -6:5:10 29:13:2164 -51:15:20970 7:6:59 -29:14:14455 52:15:20969 -7:6:58 30:14:14441 -52:15:20968 8:6:43 -30:14:14440 53:15:20967 -8:6:42 31:14:4331 -53:15:20966 9:6:19 -31:14:4330 54:15:20965 -9:6:18 32:15:28909 -54:15:20964 10:7:115 -32:15:28908 55:15:20963 -10:7:114 33:15:28879 -55:15:20962 11:7:83 -33:15:28878 56:15:20961 -11:7:82 34:15:28877 -56:15:20960 12:7:35 -34:15:28876 57:15:20959 -12:7:34 35:15:28875 -57:15:20958 13:8:227 -35:15:28874 58:15:20957 -13:8:226 36:15:28873 -58:15:20956 14:8:162 -36:15:28872 59:15:20955 -14:8:161 37:15:28871 -59:15:20954 15:8:66 -37:15:28870 60:15:20953 -15:8:65 38:15:28869 -60:15:20952 16:9:450 -38:15:28868 61:15:20951 -16:9:449 39:15:28867 -61:15:20950 17:9:321 -39:15:28866 62:15:20949 -17:9:320 40:15:28865 -62:15:20948 18:9:129 -40:15:28864 63:15:20947 -18:9:128 41:15:20991 -63:15:20946 19:10:897 -41:15:20990 64:15:20945 -19:10:896 42:15:20989 -64:15:20944 20:10:652 -42:15:20988 -20:10:271 43:15:20987 21:10:268 -43:15:20986 -21:11:1807 44:15:20985 22:11:1308 -44:15:20984 -22:11:1307 45:15:20983 | ||
| 70 | -huff SD129 | D.5 | 0:2:0 23:15:28599 -45:15:28554 1:3:5 -23:15:28598 46:15:28553 -1:3:4 24:15:28597 -46:15:28552 2:4:15 -24:15:28596 47:15:28551 -2:4:14 25:15:28595 -47:15:28550 3:4:7 -25:15:28594 48:15:28549 -3:4:6 26:15:28593 -48:15:28548 4:5:26 -26:15:28592 49:15:28547 -4:5:25 27:15:28591 -49:15:28546 5:5:10 -27:15:28590 50:15:28545 -5:5:9 28:15:28589 -50:15:28544 6:6:54 -28:15:28588 51:15:28543 -6:6:49 29:15:28587 -51:15:28542 7:6:22 -29:15:28586 52:15:28541 -7:6:17 30:15:28585 -52:15:28540 8:7:110 -30:15:28584 53:15:28539 -8:7:97 31:15:28583 -53:15:28538 9:7:46 -31:15:28582 54:15:28537 -9:7:33 32:15:28581 -54:15:28536 10:8:193 -32:15:28580 55:15:28535 -10:8:192 33:15:28579 -55:15:28534 11:8:65 -33:15:28578 56:15:28533 -11:8:64 34:15:28577 -56:15:28532 12:9:444 -34:15:28576 57:15:28531 -12:9:191 35:15:28575 -57:15:28530 13:9:188 -35:15:28574 58:15:28529 -13:10:895 36:15:28573 -58:15:28528 14:10:890 -36:15:28572 59:15:28527 -14:10:381 37:15:28571 -59:15:28526 15:10:378 -37:15:28570 60:15:28525 -15:11:1789 38:15:28569 -60:15:28524 16:11:761 -38:15:28568 61:15:28523 -16:11:760 39:15:28567 -61:15:28522 17:12:3577 -39:15:28566 62:15:28521 -17:12:3576 40:15:28565 -62:15:28520 18:12:1519 -40:15:28564 63:15:28519 -18:12:1518 41:15:28563 -63:15:28518 19:12:1516 -41:15:28562 64:15:28517 -19:13:7151 42:15:28561 -64:15:28516 20:13:7128 -42:15:28560 -20:13:3035 43:15:28559 21:14:14301 -43:15:28558 -21:14:14300 44:15:28557 22:14:6069 -44:15:28556 -22:14:6068 45:15:28555 | ||
| 71 | -huff SE129 | D.5 | 0:4:14 23:9:189 -45:15:28662 1:4:11 -23:9:188 46:15:28585 -1:4:10 24:9:61 -46:15:28584 2:4:7 -24:9:60 47:15:12267 -2:4:6 25:10:892 -47:15:12266 3:4:3 -25:10:639 48:15:4073 -3:4:2 26:10:637 -48:15:4072 4:5:31 -26:10:636 49:16:57315 -4:5:30 27:10:381 -49:16:57314 5:5:25 -27:10:380 50:16:57313 -5:5:24 28:10:125 -50:16:57312 6:5:17 -28:10:124 51:16:57311 -6:5:16 29:11:1788 -51:16:57310 7:5:9 -29:11:1787 52:16:57309 -7:5:8 30:11:1276 -52:16:57308 8:5:1 -30:11:767 53:16:57307 -8:5:0 31:11:764 -53:16:57306 9:6:53 -31:11:255 54:16:57305 -9:6:52 32:11:252 -54:16:57304 10:6:37 -32:12:3583 55:16:57303 -10:6:36 33:12:3579 -55:16:57302 11:6:21 -33:12:3578 56:16:57301 -11:6:20 34:12:2555 -56:16:57300 12:6:5 -34:12:2554 57:16:57299 -12:6:4 35:12:1531 -57:16:57298 13:7:109 -35:12:1530 58:16:57297 -13:7:108 36:12:507 -58:16:57296 14:7:77 -36:12:506 59:16:57295 -14:7:76 37:13:7160 -59:16:57294 15:7:45 -37:13:7147 60:16:57293 -15:7:44 38:13:7144 -60:16:57292 16:7:13 -38:13:3067 61:16:57291 -16:7:12 39:13:3065 -61:16:57290 17:8:221 -39:13:3064 62:16:57289 -17:8:220 40:13:1017 -62:16:57288 18:8:157 -40:13:1016 63:16:57175 -18:8:156 41:14:14330 -63:16:57174 19:8:93 -41:14:14329 64:16:57173 -19:8:92 42:14:14291 -64:16:57172 20:8:29 -42:14:14290 -20:8:28 43:14:6132 21:9:445 -43:14:2039 -21:9:444 44:14:2038 22:9:317 -44:14:2037 -22:9:316 45:15:28663 | ||
| 72 | -huff A4 | D.5 | 0:1:0 1:2:2 2:3:6 3:3:7 | ||
| 73 | -huff B4 | D.5 | 0:2:2 1:3:6 2:3:7 3:1:0 | ||
| 74 | -huff C4 | D.5 | 0:3:6 1:3:7 2:1:0 3:2:2 | ||
| 75 | -huff D4 | D.5 | 0:2:0 1:2:1 2:2:2 3:2:3 | ||
crates/ec-truehd/examples/bench.rsdeleted+0 -64
| @@ -1,64 +0,0 @@ | |||
| 1 | -//! bench: TrueHD decode throughput for lanes/bench.md ("lane benchaudio"). | ||
| 2 | -//! | ||
| 3 | -//! usage: bench dec <in.thd> <out.s32le> [reps] | ||
| 4 | -//! | ||
| 5 | -//! Splits a raw TrueHD elementary stream (as ffmpeg's `truehd` muxer writes it) into access | ||
| 6 | -//! units with `frame_length`, decodes each with `TrueHdDecoder`, `reps` times (default 5), and | ||
| 7 | -//! keeps the best wall time. The decoded interleaved S32 samples of the last run are written to | ||
| 8 | -//! `out.s32le`. The lossless self-checks (`check_stats`) are printed; any failure count other | ||
| 9 | -//! than zero means the decode is not trustworthy. | ||
| 10 | -use std::hint::black_box; | ||
| 11 | -use std::time::Instant; | ||
| 12 | - | ||
| 13 | -use ec_truehd::{TrueHdDecoder, frame_length}; | ||
| 14 | - | ||
| 15 | -/// Decode the whole stream once: (S32 bytes, channels, rate, access units, lossless failures). | ||
| 16 | -fn decode_once(data: &[u8]) -> (Vec<u8>, usize, u32, usize, u64) { | ||
| 17 | - let mut decoder = TrueHdDecoder::new(); | ||
| 18 | - let mut out = Vec::new(); | ||
| 19 | - let (mut channels, mut rate, mut units) = (0usize, 0u32, 0usize); | ||
| 20 | - let mut at = 0usize; | ||
| 21 | - while at < data.len() { | ||
| 22 | - let len = match frame_length(&data[at..]) { | ||
| 23 | - Ok(len) if len > 0 => len.min(data.len() - at), | ||
| 24 | - _ => break, | ||
| 25 | - }; | ||
| 26 | - if let Some(frame) = decoder | ||
| 27 | - .decode_access_unit(&data[at..at + len]) | ||
| 28 | - .expect("truehd access unit") | ||
| 29 | - { | ||
| 30 | - channels = frame.layout.channel_count(); | ||
| 31 | - rate = frame.rate; | ||
| 32 | - out.extend_from_slice(&frame.data[0]); | ||
| 33 | - } | ||
| 34 | - units += 1; | ||
| 35 | - at += len; | ||
| 36 | - } | ||
| 37 | - let stats = decoder.check_stats(); | ||
| 38 | - let failures = stats.lossless_check_failures + stats.parity_failures + stats.restart_crc_failures; | ||
| 39 | - (out, channels, rate, units, failures) | ||
| 40 | -} | ||
| 41 | - | ||
| 42 | -fn main() { | ||
| 43 | - let args: Vec<String> = std::env::args().collect(); | ||
| 44 | - if args.len() < 4 || args[1] != "dec" { | ||
| 45 | - eprintln!("usage: bench dec <in.thd> <out.s32le> [reps]"); | ||
| 46 | - std::process::exit(2); | ||
| 47 | - } | ||
| 48 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | ||
| 49 | - let data = std::fs::read(&args[2]).expect("read input"); | ||
| 50 | - let (pcm, channels, rate, units, failures) = decode_once(&data); | ||
| 51 | - let mut best = f64::MAX; | ||
| 52 | - for _ in 0..reps { | ||
| 53 | - let t = Instant::now(); | ||
| 54 | - black_box(decode_once(black_box(&data)).0.len()); | ||
| 55 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 56 | - } | ||
| 57 | - std::fs::write(&args[3], &pcm).expect("write output"); | ||
| 58 | - let samples = pcm.len() / 4; | ||
| 59 | - println!( | ||
| 60 | - "access_units={units} channels={channels} rate={rate} samples={} check_failures={failures} best_decode_s={best:.4} reps={reps} audio_s={:.3}", | ||
| 61 | - samples / channels.max(1), | ||
| 62 | - samples as f64 / channels.max(1) as f64 / f64::from(rate.max(1)) | ||
| 63 | - ); | ||
| 64 | -} | ||
crates/ec-truehd/src/sync.rsmodified+0 -5
| @@ -337,11 +337,6 @@ impl TrueHdDecoder { | |||
| 337 | /// One access unit in; one frame of the highest presentation out — | 337 | /// One access unit in; one frame of the highest presentation out — |
| 338 | /// `None` until the first major sync and every substream's first | 338 | /// `None` until the first major sync and every substream's first |
| 339 | /// restart header have been seen. | 339 | /// restart header have been seen. |
| 340 | - pub fn push(&mut self, data: &[u8]) -> Result<Option<AudioFrame>> { | ||
| 341 | - self.decode_access_unit(data) | ||
| 342 | - } | ||
| 343 | - | ||
| 344 | - /// See [`TrueHdDecoder::push`]. | ||
| 345 | pub fn decode_access_unit(&mut self, data: &[u8]) -> Result<Option<AudioFrame>> { | 340 | pub fn decode_access_unit(&mut self, data: &[u8]) -> Result<Option<AudioFrame>> { |
| 346 | let header = AccessUnitHeader::parse(data, self.substream_count)?; | 341 | let header = AccessUnitHeader::parse(data, self.substream_count)?; |
| 347 | self.substream_count = header.substreams.len(); | 342 | self.substream_count = header.substreams.len(); |
crates/ec-truehd/tests/it/atmos_synth.rsdeleted+0 -227
| @@ -1,227 +0,0 @@ | |||
| 1 | -use std::path::Path; | ||
| 2 | - | ||
| 3 | -use ec_core::frame::ChannelLayout; | ||
| 4 | -use ec_truehd::TrueHdDecoder; | ||
| 5 | -use ec_truehd::sync::AccessUnitHeader; | ||
| 6 | - | ||
| 7 | -use crate::common::raw_access_units; | ||
| 8 | - | ||
| 9 | -const MIN_ACCESS_UNITS: usize = 100; | ||
| 10 | -const FILLER_WORDS: u16 = 4; | ||
| 11 | -const MAX_AU_WORDS: usize = 0x0FFF; | ||
| 12 | - | ||
| 13 | -fn sample_access_units() -> Vec<Vec<u8>> { | ||
| 14 | - let data = | ||
| 15 | - std::fs::read(ec_testkit::fixture("open/fate/truehd/atmos.thd")).expect("read atmos.thd"); | ||
| 16 | - let aus = raw_access_units(&data); | ||
| 17 | - assert!( | ||
| 18 | - aus.len() >= MIN_ACCESS_UNITS, | ||
| 19 | - "atmos.thd has only {} access units", | ||
| 20 | - aus.len() | ||
| 21 | - ); | ||
| 22 | - aus | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -fn header_of(au: &[u8], substreams: usize) -> AccessUnitHeader { | ||
| 26 | - AccessUnitHeader::parse(au, substreams).expect("access unit parses") | ||
| 27 | -} | ||
| 28 | - | ||
| 29 | -fn crc16_table() -> [u32; 256] { | ||
| 30 | - let mut table = [0u32; 256]; | ||
| 31 | - for (i, entry) in table.iter_mut().enumerate() { | ||
| 32 | - let mut c = (i as i32) << 24; | ||
| 33 | - for _ in 0..8 { | ||
| 34 | - let overflow = c >> 31; | ||
| 35 | - c = (c << 1) ^ ((0x002D_i32 << 16) & overflow); | ||
| 36 | - } | ||
| 37 | - *entry = (c as u32).swap_bytes(); | ||
| 38 | - } | ||
| 39 | - table | ||
| 40 | -} | ||
| 41 | - | ||
| 42 | -fn major_sync_checksum(sync: &[u8]) -> u16 { | ||
| 43 | - let n = sync.len() - 4; | ||
| 44 | - let table = crc16_table(); | ||
| 45 | - let mut crc: u32 = 0; | ||
| 46 | - for &b in &sync[..n] { | ||
| 47 | - crc = table[usize::from((crc as u8) ^ b)] ^ (crc >> 8); | ||
| 48 | - } | ||
| 49 | - (crc as u16) ^ u16::from_le_bytes([sync[n], sync[n + 1]]) | ||
| 50 | -} | ||
| 51 | - | ||
| 52 | -fn checksum_is_valid(sync: &[u8]) -> bool { | ||
| 53 | - let n = sync.len() - 2; | ||
| 54 | - major_sync_checksum(sync) == u16::from_le_bytes([sync[n], sync[n + 1]]) | ||
| 55 | -} | ||
| 56 | - | ||
| 57 | -fn set_substream_count(sync: &mut [u8], count: u8) { | ||
| 58 | - sync[16] = (sync[16] & 0x0F) | (count << 4); | ||
| 59 | - let checksum = major_sync_checksum(sync); | ||
| 60 | - let n = sync.len() - 2; | ||
| 61 | - sync[n..].copy_from_slice(&checksum.to_le_bytes()); | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -fn parity_ok(header: &[u8], directory: &[u8]) -> bool { | ||
| 65 | - let p = header.iter().chain(directory).fold(0u8, |a, &b| a ^ b); | ||
| 66 | - ((p >> 4) ^ p) & 0xF == 0xF | ||
| 67 | -} | ||
| 68 | - | ||
| 69 | -fn assemble(timing: [u8; 2], sync: Option<&[u8]>, dir: &[u8], coded: &[u8]) -> Vec<u8> { | ||
| 70 | - let mut body = Vec::new(); | ||
| 71 | - body.extend_from_slice(sync.unwrap_or(&[])); | ||
| 72 | - body.extend_from_slice(dir); | ||
| 73 | - body.extend_from_slice(coded); | ||
| 74 | - let words = (4 + body.len()) / 2; | ||
| 75 | - assert!(words <= MAX_AU_WORDS, "synthetic access unit too long"); | ||
| 76 | - let nibble = (0u8..16) | ||
| 77 | - .find(|&cn| { | ||
| 78 | - let head = [ | ||
| 79 | - (cn << 4) | ((words >> 8) as u8 & 0x0F), | ||
| 80 | - (words & 0xFF) as u8, | ||
| 81 | - timing[0], | ||
| 82 | - timing[1], | ||
| 83 | - ]; | ||
| 84 | - parity_ok(&head, dir) | ||
| 85 | - }) | ||
| 86 | - .expect("one of the 16 nibble values satisfies the fold"); | ||
| 87 | - let word = (u16::from(nibble) << 12) | words as u16; | ||
| 88 | - let mut out = Vec::with_capacity(4 + body.len()); | ||
| 89 | - out.extend_from_slice(&word.to_be_bytes()); | ||
| 90 | - out.extend_from_slice(&timing); | ||
| 91 | - out.extend_from_slice(&body); | ||
| 92 | - out | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -fn sync_of(au: &[u8], header: &AccessUnitHeader) -> Option<Vec<u8>> { | ||
| 96 | - header.major_sync.map(|s| au[4..4 + s.len].to_vec()) | ||
| 97 | -} | ||
| 98 | - | ||
| 99 | -fn directory_start(header: &AccessUnitHeader) -> usize { | ||
| 100 | - 4 + header.major_sync.map_or(0, |s| s.len) | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -fn convert(aus: &[Vec<u8>], f: impl Fn(&[u8], usize) -> Vec<u8>) -> Vec<Vec<u8>> { | ||
| 104 | - let mut count = 0; | ||
| 105 | - aus.iter() | ||
| 106 | - .map(|au| { | ||
| 107 | - let out = f(au.as_slice(), count); | ||
| 108 | - count = header_of(au.as_slice(), count).substreams.len(); | ||
| 109 | - out | ||
| 110 | - }) | ||
| 111 | - .collect() | ||
| 112 | -} | ||
| 113 | - | ||
| 114 | -fn strip_object_substream(au: &[u8], substreams: usize) -> Vec<u8> { | ||
| 115 | - let header = header_of(au, substreams); | ||
| 116 | - assert_eq!(header.substreams.len(), 4, "the sample has 4 substreams"); | ||
| 117 | - let entry_len = if header.substreams[3].extra.is_some() { | ||
| 118 | - 4 | ||
| 119 | - } else { | ||
| 120 | - 2 | ||
| 121 | - }; | ||
| 122 | - let dir = &au[directory_start(&header)..header.data_start - entry_len]; | ||
| 123 | - let mut sync = sync_of(au, &header); | ||
| 124 | - if let Some(s) = sync.as_mut() { | ||
| 125 | - assert!(checksum_is_valid(s), "the sample's major sync checksum"); | ||
| 126 | - set_substream_count(s, 3); | ||
| 127 | - } | ||
| 128 | - let (_, end) = header.substream_span(2); | ||
| 129 | - assemble( | ||
| 130 | - [au[2], au[3]], | ||
| 131 | - sync.as_deref(), | ||
| 132 | - dir, | ||
| 133 | - &au[header.data_start..end], | ||
| 134 | - ) | ||
| 135 | -} | ||
| 136 | - | ||
| 137 | -fn with_object_substream(au: &[u8], substreams: usize, filler: u8) -> Vec<u8> { | ||
| 138 | - let header = header_of(au, substreams); | ||
| 139 | - assert_eq!(header.substreams.len(), 3, "the input is a 7.1 access unit"); | ||
| 140 | - let last = header.substreams[2]; | ||
| 141 | - let nonrestart = last.flags & 0x4; | ||
| 142 | - let entry = (u16::from(nonrestart) << 12) | (last.end_offset_words + FILLER_WORDS); | ||
| 143 | - let mut dir = au[directory_start(&header)..header.data_start].to_vec(); | ||
| 144 | - dir.extend_from_slice(&entry.to_be_bytes()); | ||
| 145 | - let mut sync = sync_of(au, &header); | ||
| 146 | - if let Some(s) = sync.as_mut() { | ||
| 147 | - set_substream_count(s, 4); | ||
| 148 | - } | ||
| 149 | - let (_, end) = header.substream_span(2); | ||
| 150 | - let mut coded = au[header.data_start..end].to_vec(); | ||
| 151 | - coded.extend(std::iter::repeat_n(filler, usize::from(FILLER_WORDS) * 2)); | ||
| 152 | - assemble([au[2], au[3]], sync.as_deref(), &dir, &coded) | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -fn with_object_payload(au: &[u8], substreams: usize, fill: u8) -> Vec<u8> { | ||
| 156 | - let header = header_of(au, substreams); | ||
| 157 | - assert_eq!(header.substreams.len(), 4, "the sample has 4 substreams"); | ||
| 158 | - let (start, end) = header.substream_span(3); | ||
| 159 | - assert!(start < end, "the object substream has coded data"); | ||
| 160 | - let mut out = au.to_vec(); | ||
| 161 | - out[start..end].fill(fill); | ||
| 162 | - out | ||
| 163 | -} | ||
| 164 | - | ||
| 165 | -type Decoded = Vec<(ChannelLayout, Vec<Vec<u8>>)>; | ||
| 166 | - | ||
| 167 | -fn decode_all(aus: &[Vec<u8>]) -> (Decoded, ec_truehd::CheckStats) { | ||
| 168 | - let mut decoder = TrueHdDecoder::new(); | ||
| 169 | - let mut frames = Vec::new(); | ||
| 170 | - for au in aus { | ||
| 171 | - if let Some(frame) = decoder.push(au).expect("access unit decodes") { | ||
| 172 | - let planes = frame.data.iter().map(|b| b.as_ref().to_vec()).collect(); | ||
| 173 | - frames.push((frame.layout, planes)); | ||
| 174 | - } | ||
| 175 | - } | ||
| 176 | - (frames, decoder.check_stats()) | ||
| 177 | -} | ||
| 178 | - | ||
| 179 | -#[test] | ||
| 180 | -fn synthetic_atmos_decodes_bit_exact_to_the_original_7_1() { | ||
| 181 | - let originals = sample_access_units(); | ||
| 182 | - let sevens = convert(&originals, strip_object_substream); | ||
| 183 | - let atmos = convert(&sevens, |au, n| with_object_substream(au, n, 0xA5)); | ||
| 184 | - | ||
| 185 | - if let Some(out) = std::env::var_os("EC_ATMOS_SYNTH_OUT") { | ||
| 186 | - let raw: Vec<u8> = atmos.iter().flatten().copied().collect(); | ||
| 187 | - std::fs::write(&out, raw).expect("write the synthetic TrueHD stream"); | ||
| 188 | - eprintln!("wrote synthetic stream to {}", Path::new(&out).display()); | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - let (ours, _) = decode_all(&originals); | ||
| 192 | - let (seven, _) = decode_all(&sevens); | ||
| 193 | - let (synth, stats) = decode_all(&atmos); | ||
| 194 | - assert!(!ours.is_empty(), "the original stream decodes to frames"); | ||
| 195 | - assert_eq!(seven.len(), ours.len(), "7.1 rebuild: same number of frames"); | ||
| 196 | - assert!(seven == ours, "the 3-substream 7.1 stream differs from the original"); | ||
| 197 | - assert_eq!(synth.len(), ours.len(), "synthetic: same number of frames"); | ||
| 198 | - for (i, ((la, pa), (lb, pb))) in ours.iter().zip(&synth).enumerate() { | ||
| 199 | - assert_eq!(*la, ChannelLayout::Surround7_1, "frame {i} is 7.1"); | ||
| 200 | - assert_eq!(*lb, ChannelLayout::Surround7_1, "frame {i} is 7.1"); | ||
| 201 | - assert_eq!(pa, pb, "frame {i} differs from the original"); | ||
| 202 | - } | ||
| 203 | - assert_eq!(stats.parity_failures, 0, "substream parity"); | ||
| 204 | - assert_eq!(stats.restart_crc_failures, 0, "restart header CRC"); | ||
| 205 | - assert_eq!(stats.lossless_check_failures, 0, "lossless check"); | ||
| 206 | - assert_eq!(stats.length_mismatches, 0, "substream lengths"); | ||
| 207 | -} | ||
| 208 | - | ||
| 209 | -#[test] | ||
| 210 | -fn object_substream_contents_do_not_change_the_pcm_output() { | ||
| 211 | - let originals = sample_access_units(); | ||
| 212 | - let zeros = convert(&originals, |au, n| with_object_payload(au, n, 0x00)); | ||
| 213 | - let ones = convert(&originals, |au, n| with_object_payload(au, n, 0xFF)); | ||
| 214 | - assert_ne!(zeros, originals, "the object payload was replaced"); | ||
| 215 | - let (a, sa) = decode_all(&originals); | ||
| 216 | - let (b, sb) = decode_all(&zeros); | ||
| 217 | - let (c, sc) = decode_all(&ones); | ||
| 218 | - for s in [sa, sb, sc] { | ||
| 219 | - assert_eq!(s.parity_failures, 0, "substream parity"); | ||
| 220 | - assert_eq!(s.restart_crc_failures, 0, "restart header CRC"); | ||
| 221 | - assert_eq!(s.lossless_check_failures, 0, "lossless check"); | ||
| 222 | - assert_eq!(s.length_mismatches, 0, "substream lengths"); | ||
| 223 | - } | ||
| 224 | - assert!(!a.is_empty()); | ||
| 225 | - assert!(a == b, "object payload of zeros changes the PCM"); | ||
| 226 | - assert!(a == c, "object payload of ones changes the PCM"); | ||
| 227 | -} | ||
crates/ec-truehd/tests/it/library.rsdeleted+0 -29
| @@ -1,29 +0,0 @@ | |||
| 1 | -use crate::common::raw_access_units; | ||
| 2 | - | ||
| 3 | -#[test] | ||
| 4 | -fn walks_every_truehd_access_unit_of_atmos() { | ||
| 5 | - let path = ec_testkit::fixture("open/fate/truehd/atmos.thd"); | ||
| 6 | - let data = std::fs::read(&path).expect("read atmos.thd"); | ||
| 7 | - let aus = raw_access_units(&data); | ||
| 8 | - assert!(!aus.is_empty(), "found no TrueHD access units at all"); | ||
| 9 | - let out = ec_testkit::ffprobe() | ||
| 10 | - .args([ | ||
| 11 | - "-v", | ||
| 12 | - "error", | ||
| 13 | - "-select_streams", | ||
| 14 | - "a:0", | ||
| 15 | - "-count_packets", | ||
| 16 | - "-show_entries", | ||
| 17 | - "stream=nb_read_packets", | ||
| 18 | - "-of", | ||
| 19 | - "csv=p=0", | ||
| 20 | - ]) | ||
| 21 | - .arg(&path) | ||
| 22 | - .output() | ||
| 23 | - .expect("run ffprobe"); | ||
| 24 | - let expected: usize = String::from_utf8_lossy(&out.stdout) | ||
| 25 | - .trim() | ||
| 26 | - .parse() | ||
| 27 | - .expect("ffprobe packet count"); | ||
| 28 | - assert_eq!(aus.len(), expected, "AU count vs ffprobe's packet count"); | ||
| 29 | -} | ||
crates/ec-truehd/tests/it/main.rsmodified+0 -3
| @@ -1,10 +1,7 @@ | |||
| 1 | //! One integration-test binary for ec-truehd; each module is one former `tests/*.rs` file. | 1 | //! One integration-test binary for ec-truehd; each module is one former `tests/*.rs` file. |
| 2 | #![forbid(unsafe_code)] | 2 | #![forbid(unsafe_code)] |
| 3 | 3 | ||
| 4 | -mod atmos_synth; | ||
| 5 | mod common; | 4 | mod common; |
| 6 | mod fixture_exact; | 5 | mod fixture_exact; |
| 7 | mod fuzz_regressions; | 6 | mod fuzz_regressions; |
| 8 | -mod library; | ||
| 9 | mod oracle; | 7 | mod oracle; |
| 10 | -mod refused_au_recovery; | ||
crates/ec-truehd/tests/it/refused_au_recovery.rsdeleted+0 -136
| @@ -1,136 +0,0 @@ | |||
| 1 | -//! A refused access unit must not poison the access units after it. | ||
| 2 | -//! | ||
| 3 | -//! The oracle is the same stream with the corrupt access unit removed. A refused unit is | ||
| 4 | -//! defined to leave no trace: every later unit must decode exactly as it would have if the | ||
| 5 | -//! refused unit had never been sent. This is checked for every single-byte corruption of one | ||
| 6 | -//! access unit in the middle of each committed fixture that the decoder refuses. | ||
| 7 | -//! | ||
| 8 | -//! Each fixture is read from `crates/ec-truehd/fixtures/` (made with ffmpeg's encoder, see | ||
| 9 | -//! `fixture_exact.rs`). Nothing here needs ffmpeg at run time. | ||
| 10 | - | ||
| 11 | -use std::fs::File; | ||
| 12 | -use std::io::BufReader; | ||
| 13 | -use std::path::{Path, PathBuf}; | ||
| 14 | - | ||
| 15 | -use ec_core::{CodecId, Demuxer}; | ||
| 16 | -use ec_matroska::MatroskaDemuxer; | ||
| 17 | -use ec_truehd::TrueHdDecoder; | ||
| 18 | - | ||
| 19 | -/// One access unit's outcome: `Ok(frame bytes)` (or `None` when no frame yet) or a refusal. | ||
| 20 | -type Outcome = Result<Option<Vec<u8>>, String>; | ||
| 21 | - | ||
| 22 | -const FIXTURES: [&str; 4] = [ | ||
| 23 | - "truehd-s16-2ch.mkv", | ||
| 24 | - "truehd-s16-51.mkv", | ||
| 25 | - "truehd-s24-2ch.mkv", | ||
| 26 | - "truehd-s24-51.mkv", | ||
| 27 | -]; | ||
| 28 | - | ||
| 29 | -fn fixture(name: &str) -> PathBuf { | ||
| 30 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures").join(name) | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | -/// Every access unit of the file's TrueHD track, in stream order. | ||
| 34 | -fn access_units(path: &Path) -> Vec<Vec<u8>> { | ||
| 35 | - let mut demux = MatroskaDemuxer::new(BufReader::new(File::open(path).unwrap())).unwrap(); | ||
| 36 | - let stream = demux | ||
| 37 | - .streams() | ||
| 38 | - .iter() | ||
| 39 | - .find(|s| s.params.codec == CodecId::TrueHd) | ||
| 40 | - .expect("a TrueHD track") | ||
| 41 | - .index; | ||
| 42 | - let mut aus = Vec::new(); | ||
| 43 | - loop { | ||
| 44 | - let packet = match demux.next_packet() { | ||
| 45 | - Ok(p) => p, | ||
| 46 | - Err(e) if e.is_eof() => break, | ||
| 47 | - Err(e) => panic!("{}: demux: {e}", path.display()), | ||
| 48 | - }; | ||
| 49 | - if packet.stream == stream { | ||
| 50 | - aus.push(packet.data.to_vec()); | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | - aus | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | -/// Decodes `aus` in order through one decoder, recording each unit's outcome. | ||
| 57 | -fn run(aus: &[Vec<u8>]) -> Vec<Outcome> { | ||
| 58 | - let mut dec = TrueHdDecoder::new(); | ||
| 59 | - aus.iter() | ||
| 60 | - .map(|au| match dec.decode_access_unit(au) { | ||
| 61 | - Ok(frame) => Ok(frame.map(|f| f.data[0].to_vec())), | ||
| 62 | - Err(e) => Err(e.to_string()), | ||
| 63 | - }) | ||
| 64 | - .collect() | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -#[test] | ||
| 68 | -fn refused_access_unit_does_not_poison_later_units() { | ||
| 69 | - let mut total_refusals = 0; | ||
| 70 | - let mut total_checked = 0; | ||
| 71 | - let mut failures = Vec::new(); | ||
| 72 | - | ||
| 73 | - for name in FIXTURES { | ||
| 74 | - let clean = access_units(&fixture(name)); | ||
| 75 | - assert!(clean.len() > 40, "{name}: too few access units ({})", clean.len()); | ||
| 76 | - | ||
| 77 | - let clean_run = run(&clean); | ||
| 78 | - assert!( | ||
| 79 | - clean_run.iter().all(Result::is_ok), | ||
| 80 | - "{name}: the clean stream must decode without refusals" | ||
| 81 | - ); | ||
| 82 | - let frames = clean_run.iter().filter(|o| matches!(o, Ok(Some(_)))).count(); | ||
| 83 | - assert!(frames > 20, "{name}: only {frames} frames decoded"); | ||
| 84 | - | ||
| 85 | - // One unit in the middle of the stream, after the first major sync and several restarts. | ||
| 86 | - let k = clean.len() / 3; | ||
| 87 | - let without_k: Vec<Vec<u8>> = clean | ||
| 88 | - .iter() | ||
| 89 | - .enumerate() | ||
| 90 | - .filter(|(i, _)| *i != k) | ||
| 91 | - .map(|(_, au)| au.clone()) | ||
| 92 | - .collect(); | ||
| 93 | - let oracle = run(&without_k); | ||
| 94 | - | ||
| 95 | - for pos in 0..clean[k].len() { | ||
| 96 | - let mut corrupt = clean[k].clone(); | ||
| 97 | - corrupt[pos] ^= 0xFF; | ||
| 98 | - | ||
| 99 | - // Only units the decoder refuses matter here. Check that cheaply on the prefix. | ||
| 100 | - let mut prefix: Vec<Vec<u8>> = clean[..k].to_vec(); | ||
| 101 | - prefix.push(corrupt.clone()); | ||
| 102 | - let Err(err) = run(&prefix).pop().expect("prefix is non-empty") else { | ||
| 103 | - continue; | ||
| 104 | - }; | ||
| 105 | - total_refusals += 1; | ||
| 106 | - | ||
| 107 | - let mut stream = clean.clone(); | ||
| 108 | - stream[k] = corrupt; | ||
| 109 | - let got = run(&stream); | ||
| 110 | - assert!(got[k].is_err(), "{name} byte {pos}: the corrupt unit must be refused"); | ||
| 111 | - | ||
| 112 | - for j in k + 1..clean.len() { | ||
| 113 | - total_checked += 1; | ||
| 114 | - if got[j] != oracle[j - 1] { | ||
| 115 | - failures.push(format!( | ||
| 116 | - "{name}: byte {pos} of unit {k} refused ({err}); unit {j} differs from the \ | ||
| 117 | - stream without unit {k}: got {:?}, want {:?}", | ||
| 118 | - got[j].as_ref().map(|o| o.as_ref().map(Vec::len)), | ||
| 119 | - oracle[j - 1].as_ref().map(|o| o.as_ref().map(Vec::len)), | ||
| 120 | - )); | ||
| 121 | - break; | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - assert!(total_refusals >= 10, "only {total_refusals} refused corruptions found"); | ||
| 128 | - assert!( | ||
| 129 | - failures.is_empty(), | ||
| 130 | - "{} of {} refused corruptions poisoned later units; first: {}", | ||
| 131 | - failures.len(), | ||
| 132 | - total_refusals, | ||
| 133 | - failures[0] | ||
| 134 | - ); | ||
| 135 | - eprintln!("refused corruptions: {total_refusals}, later units compared: {total_checked}"); | ||
| 136 | -} | ||