S11: ac3 fold split: downmix_gains builds the per-channel matrix; fold applies it (same ops, same order)
Browse files at this commita4831bd49c1459ae317d2455ff601d4cfb92be10Parent: 6789dd11 changed file +18 -12
- crates/ec-ac3/src/decoder.rs +18 -12
crates/ec-ac3/src/decoder.rsmodified+18 -12
| @@ -413,20 +413,10 @@ impl Ac3Decoder { | ||
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| 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>) { | |
| 425 | 418 | let clev = info.center_mix_level.unwrap_or(0.707); |
| 426 | 419 | 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. | |
| 430 | 420 | let (mut left, mut right) = (Vec::new(), Vec::new()); |
| 431 | 421 | for &p in positions { |
| 432 | 422 | let (l, r) = match p { |
| @@ -447,6 +437,22 @@ impl Ac3Decoder { | ||
| 447 | 437 | left.push(l); |
| 448 | 438 | right.push(r); |
| 449 | 439 | } |
| 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); | |
| 450 | 456 | let peak = left |
| 451 | 457 | .iter() |
| 452 | 458 | .sum::<f32>() |