mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
Add some helpful comments
This commit is contained in:
parent
7f0c0ee922
commit
c6a02c6b73
6 changed files with 21 additions and 15 deletions
|
@ -1,3 +1,4 @@
|
|||
#[allow(unused)]
|
||||
pub(super) const INVALID_KEYS: [&str; 4] = ["ID3", "TAG", "OGGS", "MP+"];
|
||||
pub(crate) const APE_PREAMBLE: &[u8; 8] = b"APETAGEX";
|
||||
|
||||
// https://wiki.hydrogenaud.io/index.php?title=APE_Tags_Header
|
||||
pub(crate) const APE_PREAMBLE: &[u8; 8] = b"APETAGEX";
|
|
@ -196,7 +196,7 @@ pub const GENRES: [&str; 192] = [
|
|||
"Psybient",
|
||||
];
|
||||
|
||||
pub const VALID_ITEMKEYS: [ItemKey; 7] = [
|
||||
pub(crate) const VALID_ITEMKEYS: [ItemKey; 7] = [
|
||||
ItemKey::TrackTitle,
|
||||
ItemKey::TrackArtist,
|
||||
ItemKey::AlbumTitle,
|
||||
|
|
|
@ -19,10 +19,13 @@ pub fn parse_id3v1(reader: [u8; 128]) -> Id3v1Tag {
|
|||
tag.album = decode_text(&reader[60..90]);
|
||||
tag.year = decode_text(&reader[90..94]);
|
||||
|
||||
let range = if reader[119] == 0 && reader[123] != 0 {
|
||||
// Determine the range of the comment (30 bytes for ID3v1 and 28 for ID3v1.1)
|
||||
// We check for the null terminator 28 bytes in, and for a non-zero track number after it.
|
||||
// A track number of 0 is invalid.
|
||||
let range = if reader[122] == 0 && reader[123] != 0 {
|
||||
tag.track_number = Some(reader[123]);
|
||||
|
||||
94_usize..122
|
||||
94_usize..123
|
||||
} else {
|
||||
94..124
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
// https://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-620004.2.1
|
||||
pub const VORBIS_IDENT_HEAD: &[u8] = &[1, 118, 111, 114, 98, 105, 115];
|
||||
pub const VORBIS_COMMENT_HEAD: &[u8] = &[3, 118, 111, 114, 98, 105, 115];
|
||||
#[allow(unused)]
|
||||
pub const VORBIS_SETUP_HEAD: &[u8] = &[5, 118, 111, 114, 98, 105, 115];
|
||||
|
||||
// https://datatracker.ietf.org/doc/pdf/rfc7845.pdf#section-5.1
|
||||
pub const OPUSTAGS: &[u8] = &[79, 112, 117, 115, 84, 97, 103, 115];
|
||||
pub const OPUSHEAD: &[u8] = &[79, 112, 117, 115, 72, 101, 97, 100];
|
||||
|
||||
// https://www.speex.org/docs/manual/speex-manual/node8.html
|
||||
pub const SPEEXHEADER: &[u8] = &[83, 112, 101, 101, 120, 32, 32, 32];
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct SpeexProperties {
|
|||
vbr: bool,
|
||||
overall_bitrate: u32,
|
||||
audio_bitrate: u32,
|
||||
nominal_bitrate: u32,
|
||||
nominal_bitrate: i32,
|
||||
}
|
||||
|
||||
impl From<SpeexProperties> for FileProperties {
|
||||
|
@ -47,7 +47,7 @@ impl SpeexProperties {
|
|||
vbr: bool,
|
||||
overall_bitrate: u32,
|
||||
audio_bitrate: u32,
|
||||
nominal_bitrate: u32,
|
||||
nominal_bitrate: i32,
|
||||
) -> Self {
|
||||
Self {
|
||||
duration,
|
||||
|
@ -102,8 +102,8 @@ impl SpeexProperties {
|
|||
self.audio_bitrate
|
||||
}
|
||||
|
||||
/// Audio bitrate (kbps)
|
||||
pub fn nominal_bitrate(&self) -> u32 {
|
||||
/// Audio bitrate (bps)
|
||||
pub fn nominal_bitrate(&self) -> i32 {
|
||||
self.nominal_bitrate
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ where
|
|||
}
|
||||
|
||||
properties.channels = channels as u8;
|
||||
properties.nominal_bitrate = first_page_content.read_u32::<LittleEndian>()?;
|
||||
properties.nominal_bitrate = first_page_content.read_i32::<LittleEndian>()?;
|
||||
|
||||
// The size of the frames in samples
|
||||
let _frame_size = first_page_content.read_u32::<LittleEndian>()?;
|
||||
|
@ -167,7 +167,7 @@ where
|
|||
properties.duration = Duration::from_millis(length as u64);
|
||||
|
||||
properties.overall_bitrate = ((file_length * 8) / length) as u32;
|
||||
properties.audio_bitrate = properties.nominal_bitrate / 1000;
|
||||
properties.audio_bitrate = (properties.nominal_bitrate as u64 / 1000) as u32;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,17 +91,17 @@ impl VorbisProperties {
|
|||
self.version
|
||||
}
|
||||
|
||||
/// Maximum bitrate
|
||||
/// Maximum bitrate (bps)
|
||||
pub fn bitrate_max(&self) -> i32 {
|
||||
self.bitrate_maximum
|
||||
}
|
||||
|
||||
/// Nominal bitrate
|
||||
/// Nominal bitrate (bps)
|
||||
pub fn bitrate_nominal(&self) -> i32 {
|
||||
self.bitrate_nominal
|
||||
}
|
||||
|
||||
/// Minimum bitrate
|
||||
/// Minimum bitrate (bps)
|
||||
pub fn bitrate_min(&self) -> i32 {
|
||||
self.bitrate_minimum
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue