1 | import { expect } from "chai";
|
2 | import { BasicTests } from "../../test/helper/Basic.js";
|
3 | import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
4 | import { InstrumentTest } from "../../test/helper/InstrumentTests.js";
|
5 | import { NoiseSynth } from "./NoiseSynth.js";
|
6 |
|
7 | describe("NoiseSynth", () => {
|
8 | BasicTests(NoiseSynth);
|
9 |
|
10 | InstrumentTest(NoiseSynth, undefined, {
|
11 | envelope: {
|
12 | decay: 0.1,
|
13 | release: 0.2,
|
14 | sustain: 0.5,
|
15 | },
|
16 | });
|
17 |
|
18 | it("matches a file", () => {
|
19 | return CompareToFile(
|
20 | () => {
|
21 | const synth = new NoiseSynth({
|
22 | envelope: {
|
23 | attack: 0.01,
|
24 | decay: 0.4,
|
25 | },
|
26 | }).toDestination();
|
27 | synth.triggerAttack(0);
|
28 | synth.triggerAttack(0.3);
|
29 | },
|
30 | "noiseSynth.wav",
|
31 | 4
|
32 | );
|
33 | });
|
34 |
|
35 | it("matches another file", () => {
|
36 | return CompareToFile(
|
37 | () => {
|
38 | const synth = new NoiseSynth({
|
39 | envelope: {
|
40 | attack: 0.01,
|
41 | decay: 0.4,
|
42 | },
|
43 | }).toDestination();
|
44 | synth.triggerAttackRelease(0.1, 0);
|
45 | },
|
46 | "noiseSynthRelease.wav",
|
47 | 4
|
48 | );
|
49 | });
|
50 |
|
51 | context("API", () => {
|
52 | it("can get and set noise type", () => {
|
53 | const noiseSynth = new NoiseSynth();
|
54 | noiseSynth.noise.type = "pink";
|
55 | expect(noiseSynth.noise.type).to.equal("pink");
|
56 | noiseSynth.dispose();
|
57 | });
|
58 |
|
59 | it("can get and set envelope attributes", () => {
|
60 | const noiseSynth = new NoiseSynth();
|
61 | noiseSynth.envelope.attack = 0.24;
|
62 | expect(noiseSynth.envelope.attack).to.equal(0.24);
|
63 | noiseSynth.dispose();
|
64 | });
|
65 |
|
66 | it("can be constructed with an options object", () => {
|
67 | const noiseSynth = new NoiseSynth({
|
68 | envelope: {
|
69 | sustain: 0.3,
|
70 | },
|
71 | });
|
72 | expect(noiseSynth.envelope.sustain).to.equal(0.3);
|
73 | noiseSynth.dispose();
|
74 | });
|
75 |
|
76 | it("can get/set attributes", () => {
|
77 | const noiseSynth = new NoiseSynth();
|
78 | noiseSynth.set({
|
79 | envelope: {
|
80 | decay: 0.24,
|
81 | },
|
82 | });
|
83 | expect(noiseSynth.get().envelope.decay).to.equal(0.24);
|
84 | noiseSynth.dispose();
|
85 | });
|
86 | });
|
87 | });
|