2019-04-12 14:37:47 +00:00
|
|
|
import { expect } from "chai";
|
2019-05-23 18:00:49 +00:00
|
|
|
import { BasicTests } from "test/helper/Basic";
|
|
|
|
import { connectFrom, connectTo } from "test/helper/Connect";
|
|
|
|
import { ConstantOutput } from "test/helper/ConstantOutput";
|
|
|
|
import { Offline } from "test/helper/Offline";
|
2019-07-30 19:35:27 +00:00
|
|
|
import { Decibels, Frequency, Time } from "Tone/core/type/Units";
|
2019-05-23 18:00:49 +00:00
|
|
|
import { Gain } from "../core/context/Gain";
|
|
|
|
import { Signal } from "./Signal";
|
2019-04-12 14:37:47 +00:00
|
|
|
|
|
|
|
describe("Signal", () => {
|
|
|
|
|
|
|
|
BasicTests(Signal);
|
|
|
|
|
|
|
|
context("Signal Rate Value", () => {
|
|
|
|
|
2019-08-04 14:07:19 +00:00
|
|
|
it("has 1 input and 1 output", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>();
|
2019-08-04 14:07:19 +00:00
|
|
|
expect(signal.numberOfInputs).to.equal(1);
|
|
|
|
expect(signal.numberOfOutputs).to.equal(1);
|
2019-04-12 14:37:47 +00:00
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be created with an options object", () => {
|
2019-07-15 19:39:47 +00:00
|
|
|
const signal = new Signal({
|
|
|
|
units: "positive",
|
2019-04-12 14:37:47 +00:00
|
|
|
value: 0.2,
|
|
|
|
});
|
|
|
|
expect(signal.value).to.be.closeTo(0.2, 0.001);
|
|
|
|
expect(signal.units).to.equal("positive");
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can start with a value initially", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(2);
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.equal(2);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set a value", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(0);
|
2019-04-12 14:37:47 +00:00
|
|
|
signal.value = 10;
|
|
|
|
expect(signal.value).to.equal(10);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a constant signal", () => {
|
|
|
|
return ConstantOutput((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(2.5).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
}, 2.5);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("takes on another signal's value when connected", () => {
|
|
|
|
return ConstantOutput((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sigA = new Signal<number>(1).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const sigB = new Signal<number>(3);
|
2019-04-12 14:37:47 +00:00
|
|
|
sigB.connect(sigA);
|
|
|
|
}, 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("takes the first signals value when many values are chained", () => {
|
|
|
|
return ConstantOutput((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sigA = new Signal<number>(3).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const sigB = new Signal<number>(1).connect(sigA);
|
|
|
|
const sigC = new Signal<number>(2).connect(sigB);
|
2019-04-12 14:37:47 +00:00
|
|
|
}, 2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
context("Scheduling", () => {
|
|
|
|
|
2019-06-19 21:33:00 +00:00
|
|
|
afterEach(done => {
|
|
|
|
setTimeout(() => done(), 100);
|
|
|
|
});
|
|
|
|
|
2019-04-12 14:37:47 +00:00
|
|
|
it("can be scheduled to set a value in the future", async () => {
|
|
|
|
const buffer = await Offline((context) => {
|
2019-09-14 22:06:46 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
|
|
|
sig.setValueAtTime(2, 0.2);
|
2019-04-12 14:37:47 +00:00
|
|
|
}, 0.25);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.19)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.2)).to.be.closeTo(2, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.24)).to.be.closeTo(2, 0.001);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can linear ramp from the current value to another value in the future", async () => {
|
|
|
|
const buffer = await Offline(context => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(1, 0.1);
|
|
|
|
}, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.05)).to.be.closeTo(0.5, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(1, 0.001);
|
|
|
|
});
|
|
|
|
|
2019-08-12 13:23:01 +00:00
|
|
|
it("can set a ramp point and then ramp from there", async () => {
|
|
|
|
const buffer = await Offline(context => {
|
|
|
|
const sig = new Signal<number>(0).toDestination();
|
|
|
|
sig.setRampPoint(0);
|
|
|
|
sig.linearRampToValueAtTime(1, 1);
|
|
|
|
sig.setRampPoint(0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(0.5, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(1)).to.be.closeTo(0, 0.001);
|
|
|
|
});
|
|
|
|
|
2019-04-12 14:37:47 +00:00
|
|
|
it("can schedule multiple automations", async () => {
|
|
|
|
const buffer = await Offline(context => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(0.5, 0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.25)).to.be.closeTo(0.25, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(0.5, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.75)).to.be.closeTo(0.25, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(1)).to.be.closeTo(0, 0.001);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can schedule multiple automations from a connected signal", async () => {
|
|
|
|
const buffer = await Offline((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const output = new Signal<number>(1).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const sig = new Signal<number>(0).connect(output);
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(0.5, 0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.25)).to.be.closeTo(0.25, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(0.5, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(0.75)).to.be.closeTo(0.25, 0.001);
|
|
|
|
expect(buffer.getValueAtTime(1)).to.be.closeTo(0, 0.001);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can disconnect from all the connected notes", () => {
|
|
|
|
return ConstantOutput((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const output0 = new Signal<number>(1).toDestination();
|
|
|
|
const output1 = new Signal<number>(1).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const sig = new Signal<number>(0).connect(output0);
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.connect(output1);
|
|
|
|
sig.disconnect();
|
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(0.5, 0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can disconnect from a specific node", () => {
|
|
|
|
return ConstantOutput((context) => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const output = new Signal<number>(1).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const sig = new Signal<number>(0).connect(output);
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.disconnect(output);
|
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(0.5, 0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
it("can schedule multiple automations from a connected signal through a multiple nodes", async () => {
|
|
|
|
const buffer = await Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const output = new Signal<number>(0).toDestination();
|
2019-07-15 19:37:25 +00:00
|
|
|
const proxy = new Signal<number>(0).connect(output);
|
2019-04-12 14:37:47 +00:00
|
|
|
const gain = new Gain(1).connect(proxy);
|
2019-07-15 19:37:25 +00:00
|
|
|
const sig = new Signal<number>(0).connect(gain);
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueAtTime(0, 0);
|
|
|
|
sig.linearRampToValueAtTime(0.5, 0.5);
|
|
|
|
sig.linearRampToValueAtTime(0, 1);
|
|
|
|
}, 1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.1, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.25)).to.be.closeTo(0.25, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(0.5, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.75)).to.be.closeTo(0.25, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(1)).to.be.closeTo(0, 0.01);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can cancel an automation", () => {
|
|
|
|
return ConstantOutput(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueAtTime(4, 0.1);
|
|
|
|
sig.exponentialRampToValueAtTime(3, 0.2);
|
|
|
|
sig.cancelScheduledValues(0);
|
|
|
|
}, 1);
|
|
|
|
});
|
|
|
|
it("can cancel and hold a linear automation curve", async () => {
|
2019-09-14 22:12:44 +00:00
|
|
|
const buffer = await Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.linearRampTo(2, 1);
|
|
|
|
sig.cancelAndHoldAtTime(0.5);
|
|
|
|
}, 1);
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.25)).to.be.closeTo(0.5, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(1, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.75)).to.be.closeTo(1, 0.1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can cancel and hold an exponential automation curve", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.exponentialRampTo(2, 1);
|
|
|
|
sig.cancelAndHoldAtTime(0.5);
|
|
|
|
}, 1).then(buffer => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(1, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.25)).to.be.closeTo(1.2, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(1.4, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.75)).to.be.closeTo(1.4, 0.1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set a linear ramp from the current time", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.linearRampTo(2, 0.3);
|
|
|
|
}, 0.5).then((buffer) => {
|
|
|
|
buffer.forEach((sample, time) => {
|
|
|
|
if (time > 0.3) {
|
|
|
|
expect(sample).to.be.closeTo(2, 0.02);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set an linear ramp in the future", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.linearRampTo(50, 0.3, 0.2);
|
|
|
|
}, 0.7).then((buffer) => {
|
2019-09-14 22:12:44 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2019-04-12 14:37:47 +00:00
|
|
|
if (time >= 0.6) {
|
|
|
|
expect(sample).to.be.closeTo(50, 0.5);
|
|
|
|
} else if (time < 0.2) {
|
|
|
|
expect(sample).to.closeTo(1, 0.01);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set a exponential approach ramp from the current time", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.targetRampTo(1, 0.3);
|
|
|
|
}, 0.5).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.below(0.0001);
|
|
|
|
expect(buffer.getValueAtTime(0.3)).to.be.closeTo(1, 0.02);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set an exponential approach ramp in the future", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.targetRampTo(50, 0.3, 0.2);
|
|
|
|
}, 0.7).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(1, 0.0001);
|
|
|
|
expect(buffer.getValueAtTime(0.2)).to.be.closeTo(1, 0.0001);
|
|
|
|
expect(buffer.getValueAtTime(0.6)).to.be.closeTo(50, 0.5);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("can set an exponential ramp from the current time", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.exponentialRampTo(50, 0.4);
|
|
|
|
}, 0.6).then((buffer) => {
|
2019-09-14 22:12:44 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2019-04-12 14:37:47 +00:00
|
|
|
if (time >= 0.4) {
|
|
|
|
expect(sample).to.be.closeTo(50, 0.5);
|
|
|
|
} else if (time < 0.39) {
|
|
|
|
expect(sample).to.be.lessThan(50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set an exponential ramp in the future", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(1).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.exponentialRampTo(50, 0.3, 0.2);
|
|
|
|
}, 0.8).then((buffer) => {
|
2019-09-14 22:12:44 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2019-04-12 14:37:47 +00:00
|
|
|
if (time >= 0.6) {
|
|
|
|
expect(sample).to.be.closeTo(50, 0.5);
|
|
|
|
} else if (time < 0.2) {
|
|
|
|
expect(sample).to.equal(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rampTo ramps from the current value", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(3).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.rampTo(0.2, 0.1);
|
|
|
|
}, 0.4).then((buffer) => {
|
2019-09-14 22:12:44 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2019-04-12 14:37:47 +00:00
|
|
|
if (time >= 0.1) {
|
|
|
|
expect(sample).to.be.closeTo(0.2, 0.1);
|
|
|
|
} else {
|
|
|
|
expect(sample).to.be.greaterThan(0.2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rampTo ramps from the current value at a specific time", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.rampTo(2, 0.1, 0.4);
|
|
|
|
}, 0.6).then((buffer) => {
|
2019-09-14 22:12:44 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2019-04-12 14:37:47 +00:00
|
|
|
if (time < 0.4) {
|
|
|
|
expect(sample).to.be.closeTo(0, 0.1);
|
|
|
|
} else if (time > 0.5) {
|
|
|
|
expect(sample).to.be.closeTo(2, 0.1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set a value curve", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueCurveAtTime([0, 1, 0.5, 0.2], 0, 1);
|
|
|
|
}, 1).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.33 / 2)).to.be.closeTo(0.5, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.33)).to.be.closeTo(1, 0.02);
|
|
|
|
expect(buffer.getValueAtTime(0.66)).to.be.closeTo(0.5, 0.02);
|
|
|
|
expect(buffer.getValueAtTime(0.99)).to.be.closeTo(0.2, 0.02);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set a value curve in the future", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.setValueCurveAtTime([0, 1, 0.5, 0.2], 0.5, 1);
|
|
|
|
}, 1.5).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0 + 0.5)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.33 / 2 + 0.5)).to.be.closeTo(0.5, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.33 + 0.5)).to.be.closeTo(1, 0.02);
|
|
|
|
expect(buffer.getValueAtTime(0.66 + 0.5)).to.be.closeTo(0.5, 0.02);
|
|
|
|
expect(buffer.getValueAtTime(0.99 + 0.5)).to.be.closeTo(0.2, 0.02);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set an exponential approach", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const sig = new Signal<number>(0).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
sig.exponentialApproachValueAtTime(2, 0.1, 0.5);
|
|
|
|
}, 1).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.4)).to.be.closeTo(1.9, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.6)).to.be.closeTo(2, 0.01);
|
|
|
|
});
|
|
|
|
});
|
2019-08-12 13:23:01 +00:00
|
|
|
|
|
|
|
it("can set a target at time", () => {
|
|
|
|
return Offline(() => {
|
|
|
|
const sig = new Signal<number>(0).toDestination();
|
|
|
|
sig.setTargetAtTime(2, 0.1, 0.1);
|
|
|
|
}, 1).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
|
|
|
|
expect(buffer.getValueAtTime(0.6)).to.be.closeTo(2, 0.1);
|
|
|
|
});
|
|
|
|
});
|
2019-04-12 14:37:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
context("Units", () => {
|
|
|
|
|
|
|
|
it("can be created with specific units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(0, "bpm");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.units).to.equal("bpm");
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can evaluate the given units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(2, "time");
|
2019-04-12 14:37:47 +00:00
|
|
|
signal.value = 0.5;
|
|
|
|
expect(signal.value).to.be.closeTo(0.5, 0.001);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("converts the given units when passed in the constructor", () => {
|
|
|
|
return ConstantOutput(() => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<Decibels>({
|
2019-04-12 14:37:47 +00:00
|
|
|
units: "decibels",
|
|
|
|
value: -10,
|
2019-07-25 15:32:56 +00:00
|
|
|
}).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
}, 0.315);
|
|
|
|
});
|
|
|
|
|
2019-08-12 14:20:24 +00:00
|
|
|
it("can be set to not convert the given units in constructor", () => {
|
2019-04-12 14:37:47 +00:00
|
|
|
return ConstantOutput(() => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<Decibels>({
|
2019-04-12 14:37:47 +00:00
|
|
|
convert: false,
|
|
|
|
units: "decibels",
|
|
|
|
value: -10,
|
2019-07-25 15:32:56 +00:00
|
|
|
}).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
}, -10);
|
|
|
|
});
|
|
|
|
|
2019-08-12 14:20:24 +00:00
|
|
|
it("can be set to not convert the given units in member", () => {
|
|
|
|
return ConstantOutput(() => {
|
|
|
|
const signal = new Signal<Decibels>({
|
|
|
|
units: "decibels",
|
|
|
|
}).toDestination();
|
|
|
|
signal.convert = false;
|
2019-08-12 17:23:11 +00:00
|
|
|
signal.value = -10;
|
2019-08-12 14:20:24 +00:00
|
|
|
}, -10);
|
|
|
|
});
|
|
|
|
|
2019-04-12 14:37:47 +00:00
|
|
|
it("converts Frequency units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<Frequency>("50hz", "frequency");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.be.closeTo(50, 0.01);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("converts Time units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<Time>("4n", "time");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.be.closeTo(0.5, 0.01);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("converts NormalRange units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(2, "normalRange");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.be.closeTo(1, 0.01);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("converts AudioRange units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(-2, "audioRange");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.be.closeTo(-1, 0.01);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("converts Positive units", () => {
|
2019-07-15 19:37:25 +00:00
|
|
|
const signal = new Signal<number>(-2, "positive");
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(signal.value).to.be.closeTo(0, 0.01);
|
|
|
|
signal.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// context("Transport Syncing", () => {
|
|
|
|
|
|
|
|
// it("maintains its original value after being synced to the transport", () => {
|
|
|
|
// return ConstantOutput(function(Transport) {
|
2019-07-25 15:32:56 +00:00
|
|
|
// const sig = new Signal<number>(3).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
// Transport.syncSignal(sig);
|
|
|
|
// }, 3);
|
|
|
|
// });
|
|
|
|
|
|
|
|
// it("keeps the ratio when the bpm changes", () => {
|
|
|
|
// return ConstantOutput(function(Transport) {
|
|
|
|
// Transport.bpm.value = 120;
|
2019-07-25 15:32:56 +00:00
|
|
|
// const sig = new Signal<number>(5).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
// Transport.syncSignal(sig);
|
|
|
|
// Transport.bpm.value = 240;
|
|
|
|
// }, 10);
|
|
|
|
// });
|
|
|
|
|
|
|
|
// it("can ramp along with the bpm", () => {
|
|
|
|
// return Offline(function(Transport) {
|
|
|
|
// Transport.bpm.value = 120;
|
2019-07-25 15:32:56 +00:00
|
|
|
// const sig = new Signal<number>(2).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
// Transport.syncSignal(sig);
|
|
|
|
// Transport.bpm.rampTo(240, 0.5);
|
|
|
|
// }).then((buffer) => {
|
|
|
|
// buffer.forEach((sample, time) => {
|
|
|
|
// if (time >= 0.5) {
|
|
|
|
// expect(sample).to.be.closeTo(4, 0.04);
|
|
|
|
// } else if (time < 0.4) {
|
|
|
|
// expect(sample).to.be.within(1.95, 3);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
// it("returns to the original value when unsynced", () => {
|
|
|
|
// return ConstantOutput(function(Transport) {
|
|
|
|
// Transport.bpm.value = 120;
|
2019-07-25 15:32:56 +00:00
|
|
|
// const sig = new Signal<number>(5).toDestination();
|
2019-04-12 14:37:47 +00:00
|
|
|
// Transport.syncSignal(sig);
|
|
|
|
// Transport.bpm.value = 240;
|
|
|
|
// Transport.unsyncSignal(sig);
|
|
|
|
// }, 5);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
});
|