Skip to content

Commit 59f8325

Browse files
committed
adds basic channel volume test not using queue
1 parent 59a0b5a commit 59f8325

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ rstest_reuse = "0.6.0"
5656
approx = "0.5.1"
5757
dasp_sample = "0.11.0"
5858
divan = "0.1.14"
59+
itertools = "0.14"
5960

6061
[[bench]]
6162
name = "effects"

src/queue.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ where
111111
// This function is non-trivial because the boundary between two
112112
// sounds in the queue should be a span boundary as well. Further more
113113
// we can *only* return Some(0) if the queue should stop playing.
114+
//
114115
// This function can be called at any time though its normally only
115116
// called at the end of the span to get how long the next span will be.
116117
//
@@ -123,30 +124,6 @@ where
123124
// scenario. To handle this situation we force a span to have a
124125
// maximum number of samples with a constant. If the source ends before
125126
// that point we need to start silence for the remainder of the forced span.
126-
//
127-
// There are a lot of cases here:
128-
// - not filling silence, current span is done
129-
// move to next
130-
// - not filling silence, known span length.
131-
// report span length from current
132-
// - not filling silence, unknown span length have lower bound.
133-
// report lower bound
134-
// - not filling silence, unknown span length, no lower bound.
135-
// report fixed number of frames, if its too long we will get
136-
// silence for that length
137-
// - filling silence, we have a next, however span is not finished,
138-
// next is same channel count and sample rate.
139-
// move to next,
140-
// - filling silence, we have a next, however span is not finished,
141-
// next is diff channel count or sample rate.
142-
// play silence for rest of span
143-
// - filling silence, we have a next, span is done
144-
// move to next
145-
// - filling silence, no next, however span is not finished.
146-
// return samples left in span
147-
// - filling silence, no next, span is done.
148-
// new silence span with fixed length, match previous sample_rate
149-
// and channel count.
150127

151128
if let Some(len) = self.current.current_span_len() {
152129
// correct len for buffered sample

tests/channel_volume.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::fs;
2+
use std::io::BufReader;
3+
4+
use itertools::Itertools;
5+
6+
use rodio::source::ChannelVolume;
7+
use rodio::{Decoder, Source};
8+
9+
#[test]
10+
fn tomato() {
11+
let file = fs::File::open("assets/music.mp3").unwrap();
12+
let decoder = Decoder::new(BufReader::new(file)).unwrap();
13+
assert_eq!(decoder.channels(), 2);
14+
let channel_volume = ChannelVolume::new(decoder, vec![1.0, 1.0, 0.0, 0.0, 0.0, 0.0]);
15+
assert_eq!(channel_volume.channels(), 6);
16+
17+
assert_output_only_on_channel_1_and_2(channel_volume);
18+
}
19+
20+
fn assert_output_only_on_channel_1_and_2(source: impl Source<Item = i16>) {
21+
for (frame_number, mut frame) in source.chunks(6).into_iter().enumerate() {
22+
let frame: [_; 6] = frame.next_array().expect(&format!(
23+
"Source should contain whole frames, frame {frame_number} was partial"
24+
));
25+
assert_eq!(
26+
&frame[2..],
27+
&[0, 0, 0, 0],
28+
"frame number {frame_number} had nonzero volume on channels 3,4,5 & 6"
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)