2019-09-09 21:53:39 +00:00
|
|
|
import { expect } from "chai";
|
2019-09-09 23:27:45 +00:00
|
|
|
import { BasicTests, warns } from "test/helper/Basic";
|
2019-09-09 21:53:39 +00:00
|
|
|
import { PassAudio } from "test/helper/PassAudio";
|
2019-09-09 23:27:45 +00:00
|
|
|
import { ONLINE_TESTING } from "test/helper/Supports";
|
2019-09-09 21:53:39 +00:00
|
|
|
import { Signal } from "Tone/signal/Signal";
|
|
|
|
import { Oscillator } from "Tone/source/oscillator/Oscillator";
|
|
|
|
import { Meter } from "./Meter";
|
|
|
|
|
|
|
|
describe("Meter", () => {
|
|
|
|
|
|
|
|
BasicTests(Meter);
|
|
|
|
|
|
|
|
context("Metering", () => {
|
|
|
|
|
|
|
|
it("handles getter/setter as Object", () => {
|
|
|
|
const meter = new Meter();
|
|
|
|
const values = {
|
2019-09-16 03:32:40 +00:00
|
|
|
smoothing: 0.2,
|
2019-09-09 21:53:39 +00:00
|
|
|
};
|
|
|
|
meter.set(values);
|
|
|
|
expect(meter.get().smoothing).to.equal(0.2);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with the smoothing", () => {
|
|
|
|
const meter = new Meter(0.5);
|
|
|
|
expect(meter.smoothing).to.equal(0.5);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
2019-12-15 21:43:41 +00:00
|
|
|
it("returns an array of channels if channels > 1", () => {
|
|
|
|
const meter = new Meter({
|
2021-10-13 17:09:09 +00:00
|
|
|
channelCount: 4,
|
2019-12-15 21:43:41 +00:00
|
|
|
});
|
|
|
|
expect((meter.getValue() as number[]).length).to.equal(4);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
2019-09-09 21:53:39 +00:00
|
|
|
it("can be constructed with an object", () => {
|
|
|
|
const meter = new Meter({
|
2019-09-16 03:32:40 +00:00
|
|
|
smoothing: 0.3,
|
2019-09-09 21:53:39 +00:00
|
|
|
});
|
|
|
|
expect(meter.smoothing).to.equal(0.3);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("passes the audio through", () => {
|
|
|
|
return PassAudio((input) => {
|
|
|
|
const meter = new Meter().toDestination();
|
|
|
|
input.connect(meter);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-16 03:32:40 +00:00
|
|
|
it("warns of deprecated method", () => {
|
2019-09-09 23:27:45 +00:00
|
|
|
warns(() => {
|
|
|
|
const meter = new Meter().toDestination();
|
|
|
|
meter.getLevel();
|
|
|
|
meter.dispose();
|
2019-09-09 21:53:39 +00:00
|
|
|
});
|
2019-09-09 23:27:45 +00:00
|
|
|
});
|
2019-12-15 21:01:19 +00:00
|
|
|
|
2019-09-09 23:27:45 +00:00
|
|
|
if (ONLINE_TESTING) {
|
2019-12-15 21:01:19 +00:00
|
|
|
|
2019-09-09 21:53:39 +00:00
|
|
|
it("can get the rms level of the incoming signal", (done) => {
|
|
|
|
const meter = new Meter();
|
|
|
|
const osc = new Oscillator().connect(meter).start();
|
|
|
|
osc.volume.value = -6;
|
|
|
|
setTimeout(() => {
|
2019-09-09 23:27:45 +00:00
|
|
|
expect(meter.getValue()).to.be.closeTo(-9, 1);
|
2019-09-09 21:53:39 +00:00
|
|
|
meter.dispose();
|
|
|
|
osc.dispose();
|
|
|
|
done();
|
|
|
|
}, 400);
|
|
|
|
});
|
2019-12-15 21:01:19 +00:00
|
|
|
|
|
|
|
it("can get the values in normal range", (done) => {
|
|
|
|
const meter = new Meter({
|
|
|
|
normalRange: true,
|
|
|
|
});
|
|
|
|
const osc = new Oscillator().connect(meter).start();
|
|
|
|
osc.volume.value = -6;
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(meter.getValue()).to.be.closeTo(0.35, 0.15);
|
|
|
|
meter.dispose();
|
|
|
|
osc.dispose();
|
|
|
|
done();
|
|
|
|
}, 400);
|
|
|
|
});
|
2019-09-09 21:53:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|