mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 13:42:34 +00:00
Add tests for dynamic_mixer
This commit is contained in:
parent
c3d573db9f
commit
c7bd21b75a
1 changed files with 67 additions and 1 deletions
|
@ -116,7 +116,11 @@ impl<S> Iterator for DynamicMixer<S> where S: Sample + Send + 'static {
|
|||
self.current_sources.remove(td);
|
||||
}
|
||||
|
||||
Some(sum)
|
||||
if self.current_sources.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(sum)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -124,3 +128,65 @@ impl<S> Iterator for DynamicMixer<S> where S: Sample + Send + 'static {
|
|||
(0, None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use dynamic_mixer;
|
||||
use buffer::SamplesBuffer;
|
||||
use source::Source;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
let (tx, mut rx) = dynamic_mixer::mixer(1, 48000);
|
||||
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![10i16, -10, 10, -10]));
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![5i16, 5, 5, 5]));
|
||||
|
||||
assert_eq!(rx.get_channels(), 1);
|
||||
assert_eq!(rx.get_samples_rate(), 48000);
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channels_conv() {
|
||||
let (tx, mut rx) = dynamic_mixer::mixer(2, 48000);
|
||||
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![10i16, -10, 10, -10]));
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![5i16, 5, 5, 5]));
|
||||
|
||||
assert_eq!(rx.get_channels(), 2);
|
||||
assert_eq!(rx.get_samples_rate(), 48000);
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_conv() {
|
||||
let (tx, mut rx) = dynamic_mixer::mixer(1, 96000);
|
||||
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![10i16, -10, 10, -10]));
|
||||
tx.add(SamplesBuffer::new(1, 48000, vec![5i16, 5, 5, 5]));
|
||||
|
||||
assert_eq!(rx.get_channels(), 1);
|
||||
assert_eq!(rx.get_samples_rate(), 96000);
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(5));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), Some(5));
|
||||
assert_eq!(rx.next(), Some(15));
|
||||
assert_eq!(rx.next(), Some(5));
|
||||
assert_eq!(rx.next(), Some(-5));
|
||||
assert_eq!(rx.next(), None);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue