Skip to content

Commit

Permalink
adds channel volume with queue test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk committed Jan 24, 2025
1 parent 40c6c86 commit bf98f34
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/channel_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::io::BufReader;
use itertools::Itertools;

use rodio::source::ChannelVolume;
use rodio::{Decoder, Source};
use rodio::{queue, Decoder, Source};

#[test]
fn tomato() {
fn no_queue() {
let file = fs::File::open("assets/music.mp3").unwrap();
let decoder = Decoder::new(BufReader::new(file)).unwrap();
assert_eq!(decoder.channels(), 2);
Expand All @@ -17,6 +17,20 @@ fn tomato() {
assert_output_only_on_channel_1_and_2(channel_volume);
}

#[test]
fn with_queue_in_between() {
let file = fs::File::open("assets/music.mp3").unwrap();
let decoder = Decoder::new(BufReader::new(file)).unwrap();
assert_eq!(decoder.channels(), 2);
let channel_volume = ChannelVolume::new(decoder, vec![1.0, 1.0, 0.0, 0.0, 0.0, 0.0]);
assert_eq!(channel_volume.channels(), 6);

let (controls, queue) = queue::queue(false);
controls.append(channel_volume);

assert_output_only_on_channel_1_and_2(queue);
}

fn assert_output_only_on_channel_1_and_2(source: impl Source<Item = i16>) {
for (frame_number, mut frame) in source.chunks(6).into_iter().enumerate() {
let frame: [_; 6] = frame.next_array().expect(&format!(
Expand All @@ -25,7 +39,7 @@ fn assert_output_only_on_channel_1_and_2(source: impl Source<Item = i16>) {
assert_eq!(
&frame[2..],
&[0, 0, 0, 0],
"frame number {frame_number} had nonzero volume on channels 3,4,5 & 6"
"frame {frame_number} had nonzero volume on a channel that should be zero"
)
}
}

0 comments on commit bf98f34

Please sign in to comment.