bit_depth prototype

This commit is contained in:
sagudev 2022-01-22 19:54:42 +01:00
parent d034782a27
commit 29378f53a5
10 changed files with 20 additions and 0 deletions

View file

@ -25,6 +25,7 @@ impl From<ApeProperties> 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),
}
}

View file

@ -66,6 +66,7 @@ pub(super) fn read_properties(
overall_bitrate,
audio_bitrate,
sample_rate: Some(sample_rate),
bit_depth: None,
channels: Some(channels),
})
}

View file

@ -42,6 +42,7 @@ impl From<WavProperties> 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),
}
}

View file

@ -23,6 +23,7 @@ impl From<Mp3Properties> 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),
}
}

View file

@ -42,6 +42,7 @@ impl From<Mp4Properties> 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),
}
}

View file

@ -32,6 +32,7 @@ where
let info = stream_info.read_u32::<BigEndian>()?;
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),
})
}

View file

@ -26,6 +26,7 @@ impl From<OpusProperties> 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),
}
}

View file

@ -29,6 +29,7 @@ impl From<VorbisProperties> 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),
}
}

View file

@ -7,6 +7,7 @@ pub struct FileProperties {
pub(crate) overall_bitrate: Option<u32>,
pub(crate) audio_bitrate: Option<u32>,
pub(crate) sample_rate: Option<u32>,
pub(crate) bit_depth: Option<u8>,
pub(crate) channels: Option<u8>,
}
@ -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<u32>,
audio_bitrate: Option<u32>,
sample_rate: Option<u32>,
bit_depth: Option<u8>,
channels: Option<u8>,
) -> 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<u8> {
self.bit_depth
}
/// Channel count
pub fn channels(&self) -> Option<u8> {
self.channels

View file

@ -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),
);