interleave_to_vec_variable

Function interleave_to_vec_variable 

Source
pub fn interleave_to_vec_variable<T: Copy + Default, Vin: AsRef<[T]>>(
    input: &[Vin],
    input_range: Range<usize>,
    num_out_channels: NonZeroUsize,
) -> Vec<T>
Expand description

Interleave a variable number of input channels into a new interleaved Vec with a variable number of channels.

The returned Vec with have a length of (input_range.end - input_range.start) * num_out_channels.get().

  • input - The input channels.
  • input_range - The range in each channel in input to read from.
  • num_out_channels - The number of interleaved channels in output Vec.

Note, if num_out_channels.get() > input.len(), then the extra samples in each output frame will be set to the default value.

§Example

let input: Vec<Vec<i32>> = vec![vec![1, 3, 5, 7], vec![2, 4, 6, 8]];
let mut output: Vec<i32> = vec![0; 12];

let output = interleave_to_vec_variable(&input, 0..4, NonZeroUsize::new(3).unwrap());

assert_eq!(&output, &[1, 2, 0, 3, 4, 0, 5, 6, 0, 7, 8, 0]);

§Panics

Panics if input_range is out-of-bounds for any input channel.