UNPKG

2.07 kBPlain TextView Raw
1import { AMSynth } from "./AMSynth.js";
2import { BasicTests } from "../../test/helper/Basic.js";
3import { InstrumentTest } from "../../test/helper/InstrumentTests.js";
4import { CompareToFile } from "../../test/helper/CompareToFile.js";
5import { expect } from "chai";
6import { Offline } from "../../test/helper/Offline.js";
7
8describe("AMSynth", () => {
9 BasicTests(AMSynth);
10 InstrumentTest(AMSynth, "C4");
11
12 it("matches a file", () => {
13 return CompareToFile(
14 () => {
15 const synth = new AMSynth().toDestination();
16 synth.triggerAttackRelease("C5", 0.1, 0.1);
17 },
18 "amSynth.wav",
19 0.15
20 );
21 });
22
23 context("API", () => {
24 it("invokes the onsilence callback", (done) => {
25 Offline(() => {
26 const amSynth = new AMSynth({
27 onsilence: () => done(),
28 });
29 amSynth.triggerAttackRelease("C3", 0.2, 0);
30 }, 2);
31 });
32
33 it("can get and set carrier attributes", () => {
34 const amSynth = new AMSynth();
35 amSynth.oscillator.type = "triangle";
36 expect(amSynth.oscillator.type).to.equal("triangle");
37 amSynth.dispose();
38 });
39
40 it("can get and set modulator attributes", () => {
41 const amSynth = new AMSynth();
42 amSynth.envelope.attack = 0.24;
43 expect(amSynth.envelope.attack).to.equal(0.24);
44 amSynth.dispose();
45 });
46
47 it("can get and set harmonicity", () => {
48 const amSynth = new AMSynth();
49 amSynth.harmonicity.value = 2;
50 expect(amSynth.harmonicity.value).to.equal(2);
51 amSynth.dispose();
52 });
53
54 it("can be constructed with an options object", () => {
55 const amSynth = new AMSynth({
56 oscillator: {
57 type: "square",
58 },
59 modulationEnvelope: {
60 attack: 0.3,
61 },
62 });
63 expect(amSynth.modulationEnvelope.attack).to.equal(0.3);
64 expect(amSynth.oscillator.type).to.equal("square");
65 amSynth.dispose();
66 });
67
68 it("can get/set attributes", () => {
69 const amSynth = new AMSynth();
70 amSynth.set({
71 harmonicity: 1.5,
72 detune: 1200,
73 });
74 expect(amSynth.get().harmonicity).to.equal(1.5);
75 expect(amSynth.get().detune).to.be.closeTo(1200, 1);
76 amSynth.dispose();
77 });
78 });
79});