2019-07-18 15:24:32 +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 { connectFrom, connectTo } from "../../../test/helper/Connect.js";
|
|
|
|
import { Offline } from "../../../test/helper/Offline.js";
|
|
|
|
import { Signal } from "../../signal/Signal.js";
|
|
|
|
import { Oscillator } from "../../source/oscillator/Oscillator.js";
|
|
|
|
import { AmplitudeEnvelope } from "./AmplitudeEnvelope.js";
|
|
|
|
import { Envelope } from "./Envelope.js";
|
2019-07-18 15:24:32 +00:00
|
|
|
|
|
|
|
describe("AmplitudeEnvelope", () => {
|
|
|
|
BasicTests(AmplitudeEnvelope);
|
|
|
|
|
|
|
|
context("Comparisons", () => {
|
|
|
|
it("matches a file", () => {
|
|
|
|
return CompareToFile(() => {
|
|
|
|
const ampEnv = new AmplitudeEnvelope({
|
2019-09-16 03:32:40 +00:00
|
|
|
attack: 0.1,
|
|
|
|
decay: 0.2,
|
|
|
|
release: 0.2,
|
|
|
|
sustain: 0.1,
|
2019-07-25 15:32:56 +00:00
|
|
|
}).toDestination();
|
2019-07-18 15:24:32 +00:00
|
|
|
const osc = new Oscillator().start(0).connect(ampEnv);
|
|
|
|
ampEnv.triggerAttack(0);
|
|
|
|
ampEnv.triggerRelease(0.3);
|
|
|
|
}, "ampEnvelope.wav");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("matches a file with multiple retriggers", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const ampEnv = new AmplitudeEnvelope({
|
|
|
|
attack: 0.1,
|
|
|
|
decay: 0.2,
|
|
|
|
release: 0.2,
|
|
|
|
sustain: 0.1,
|
|
|
|
}).toDestination();
|
|
|
|
const osc = new Oscillator().start(0).connect(ampEnv);
|
|
|
|
ampEnv.triggerAttack(0);
|
|
|
|
ampEnv.triggerAttack(0.3);
|
|
|
|
},
|
|
|
|
"ampEnvelope2.wav",
|
|
|
|
0.004
|
|
|
|
);
|
2019-07-18 15:24:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("matches a file with ripple attack/release", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const ampEnv = new AmplitudeEnvelope({
|
|
|
|
attack: 0.5,
|
|
|
|
attackCurve: "ripple",
|
|
|
|
decay: 0.2,
|
|
|
|
release: 0.3,
|
|
|
|
releaseCurve: "ripple",
|
|
|
|
sustain: 0.1,
|
|
|
|
}).toDestination();
|
|
|
|
const osc = new Oscillator().start(0).connect(ampEnv);
|
|
|
|
ampEnv.triggerAttack(0);
|
|
|
|
ampEnv.triggerRelease(0.7);
|
|
|
|
ampEnv.triggerAttack(1);
|
|
|
|
ampEnv.triggerRelease(1.6);
|
|
|
|
},
|
|
|
|
"ampEnvelope3.wav",
|
|
|
|
0.002
|
|
|
|
);
|
2019-07-18 15:24:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
context("Envelope", () => {
|
|
|
|
it("extends envelope", () => {
|
|
|
|
const ampEnv = new AmplitudeEnvelope();
|
|
|
|
expect(ampEnv).to.be.instanceOf(Envelope);
|
|
|
|
ampEnv.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes no signal before being triggered", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const ampEnv = new AmplitudeEnvelope().toDestination();
|
2019-07-18 15:24:32 +00:00
|
|
|
new Signal(1).connect(ampEnv);
|
|
|
|
}).then((buffer) => {
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes signal once triggered", () => {
|
|
|
|
return Offline(() => {
|
2019-07-25 15:32:56 +00:00
|
|
|
const ampEnv = new AmplitudeEnvelope().toDestination();
|
2019-07-18 15:24:32 +00:00
|
|
|
new Signal(1).connect(ampEnv);
|
|
|
|
ampEnv.triggerAttack(0.1);
|
|
|
|
}, 0.2).then((buffer) => {
|
|
|
|
expect(buffer.getTimeOfFirstSound()).to.be.closeTo(0.1, 0.001);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|