1 | import { AutoPanner } from "./AutoPanner.js";
|
2 | import { BasicTests } from "../../test/helper/Basic.js";
|
3 | import { EffectTests } from "../../test/helper/EffectTests.js";
|
4 | import { Offline } from "../../test/helper/Offline.js";
|
5 | import { expect } from "chai";
|
6 | import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
7 | import { Oscillator } from "../source/oscillator/Oscillator.js";
|
8 |
|
9 | describe("AutoPanner", () => {
|
10 | BasicTests(AutoPanner);
|
11 | EffectTests(AutoPanner);
|
12 |
|
13 | it("matches a file", () => {
|
14 | return CompareToFile(
|
15 | () => {
|
16 | const autoFilter = new AutoPanner({
|
17 | type: "sine",
|
18 | frequency: 3,
|
19 | }).toDestination();
|
20 | new Oscillator().connect(autoFilter).start();
|
21 | autoFilter.start(0.2);
|
22 | },
|
23 | "autoPanner.wav",
|
24 | 0.01
|
25 | );
|
26 | });
|
27 |
|
28 | context("API", () => {
|
29 | it("can pass in options in the constructor", () => {
|
30 | const autoPanner = new AutoPanner({
|
31 | type: "sawtooth",
|
32 | depth: 0.2,
|
33 | });
|
34 | expect(autoPanner.depth.value).to.be.closeTo(0.2, 0.01);
|
35 | expect(autoPanner.type).to.equal("sawtooth");
|
36 | autoPanner.dispose();
|
37 | });
|
38 |
|
39 | it("can be started and stopped", () => {
|
40 | const autoPanner = new AutoPanner();
|
41 | autoPanner.start().stop("+0.2");
|
42 | autoPanner.dispose();
|
43 | });
|
44 |
|
45 | it("can get/set the options", () => {
|
46 | const autoPanner = new AutoPanner();
|
47 | autoPanner.set({
|
48 | frequency: 2.4,
|
49 | type: "triangle",
|
50 | });
|
51 | expect(autoPanner.get().frequency).to.be.closeTo(2.4, 0.01);
|
52 | expect(autoPanner.get().type).to.equal("triangle");
|
53 | autoPanner.dispose();
|
54 | });
|
55 |
|
56 | it("can set the frequency and depth", () => {
|
57 | const autoPanner = new AutoPanner();
|
58 | autoPanner.depth.value = 0.4;
|
59 | autoPanner.frequency.value = 0.4;
|
60 | expect(autoPanner.depth.value).to.be.closeTo(0.4, 0.01);
|
61 | expect(autoPanner.frequency.value).to.be.closeTo(0.4, 0.01);
|
62 | autoPanner.dispose();
|
63 | });
|
64 |
|
65 | it("can sync the frequency to the transport", () => {
|
66 | return Offline(({ transport }) => {
|
67 | const panner = new AutoPanner(2);
|
68 | panner.sync();
|
69 | panner.frequency.toDestination();
|
70 | transport.bpm.setValueAtTime(transport.bpm.value * 2, 0.05);
|
71 |
|
72 | }, 0.1).then((buffer) => {
|
73 | expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
|
74 | expect(buffer.getValueAtTime(0.05)).to.be.closeTo(4, 0.1);
|
75 | });
|
76 | });
|
77 |
|
78 | it("can unsync the frequency to the transport", () => {
|
79 | return Offline(({ transport }) => {
|
80 | const panner = new AutoPanner(2);
|
81 | panner.sync();
|
82 | panner.frequency.toDestination();
|
83 | transport.bpm.setValueAtTime(transport.bpm.value * 2, 0.05);
|
84 | panner.unsync();
|
85 |
|
86 | }, 0.1).then((buffer) => {
|
87 | expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
|
88 | expect(buffer.getValueAtTime(0.05)).to.be.closeTo(2, 0.1);
|
89 | });
|
90 | });
|
91 | });
|
92 | });
|