use pointillism::prelude::*;
use rand::Rng;
const SAMPLE_RATE: unt::SampleRate = unt::SampleRate::TELEPHONE;
fn main() {
const BASE: unt::RawFreq = unt::RawFreq::new(350.0);
const NOTE_LEN: unt::RawTime = unt::RawTime::new(5.0);
let base = unt::Freq::from_raw(BASE, SAMPLE_RATE);
let note_len = unt::Time::from_raw(NOTE_LEN, SAMPLE_RATE);
let osc = |freq| {
eff::env::AdsrEnv::new(
gen::Loop::<smp::Stereo, _>::new(crv::Sin, freq),
eff::env::Adsr::new(
0.8 * note_len,
0.2 * note_len,
unt::Vol::new(0.8),
1.5 * note_len,
),
)
};
let mut poly = gen::Polyphony::new();
let mut index = 0;
poly.add(index, osc(base));
let poly_loop = ctr::Loop::new(
vec![note_len],
poly,
map::Func::new(|poly: &mut gen::Polyphony<_, _>| {
poly.stop(&index);
index += 1;
poly.add(
index,
osc(base.bend_edo(5, rand::thread_rng().gen_range(0..=7) as f64)),
);
}),
);
let mut dist = eff::PwMapSgn::cubic(poly_loop);
Song::new_sgn(10u8 * note_len, SAMPLE_RATE, &mut dist)
.export("pointillism/examples/distortion.wav");
}