interleave_variable

Function interleave_variable 

Source
pub fn interleave_variable<T: Copy, Vin: AsRef<[T]>>(
    input: &[Vin],
    input_range: Range<usize>,
    output: &mut [T],
    num_out_channels: NonZeroUsize,
)
Expand description

Interleave a variable number of input channels into the output buffer with a variable number of channels.

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

Note, if num_out_channels.get() > input.len(), then the extra samples in each output frame will be left untouched.

§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];

interleave_variable(&input, 0..4, &mut output, NonZeroUsize::new(3).unwrap());

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

§Panics

Panics when any of the following are true:

  • input_range is out-of-bounds for any input channel
  • output.len() < (input_range.end - input_range.start) * num_out_channels.get()