2019-09-27 13:36:26 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { FMSynth } from "./FMSynth.js";
|
|
|
|
import { BasicTests } from "../../test/helper/Basic.js";
|
|
|
|
import { InstrumentTest } from "../../test/helper/InstrumentTests.js";
|
|
|
|
import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
|
|
|
import { Offline } from "../../test/helper/Offline.js";
|
2019-09-27 13:36:26 +00:00
|
|
|
|
|
|
|
describe("FMSynth", () => {
|
|
|
|
BasicTests(FMSynth);
|
|
|
|
InstrumentTest(FMSynth, "C4");
|
|
|
|
|
2019-09-30 20:48:39 +00:00
|
|
|
it("matches a file", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const synth = new FMSynth().toDestination();
|
|
|
|
synth.triggerAttackRelease("G4", 0.1, 0.05);
|
|
|
|
},
|
|
|
|
"fmSynth.wav",
|
|
|
|
0.08
|
|
|
|
);
|
2019-09-30 20:48:39 +00:00
|
|
|
});
|
2019-09-27 13:36:26 +00:00
|
|
|
|
|
|
|
context("API", () => {
|
|
|
|
it("can get and set carrier attributes", () => {
|
|
|
|
const fmSynth = new FMSynth();
|
|
|
|
fmSynth.oscillator.type = "triangle";
|
|
|
|
expect(fmSynth.oscillator.type).to.equal("triangle");
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
2019-10-28 19:11:36 +00:00
|
|
|
it("invokes the onsilence callback", (done) => {
|
|
|
|
Offline(() => {
|
|
|
|
const synth = new FMSynth({
|
2024-05-03 18:31:14 +00:00
|
|
|
onsilence: () => done(),
|
2019-10-28 19:11:36 +00:00
|
|
|
});
|
|
|
|
synth.triggerAttackRelease("C3", 0.2, 0);
|
|
|
|
}, 2);
|
|
|
|
});
|
|
|
|
|
2019-09-27 13:36:26 +00:00
|
|
|
it("can get and set modulator attributes", () => {
|
|
|
|
const fmSynth = new FMSynth();
|
|
|
|
fmSynth.modulationEnvelope.attack = 0.24;
|
|
|
|
expect(fmSynth.modulationEnvelope.attack).to.equal(0.24);
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get and set harmonicity", () => {
|
|
|
|
const fmSynth = new FMSynth();
|
|
|
|
fmSynth.harmonicity.value = 2;
|
|
|
|
expect(fmSynth.harmonicity.value).to.equal(2);
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with an options object", () => {
|
|
|
|
const fmSynth = new FMSynth({
|
|
|
|
envelope: {
|
2024-05-03 18:31:14 +00:00
|
|
|
release: 0.3,
|
|
|
|
},
|
2019-09-27 13:36:26 +00:00
|
|
|
});
|
|
|
|
expect(fmSynth.envelope.release).to.equal(0.3);
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get/set attributes", () => {
|
|
|
|
const fmSynth = new FMSynth();
|
|
|
|
fmSynth.set({
|
|
|
|
harmonicity: 1.5,
|
2024-05-03 18:31:14 +00:00
|
|
|
detune: 1200,
|
2019-09-27 13:36:26 +00:00
|
|
|
});
|
|
|
|
expect(fmSynth.get().harmonicity).to.equal(1.5);
|
|
|
|
expect(fmSynth.get().detune).to.be.closeTo(1200, 1);
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|