Feedback FM

A simple example of frequency modulation synthesis with feedback.

Log in to post a comment.

input.feedback = 1.3; // min=0, max=4, step=0.001
input.decay = 0.05; // min=0.0001, max=0.1 ,step=0.0001

// Feedback frequency modulation happens when the oscillator modulates itself.
// This can lead to very interesting phenomena!

// If there is no feedback, the signal is a sine wave.
// As long as the feedback value is less than 1, everything is fine.
// When it increases beyond that, weird behaviors start to emerge,
// including chaotic behavior (which we hear as noise).
const feedbackFM = synth.def( class {
    constructor(options) {
        this.v = 0; // Last value of the synth
        this.phase = 0;
    }
    process(note,env,tick,options) {
        this.phase += ditty.dt * midi_to_hz(note);
        // The next value depends on the last value
        this.v = Math.sin(2*Math.PI*this.phase + input.feedback * this.v) * env.value;
        if(options.probe && tick < 0.5) {
            debug.probe("feedbackFM", this.v,  1, 5/midi_to_hz(note));
        }
        return this.v * 0.2;
    }
}, {attack:0.0001, decay:() => input.decay, probe:false});

// A simple bass + lead pattern

ditty.bpm = 120;
const nn = [c3,f2,ab2,g2];
loop( (i) => {
    feedbackFM.play(nn.ring(Math.floor(i/16)));
    sleep(0.25);
}, {name:"bass"});

const nn2 = [0,c4,eb4,0,c4,f4,0,c4];
loop( (i) => {
    if(nn2.ring(i)) {
        feedbackFM.play(nn2.ring(i), {decay:() => 3*input.decay, probe:true});
    }
    sleep(0.5);
}, {name:"lead"});