bppt_wav/
mixing.rs

1use crate::structure;
2use anyhow::Result;
3
4pub(crate) type Samples = Vec<f32>;
5
6mod processing;
7#[cfg(test)]
8mod tests;
9
10impl structure::Track {
11    pub fn mix(&mut self) -> Result<Samples> {
12        let mut sorted = self.process()?;
13        sorted.sort_by(|a, b| a.len().partial_cmp(&b.len()).unwrap());
14        Ok(sorted.iter().cloned().fold(vec![], |acc, v| {
15            v.iter()
16                .zip(acc.iter().chain([0f32].iter().cycle()))
17                .map(|(s, acc)| *s / (sorted.len() as f32) + acc)
18                .collect()
19        }))
20    }
21}