Skip to content

Instantly share code, notes, and snippets.

@sang4lv
Created October 17, 2015 03:48
Show Gist options
  • Save sang4lv/4fdf83ae340beaf576d8 to your computer and use it in GitHub Desktop.
Save sang4lv/4fdf83ae340beaf576d8 to your computer and use it in GitHub Desktop.
initFromBuffer
AudioComponent.prototype.initFromBuffer = function(bufferData) {
this.panner = this.context.createPanner();
this.gainNode = this.context.createGain();
this.sourceNode = this.context.createBufferSource();
this.context.decodeAudioData(bufferData, function(buffer) {
this.meta.duration = 1000 * buffer.duration; //in milliseconds
// connect them up
this.sourceNode = buffer;
this.sourceNode.connect(this.gainNode); //this.sourceNode does not have a method called 'connect'
this.gainNode.connect(this.panner);
//this.panner.connect(this.context.destination); don't connect just yet
}.bind(this));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment