mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 21:52:33 +00:00
bit-depth for ALAC and getter for wav
This commit is contained in:
parent
504ac31cda
commit
bd896287b6
4 changed files with 41 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -32,6 +32,7 @@ pub struct Mp4Properties {
|
|||
overall_bitrate: u32,
|
||||
audio_bitrate: u32,
|
||||
sample_rate: u32,
|
||||
bit_depth: Option<u8>,
|
||||
channels: u8,
|
||||
}
|
||||
|
||||
|
@ -42,7 +43,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,
|
||||
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<u8>,
|
||||
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<u8> {
|
||||
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()?;
|
||||
|
||||
|
|
BIN
tests/files/assets/b.m4a
Normal file
BIN
tests/files/assets/b.m4a
Normal file
Binary file not shown.
|
@ -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::<Mp4File>("tests/files/assets/b.m4a").bit_depth(),
|
||||
ALAC_PROPERTIES.bit_depth()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opus_properties() {
|
||||
assert_eq!(
|
||||
|
|
Loading…
Reference in a new issue