Jump To …

a.js

(function (global) {

var a = {};

a.silence = function (c) {
  var that = {};
  that.audioCallback = function (samples, r) {
    var i, 
        iMax = samples.length;
    for (i=0; i<iMax; i++) {
      samples[i] = 0;
    }        
  };
  return that;
};


a.sine = function (c, p, ae) {
  var that = {},
    w = 2 * Math.PI / c.sampleRate;

  that.audioCallback = function (samples, r) {
    var i, iMax = samples.length,
      currentSample;
    currentSample = r.currentSample;
    for (i=0; i<iMax; i++) {
      samples[i] = that.p.amp * 
          Math.sin(w * that.aev.freq[i] * currentSample++);
    }        
  };

  that.p = p; 
  that.ae = ae; 
  that.aev = {};
  return that;
};


a.test = function (c) {
  var that = {},
    amp = 1.0,
    freq = 440,
    w = 2 * Math.PI / c.sampleRate;
    
  that.audioCallback = function (samples, r) {
    var i, iMax = samples.length,
      currentSample;
    currentSample = r.currentSample;
    for (i=0; i<iMax; i++) {
      samples[i] = amp * Math.sin(w * freq * currentSample++);
    }        
  };

  return that;
};



if (typeof module != 'undefined' && module.exports) {
  module.exports = a;
} else {
  global.trurl = global.trurl || {};
  global.trurl.opcodes = global.trurl.opcodes || {};
  global.trurl.opcodes.a = a;
}

}(this));