use pointillism::prelude::*;
const SAMPLE_RATE: unt::SampleRate = unt::SampleRate::CD;
fn main() {
const NUM_OSC: usize = 5;
const BASE: unt::RawFreq = unt::RawFreq::new(400.0);
const TIME: unt::RawTime = unt::RawTime::new(10.0);
let base = unt::Freq::from_raw(BASE, SAMPLE_RATE);
let time = unt::Time::from_raw(TIME, SAMPLE_RATE);
let osc = |phase| {
eff::MutSgn::new(
gen::Loop::new(crv::Tri, base),
gen::Loop::new_phase(crv::Sin, (NUM_OSC * time).freq(), phase),
map::Func::new(|sgn: &mut gen::Loop<_, _>, val: smp::Env| {
*sgn.freq_mut() = base * (val.0 / 2.0 + 1.0);
}),
)
};
let mut oscillators: [_; NUM_OSC] =
std::array::from_fn(|i| osc(unt::Val::new(i as f64 / NUM_OSC as f64)));
Song::new(2u8 * time, SAMPLE_RATE, |_| {
oscillators
.iter_mut()
.map(|osc| osc.next())
.sum::<smp::Mono>()
/ NUM_OSC as f64
})
.export("pointillism/examples/fiveosc.wav");
}