interleave

Function interleave 

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

Interleave the given channels into the output buffer.

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

§Example

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

interleave::<_, _, 2>(&input, 0..4, &mut output);

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

// Interleave range in input:
interleave::<_, _, 2>(&input, 2..4, &mut output[0..4]);

assert_eq!(&output, &[5, 6, 7, 8, 5, 6, 7, 8]);

§Panics

Panics when any of the following are true:

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