2024-05-03 18:31:14 +00:00
|
|
|
import { AutoPanner } from "./AutoPanner.js";
|
|
|
|
import { BasicTests } from "../../test/helper/Basic.js";
|
|
|
|
import { EffectTests } from "../../test/helper/EffectTests.js";
|
|
|
|
import { Offline } from "../../test/helper/Offline.js";
|
2019-10-28 21:50:31 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
|
|
|
import { Oscillator } from "../source/oscillator/Oscillator.js";
|
2019-10-28 21:50:31 +00:00
|
|
|
|
|
|
|
describe("AutoPanner", () => {
|
|
|
|
BasicTests(AutoPanner);
|
|
|
|
EffectTests(AutoPanner);
|
|
|
|
|
2019-10-29 22:18:04 +00:00
|
|
|
it("matches a file", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const autoFilter = new AutoPanner({
|
|
|
|
type: "sine",
|
|
|
|
frequency: 3,
|
|
|
|
}).toDestination();
|
|
|
|
new Oscillator().connect(autoFilter).start();
|
|
|
|
autoFilter.start(0.2);
|
|
|
|
},
|
|
|
|
"autoPanner.wav",
|
|
|
|
0.01
|
|
|
|
);
|
2019-10-29 22:18:04 +00:00
|
|
|
});
|
|
|
|
|
2019-10-28 21:50:31 +00:00
|
|
|
context("API", () => {
|
|
|
|
it("can pass in options in the constructor", () => {
|
|
|
|
const autoPanner = new AutoPanner({
|
|
|
|
type: "sawtooth",
|
2024-05-03 18:31:14 +00:00
|
|
|
depth: 0.2,
|
2019-10-28 21:50:31 +00:00
|
|
|
});
|
|
|
|
expect(autoPanner.depth.value).to.be.closeTo(0.2, 0.01);
|
|
|
|
expect(autoPanner.type).to.equal("sawtooth");
|
|
|
|
autoPanner.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be started and stopped", () => {
|
|
|
|
const autoPanner = new AutoPanner();
|
|
|
|
autoPanner.start().stop("+0.2");
|
|
|
|
autoPanner.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get/set the options", () => {
|
|
|
|
const autoPanner = new AutoPanner();
|
|
|
|
autoPanner.set({
|
|
|
|
frequency: 2.4,
|
2024-05-03 18:31:14 +00:00
|
|
|
type: "triangle",
|
2019-10-28 21:50:31 +00:00
|
|
|
});
|
|
|
|
expect(autoPanner.get().frequency).to.be.closeTo(2.4, 0.01);
|
|
|
|
expect(autoPanner.get().type).to.equal("triangle");
|
|
|
|
autoPanner.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set the frequency and depth", () => {
|
|
|
|
const autoPanner = new AutoPanner();
|
|
|
|
autoPanner.depth.value = 0.4;
|
|
|
|
autoPanner.frequency.value = 0.4;
|
|
|
|
expect(autoPanner.depth.value).to.be.closeTo(0.4, 0.01);
|
|
|
|
expect(autoPanner.frequency.value).to.be.closeTo(0.4, 0.01);
|
|
|
|
autoPanner.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can sync the frequency to the transport", () => {
|
|
|
|
return Offline(({ transport }) => {
|
2019-11-17 18:09:19 +00:00
|
|
|
const panner = new AutoPanner(2);
|
2019-10-28 21:50:31 +00:00
|
|
|
panner.sync();
|
|
|
|
panner.frequency.toDestination();
|
|
|
|
transport.bpm.setValueAtTime(transport.bpm.value * 2, 0.05);
|
|
|
|
// transport.start(0)
|
|
|
|
}, 0.1).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.05)).to.be.closeTo(4, 0.1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can unsync the frequency to the transport", () => {
|
|
|
|
return Offline(({ transport }) => {
|
2019-11-17 18:09:19 +00:00
|
|
|
const panner = new AutoPanner(2);
|
2019-10-28 21:50:31 +00:00
|
|
|
panner.sync();
|
|
|
|
panner.frequency.toDestination();
|
|
|
|
transport.bpm.setValueAtTime(transport.bpm.value * 2, 0.05);
|
|
|
|
panner.unsync();
|
|
|
|
// transport.start(0)
|
|
|
|
}, 0.1).then((buffer) => {
|
|
|
|
expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
|
|
|
|
expect(buffer.getValueAtTime(0.05)).to.be.closeTo(2, 0.1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|