Tone.js/test/core/Offline.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-02-19 16:52:46 +00:00
define(["Test", "Tone/core/Offline", "Tone/core/Transport", "Tone/source/Oscillator",
"Tone/core/Tone", "Tone/core/Buffer", "helper/BufferTest"],
2017-12-30 16:26:29 +00:00
function (Test, Offline, Transport, Oscillator, Tone, AudioBuffer, BufferTest) {
2017-02-19 16:52:46 +00:00
describe("Offline", function(){
2017-12-30 16:26:29 +00:00
it("exists", function(){
2017-02-19 16:52:46 +00:00
expect(Offline).to.exist;
expect(Tone.Offline).to.exist;
});
2017-12-30 16:26:29 +00:00
it("accepts a callback and a duration", function(){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01);
});
2017-12-30 16:26:29 +00:00
it("returns a promise", function(){
2017-02-19 16:52:46 +00:00
expect(Offline(function(){}, 0.01)).to.be.instanceOf(Promise);
});
2017-12-30 16:26:29 +00:00
it("generates a buffer", function(done){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01).then(function(buffer){
expect(buffer).to.be.instanceOf(AudioBuffer);
done();
});
});
2017-12-30 16:26:29 +00:00
it("silent by default", function(done){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.isSilent()).to.be.true;
2017-02-19 16:52:46 +00:00
done();
});
});
2017-12-30 16:26:29 +00:00
it("records the master output", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(){
new Oscillator().toMaster().start();
}, 0.01).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.isSilent()).to.be.false;
2017-02-19 16:52:46 +00:00
});
});
2017-12-30 16:26:29 +00:00
it("can schedule specific timing outputs", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(){
new Oscillator().toMaster().start(0.05);
}, 0.1).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.0001);
2017-02-19 16:52:46 +00:00
});
});
2017-12-30 16:26:29 +00:00
it("can schedule Transport events", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(Transport){
var osc = new Oscillator().toMaster();
Transport.schedule(function(time){
osc.start(time);
}, 0.05);
Transport.start(0);
}, 0.1).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.001);
2017-02-19 16:52:46 +00:00
});
});
});
2017-12-30 16:26:29 +00:00
});