forge
Explore
Log in

Don't you dare go Hollow

ec-ac3: place a dependent substream's channels like ffmpeg: the k-th channel-map entry takes output slot ff_ac3_dec_channel_map[acmod][lfeon][k] (ac3dec.c extended_channel_map); the_great_wall_7.1 (3/1 dependent, map Ls Rs Lrs/Rrs) had BL and SR swapped vs ffmpeg

Browse files at this commit

acbfd4cf6bbc6a44f755e33fd0d790ce5b77903dAhmet Kaan GümüşParent: 443844f
crates/ec-ac3/src/decoder.rsmodified+1 -1
@@ -342,7 +342,7 @@ impl Ac3Decoder {
342 )));342 )));
343 }343 }
344 let channels = hdr.nfchans + usize::from(hdr.bsi.lfeon);344 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)?;
346 if self.dependents.len() <= slot {346 if self.dependents.len() <= slot {
347 self.dependents.push(Core::new());347 self.dependents.push(Core::new());
348 }348 }
crates/ec-ac3/src/dependent.rsmodified+36 -11
@@ -28,6 +28,7 @@
28 28
29 use ec_core::{BitReader, ChannelPosition, Error, Result};29 use ec_core::{BitReader, ChannelPosition, Error, Result};
30 30
31+use crate::bsi::Acmod;
31 use crate::eac3::{self, Eac3Bsi, StreamType};32 use crate::eac3::{self, Eac3Bsi, StreamType};
32 use crate::syncinfo::SYNCWORD;33 use crate::syncinfo::SYNCWORD;
33 34
@@ -54,7 +55,7 @@ pub(crate) fn peek(data: &[u8]) -> Option<Eac3Bsi> {
54 55
55 /// The loudspeaker positions a dependent substream's `channels` coded channels56 /// The loudspeaker positions a dependent substream's `channels` coded channels
56 /// fill, in coded order, from its custom channel map (Table E2.5).57 /// 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>> {
58 use ChannelPosition::*;59 use ChannelPosition::*;
59 let Some(map) = map else {60 let Some(map) = map else {
60 return Err(Error::unsupported(61 return Err(Error::unsupported(
@@ -99,7 +100,31 @@ pub(crate) fn positions(map: Option<u16>, channels: usize) -> Result<Vec<Channel
99 out.len()100 out.len()
100 )));101 )));
101 }102 }
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+ }
103 }128 }
104 129
105 /// The Table E2.5 name of the map entry `i` that this build cannot place.130 /// The Table E2.5 name of the map entry `i` that this build cannot place.
@@ -188,26 +213,26 @@ mod tests {
188 213
189 #[test]214 #[test]
190 fn map_bits_name_positions_as_ffmpeg_does() {215 fn map_bits_name_positions_as_ffmpeg_does() {
191- assert_eq!(positions(Some(0x8000), 1).unwrap(), vec![FrontLeft]);216+ assert_eq!(positions(Some(0x8000), 1, Acmod::Mono, false).unwrap(), vec![FrontLeft]);
192- assert_eq!(positions(Some(0x0400), 2).unwrap(), vec![FrontLeftOfCenter, FrontRightOfCenter]);217+ assert_eq!(positions(Some(0x0400), 2, Acmod::Stereo, false).unwrap(), vec![FrontLeftOfCenter, FrontRightOfCenter]);
193- assert_eq!(positions(Some(0x0200), 2).unwrap(), vec![BackLeft, BackRight]);218+ assert_eq!(positions(Some(0x0200), 2, Acmod::Stereo, false).unwrap(), vec![BackLeft, BackRight]);
194- assert_eq!(positions(Some(0x1800), 2).unwrap(), vec![SideLeft, SideRight]);219+ assert_eq!(positions(Some(0x1800), 2, Acmod::Stereo, false).unwrap(), vec![SideLeft, SideRight]);
195- assert_eq!(positions(Some(0x0001), 1).unwrap(), vec![Lfe]);220+ assert_eq!(positions(Some(0x0001), 1, Acmod::Mono, false).unwrap(), vec![Lfe]);
196- assert_eq!(positions(Some(0x8400), 3).unwrap(), vec![FrontLeft, FrontLeftOfCenter, FrontRightOfCenter]);221+ assert_eq!(positions(Some(0x8400), 3, Acmod::Surround2_1, false).unwrap(), vec![FrontLeft, FrontLeftOfCenter, FrontRightOfCenter]);
197 }222 }
198 223
199 #[test]224 #[test]
200 fn unnamed_and_missing_maps_are_refused_by_name() {225 fn unnamed_and_missing_maps_are_refused_by_name() {
201 for map in [None, Some(0x0080), Some(0x0040), Some(0x0010), Some(0x0004), Some(0x0002)] {226 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");
203 assert!(matches!(err, Error::Unsupported { .. }), "{map:?}: {err}");228 assert!(matches!(err, Error::Unsupported { .. }), "{map:?}: {err}");
204 }229 }
205 }230 }
206 231
207 #[test]232 #[test]
208 fn map_that_disagrees_with_the_channel_count_is_corrupt() {233 fn map_that_disagrees_with_the_channel_count_is_corrupt() {
209- assert!(matches!(positions(Some(0x1800), 1), Err(Error::Corrupt { .. })));234+ assert!(matches!(positions(Some(0x1800), 1, Acmod::Mono, false), Err(Error::Corrupt { .. })));
210- assert!(matches!(positions(Some(0x0400), 3), Err(Error::Corrupt { .. })));235+ assert!(matches!(positions(Some(0x0400), 3, Acmod::Surround2_1, false), Err(Error::Corrupt { .. })));
211 }236 }
212 237
213 #[test]238 #[test]
crates/ec-ac3/src/mantissa.rsmodified+1 -1
@@ -50,7 +50,7 @@ impl Default for Dither {
50 }50 }
51 51
52 impl Dither {52 impl Dither {
53- pub fn value(&mut self) -> f32 {53+ pub(crate) fn value(&mut self) -> f32 {
54 let x = self.next_word() & 0x7f_ffff;54 let x = self.next_word() & 0x7f_ffff;
55 (x as i32 - 0x40_0000) as f32 / 8_388_608.055 (x as i32 - 0x40_0000) as f32 / 8_388_608.0
56 }56 }