Remove unnecessary asio_utils mod
This commit is contained in:
parent
50aa0585be
commit
dc6c5c5a7c
|
@ -1,51 +0,0 @@
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use std::marker::Copy;
|
|
||||||
|
|
||||||
/// Interleave the buffer from asio to cpal
|
|
||||||
/// asio: LLLLRRRR
|
|
||||||
/// cpal: LRLRLRLR
|
|
||||||
/// More then stereo:
|
|
||||||
/// asio: 111122223333
|
|
||||||
/// cpal: 123123123123
|
|
||||||
/// cpal buffer must have a length of exactly sum( all asio channel lengths )
|
|
||||||
/// this check is ommited for performance
|
|
||||||
pub fn interleave<T>(channels: &[Vec<T>], target: &mut Vec<T>)
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
{
|
|
||||||
assert!(
|
|
||||||
target.len() % channels.len() == 0,
|
|
||||||
"the length of the interleaved buffer must be a multiple of the expected number of channels"
|
|
||||||
);
|
|
||||||
assert!(!channels.is_empty());
|
|
||||||
target.clear();
|
|
||||||
let frames = channels[0].len();
|
|
||||||
target.extend((0 .. frames).flat_map(|f| channels.iter().map(move |ch| ch[f])));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Function for deinterleaving because
|
|
||||||
/// cpal writes to buffer interleaved
|
|
||||||
/// cpal: LRLRLRLR
|
|
||||||
/// asio: LLLLRRRR
|
|
||||||
/// More then stereo:
|
|
||||||
/// cpal: 123123123123
|
|
||||||
/// asio: 111122223333
|
|
||||||
pub fn deinterleave<T>(cpal_buffer: &[T], asio_channels: &mut [Vec<T>])
|
|
||||||
where
|
|
||||||
T: Copy,
|
|
||||||
{
|
|
||||||
assert!(
|
|
||||||
cpal_buffer.len() % asio_channels.len() == 0,
|
|
||||||
"the length of the interleaved buffer must be a multiple of the expected number of channels"
|
|
||||||
);
|
|
||||||
for ch in asio_channels.iter_mut() {
|
|
||||||
ch.clear();
|
|
||||||
}
|
|
||||||
let num_channels = asio_channels.len();
|
|
||||||
let mut ch = (0 .. num_channels).cycle();
|
|
||||||
for &sample in cpal_buffer.iter() {
|
|
||||||
asio_channels[ch.next().unwrap()].push(sample);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
use super::{deinterleave, interleave};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn interleave_two() {
|
|
||||||
let a = vec![vec![1, 1, 1, 1], vec![2, 2, 2, 2]];
|
|
||||||
let goal = vec![1, 2, 1, 2, 1, 2, 1, 2];
|
|
||||||
let mut result = vec![0; 8];
|
|
||||||
|
|
||||||
interleave(&a[..], &mut result);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn interleave_three() {
|
|
||||||
let a = vec![vec![1, 1, 1, 1], vec![2, 2, 2, 2], vec![3, 3, 3, 3]];
|
|
||||||
let goal = vec![1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
|
|
||||||
let mut result = vec![0; 12];
|
|
||||||
|
|
||||||
interleave(&a[..], &mut result);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn interleave_none() {
|
|
||||||
let a = vec![Vec::<i32>::new()];
|
|
||||||
let goal = Vec::<i32>::new();
|
|
||||||
let mut result = Vec::<i32>::new();
|
|
||||||
|
|
||||||
interleave(&a[..], &mut result);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn interleave_two_diff() {
|
|
||||||
let a = vec![vec![1, 2, 3, 4], vec![5, 6, 7, 8]];
|
|
||||||
let goal = vec![1, 5, 2, 6, 3, 7, 4, 8];
|
|
||||||
let mut result = vec![0; 8];
|
|
||||||
|
|
||||||
interleave(&a[..], &mut result);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deinterleave_two() {
|
|
||||||
let goal = vec![vec![1, 1, 1, 1], vec![2, 2, 2, 2]];
|
|
||||||
let a = vec![1, 2, 1, 2, 1, 2, 1, 2];
|
|
||||||
let mut result = vec![vec![0; 4]; 2];
|
|
||||||
|
|
||||||
deinterleave(&a[..], &mut result[..]);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deinterleave_three() {
|
|
||||||
let goal = vec![vec![1, 1, 1, 1], vec![2, 2, 2, 2], vec![3, 3, 3, 3]];
|
|
||||||
let a = vec![1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
|
|
||||||
let mut result = vec![vec![0; 4]; 3];
|
|
||||||
|
|
||||||
deinterleave(&a[..], &mut result[..]);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deinterleave_none() {
|
|
||||||
let goal = vec![Vec::<i32>::new()];
|
|
||||||
let a = Vec::<i32>::new();
|
|
||||||
let mut result = vec![Vec::<i32>::new()];
|
|
||||||
|
|
||||||
deinterleave(&a[..], &mut result[..]);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deinterleave_two_diff() {
|
|
||||||
let goal = vec![vec![1, 2, 3, 4], vec![5, 6, 7, 8]];
|
|
||||||
let a = vec![1, 5, 2, 6, 3, 7, 4, 8];
|
|
||||||
let mut result = vec![vec![0; 4]; 2];
|
|
||||||
|
|
||||||
deinterleave(&a[..], &mut result[..]);
|
|
||||||
|
|
||||||
assert_eq!(goal, result);
|
|
||||||
}
|
|
|
@ -22,7 +22,6 @@ use std::sync::Arc;
|
||||||
|
|
||||||
mod device;
|
mod device;
|
||||||
mod stream;
|
mod stream;
|
||||||
mod asio_utils;
|
|
||||||
|
|
||||||
/// The host for ASIO.
|
/// The host for ASIO.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Reference in New Issue