Open AldaronLau opened 2 years ago
I have thought about the right way to do this probably too way much without writing code. I want to avoid writing a VM within Twang due to performance concerns. So how should a synthesis format work?
The new API will heavily use the type system.
use twang::Synth::{Sig, Mix};
let mut audio = Audio::<Ch16, 2>::with_silence(48_000, 48_000 * 5);
// Two sine oscillators, an octave apart
let oscs = [
Sig(440.0).sine(),
Sig(880.0).sine(),
];
// Mix the two together
let synth = Mix(&oscs);
synth.stream(audio.sink());
For the format, twang will attempt to use postcard
(as an optional feature). An intermediate MuON based format for human-readable/writeable will be able to be used with it.
Currently the API requires the user to pass a closure for synthesis.
I'd like to re-work this to be data-oriented (savable and loadable as a file), and synthesis constructable with the builder pattern. Users must be able to pass in their own variables, and still be able to get step events in custom closures for flexibility and backwards-compatibility.