2019-09-01 06:27:50 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { BasicTests } from "../../test/helper/Basic.js";
|
|
|
|
import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
|
|
|
import { InstrumentTest } from "../../test/helper/InstrumentTests.js";
|
|
|
|
import { NoiseSynth } from "./NoiseSynth.js";
|
2019-09-01 06:27:50 +00:00
|
|
|
|
|
|
|
describe("NoiseSynth", () => {
|
|
|
|
BasicTests(NoiseSynth);
|
2019-09-17 17:52:57 +00:00
|
|
|
|
2019-09-01 06:27:50 +00:00
|
|
|
InstrumentTest(NoiseSynth, undefined, {
|
|
|
|
envelope: {
|
|
|
|
decay: 0.1,
|
|
|
|
release: 0.2,
|
|
|
|
sustain: 0.5,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
it("matches a file", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const synth = new NoiseSynth({
|
|
|
|
envelope: {
|
|
|
|
attack: 0.01,
|
|
|
|
decay: 0.4,
|
|
|
|
},
|
|
|
|
}).toDestination();
|
|
|
|
synth.triggerAttack(0);
|
|
|
|
synth.triggerAttack(0.3);
|
|
|
|
},
|
|
|
|
"noiseSynth.wav",
|
|
|
|
4
|
|
|
|
);
|
2019-09-01 06:27:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("matches another file", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const synth = new NoiseSynth({
|
|
|
|
envelope: {
|
|
|
|
attack: 0.01,
|
|
|
|
decay: 0.4,
|
|
|
|
},
|
|
|
|
}).toDestination();
|
|
|
|
synth.triggerAttackRelease(0.1, 0);
|
|
|
|
},
|
|
|
|
"noiseSynthRelease.wav",
|
|
|
|
4
|
|
|
|
);
|
2019-09-01 06:27:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
context("API", () => {
|
|
|
|
it("can get and set noise type", () => {
|
|
|
|
const noiseSynth = new NoiseSynth();
|
|
|
|
noiseSynth.noise.type = "pink";
|
|
|
|
expect(noiseSynth.noise.type).to.equal("pink");
|
|
|
|
noiseSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get and set envelope attributes", () => {
|
|
|
|
const noiseSynth = new NoiseSynth();
|
|
|
|
noiseSynth.envelope.attack = 0.24;
|
|
|
|
expect(noiseSynth.envelope.attack).to.equal(0.24);
|
|
|
|
noiseSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with an options object", () => {
|
|
|
|
const noiseSynth = new NoiseSynth({
|
2019-09-17 17:54:24 +00:00
|
|
|
envelope: {
|
2019-09-01 06:27:50 +00:00
|
|
|
sustain: 0.3,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(noiseSynth.envelope.sustain).to.equal(0.3);
|
|
|
|
noiseSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get/set attributes", () => {
|
|
|
|
const noiseSynth = new NoiseSynth();
|
|
|
|
noiseSynth.set({
|
|
|
|
envelope: {
|
|
|
|
decay: 0.24,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(noiseSynth.get().envelope.decay).to.equal(0.24);
|
|
|
|
noiseSynth.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|