mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-17 00:58:09 +00:00
f88f68081d
[skip ci]
35 lines
No EOL
1 KiB
JavaScript
35 lines
No EOL
1 KiB
JavaScript
///////////////////////////////////////////////////////////////////////////
|
|
// P5 PRELOAD SHIM
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
Tone.registeredPreload = function(callback){
|
|
return function(){
|
|
callback();
|
|
}
|
|
};
|
|
|
|
//overwrite load function
|
|
Tone.Buffer.load = function (url, callback) {
|
|
var handle = Tone.registeredPreload();
|
|
var request = new XMLHttpRequest();
|
|
request.open("GET", url, true);
|
|
request.responseType = "arraybuffer";
|
|
// decode asynchronously
|
|
request.onload = function () {
|
|
Tone.context.decodeAudioData(request.response, function (buff) {
|
|
if (!buff) {
|
|
throw new Error("could not decode audio data:" + url);
|
|
}
|
|
callback(buff);
|
|
handle();
|
|
});
|
|
};
|
|
//send the request
|
|
request.send();
|
|
return request;
|
|
};
|
|
|
|
p5.prototype.registerPreloadMethod("registeredPreload", Tone);
|
|
|
|
return Tone
|
|
})); |