Wide snare

I experimented a bit more with artificial snare drums, partly inspired by athibaul's "Making music in shadertoy" series.

Log in to post a comment.

const TAU = Math.PI * 2;
const sin = Math.sin;

ditty.bpm = 120;

input.note = 35; // min=1, max=50, step=0.5
input.wide = 0; // min=0, max=1, step=1

const Snare = synth.def(class {
    constructor(options) {
        this.t = 0; Math.random();
    }
    fm(fc, fm, iom, t) {
        return sin(fc*TAU*t + iom*sin(fm*TAU*t));
    }
    snare(f, t) {
        let sig = 0;
        // click
        sig += this.fm(f*10, 0, 0, t) * 0.05 * Math.exp(-400*t);

        // body
        const df = -f*1.5 * t;
        const fb = f+df;
        sig += this.fm(fb, fb*3, 2.5, t) * 0.3 * Math.exp(-60*t);

        // noise
        sig += Math.random(1) * 0.4 * Math.exp(-22*t);
        return sig;
    }
    process(note, env, tick, options) {
        const f = midi_to_hz(input.note);
        this.t += ditty.dt;

        let l,r = 0;
        if (input.wide) {
            l = this.snare(f, this.t*1.01);
            r = this.snare(f, this.t*0.99);
        } else {
            l = this.snare(f, this.t);
            r = l;
        }
        //sig += this.snare(f, this.t);

        return [l,r];
    }
});

loop( () => {
    Snare.play();
    sleep(2);

}, { name: 'Snare' });