hound testing

This commit is contained in:
sagudev 2022-01-23 12:32:51 +01:00
parent 23cf587940
commit c8c84e6660
26 changed files with 46 additions and 8 deletions

4
.gitignore vendored
View file

@ -9,7 +9,3 @@
**/.idea/ **/.idea/
**/Cargo.lock **/Cargo.lock
# Test assets
/tests/files/assets/
/tests/picture/assets/

View file

@ -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

View file

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

View file

@ -0,0 +1 @@
RIFFPIFFWAVEooooRIF±FF

Binary file not shown.

Binary file not shown.

Binary file not shown.

30
tests/hound.rs Normal file
View 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);
}
}
}