2019-01-27 18:05:20 +00:00
|
|
|
import Test from "helper/Test";
|
|
|
|
import OfflineContext from "Tone/core/OfflineContext";
|
2017-02-19 16:52:53 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
context("OfflineContext", function(){
|
2017-02-19 16:52:53 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be created an disposed", function(){
|
|
|
|
var ctx = new OfflineContext(1, 0.1, 44100);
|
|
|
|
return ctx.dispose().then(function(){
|
|
|
|
Test.wasDisposed(ctx);
|
|
|
|
});
|
|
|
|
});
|
2017-07-05 17:59:24 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("is setup with 0 lookAhead and offline clockSource", function(){
|
|
|
|
var ctx = new OfflineContext(1, 0.1, 44100);
|
|
|
|
expect(ctx.lookAhead).to.equal(0);
|
|
|
|
expect(ctx.clockSource).to.equal("offline");
|
|
|
|
return ctx.dispose();
|
|
|
|
});
|
2017-02-19 16:52:53 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can render audio", function(){
|
|
|
|
var ctx = new OfflineContext(1, 0.2, 44100);
|
|
|
|
var osc = ctx.createOscillator();
|
|
|
|
osc.connect(ctx.destination);
|
|
|
|
osc.start(0.1);
|
|
|
|
return ctx.render().then(function(buffer){
|
|
|
|
expect(buffer).to.be.instanceOf(AudioBuffer);
|
|
|
|
var array = buffer.getChannelData(0);
|
|
|
|
for (var i = 0; i < array.length; i++){
|
|
|
|
if (array[i] !== 0){
|
|
|
|
expect(i/array.length).to.be.closeTo(0.5, 0.01);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 16:52:53 +00:00
|
|
|
});
|
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
|
|
|
|