2019-06-18 01:51:02 +00:00
|
|
|
import { TestAudioBuffer } from "@tonejs/plot";
|
2019-06-17 18:04:17 +00:00
|
|
|
import { expect } from "chai";
|
2019-06-18 01:51:02 +00:00
|
|
|
import { ToneOscillatorNode } from "Tone/source/oscillator/OscillatorNode";
|
2019-06-17 18:04:17 +00:00
|
|
|
import { noOp } from "../util/Interface";
|
|
|
|
import { Offline } from "./Offline";
|
|
|
|
import { ToneAudioBuffer } from "./ToneAudioBuffer";
|
|
|
|
|
|
|
|
describe("Offline", () => {
|
|
|
|
|
|
|
|
it("accepts a callback and a duration", () => {
|
2019-06-18 01:51:02 +00:00
|
|
|
return Offline(noOp, 0.01);
|
2019-06-17 18:04:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a promise", () => {
|
2019-06-18 01:51:02 +00:00
|
|
|
const ret = Offline(noOp, 0.01);
|
|
|
|
expect(ret).to.have.property("then");
|
|
|
|
return ret;
|
2019-06-17 18:04:17 +00:00
|
|
|
});
|
|
|
|
|
2019-06-18 01:51:02 +00:00
|
|
|
it("generates a buffer", () => {
|
|
|
|
return Offline(noOp, 0.01).then((buffer) => {
|
2019-06-17 18:04:17 +00:00
|
|
|
expect(buffer).to.be.instanceOf(ToneAudioBuffer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-18 01:51:02 +00:00
|
|
|
it("silent by default", () => {
|
|
|
|
return Offline(noOp, 0.01, 1).then((buffer) => {
|
2019-06-17 18:04:17 +00:00
|
|
|
const isSilent = buffer.toArray().every(sample => sample === 0);
|
|
|
|
expect(isSilent).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-18 01:51:02 +00:00
|
|
|
it("records the master output", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
new ToneOscillatorNode().toDestination().start();
|
2019-06-18 01:51:02 +00:00
|
|
|
}, 0.01).then((buffer) => {
|
|
|
|
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
|
|
expect(testBuff.isSilent()).is.equal(false);
|
|
|
|
});
|
|
|
|
});
|
2019-06-17 18:04:17 +00:00
|
|
|
|
2019-06-18 01:51:02 +00:00
|
|
|
it("returning a promise defers the rendering till the promise resolves", () => {
|
|
|
|
let wasInvoked = false;
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
new ToneOscillatorNode().toDestination().start();
|
2019-06-18 01:51:02 +00:00
|
|
|
return new Promise((done) => {
|
|
|
|
setTimeout(done, 100);
|
|
|
|
}).then(() => {
|
|
|
|
wasInvoked = true;
|
|
|
|
});
|
|
|
|
}, 0.01).then((buffer) => {
|
|
|
|
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
|
|
expect(wasInvoked).is.equal(true);
|
|
|
|
expect(testBuff.isSilent()).to.equal(false);
|
|
|
|
});
|
|
|
|
});
|
2019-06-17 18:04:17 +00:00
|
|
|
|
2019-06-18 01:51:02 +00:00
|
|
|
it("can schedule specific timing outputs", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
new ToneOscillatorNode().toDestination().start(0.05);
|
2019-06-18 01:51:02 +00:00
|
|
|
}, 0.1).then((buffer) => {
|
|
|
|
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
|
|
expect(testBuff.getTimeOfFirstSound()).to.be.closeTo(0.05, 0.0001);
|
|
|
|
});
|
|
|
|
});
|
2019-06-17 18:04:17 +00:00
|
|
|
|
|
|
|
// it("can schedule Transport events", () => {
|
|
|
|
// return Offline(function (Transport) {
|
2019-07-25 15:32:56 +00:00
|
|
|
// var osc = new Oscillator().toDestination();
|
2019-06-17 18:04:17 +00:00
|
|
|
// Transport.schedule(function (time) {
|
|
|
|
// osc.start(time);
|
|
|
|
// }, 0.05);
|
|
|
|
// Transport.start(0);
|
|
|
|
// }, 0.1).then((buffer) => {
|
|
|
|
// BufferTest(buffer);
|
|
|
|
// expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.001);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
});
|