Trippy FM

This synthesizer uses two sawtooth oscillators, where the first modulates the frequency of the second; it can lead to some trippy sound effects.
Share some interesting sounds you find in the comments!

Log in to post a comment.

// Inspired by a modular synth of a colleague of mine


input.freq1 = 0.35;
input.freq2 = 0.5;
input.fm = 0.5;
input.cutoff = 0.5;

// Mapping from the 0..1 parameter range to the actual values to use
let param2freq = (param) => 1 + 1000*param**2;
let param2fm = (param) => 5000*param**2;
let param2cutoff = (param) => 200 + 10000*param**2;

let theSynth = synth.def( class {
    constructor(options) {
        this.phase1 = 0;
        this.phase2 = 0;
        this.lp1 = 0;
        this.lp2 = 0;
        this.f1smoo = input.freq1;
        this.f2smoo = input.freq2;
        this.fmsmoo = input.fm;
        this.cosmoo = input.cutoff;
    }
    process(note,env,tick,options) {
        // Apply smoothing to the input parameters
        let a0 = clamp01(ditty.dt / 0.03);
        this.f1smoo += a0 * (input.freq1  - this.f1smoo);
        this.f2smoo += a0 * (input.freq2  - this.f2smoo);
        this.fmsmoo += a0 * (input.fm     - this.fmsmoo);
        this.cosmoo += a0 * (input.cutoff - this.cosmoo);
        
        // The actual oscillators : two sawtooth oscillators.
        // The frequency of the second oscillator depends on the value output by the first.
        this.phase1 = (this.phase1 + ditty.dt * param2freq(this.f1smoo)) % 1;
        let freq2 = param2freq(this.f2smoo) + param2fm(this.fmsmoo) * (0.5 - this.phase1);
        //freq2 = Math.max(freq2, 0); // Uncomment for positive-only frequencies (better for sound effects, less convenient for pitched sounds)
        this.phase2 = (this.phase2 + ditty.dt * freq2) % 1.0;
        
        // Simple low pass filter
        let a1 = clamp01(6.28 * ditty.dt * param2cutoff(this.cosmoo));
        this.lp1 += a1 * ((this.phase2 - 0.5) - this.lp1);
        this.lp2 += a1 * (this.lp1 - this.lp2);
        return this.lp2;
    }
}, {env:one, amp:0.2});

theSynth.play(0);