2021-06-29 07:12:28 +00:00
|
|
|
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
|
2019-05-15 01:13:24 +00:00
|
|
|
use rodio::Source;
|
2021-06-29 07:12:28 +00:00
|
|
|
use std::io::BufReader;
|
|
|
|
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
|
|
|
|
use std::time::Duration;
|
2019-05-15 01:13:24 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_flac_encodings() {
|
|
|
|
// 16 bit FLAC file exported from Audacity (2 channels, compression level 5)
|
2022-03-26 19:15:18 +00:00
|
|
|
let file = std::fs::File::open("assets/audacity16bit_level5.flac").unwrap();
|
2019-05-15 01:13:24 +00:00
|
|
|
let mut decoder = rodio::Decoder::new(BufReader::new(file)).unwrap();
|
2021-06-29 07:12:28 +00:00
|
|
|
// File is not just silence
|
|
|
|
assert!(decoder.any(|x| x != 0));
|
|
|
|
// Symphonia does not expose functionality to get the duration so this check must be disabled
|
|
|
|
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
|
2019-05-15 01:13:24 +00:00
|
|
|
assert_eq!(decoder.total_duration(), Some(Duration::from_secs(3))); // duration is calculated correctly
|
|
|
|
|
|
|
|
// 24 bit FLAC file exported from Audacity (2 channels, various compression levels)
|
|
|
|
for level in &[0, 5, 8] {
|
2024-07-04 07:09:44 +00:00
|
|
|
let file = std::fs::File::open(format!("assets/audacity24bit_level{level}.flac")).unwrap();
|
2019-05-15 01:13:24 +00:00
|
|
|
let mut decoder = rodio::Decoder::new(BufReader::new(file)).unwrap();
|
|
|
|
assert!(decoder.any(|x| x != 0));
|
2021-06-29 07:12:28 +00:00
|
|
|
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
|
2019-05-15 01:13:24 +00:00
|
|
|
assert_eq!(decoder.total_duration(), Some(Duration::from_secs(3)));
|
|
|
|
}
|
|
|
|
}
|