forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/c-ac3'

Browse files at this commit

5fa31c7eae5f8aca4c0a6f52154417e08b166e9eAhmet Kaan GümüşParent: 35cac3aacbfd4c
crates/ec-ac3/src/aht.rsmodified+3 -10
@@ -107,10 +107,10 @@ pub(crate) fn read_channel(
107107 let mut next_gain = 0usize;
108108 for bin in start..end {
109109 let h = hebap[bin];
110- let mut zero_bits = false;
111110 if h == 0 {
112- pre = [0.0; AHT_BLOCKS];
113- zero_bits = true;
111+ for slot in &mut pre {
112+ *slot = if dither_on { dither.value() } else { 0.0 };
113+ }
114114 } else if h <= 7 {
115115 let index = r.read_bits(VQ_BITS[h as usize])? as usize;
116116 let table = vq_table(h);
@@ -131,13 +131,6 @@ pub(crate) fn read_channel(
131131 }
132132 }
133133
134- if zero_bits {
135- // A zero-bit AHT bin is the same silence AC-3 fills with dither.
136- for blk in 0..AHT_BLOCKS {
137- out[blk * COEFFS + bin] = if dither_on { dither.value() } else { 0.0 };
138- }
139- continue;
140- }
141134 // §3.4.5: invert the six-point DCT across blocks.
142135 for (blk, slot) in idct6(&pre).into_iter().enumerate() {
143136 out[blk * COEFFS + bin] = slot;
crates/ec-ac3/src/decode.rsmodified+27 -34
@@ -12,7 +12,7 @@ use ec_core::{BitReader, Error, Result};
1212 use crate::bitalloc::{self, Allocation, BitAllocParams, Channel, DeltaBa};
1313 use crate::bsi::{Acmod, Bsi};
1414 use crate::exps::{self, Strategy};
15-use crate::mantissa::{Dither, Mantissas, scale};
15+use crate::mantissa::{Dither, Mantissas, scale, shift};
1616 use crate::transform::{BLOCK_SAMPLES, Imdct};
1717
1818 /// Full-bandwidth channels at most (3/2 mode).
@@ -64,7 +64,7 @@ pub(crate) struct Core {
6464 pub(crate) ncplbnd: usize,
6565 /// Coupling band each sub-band belongs to, after `cplbndstrc` merging.
6666 pub(crate) cplband: [usize; 18],
67- pub(crate) cplco: [[f32; 18]; MAX_FBW],
67+ pub(crate) cplco: [[i32; 18]; MAX_FBW],
6868 pub(crate) phsflg: [bool; 18],
6969 pub(crate) cplleak: (i32, i32),
7070 /// Annex E sends a channel's coupling coordinates in the first block of
@@ -118,9 +118,6 @@ pub(crate) struct Core {
118118 pub(crate) first_spxco: [bool; MAX_FBW],
119119 pub(crate) chinspxatten: [bool; MAX_FBW],
120120 pub(crate) spxattencod: [u8; MAX_FBW],
121- /// The noise source of §3.6.4.2.4, kept apart from the dither source so
122- /// neither one's sequence depends on the other's use.
123- pub(crate) spx_noise: Dither,
124121 // Adaptive hybrid transform (Annex E §3.4). All false under AC-3.
125122 /// Which channels are AHT-coded this frame.
126123 pub(crate) aht: [bool; CHANNELS],
@@ -152,7 +149,7 @@ impl Core {
152149 ncplsubnd: 0,
153150 ncplbnd: 0,
154151 cplband: [0; 18],
155- cplco: [[0.0; 18]; MAX_FBW],
152+ cplco: [[0; 18]; MAX_FBW],
156153 phsflg: [false; 18],
157154 cplleak: (0, 0),
158155 first_cplco: [true; MAX_FBW],
@@ -190,7 +187,6 @@ impl Core {
190187 first_spxco: [true; MAX_FBW],
191188 chinspxatten: [false; MAX_FBW],
192189 spxattencod: [0; MAX_FBW],
193- spx_noise: Dither::default(),
194190 aht: [false; CHANNELS],
195191 aht_read: [false; CHANNELS],
196192 aht_mant: vec![0.0; CHANNELS * crate::aht::AHT_BLOCKS * COEFFS],
@@ -330,13 +326,8 @@ impl Core {
330326 let mstrcplco = r.read_bits(2)? as i32;
331327 for bnd in 0..self.ncplbnd {
332328 let cplcoexp = r.read_bits(4)? as i32;
333- let cplcomant = r.read_bits(4)? as f32;
334- let mant = if cplcoexp == 15 {
335- cplcomant / 16.0
336- } else {
337- (cplcomant + 16.0) / 32.0
338- };
339- self.cplco[ch][bnd] = mant * scale((cplcoexp + 3 * mstrcplco).min(24) as u8);
329+ let cplcomant = r.read_bits(4)? as i32;
330+ self.cplco[ch][bnd] = coupling_coord(cplcoexp, cplcomant, mstrcplco);
340331 }
341332 }
342333 if self.acmod == Acmod::Stereo && self.phsflginu && (cplcoe[0] || cplcoe[1]) {
@@ -573,11 +564,12 @@ impl Core {
573564 for bin in 0..end {
574565 let bap = self.bap[ch][bin];
575566 let value = m.read(r, bap)?;
576- self.coeffs[ch][bin] = if bap == 0 && self.dithflag[ch] && self.dither_on {
577- self.dither.value() * scale(self.exps[ch][bin])
567+ let mant = if bap == 0 && self.dithflag[ch] && self.dither_on {
568+ self.dither.mantissa()
578569 } else {
579- value * scale(self.exps[ch][bin])
570+ value
580571 };
572+ self.coeffs[ch][bin] = shift(mant, self.exps[ch][bin]);
581573 }
582574 }
583575 self.coeffs[ch][end..].fill(0.0);
@@ -589,14 +581,12 @@ impl Core {
589581 for bin in start..end {
590582 let bap = self.bap[CPL][bin];
591583 let value = m.read(r, bap)?;
592- // The coupling channel always draws dither for its zero-bit
593- // mantissas, whatever the coupled channels' dithflag says:
594- // each coupled channel decides later whether to keep it.
595- self.coeffs[CPL][bin] = if bap == 0 && self.dither_on {
596- self.dither.value() * scale(self.exps[CPL][bin])
584+ let mant = if bap == 0 && self.dither_on {
585+ self.dither.mantissa()
597586 } else {
598- value * scale(self.exps[CPL][bin])
587+ value
599588 };
589+ self.coeffs[CPL][bin] = shift(mant, self.exps[CPL][bin]);
600590 }
601591 }
602592 got_cplchan = true;
@@ -608,7 +598,7 @@ impl Core {
608598 } else {
609599 for bin in 0..7 {
610600 let value = m.read(r, self.bap[LFE][bin])?;
611- self.coeffs[LFE][bin] = value * scale(self.exps[LFE][bin]);
601+ self.coeffs[LFE][bin] = shift(value, self.exps[LFE][bin]);
612602 }
613603 }
614604 self.coeffs[LFE][7..].fill(0.0);
@@ -660,22 +650,20 @@ impl Core {
660650 }
661651 for sbnd in 0..self.ncplsubnd {
662652 let bnd = self.cplband[sbnd];
663- let mut co = self.cplco[ch][bnd] * 8.0;
664- // §5.4.3.18: in 2/0 with phase flags, the right channel's
665- // contribution is inverted for the flagged bands.
666- if ch == 1 && self.phsflginu && self.phsflg[bnd] {
667- co = -co;
668- }
653+ let co = i64::from(self.cplco[ch][bnd]);
654+ let invert = ch == 1 && self.phsflginu && self.phsflg[bnd];
669655 let from = start + sbnd * 12;
670656 for bin in from..(from + 12).min(end) {
671657 // §7.3.4: a coupled channel without dithflag gets silence where
672658 // the coupling channel's mantissa was zero-bit.
673- let cpl = if self.bap[CPL][bin] == 0 && !self.dithflag[ch] {
674- 0.0
659+ let out = if self.bap[CPL][bin] == 0 && !self.dithflag[ch] {
660+ 0
675661 } else {
676- self.coeffs[CPL][bin]
662+ let cpl = (self.coeffs[CPL][bin] * 8_388_608.0) as i64;
663+ let v = ((cpl * co) >> 23) as i32;
664+ if invert { -v } else { v }
677665 };
678- self.coeffs[ch][bin] = cpl * co;
666+ self.coeffs[ch][bin] = out as f32 / 8_388_608.0;
679667 }
680668 }
681669 self.coeffs[ch][end..].fill(0.0);
@@ -774,6 +762,11 @@ impl Core {
774762 }
775763 }
776764
765+pub(crate) fn coupling_coord(exp: i32, mant: i32, master: i32) -> i32 {
766+ let base = if exp == 15 { mant << 22 } else { (mant + 16) << 21 };
767+ base >> (exp + 3 * master).min(24)
768+}
769+
777770 /// §7.7.1.2: the 8-bit `dynrng` word as a linear gain.
778771 ///
779772 /// The three most significant bits are a signed power of two from -4 to 3 with
crates/ec-ac3/src/decoder.rsmodified+1 -1
@@ -342,7 +342,7 @@ impl Ac3Decoder {
342342 )));
343343 }
344344 let channels = hdr.nfchans + usize::from(hdr.bsi.lfeon);
345- let positions = dependent::positions(hdr.chanmap, channels)?;
345+ let positions = dependent::positions(hdr.chanmap, channels, hdr.bsi.acmod, hdr.bsi.lfeon)?;
346346 if self.dependents.len() <= slot {
347347 self.dependents.push(Core::new());
348348 }
crates/ec-ac3/src/dependent.rsmodified+36 -11
@@ -28,6 +28,7 @@
2828
2929 use ec_core::{BitReader, ChannelPosition, Error, Result};
3030
31+use crate::bsi::Acmod;
3132 use crate::eac3::{self, Eac3Bsi, StreamType};
3233 use crate::syncinfo::SYNCWORD;
3334
@@ -54,7 +55,7 @@ pub(crate) fn peek(data: &[u8]) -> Option<Eac3Bsi> {
5455
5556 /// The loudspeaker positions a dependent substream's `channels` coded channels
5657 /// fill, in coded order, from its custom channel map (Table E2.5).
57-pub(crate) fn positions(map: Option<u16>, channels: usize) -> Result<Vec<ChannelPosition>> {
58+pub(crate) fn positions(map: Option<u16>, channels: usize, acmod: Acmod, lfeon: bool) -> Result<Vec<ChannelPosition>> {
5859 use ChannelPosition::*;
5960 let Some(map) = map else {
6061 return Err(Error::unsupported(
@@ -99,7 +100,31 @@ pub(crate) fn positions(map: Option<u16>, channels: usize) -> Result<Vec<Channel
99100 out.len()
100101 )));
101102 }
102- Ok(out)
103+ let slots = slot_order(acmod, lfeon);
104+ let mut placed = out.clone();
105+ for (k, position) in out.into_iter().enumerate() {
106+ placed[usize::from(slots[k])] = position;
107+ }
108+ Ok(placed)
109+}
110+
111+fn slot_order(acmod: Acmod, lfeon: bool) -> &'static [u8] {
112+ match (acmod, lfeon) {
113+ (Acmod::DualMono | Acmod::Stereo, false) => &[0, 1],
114+ (Acmod::DualMono | Acmod::Stereo, true) => &[0, 1, 2],
115+ (Acmod::Mono, false) => &[0],
116+ (Acmod::Mono, true) => &[0, 1],
117+ (Acmod::Surround3_0, false) => &[0, 2, 1],
118+ (Acmod::Surround3_0, true) => &[0, 2, 1, 3],
119+ (Acmod::Surround2_1, false) => &[0, 1, 2],
120+ (Acmod::Surround2_1, true) => &[0, 1, 3, 2],
121+ (Acmod::Surround3_1, false) => &[0, 2, 1, 3],
122+ (Acmod::Surround3_1, true) => &[0, 2, 1, 4, 3],
123+ (Acmod::Surround2_2, false) => &[0, 1, 2, 3],
124+ (Acmod::Surround2_2, true) => &[0, 1, 4, 2, 3],
125+ (Acmod::Surround3_2, false) => &[0, 2, 1, 3, 4],
126+ (Acmod::Surround3_2, true) => &[0, 2, 1, 5, 3, 4],
127+ }
103128 }
104129
105130 /// The Table E2.5 name of the map entry `i` that this build cannot place.
@@ -188,26 +213,26 @@ mod tests {
188213
189214 #[test]
190215 fn map_bits_name_positions_as_ffmpeg_does() {
191- assert_eq!(positions(Some(0x8000), 1).unwrap(), vec![FrontLeft]);
192- assert_eq!(positions(Some(0x0400), 2).unwrap(), vec![FrontLeftOfCenter, FrontRightOfCenter]);
193- assert_eq!(positions(Some(0x0200), 2).unwrap(), vec![BackLeft, BackRight]);
194- assert_eq!(positions(Some(0x1800), 2).unwrap(), vec![SideLeft, SideRight]);
195- assert_eq!(positions(Some(0x0001), 1).unwrap(), vec![Lfe]);
196- assert_eq!(positions(Some(0x8400), 3).unwrap(), vec![FrontLeft, FrontLeftOfCenter, FrontRightOfCenter]);
216+ assert_eq!(positions(Some(0x8000), 1, Acmod::Mono, false).unwrap(), vec![FrontLeft]);
217+ assert_eq!(positions(Some(0x0400), 2, Acmod::Stereo, false).unwrap(), vec![FrontLeftOfCenter, FrontRightOfCenter]);
218+ assert_eq!(positions(Some(0x0200), 2, Acmod::Stereo, false).unwrap(), vec![BackLeft, BackRight]);
219+ assert_eq!(positions(Some(0x1800), 2, Acmod::Stereo, false).unwrap(), vec![SideLeft, SideRight]);
220+ assert_eq!(positions(Some(0x0001), 1, Acmod::Mono, false).unwrap(), vec![Lfe]);
221+ assert_eq!(positions(Some(0x8400), 3, Acmod::Surround2_1, false).unwrap(), vec![FrontLeft, FrontLeftOfCenter, FrontRightOfCenter]);
197222 }
198223
199224 #[test]
200225 fn unnamed_and_missing_maps_are_refused_by_name() {
201226 for map in [None, Some(0x0080), Some(0x0040), Some(0x0010), Some(0x0004), Some(0x0002)] {
202- let err = positions(map, 2).expect_err("refused");
227+ let err = positions(map, 2, Acmod::Stereo, false).expect_err("refused");
203228 assert!(matches!(err, Error::Unsupported { .. }), "{map:?}: {err}");
204229 }
205230 }
206231
207232 #[test]
208233 fn map_that_disagrees_with_the_channel_count_is_corrupt() {
209- assert!(matches!(positions(Some(0x1800), 1), Err(Error::Corrupt { .. })));
210- assert!(matches!(positions(Some(0x0400), 3), Err(Error::Corrupt { .. })));
234+ assert!(matches!(positions(Some(0x1800), 1, Acmod::Mono, false), Err(Error::Corrupt { .. })));
235+ assert!(matches!(positions(Some(0x0400), 3, Acmod::Surround2_1, false), Err(Error::Corrupt { .. })));
211236 }
212237
213238 #[test]
crates/ec-ac3/src/eac3.rsmodified+4 -12
@@ -781,7 +781,7 @@ fn parse_block(
781781 // §3.6.4.2.1: the blend follows the band's frequency midpoint.
782782 let bandsize = core.spxbndsz[bnd] as f32;
783783 let nratio = ((spxmant + 0.5 * bandsize) / end - spxblnd).clamp(0.0, 1.0);
784- core.nblend[ch][bnd] = nratio.sqrt();
784+ core.nblend[ch][bnd] = (3.0 * nratio).sqrt();
785785 core.sblend[ch][bnd] = (1.0 - nratio).sqrt();
786786 spxmant += bandsize;
787787 }
@@ -885,14 +885,9 @@ fn parse_block(
885885 let mstrcplco = r.read_bits(2)? as i32;
886886 for bnd in 0..core.ncplbnd {
887887 let cplcoexp = r.read_bits(4)? as i32;
888- let cplcomant = r.read_bits(4)? as f32;
889- let mant = if cplcoexp == 15 {
890- cplcomant / 16.0
891- } else {
892- (cplcomant + 16.0) / 32.0
893- };
888+ let cplcomant = r.read_bits(4)? as i32;
894889 core.cplco[ch][bnd] =
895- mant * crate::mantissa::scale((cplcoexp + 3 * mstrcplco).min(24) as u8);
890+ crate::decode::coupling_coord(cplcoexp, cplcomant, mstrcplco);
896891 }
897892 }
898893 }
@@ -1196,11 +1191,8 @@ fn spectral_extension(core: &mut Core, ch: usize) {
11961191 if spxmant >= COEFFS {
11971192 break;
11981193 }
1199- // §E3.6.4.2.4's noise(): a zero-mean unit-variance source the
1200- // standard leaves to the implementation, so it is switched by the
1201- // same option as §7.3.4's dither.
12021194 let noise = if core.dither_on {
1203- core.spx_noise.unit_variance()
1195+ (core.dither.next_word() as i32) as f32 / -2_147_483_648.0
12041196 } else {
12051197 0.0
12061198 };
crates/ec-ac3/src/mantissa.rsmodified+22 -30
@@ -50,27 +50,20 @@ impl Default for Dither {
5050 }
5151
5252 impl Dither {
53- /// Next dither value, uniform in ±0.707 (ffmpeg's mantissa scaled by 2^-23).
54- pub fn value(&mut self) -> f32 {
55- self.mantissa() as f32 / 8_388_608.0
56- }
57-
58- /// Next value from a zero-mean, unit-variance source — what Annex E
59- /// §3.6.4.2.4 calls `noise()`. A uniform distribution on `[-1, 1]` has
60- /// variance 1/3, so it is scaled by `sqrt(3)`.
61- pub fn unit_variance(&mut self) -> f32 {
62- self.mantissa() as f32 / 5_931_008.0 * 1.732_050_8
53+ pub(crate) fn value(&mut self) -> f32 {
54+ let x = self.next_word() & 0x7f_ffff;
55+ (x as i32 - 0x40_0000) as f32 / 8_388_608.0
6356 }
6457
6558 /// ffmpeg's integer dither mantissa: `((x >> 8) * 181 >> 8) - 5931008`.
66- fn mantissa(&mut self) -> i32 {
59+ pub fn mantissa(&mut self) -> i32 {
6760 let x = self.next_word();
6861 let u = ((x >> 8) * 181) >> 8;
6962 u as i32 - 5_931_008
7063 }
7164
7265 /// `av_lfg_get`: `state[i] = state[i-24] + state[i-55]`, returning the new word.
73- fn next_word(&mut self) -> u32 {
66+ pub fn next_word(&mut self) -> u32 {
7467 let i = self.index & 63;
7568 let v = self.state[(i + 40) & 63].wrapping_add(self.state[(i + 9) & 63]);
7669 self.state[i] = v;
@@ -87,11 +80,11 @@ impl Dither {
8780 /// the next channel begins.
8881 #[derive(Debug, Clone, Copy, Default)]
8982 pub struct Mantissas {
90- group3: [f32; 3],
83+ group3: [i32; 3],
9184 left3: usize,
92- group5: [f32; 3],
85+ group5: [i32; 3],
9386 left5: usize,
94- group11: [f32; 2],
87+ group11: [i32; 2],
9588 left11: usize,
9689 }
9790
@@ -106,9 +99,9 @@ impl Mantissas {
10699 /// `bap == 0` returns 0.0; the caller decides whether that bin gets dither,
107100 /// because in the coupled range the decision belongs to the channel rather
108101 /// than to the coupling channel the mantissa came from.
109- pub fn read(&mut self, r: &mut BitReader<'_>, bap: u8) -> Result<f32> {
102+ pub fn read(&mut self, r: &mut BitReader<'_>, bap: u8) -> Result<i32> {
110103 Ok(match bap {
111- 0 => 0.0,
104+ 0 => 0,
112105 1 => {
113106 if self.left3 == 0 {
114107 let code = r.read_bits(5)?.min(26);
@@ -159,13 +152,16 @@ impl Mantissas {
159152 // 6..=15: asymmetric two's complement, decimal point left of
160153 // the MSB (§7.3.2).
161154 let bits = QNTZTAB[(bap as usize).min(15)];
162- let value = r.read_signed(bits)?;
163- value as f32 / (1u32 << (bits - 1)) as f32
155+ r.read_signed(bits)? << (24 - bits)
164156 }
165157 })
166158 }
167159 }
168160
161+pub(crate) fn shift(mantissa: i32, exponent: u8) -> f32 {
162+ (mantissa >> exponent) as f32 / 8_388_608.0
163+}
164+
169165 /// `2^-exponent`, the right shift §7.3 applies to every mantissa.
170166 pub fn scale(exponent: u8) -> f32 {
171167 // Exponents are 0..=24, so a table lookup would buy nothing over the
@@ -188,14 +184,10 @@ mod tests {
188184 let bytes = w.into_bytes();
189185 let mut r = BitReader::new(&bytes);
190186 let mut m = Mantissas::new();
191- let got: Vec<f32> = (0..3).map(|_| m.read(&mut r, 1).unwrap()).collect();
192- assert!((got[0] - 2.0 / 3.0).abs() < 1e-6);
193- assert!(got[1].abs() < 1e-6);
194- assert!((got[2] + 2.0 / 3.0).abs() < 1e-6);
195- let a = m.read(&mut r, 4).unwrap();
196- let b = m.read(&mut r, 4).unwrap();
197- assert!((a - 10.0 / 11.0).abs() < 1e-6);
198- assert!((b + 10.0 / 11.0).abs() < 1e-6);
187+ let got: Vec<i32> = (0..3).map(|_| m.read(&mut r, 1).unwrap()).collect();
188+ assert_eq!(got, [5_592_405, 0, -5_592_405]);
189+ assert_eq!(m.read(&mut r, 4).unwrap(), 7_626_007);
190+ assert_eq!(m.read(&mut r, 4).unwrap(), -7_626_007);
199191 }
200192
201193 #[test]
@@ -206,9 +198,9 @@ mod tests {
206198 let bytes = w.into_bytes();
207199 let mut r = BitReader::new(&bytes);
208200 let mut m = Mantissas::new();
209- assert!((m.read(&mut r, 7).unwrap() + 1.0).abs() < 1e-6);
210- assert!((m.read(&mut r, 7).unwrap() - 31.0 / 32.0).abs() < 1e-6);
211- assert_eq!(m.read(&mut r, 0).unwrap(), 0.0);
201+ assert_eq!(m.read(&mut r, 7).unwrap(), -(1 << 23));
202+ assert_eq!(m.read(&mut r, 7).unwrap(), 31 << 18);
203+ assert_eq!(m.read(&mut r, 0).unwrap(), 0);
212204 }
213205
214206 #[test]
crates/ec-ac3/src/tables.rsmodified+9 -8
@@ -155,8 +155,9 @@ pub const QUANT_LEVELS: [u32; 6] = [0, 3, 5, 7, 11, 15];
155155
156156 /// The `k`-th reconstruction level of a `levels`-level symmetric quantizer
157157 /// (Tables 7.19-7.23): the uniform midtread set `(2k - (levels-1)) / levels`.
158-pub fn symmetric_level(levels: u32, k: u32) -> f32 {
159- (2.0 * k as f32 - (levels as f32 - 1.0)) / levels as f32
158+pub fn symmetric_level(levels: u32, k: u32) -> i32 {
159+ let levels = levels as i32;
160+ (2 * k as i32 - (levels - 1)) * (1 << 23) / levels
160161 }
161162
162163 /// Transform window `w[]`: 256 values used back to back to form the 512-point
@@ -216,12 +217,12 @@ mod tests {
216217 #[test]
217218 fn symmetric_quantizer_matches_printed_tables() {
218219 // Tables 7.19-7.23, as printed.
219- assert!((symmetric_level(3, 0) + 2.0 / 3.0).abs() < 1e-6);
220- assert!(symmetric_level(3, 1).abs() < 1e-6);
221- assert!((symmetric_level(5, 3) - 2.0 / 5.0).abs() < 1e-6);
222- assert!((symmetric_level(7, 6) - 6.0 / 7.0).abs() < 1e-6);
223- assert!((symmetric_level(11, 0) + 10.0 / 11.0).abs() < 1e-6);
224- assert!((symmetric_level(15, 14) - 14.0 / 15.0).abs() < 1e-6);
220+ assert_eq!(symmetric_level(3, 0), -5_592_405);
221+ assert_eq!(symmetric_level(3, 1), 0);
222+ assert_eq!(symmetric_level(5, 3), 3_355_443);
223+ assert_eq!(symmetric_level(7, 6), 7_190_235);
224+ assert_eq!(symmetric_level(11, 0), -7_626_007);
225+ assert_eq!(symmetric_level(15, 14), 7_829_367);
225226 }
226227
227228 #[test]
crates/ec-ac3/tests/it/real_library.rsmodified+11 -0
@@ -43,6 +43,17 @@ fn decode(path: &Path) -> (Vec<f32>, usize) {
4343 if pos + size > data.len() {
4444 break;
4545 }
46+ let mut end = pos + size;
47+ while end + 6 <= data.len() && data[end] == 0x0B && data[end + 1] == 0x77 && data[end + 5] >> 3 > 10 && data[end + 2] >> 6 == 1 {
48+ let Ok(more) = ec_ac3::frame_size(&data[end..]) else {
49+ break;
50+ };
51+ if end + more > data.len() {
52+ break;
53+ }
54+ end += more;
55+ }
56+ let size = end - pos;
4657 let frame = decoder
4758 .decode_frame(&data[pos..pos + size])
4859 .unwrap_or_else(|e| panic!("{}: {e}", path.display()));