scope/input/
mod.rs

1pub mod format;
2
3#[cfg(feature = "pulseaudio")]
4pub mod pulse;
5
6#[cfg(feature = "file")]
7pub mod file;
8
9#[cfg(feature = "cpal")]
10pub mod cpal;
11
12pub type Matrix<T> = Vec<Vec<T>>;
13
14pub trait DataSource<T> {
15	fn recv(&mut self) -> Option<Matrix<T>>; // TODO convert in Result and make generic error
16}
17
18/// separate a stream of alternating channels into a matrix of channel streams:
19///   L R L R L R L R L R
20/// becomes
21///   L L L L L
22///   R R R R R
23pub fn stream_to_matrix<I, O>(stream: impl Iterator<Item = I>, channels: usize, norm: O) -> Matrix<O>
24where	I : Copy + Into<O>, O : Copy + std::ops::Div<Output = O>
25{
26	let mut out = vec![vec![]; channels];
27	let mut channel = 0;
28	for sample in stream {
29		out[channel].push(sample.into() / norm);
30		channel = (channel + 1) % channels;
31	}
32	out
33}