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