1 | import { BasicTests } from "../../test/helper/Basic.js";
|
2 | import { InstrumentTest } from "../../test/helper/InstrumentTests.js";
|
3 | import { DuoSynth } from "./DuoSynth.js";
|
4 | import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
5 | import { expect } from "chai";
|
6 | import { MonophonicTest } from "../../test/helper/MonophonicTests.js";
|
7 |
|
8 | describe("DuoSynth", () => {
|
9 | BasicTests(DuoSynth);
|
10 | MonophonicTest(DuoSynth, "C4");
|
11 | InstrumentTest(DuoSynth, "C4", {
|
12 | voice0: {
|
13 | oscillator: {
|
14 | type: "square",
|
15 | },
|
16 | envelope: {
|
17 | decay: 0.1,
|
18 | sustain: 0.5,
|
19 | release: 0.2,
|
20 | },
|
21 | },
|
22 | voice1: {
|
23 | oscillator: {
|
24 | type: "square",
|
25 | },
|
26 | envelope: {
|
27 | decay: 0.1,
|
28 | sustain: 0.5,
|
29 | release: 0.3,
|
30 | },
|
31 | },
|
32 | });
|
33 |
|
34 | it("matches a file", () => {
|
35 | return CompareToFile(
|
36 | () => {
|
37 | const synth = new DuoSynth().toDestination();
|
38 | synth.triggerAttackRelease("C5", 0.1, 0.1);
|
39 | },
|
40 | "duoSynth.wav",
|
41 | 0.07
|
42 | );
|
43 | });
|
44 |
|
45 | context("API", () => {
|
46 | it("can get and set voice0 attributes", () => {
|
47 | const duoSynth = new DuoSynth();
|
48 | duoSynth.voice0.oscillator.type = "triangle";
|
49 | expect(duoSynth.voice0.oscillator.type).to.equal("triangle");
|
50 | duoSynth.dispose();
|
51 | });
|
52 |
|
53 | it("can get and set voice1 attributes", () => {
|
54 | const duoSynth = new DuoSynth();
|
55 | duoSynth.voice1.envelope.attack = 0.24;
|
56 | expect(duoSynth.voice1.envelope.attack).to.equal(0.24);
|
57 | duoSynth.dispose();
|
58 | });
|
59 |
|
60 | it("can get and set harmonicity", () => {
|
61 | const duoSynth = new DuoSynth();
|
62 | duoSynth.harmonicity.value = 2;
|
63 | expect(duoSynth.harmonicity.value).to.equal(2);
|
64 | duoSynth.dispose();
|
65 | });
|
66 |
|
67 | it("can get and set vibratoRate", () => {
|
68 | const duoSynth = new DuoSynth();
|
69 | duoSynth.vibratoRate.value = 2;
|
70 | expect(duoSynth.vibratoRate.value).to.equal(2);
|
71 | duoSynth.dispose();
|
72 | });
|
73 |
|
74 | it("can be constructed with an options object", () => {
|
75 | const duoSynth = new DuoSynth({
|
76 | voice0: {
|
77 | filter: {
|
78 | rolloff: -24,
|
79 | },
|
80 | },
|
81 | });
|
82 | expect(duoSynth.voice0.filter.rolloff).to.equal(-24);
|
83 | duoSynth.dispose();
|
84 | });
|
85 |
|
86 | it("can get/set attributes", () => {
|
87 | const duoSynth = new DuoSynth();
|
88 | duoSynth.set({
|
89 | harmonicity: 1.5,
|
90 | });
|
91 | expect(duoSynth.get().harmonicity).to.equal(1.5);
|
92 | duoSynth.dispose();
|
93 | });
|
94 | });
|
95 | });
|