2019-09-01 06:27:50 +00:00
|
|
|
import { expect } from "chai";
|
2019-09-17 17:52:57 +00:00
|
|
|
import { BasicTests } from "test/helper/Basic";
|
|
|
|
import { CompareToFile } from "test/helper/CompareToFile";
|
|
|
|
import { InstrumentTest } from "test/helper/InstrumentTests";
|
2019-09-01 06:27:50 +00:00
|
|
|
import { NoiseSynth } from "./NoiseSynth";
|
|
|
|
|
|
|
|
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", () => {
|
|
|
|
return CompareToFile(() => {
|
|
|
|
const synth = new NoiseSynth({
|
2019-09-17 17:54:24 +00:00
|
|
|
envelope: {
|
|
|
|
attack: 0.01,
|
|
|
|
decay: 0.4,
|
2019-09-01 06:27:50 +00:00
|
|
|
},
|
2019-09-17 17:52:57 +00:00
|
|
|
}).toDestination();
|
2019-09-01 06:27:50 +00:00
|
|
|
synth.triggerAttack(0);
|
|
|
|
synth.triggerAttack(0.3);
|
|
|
|
}, "noiseSynth.wav", 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("matches another file", () => {
|
|
|
|
return CompareToFile(() => {
|
|
|
|
const synth = new NoiseSynth({
|
2019-09-17 17:54:24 +00:00
|
|
|
envelope: {
|
|
|
|
attack: 0.01,
|
|
|
|
decay: 0.4,
|
2019-09-01 06:27:50 +00:00
|
|
|
},
|
2019-09-17 17:52:57 +00:00
|
|
|
}).toDestination();
|
2019-09-01 06:27:50 +00:00
|
|
|
synth.triggerAttackRelease(0.1, 0);
|
|
|
|
}, "noiseSynthRelease.wav", 4);
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|