Tone.js/Tone/instrument/FMSynth.test.ts

76 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2019-09-27 13:36:26 +00:00
import { expect } from "chai";
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", () => {
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();
});
it("invokes the onsilence callback", (done) => {
Offline(() => {
const synth = new FMSynth({
onsilence: () => done(),
});
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: {
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,
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();
});
});
});