diff --git a/src/ape/properties.rs b/src/ape/properties.rs index 84ba8f73..6b801f8b 100644 --- a/src/ape/properties.rs +++ b/src/ape/properties.rs @@ -25,6 +25,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, channels: Some(input.channels), } } diff --git a/src/iff/aiff/properties.rs b/src/iff/aiff/properties.rs index 313b4ee6..7ec7be83 100644 --- a/src/iff/aiff/properties.rs +++ b/src/iff/aiff/properties.rs @@ -66,6 +66,7 @@ pub(super) fn read_properties( overall_bitrate, audio_bitrate, sample_rate: Some(sample_rate), + bit_depth: None, channels: Some(channels), }) } diff --git a/src/iff/wav/properties.rs b/src/iff/wav/properties.rs index baf28cbd..a542ddfe 100644 --- a/src/iff/wav/properties.rs +++ b/src/iff/wav/properties.rs @@ -42,6 +42,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, channels: Some(input.channels), } } diff --git a/src/mp3/properties.rs b/src/mp3/properties.rs index ddbb8c4a..9fb516da 100644 --- a/src/mp3/properties.rs +++ b/src/mp3/properties.rs @@ -23,6 +23,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, channels: Some(input.channels), } } diff --git a/src/mp4/properties.rs b/src/mp4/properties.rs index fac29dc7..f39d4bde 100644 --- a/src/mp4/properties.rs +++ b/src/mp4/properties.rs @@ -42,6 +42,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, channels: Some(input.channels), } } diff --git a/src/ogg/flac/properties.rs b/src/ogg/flac/properties.rs index 721f824d..ff04b111 100644 --- a/src/ogg/flac/properties.rs +++ b/src/ogg/flac/properties.rs @@ -32,6 +32,7 @@ where let info = stream_info.read_u32::()?; let sample_rate = info >> 12; + let bits_per_sample = ((info >> 4) & 0b1111) + 1; let channels = ((info >> 9) & 7) + 1; // Read the remaining 32 bits of the total samples @@ -54,6 +55,7 @@ where overall_bitrate, audio_bitrate, sample_rate: Some(sample_rate as u32), + bit_depth: Some(bits_per_sample as u8), channels: Some(channels as u8), }) } diff --git a/src/ogg/opus/properties.rs b/src/ogg/opus/properties.rs index 884f94b8..0ca0c508 100644 --- a/src/ogg/opus/properties.rs +++ b/src/ogg/opus/properties.rs @@ -26,6 +26,7 @@ impl From for FileProperties { overall_bitrate: Some(input.overall_bitrate), audio_bitrate: Some(input.audio_bitrate), sample_rate: Some(input.input_sample_rate), + bit_depth: None, channels: Some(input.channels), } } diff --git a/src/ogg/vorbis/properties.rs b/src/ogg/vorbis/properties.rs index 8d375577..898620f9 100644 --- a/src/ogg/vorbis/properties.rs +++ b/src/ogg/vorbis/properties.rs @@ -29,6 +29,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, channels: Some(input.channels), } } diff --git a/src/types/properties.rs b/src/types/properties.rs index b7cc0fa4..a07b3dc5 100644 --- a/src/types/properties.rs +++ b/src/types/properties.rs @@ -7,6 +7,7 @@ pub struct FileProperties { pub(crate) overall_bitrate: Option, pub(crate) audio_bitrate: Option, pub(crate) sample_rate: Option, + pub(crate) bit_depth: Option, pub(crate) channels: Option, } @@ -17,6 +18,7 @@ impl Default for FileProperties { overall_bitrate: None, audio_bitrate: None, sample_rate: None, + bit_depth: None, channels: None, } } @@ -29,6 +31,7 @@ impl FileProperties { overall_bitrate: Option, audio_bitrate: Option, sample_rate: Option, + bit_depth: Option, channels: Option, ) -> Self { Self { @@ -36,6 +39,7 @@ impl FileProperties { overall_bitrate, audio_bitrate, sample_rate, + bit_depth, channels, } } @@ -60,6 +64,11 @@ impl FileProperties { self.sample_rate } + /// Bits per sample (usually 16 or 24 bit) + pub fn bit_depth(&self) -> Option { + self.bit_depth + } + /// Channel count pub fn channels(&self) -> Option { self.channels diff --git a/tests/properties.rs b/tests/properties.rs index cea2eacc..33c923db 100644 --- a/tests/properties.rs +++ b/tests/properties.rs @@ -13,6 +13,7 @@ const AIFF_PROPERTIES: FileProperties = FileProperties::new( Some(1542), Some(1536), Some(48000), + None, Some(2), ); @@ -24,6 +25,7 @@ const FLAC_PROPERTIES: FileProperties = FileProperties::new( Some(321), Some(275), Some(48000), + None, Some(2), );