Fix feature issue and add AIFF bench

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-07-07 21:26:30 -04:00
parent f490879263
commit 8b82e0969b
2 changed files with 28 additions and 22 deletions

View file

@ -9,6 +9,7 @@ macro_rules! test_read {
};
}
test_read!(read_aiff, "tests/assets/a_text.aiff");
test_read!(read_ape, "tests/assets/a.ape");
test_read!(read_flac, "tests/assets/a.flac");
test_read!(read_m4a, "tests/assets/a.m4a");
@ -19,6 +20,7 @@ test_read!(read_riff, "tests/assets/a.wav");
fn bench_sig(c: &mut Criterion) {
let mut g = c.benchmark_group("From signature");
g.bench_function("AIFF", |b| b.iter(read_aiff));
g.bench_function("APE", |b| b.iter(read_ape));
g.bench_function("FLAC", |b| b.iter(read_flac));
g.bench_function("MP4", |b| b.iter(read_m4a));

View file

@ -240,7 +240,7 @@ impl TagType {
77 if sig.starts_with(&MAC) => Ok(Self::Ape),
#[cfg(feature = "format-id3")]
73 if sig.starts_with(&ID3) => Ok(Self::Id3v2(Id3Format::Default)),
#[cfg(feature = "format-id3")]
#[cfg(any(feature = "format-id3", feature = "format-aiff"))]
70 if sig.starts_with(&FORM) => {
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
@ -249,33 +249,37 @@ impl TagType {
let mut id = [0; 4];
data.read_exact(&mut id)?;
if &id != b"AIFF" && &id != b"AIFC" {
return Err(LoftyError::UnknownFormat);
}
if &id == b"AIFF" || &id == b"AIFC" {
#[cfg(feature = "format-id3")]
{
let mut found_id3 = false;
let mut found_id3 = false;
while let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<BigEndian>(),
) {
if fourcc.to_le_bytes()[..3] == ID3 {
found_id3 = true;
break;
}
while let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<BigEndian>(),
) {
if fourcc.to_le_bytes()[..3] == ID3 {
found_id3 = true;
break;
data.seek(SeekFrom::Current(i64::from(u32::from_be_bytes(
size.to_be_bytes(),
))))?;
}
data.seek(SeekFrom::Start(0))?;
if found_id3 {
return Ok(Self::Id3v2(Id3Format::Form));
}
}
data.seek(SeekFrom::Current(i64::from(u32::from_be_bytes(
size.to_be_bytes(),
))))?;
#[cfg(feature = "format-aiff")]
return Ok(Self::AiffText);
}
data.seek(SeekFrom::Start(0))?;
if found_id3 {
return Ok(Self::Id3v2(Id3Format::Form));
}
Ok(Self::AiffText)
Err(LoftyError::UnknownFormat)
},
#[cfg(feature = "format-flac")]
102 if sig.starts_with(&FLAC) => Ok(Self::Ogg(OggFormat::Flac)),