I get this error when I try to run an XHR to load a sample. Uncaught TypeError: Value is not of type AudioBuffer. Everything seems to be right, but I'm not sure what the problem is.
Kit.prototype.load = function(){
if(this.startedLoading)
return;
this.startedLoading = true;
// var kick = "samples/M-808Sn2.wav";
var snare = "samples/M-808Sn2.wav";
// var hihat = "samples/M-808Sn2.wav";
// this.loadSample(0, kick, false);
this.loadSample(1, snare, false);
// this.loadSample(2, hihat, false);
}
I start it off with the request:
Kit.prototype.loadSample = function(sampleID, url, mixToMono){
// Load Asynchronously
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
var kit = this;
request.onload = function(){
var buffer;
context.decodeAudioData(request.response, function(decodedBuffer){
buffer = decodedBuffer;
});
switch(sampleID){
// case 0: kit.kickBuffer = buffer; break;
case 1: kit.snareBuffer = buffer; break;
// case 2: kit.hihatBuffer = buffer; break;
}
}
request.send();
}
Then I try to run it.
context = new webkitAudioContext();
var kit = new Kit();
kit.load();
var voice = context.createBufferSource();
voice.buffer = kit.snareBuffer;
voice.loop = true;
voice.playbackRate.value = 1;
voice.connect(gain);
voice.start(0);
voice.stop(2);
window.onload = init;
that fixed it for me. – Recapture