use super::*;
use crate::NextSample;
const SINE_WAVE_FILE: &[u8] = include_bytes!("audiocheck.net_sin_1000Hz_0dBFS_0.1s.mp3");
const STEREO_FILE: &[u8] = include_bytes!("../../../../test_files/stereo-test.mp3");
#[test]
fn samples_of_test_file1() -> std::io::Result<()> {
let mut decoder = Mp3Decoder::new(std::io::Cursor::new(SINE_WAVE_FILE));
assert_eq!(decoder.sample_rate(), 44100);
assert_eq!(decoder.channel_count(), 1);
for _i in 0..2258 {
let sample = decoder.next_sample().unwrap();
match sample {
NextSample::Sample(s) => {
assert!(s.abs() < 700)
}
NextSample::MetadataChanged => unreachable!(),
NextSample::Paused => unreachable!(),
NextSample::Finished => unreachable!(),
}
}
assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(4235)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(8784)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(12774)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(16553)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(20398)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(23584)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(25961)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(28080)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(29853)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(30800)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(31010)); assert_eq!(decoder.next_sample().unwrap(), NextSample::Sample(30771)); for _i in 0..4642 {
let sample = decoder.next_sample().unwrap();
match sample {
NextSample::Sample(_) => {}
NextSample::MetadataChanged => unreachable!(),
NextSample::Paused => unreachable!(),
NextSample::Finished => unreachable!(),
}
}
assert_eq!(decoder.next_sample().unwrap(), NextSample::Finished);
assert_eq!(decoder.next_sample().unwrap(), NextSample::Finished);
Ok(())
}
#[test]
fn samples_of_test_file2() -> std::io::Result<()> {
let mut decoder = Mp3Decoder::new(std::io::Cursor::new(STEREO_FILE));
assert_eq!(decoder.sample_rate(), 32000);
assert_eq!(decoder.channel_count(), 2);
for _i in 0..1_078_272 {
let sample = decoder.next_sample().unwrap();
match sample {
NextSample::Sample(_s) => {}
NextSample::MetadataChanged => unreachable!(),
NextSample::Paused => unreachable!(),
NextSample::Finished => unreachable!(),
}
}
assert_eq!(decoder.next_sample().unwrap(), NextSample::Finished);
Ok(())
}