Tone.js/test/helper/Offline.js

25 lines
664 B
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"],
function(Tone, Offline, BufferTest, Master) {
2015-08-16 18:23:40 +00:00
2017-12-30 16:26:29 +00:00
return function(callback, duration, channels){
duration = duration || 0.1;
channels = channels || 1;
return Offline(function(Transport){
var testFn = callback(Transport);
if (testFn instanceof Promise){
return testFn;
} else if (Tone.isFunction(testFn)){
2017-12-30 16:26:29 +00:00
Transport.context.on("tick", function(){
testFn(Transport.now());
});
}
}, duration).then(function(buffer){
BufferTest(buffer);
if (channels === 1){
buffer.toMono();
}
return buffer;
});
};
});