A small ditty to do real-time experiments on a simple FM synth and some of its parameters. Move the sliders to change the timbre.
Log in to post a comment.
// // You can find the Dittytoy API Reference here: https://Dittytoy.net/syntax // Example ditties can be found here: https://dittytoy.net/user/Dittytoy // // Most of your ditty will run 44100 times per second using javascript in the browser. // Make sure you optimize your ditty to work well on as many devices as possible. To do that, try to limit // the number of simultaneously active synths: make sure they don't last longer than necessary, or you can // hear them, and spread them over different loops (each loop runs in a separate worker). // ditty.bpm = 120; const sin = Math.sin; const TAU = 2*Math.PI; input.note = 50; // min=1, max=100, step=0.5 input.iom = 1; // min=1, max=100, step=0.1 input.mul = 1; // min=1, max=100, step=0.1 const MetallicFM = synth.def( class { constructor (options) { this.t = Math.random(); this.iom = input.iom; // options.iom || 65.51; this.mul = input.mul; // options.mul || 3.8; } process(note, env, tick, options) { // forward time this.t += ditty.dt; // carrier frequency const fc = midi_to_hz(note); // modulator frequency const fm = fc * this.mul; const mod = sin(TAU*this.t*fm); const osc = sin(TAU*this.t*fc + this.iom*mod) * env.value; debug.probe( "osc", osc, 1 ); return [osc, osc]; // left, right } }); loop( () => { MetallicFM.play(input.note, { iom: 31.1457, mul: 37, attack: 0.01, decay: 0.5, sustain: 0, release: 0, duration: 0.5, amp: 0.5 }); sleep( 1 ); }, { name: 'MetallicFM' });