Jump To …

ae.js

(function (global) {
var ae = {};

generic sample-accurate audio rate envelopes

ae.env = function (c, type, p) {
  var currentSample = 0,
    distance,
    that = {};

  if (type == 'ramp') {
    distance = p.end - p.start;
  }

  that.audioCallback = function (samples, r) {
    var i, samplesLength = samples.length,
      currentSample = r.currentSample,
      numSamples = r.numSamples;

    if (type == 'ramp') {
      for (i=0; i<samplesLength; i++) {
        samples[i] = distance * currentSample++/numSamples + p.start;
      }

    } else if (type == 'constant') {
      for (i=0; i<samplesLength; i++) {
        samples[i] = p.constant;
      }
    }      
    return samples;
  };

  that.p = p;
  return that;
};


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

}(this));