mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
hound testing
This commit is contained in:
parent
23cf587940
commit
c8c84e6660
26 changed files with 46 additions and 8 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -9,7 +9,3 @@
|
||||||
**/.idea/
|
**/.idea/
|
||||||
|
|
||||||
**/Cargo.lock
|
**/Cargo.lock
|
||||||
|
|
||||||
# Test assets
|
|
||||||
/tests/files/assets/
|
|
||||||
/tests/picture/assets/
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ criterion = { version = "0.3.5", features = ["html_reports"] }
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
# tag_writer example
|
# tag_writer example
|
||||||
structopt = { version = "0.3.26", default-features = false }
|
structopt = { version = "0.3.26", default-features = false }
|
||||||
|
hound = {git="https://github.com/ruuda/hound.git", branch="master"}
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
bench = false
|
bench = false
|
||||||
|
|
|
@ -91,6 +91,11 @@ impl WavProperties {
|
||||||
self.sample_rate
|
self.sample_rate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// bits per sample
|
||||||
|
pub fn bit_depth(&self) -> u8 {
|
||||||
|
self.bit_depth
|
||||||
|
}
|
||||||
|
|
||||||
/// Channel count
|
/// Channel count
|
||||||
pub fn channels(&self) -> u8 {
|
pub fn channels(&self) -> u8 {
|
||||||
self.channels
|
self.channels
|
||||||
|
@ -118,11 +123,16 @@ pub(super) fn read_properties(
|
||||||
let sample_rate = fmt.read_u32::<LittleEndian>()?;
|
let sample_rate = fmt.read_u32::<LittleEndian>()?;
|
||||||
let bytes_per_second = fmt.read_u32::<LittleEndian>()?;
|
let bytes_per_second = fmt.read_u32::<LittleEndian>()?;
|
||||||
|
|
||||||
// Skip 2 bytes
|
let block_align = fmt.read_u16::<LittleEndian>()?;
|
||||||
// Block align (2)
|
|
||||||
fmt.read_u16::<LittleEndian>()?;
|
|
||||||
|
|
||||||
let bits_per_sample = fmt.read_u16::<LittleEndian>()?;
|
let bits_per_sample = fmt.read_u16::<LittleEndian>()?;
|
||||||
|
let bytes_per_sample = block_align / u16::from(channels);
|
||||||
|
|
||||||
|
// We allow bits_per_sample to be less than bytes_per_sample so that
|
||||||
|
// we can support things such as 24 bit samples in 4 byte containers.
|
||||||
|
if Some(bits_per_sample) > bytes_per_sample.checked_mul(8) {
|
||||||
|
return Err(LoftyError::Wav("sample bits exceeds size of sample"));
|
||||||
|
}
|
||||||
|
|
||||||
if format_tag == EXTENSIBLE {
|
if format_tag == EXTENSIBLE {
|
||||||
if fmt.len() < 40 {
|
if fmt.len() < 40 {
|
||||||
|
@ -190,7 +200,7 @@ pub(super) fn read_properties(
|
||||||
overall_bitrate,
|
overall_bitrate,
|
||||||
audio_bitrate,
|
audio_bitrate,
|
||||||
sample_rate,
|
sample_rate,
|
||||||
bit_depth: bits_per_sample as u8,
|
bit_depth: (bytes_per_sample * 8) as u8,
|
||||||
channels,
|
channels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
RIFFPIFFWAVEooooRIF±FF
|
BIN
tests/files/assets/hound/nonstandard-01.wav
Normal file
BIN
tests/files/assets/hound/nonstandard-01.wav
Normal file
Binary file not shown.
BIN
tests/files/assets/hound/nonstandard-02.wav
Normal file
BIN
tests/files/assets/hound/nonstandard-02.wav
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/files/assets/hound/pcmwaveformat-16bit-44100Hz-mono.wav
Normal file
BIN
tests/files/assets/hound/pcmwaveformat-16bit-44100Hz-mono.wav
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/files/assets/hound/pcmwaveformat-8bit-44100Hz-mono.wav
Normal file
BIN
tests/files/assets/hound/pcmwaveformat-8bit-44100Hz-mono.wav
Normal file
Binary file not shown.
BIN
tests/files/assets/hound/pop.wav
Normal file
BIN
tests/files/assets/hound/pop.wav
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/files/assets/hound/waveformatex-16bit-44100Hz-mono.wav
Normal file
BIN
tests/files/assets/hound/waveformatex-16bit-44100Hz-mono.wav
Normal file
Binary file not shown.
BIN
tests/files/assets/hound/waveformatex-16bit-44100Hz-stereo.wav
Normal file
BIN
tests/files/assets/hound/waveformatex-16bit-44100Hz-stereo.wav
Normal file
Binary file not shown.
BIN
tests/files/assets/hound/waveformatex-8bit-11025Hz-mono.wav
Normal file
BIN
tests/files/assets/hound/waveformatex-8bit-11025Hz-mono.wav
Normal file
Binary file not shown.
BIN
tests/files/assets/hound/waveformatex-ieeefloat-44100Hz-mono.wav
Normal file
BIN
tests/files/assets/hound/waveformatex-ieeefloat-44100Hz-mono.wav
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
tests/hound.rs
Normal file
30
tests/hound.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use std::{
|
||||||
|
fs::{self, File},
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
|
|
||||||
|
use hound::WavReader;
|
||||||
|
use lofty::{iff::WavFile, AudioFile};
|
||||||
|
|
||||||
|
fn get_properties(path: &Path) -> <lofty::iff::WavFile as AudioFile>::Properties {
|
||||||
|
let mut f = File::open(path).unwrap();
|
||||||
|
let wav_file = WavFile::read_from(&mut f, true).unwrap();
|
||||||
|
*wav_file.properties()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hound() {
|
||||||
|
let paths = fs::read_dir("tests/files/assets/hound").unwrap();
|
||||||
|
|
||||||
|
for path in paths {
|
||||||
|
let path = path.unwrap().path();
|
||||||
|
if path.is_file() && path.extension().unwrap() == "wav" {
|
||||||
|
println!("Name: {}", path.display());
|
||||||
|
let wav_reader = WavReader::open(&path).unwrap();
|
||||||
|
let lofty = get_properties(&path);
|
||||||
|
assert_eq!(wav_reader.spec().channels, lofty.channels() as u16);
|
||||||
|
assert_eq!(wav_reader.spec().sample_rate, lofty.sample_rate());
|
||||||
|
assert_eq!(wav_reader.spec().bits_per_sample, lofty.bit_depth() as u16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue