UNPKG

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