2019-07-25 15:17:11 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { connectFrom, connectTo } from "./Connect.js";
|
|
|
|
import { Offline } from "./Offline.js";
|
|
|
|
import { PassAudio } from "./PassAudio.js";
|
|
|
|
import { Signal } from "../../Tone/signal/Signal.js";
|
2019-07-25 15:17:11 +00:00
|
|
|
|
|
|
|
export function EffectTests(Constr, args?, before?): void {
|
|
|
|
context("Effect Tests", () => {
|
|
|
|
it("has an input and output", () => {
|
|
|
|
const instance = new Constr(args);
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
instance.connect(connectTo());
|
|
|
|
connectFrom().connect(instance);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set the dry/wet value", () => {
|
|
|
|
const instance = new Constr(args);
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
instance.wet.value = 0;
|
|
|
|
expect(instance.wet.value).to.equal(0);
|
|
|
|
instance.wet.value = 0.5;
|
|
|
|
expect(instance.wet.value).to.equal(0.5);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with an object", () => {
|
|
|
|
const instance = new Constr({
|
2019-10-30 17:13:26 +00:00
|
|
|
wet: 0.25,
|
2019-07-25 15:17:11 +00:00
|
|
|
});
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
expect(instance.wet.value).to.equal(0.25);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes audio from input to output", () => {
|
|
|
|
return PassAudio((input) => {
|
|
|
|
const instance = new Constr(args);
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
input.connect(instance);
|
2019-07-25 15:32:56 +00:00
|
|
|
instance.toDestination();
|
2019-07-25 15:17:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-30 17:13:26 +00:00
|
|
|
it("has no sound when not connected to any inputs", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return Offline(
|
|
|
|
() => {
|
|
|
|
const instance = new Constr(args).toDestination();
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
0.5,
|
|
|
|
1
|
|
|
|
).then((buffer) => {
|
2019-10-30 17:13:26 +00:00
|
|
|
expect(buffer.isSilent()).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-30 17:23:08 +00:00
|
|
|
it.skip("can pass 100% dry signal", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return Offline(
|
|
|
|
() => {
|
|
|
|
const instance = new Constr(args).toDestination();
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
const signal = new Signal(-1).connect(instance);
|
|
|
|
// make the signals ramp
|
|
|
|
signal.linearRampTo(1, 1, 0);
|
|
|
|
instance.wet.value = 0;
|
|
|
|
},
|
|
|
|
0.5,
|
|
|
|
1
|
|
|
|
).then((buffer) => {
|
2019-07-25 17:17:21 +00:00
|
|
|
buffer.forEach((sample, time) => {
|
2024-05-03 18:31:14 +00:00
|
|
|
const value = time * 2 - 1;
|
2019-10-30 17:13:26 +00:00
|
|
|
expect(sample).to.be.closeTo(value, 0.1);
|
2019-07-25 15:17:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-25 17:23:30 +00:00
|
|
|
it.skip("effects the incoming signal", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return Offline(
|
|
|
|
() => {
|
|
|
|
const instance = new Constr(args).toDestination();
|
|
|
|
if (before) {
|
|
|
|
before(instance);
|
|
|
|
}
|
|
|
|
const signal = new Signal(-1).connect(instance);
|
|
|
|
// make the signals ramp
|
|
|
|
signal.linearRampTo(1, 1);
|
|
|
|
instance.wet.value = 1;
|
|
|
|
},
|
|
|
|
0.5,
|
|
|
|
1
|
|
|
|
).then((buffer) => {
|
2019-07-25 17:17:21 +00:00
|
|
|
let affected = false;
|
|
|
|
buffer.forEach((sample, time) => {
|
2024-05-03 18:31:14 +00:00
|
|
|
const value = time * 2 - 1;
|
2019-07-25 17:17:21 +00:00
|
|
|
if (Math.abs(value - sample) > 0.01) {
|
|
|
|
affected = true;
|
2019-07-25 15:17:11 +00:00
|
|
|
}
|
|
|
|
});
|
2019-07-25 17:17:21 +00:00
|
|
|
expect(affected).to.be.true;
|
2019-07-25 15:17:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|