From dc6c5c5a7c70f76d66506c5e0ef2f13a64edd978 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sat, 29 Jun 2019 03:44:51 +1000 Subject: [PATCH] Remove unnecessary asio_utils mod --- src/host/asio/asio_utils/mod.rs | 51 ------------------ src/host/asio/asio_utils/tests.rs | 89 ------------------------------- src/host/asio/mod.rs | 1 - 3 files changed, 141 deletions(-) delete mode 100644 src/host/asio/asio_utils/mod.rs delete mode 100644 src/host/asio/asio_utils/tests.rs diff --git a/src/host/asio/asio_utils/mod.rs b/src/host/asio/asio_utils/mod.rs deleted file mode 100644 index 017454c..0000000 --- a/src/host/asio/asio_utils/mod.rs +++ /dev/null @@ -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(channels: &[Vec], target: &mut Vec) -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(cpal_buffer: &[T], asio_channels: &mut [Vec]) -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); - } -} \ No newline at end of file diff --git a/src/host/asio/asio_utils/tests.rs b/src/host/asio/asio_utils/tests.rs deleted file mode 100644 index c43fe5f..0000000 --- a/src/host/asio/asio_utils/tests.rs +++ /dev/null @@ -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::::new()]; - let goal = Vec::::new(); - let mut result = Vec::::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::::new()]; - let a = Vec::::new(); - let mut result = vec![Vec::::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); -} diff --git a/src/host/asio/mod.rs b/src/host/asio/mod.rs index 7e5172c..9f985b6 100644 --- a/src/host/asio/mod.rs +++ b/src/host/asio/mod.rs @@ -22,7 +22,6 @@ use std::sync::Arc; mod device; mod stream; -mod asio_utils; /// The host for ASIO. #[derive(Debug)]