forge
Explore
Log in

Don't you dare go Hollow

S11: ac3 fold split: downmix_gains builds the per-channel matrix; fold applies it (same ops, same order)

Browse files at this commit

a4831bd49c1459ae317d2455ff601d4cfb92be10Ahmet Kaan GümüşParent: 6789dd1
crates/ec-ac3/src/decoder.rsmodified+18 -12
@@ -413,20 +413,10 @@ impl Ac3Decoder {
413413 }
414414 }
415415
416- /// Apply the requested downmix, if any (§7.8.2).
417- fn fold(&self, samples: Vec<f32>, info: &FrameInfo, positions: &[ChannelPosition]) -> Vec<f32> {
418- if self.options.downmix == Downmix::Native {
419- return samples;
420- }
421- let channels = positions.len();
422- if channels == 0 {
423- return samples;
424- }
416+ /// Per-channel gains into the left and right downmix sums (§7.8.2).
417+ fn downmix_gains(info: &FrameInfo, positions: &[ChannelPosition]) -> (Vec<f32>, Vec<f32>) {
425418 let clev = info.center_mix_level.unwrap_or(0.707);
426419 let slev = info.surround_mix_level.unwrap_or(0.707);
427- // §7.8.2 with the standard's own coefficients, then one scaling so a
428- // full-scale input cannot overflow the downmix — the standard's fixed
429- // -7.65 dB would quieten every stereo listener instead.
430420 let (mut left, mut right) = (Vec::new(), Vec::new());
431421 for &p in positions {
432422 let (l, r) = match p {
@@ -447,6 +437,22 @@ impl Ac3Decoder {
447437 left.push(l);
448438 right.push(r);
449439 }
440+ (left, right)
441+ }
442+
443+ /// Apply the requested downmix, if any (§7.8.2).
444+ fn fold(&self, samples: Vec<f32>, info: &FrameInfo, positions: &[ChannelPosition]) -> Vec<f32> {
445+ if self.options.downmix == Downmix::Native {
446+ return samples;
447+ }
448+ let channels = positions.len();
449+ if channels == 0 {
450+ return samples;
451+ }
452+ // The standard's own coefficients, then one scaling so a full-scale
453+ // input cannot overflow the downmix — the standard's fixed -7.65 dB
454+ // would quieten every stereo listener instead.
455+ let (left, right) = Self::downmix_gains(info, positions);
450456 let peak = left
451457 .iter()
452458 .sum::<f32>()