Artificial reverberation

using the generalized fibonacci sequence

Log in to post a comment.

class Delayline {
    constructor(n) {
        this.n = n;
        this.p = 0;
        this.lastOut = 0;
        this.data = new Float32Array(n);
    }
    clock(input) {
        this.lastOut = this.data[this.p];
        this.data[this.p] = input;
        if(++this.p >= this.n) {
            this.p = 0;
        }
    }
}

const ISQRT2 = Math.sqrt(0.5);

const reverb = filter.def(class {
    constructor(options) {
        let rt60 = 1;
        let meandelay = 2513 * ditty.dt;
        this.loopgain = 10 ** (-3*meandelay / rt60);
        this.outgain = 0.3;
        this.d1 = new Delayline(1897);
        this.d2 = new Delayline(2513);
        this.d3 = new Delayline(3329);
    }
    process(input, options) {
        let v1 = this.d1.lastOut, v2 = this.d2.lastOut, v3 = this.d3.lastOut;
        let x1 = ISQRT2 * (v1 + v3), w3 = ISQRT2 * (v1 - v3);
        let x2 = ISQRT2 * (v2 + w3), x3 = ISQRT2 * (v2 - w3);
        let out0 = x1*this.outgain, out1 = x2*this.outgain;
        x1 += input[0];
        x2 += input[1];
        x1 *= this.loopgain;
        x2 *= this.loopgain;
        x3 *= this.loopgain;
        this.d1.clock(x1);
        this.d2.clock(x2);
        this.d3.clock(x3);
        return [out0, out1];
    }
});

const impulse = synth.def( (phase, env, tick, options) => (tick <= 1.5 * ditty.dt) ? 1.0 : 0.0);
const noise = synth.def( () => Math.random() - 0.5, {env:one, duration:0.01});

ditty.bpm = 60;

loop( () => {
    noise.play();
    sleep(1);
}).connect(reverb.create());