diff --git a/src/iff/wav/properties.rs b/src/iff/wav/properties.rs index d4b1bffd..e381ab16 100644 --- a/src/iff/wav/properties.rs +++ b/src/iff/wav/properties.rs @@ -91,6 +91,11 @@ impl WavProperties { self.sample_rate } + /// Bits per sample + pub fn bit_depth(&self) -> u8 { + self.bit_depth + } + /// Channel count pub fn channels(&self) -> u8 { self.channels diff --git a/src/mp4/properties.rs b/src/mp4/properties.rs index f39d4bde..344f3a88 100644 --- a/src/mp4/properties.rs +++ b/src/mp4/properties.rs @@ -32,6 +32,7 @@ pub struct Mp4Properties { overall_bitrate: u32, audio_bitrate: u32, sample_rate: u32, + bit_depth: Option, channels: u8, } @@ -42,7 +43,7 @@ impl From for FileProperties { overall_bitrate: Some(input.overall_bitrate), audio_bitrate: Some(input.audio_bitrate), sample_rate: Some(input.sample_rate), - bit_depth: None, + bit_depth: input.bit_depth, channels: Some(input.channels), } } @@ -56,6 +57,7 @@ impl Mp4Properties { overall_bitrate: u32, audio_bitrate: u32, sample_rate: u32, + bit_depth: Option, channels: u8, ) -> Self { Self { @@ -64,6 +66,7 @@ impl Mp4Properties { overall_bitrate, audio_bitrate, sample_rate, + bit_depth, channels, } } @@ -88,6 +91,11 @@ impl Mp4Properties { self.sample_rate } + /// Bits per sample + pub fn bit_depth(&self) -> Option { + self.bit_depth + } + /// Channel count pub fn channels(&self) -> u8 { self.channels @@ -201,6 +209,7 @@ where overall_bitrate: 0, audio_bitrate: 0, sample_rate: 0, + bit_depth: None, channels: 0, }; @@ -337,15 +346,20 @@ where if alac.ident == AtomIdent::Fourcc(*b"alac") { properties.codec = Mp4Codec::ALAC; - // Skipping 13 bytes + // Skipping 9 bytes // Version (4) // Samples per frame (4) // Compatible version (1) + data.seek(SeekFrom::Current(9))?; + // Sample size (1) + properties.bit_depth = Some(data.read_u8()?); + + // Skipping 3 bytes // Rice history mult (1) // Rice initial history (1) // Rice parameter limit (1) - data.seek(SeekFrom::Current(13))?; + data.seek(SeekFrom::Current(3))?; properties.channels = data.read_u8()?; diff --git a/tests/files/assets/b.m4a b/tests/files/assets/b.m4a new file mode 100644 index 00000000..665cc978 Binary files /dev/null and b/tests/files/assets/b.m4a differ diff --git a/tests/properties.rs b/tests/properties.rs index a6142df0..2b0b7919 100644 --- a/tests/properties.rs +++ b/tests/properties.rs @@ -46,6 +46,17 @@ const MP4_PROPERTIES: Mp4Properties = Mp4Properties::new( 135, 124, 48000, + None, + 2, +); + +const ALAC_PROPERTIES: Mp4Properties = Mp4Properties::new( + Mp4Codec::ALAC, + Duration::from_millis(1428), + 331, + 124, + 48000, + Some(16), 2, ); @@ -126,6 +137,14 @@ fn mp4_properties() { ) } +#[test] +fn alac_properties() { + assert_eq!( + get_properties::("tests/files/assets/b.m4a").bit_depth(), + ALAC_PROPERTIES.bit_depth() + ) +} + #[test] fn opus_properties() { assert_eq!(