Tone.js/Tone/effect/Reverb.test.ts

76 lines
2 KiB
TypeScript
Raw Normal View History

2019-08-02 20:29:09 +00:00
import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { Offline } from "test/helper/Offline";
import { Oscillator } from "Tone/source/oscillator/Oscillator";
import { Reverb } from "./Reverb";
describe("Reverb", () => {
BasicTests(Reverb);
context("API", () => {
it("can pass in options in the constructor", () => {
const reverb = new Reverb({
2019-09-14 22:12:44 +00:00
decay: 2,
preDelay: 0.1,
2019-08-02 20:29:09 +00:00
});
expect(reverb.decay).to.be.closeTo(2, 0.001);
expect(reverb.preDelay).to.be.closeTo(0.1, 0.001);
reverb.dispose();
});
2019-12-24 04:58:40 +00:00
it("can get/set values", () => {
const reverb = new Reverb();
reverb.decay = 0.5;
expect(reverb.decay).to.be.closeTo(0.5, 0.001);
reverb.preDelay = 0.05;
expect(reverb.preDelay).to.be.closeTo(0.05, 0.001);
reverb.dispose();
});
2019-08-02 20:29:09 +00:00
it("can get/set the options", () => {
const reverb = new Reverb();
reverb.set({
2019-09-14 22:12:44 +00:00
decay: 0.4,
2019-08-02 20:29:09 +00:00
});
expect(reverb.get().decay).to.be.closeTo(0.4, 0.001);
reverb.dispose();
});
it("can generate an IR", () => {
const reverb = new Reverb();
const promise = reverb.generate();
expect(promise).to.have.property("then");
return promise.then(() => {
reverb.dispose();
});
});
2019-12-06 23:00:26 +00:00
it.skip("is silent before the reverb is generated", () => {
2019-08-02 20:29:09 +00:00
return Offline(() => {
const osc = new Oscillator();
osc.start(0).stop(0.1);
const reverb = new Reverb(0.2).toDestination();
osc.connect(reverb);
}).then((buffer) => {
expect(buffer.isSilent()).to.be.true;
});
});
it("passes audio from input to output", () => {
2019-08-02 20:29:09 +00:00
return Offline(async () => {
const osc = new Oscillator();
osc.start(0).stop(0.1);
const reverb = new Reverb(0.2).toDestination();
osc.connect(reverb);
await reverb.ready;
2019-08-02 20:29:09 +00:00
}, 0.3).then((buffer) => {
expect(buffer.getRmsAtTime(0.05)).to.be.greaterThan(0);
expect(buffer.getRmsAtTime(0.1)).to.be.greaterThan(0);
expect(buffer.getRmsAtTime(0.2)).to.be.greaterThan(0);
});
});
});
});