Tone.js/test/helper/Offline.js

23 lines
654 B
JavaScript

define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"], function(Tone, Offline, BufferTest, Master){
return function(callback, duration, channels){
duration = duration || 0.1;
channels = channels || 1;
return Offline(function(Transport){
var testFn = callback(Transport);
if (testFn && Tone.isFunction(testFn.then)){
return testFn;
} else if (Tone.isFunction(testFn)){
Transport.context.on("tick", function(){
testFn(Transport.now());
});
}
}, duration).then(function(buffer){
BufferTest(buffer);
if (channels === 1){
buffer.toMono();
}
return buffer;
});
};
});