Simple FM Synth

A sine wave synth with a 2nd oscillator that modulates the phase with controls to affect the frequency and depth of modulation too,

Log in to post a comment.

// FM Synth
//

input.freq = 600; // min=100, max=2000, step=1
input.mod_freq = 75; // min=0.1, max=100, step=0.1
input.depth = 0.67; // min=0.0, max=6.0, step=0.01

synth.def( class {
    
    constructor (options) {
        this.phase = 0;
        this.mod_phase = 0;
    }
    
    process(note, env, tick, options) {
        this.mod_phase += ditty.dt * input.mod_freq;
        const mod_wave = Math.sin( this.mod_phase * Math.PI * 2 ) * input.depth;
        this.phase += ditty.dt * input.freq * mod_wave;
        const wave = Math.sin( this.phase * Math.PI * 2 );
        
        return [wave, wave]; // left, right
    }
    
}).play(0, { env: one} );