sketch

by mohayonao

HTML

<script src="http://mohayonao.github.io/neume.js/build/neume.min.js"></script>
<button id="start">start</button>
<h4>pt</h4><pre id="pt"></pre>
<h4>amp</h4><pre id="amp"></pre>
<h4>degrade</h4><pre id="degrade"></pre>
<h4>reverb</h4><pre id="reverb"></pre>
<h4>autopan</h4><pre id="autopan"></pre>
<h4>filter</h4><pre id="filter"></pre>

CSS

h4, pre { margin:2px }

JavaScript

var pt = [];

pt[0] = {
    name: "pt1",
    score: [[4,9],0,0,0,0,0,[1],0,0,0,[5],0,0,[4,8,11],0,0,0,[1],0,0,[4,9],[0],0,0,[1],0,[4,6,8,11],0,0,0,0,[5,7,9,12],0,0],
    map: [71,67,0,65,64,62,60,59,57,55,0,52,50]
};
pt[1] = {
    name: "pt2",
    score: [[9],0,0,[4],0,0,[0],0,0,0,[2,5],0,0,0,0,0,0,0,0,[4,6,8,11],0,0,0,[1,5,7,9],[10],[0,8,10,12],0,0,0],
    map: [71,69,66,65,64,62,60,59,57,55,53,52,48]
};

var p = {};

function makeReverbBuffer(data, spec) {
    var amp = 1;
    for (var i = 0; i < data.length; i++) {
        data[i] = Math.random() * 2 - 1;    
        data[i] *= amp;
        data[i] *= i < spec.room ? 1 : 0.05;
        amp *= spec.coef;
    }
    return data;
}

var reverb = new Float32Array(65536);
makeReverbBuffer(reverb, { coef: 0.99999, room: 128 });

function Parameter(value, tC) {
    this.value = value;
    this.tC = tC;
    this.v0 = this.value;
    this.v1 = this.value;
    this.t0 = 0;
}

Parameter.prototype.set = function(value) {
    this.v0 = this.value;
    this.v1 = value;
    this.t0 = Neume.currentTime;
};

Parameter.prototype.valueOf = function() {
    var v0 = this.v0;
    var v1 = this.v1;
    var t0 = this.t0;
    var t1 = Neume.currentTime;
    
    this.value = v1 + (v0 - v1) * Math.exp(-(t1 - t0) / this.tC);
    
    return this.value;
};

var Neume = neume(new AudioContext());

neume.use(function(neume, _) {
    neume.register("p", function(ugen, spec) {
        var context = ugen.$context;
        var outlet = null;
        
        var func = spec.func;
        var rate = spec.rate;
        
        var osc = context.createOscillator();
        var scp = context.createScriptProcessor(8192, 1, 1);
        
        osc.type = "square";
        osc.frequency.value = 0;
        
        var flag = false;
        var x = _.finite(func());
        var dx = 0;
        var samples = 0;
        var sampleMax = (context.sampleRate * 0.01)|0;
        
        scp.onaudioprocess = function(e) {
            var inp =...