DualArp

Simple arpegio

Log in to post a comment.

input.freq = 0; // min=0, max=12, step=1

synth.def( class {
    
    constructor (options) {
        this.phase = 0;
        this.phase2 = 0;
        this.last = 0;
        this.last2 = 0;
    }
    
    process(note, env, tick, options) {
        const lerp = function(a,b,f){ return a*(1-f)+b*f; }        
    
        const notes = [1,2,4,3];
        var l = notes.length;
        var key = notes[((tick*0.125)|0)%l];
        var f = input.freq * 50 + notes[((tick*2)|0)%l]*100;
        var f2 = input.freq * 50 + notes[((tick*4)|0)%l]*50 + (key-1)*50;
        this.phase += ditty.dt * f;
        this.phase2 += ditty.dt * f2;
        var wave = (( this.phase )%1) > 0.5 ? 1 : 0;
        var wave2 = (( this.phase2 )%1) > 0.5 ? 1 : 0;
        wave = lerp(this.last,wave,Math.cos(tick*0.125)*0.25+0.5);
        wave2 = lerp(this.last2,wave2,Math.sin(tick*0.125)*0.25+0.5);
        this.last = wave;
        this.last2 = wave2;
        
        return ((tick*5)%1) > 0.5 ? [wave, wave2] : [wave2, wave]; // left, right
    }
    
}).play(0, { env: one} );