audio-buffer-instrument
Version:
Simple webaudio module that creates instruments from audio-buffers
24 lines (20 loc) • 690 B
JavaScript
// From: https://dev.opera.com/articles/drum-sounds-webaudio/
function audioBufferInstrument(context, buffer) {
this.context = context;
this.buffer = buffer;
}
audioBufferInstrument.prototype.setup = function () {
this.source = this.context.createBufferSource();
this.source.buffer = this.buffer;
this.source.connect(this.context.destination);
};
audioBufferInstrument.prototype.get = function () {
this.source = this.context.createBufferSource();
this.source.buffer = this.buffer;
return this.source;
};
audioBufferInstrument.prototype.trigger = function (time) {
this.setup();
this.source.start(time);
};
module.exports = audioBufferInstrument;