Tone.js/Tone/core/context/Destination.test.ts

88 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-06-23 19:03:04 +00:00
import { expect } from "chai";
import { warns } from "../../../test/helper/Basic.js";
import { Offline } from "../../../test/helper/Offline.js";
import { PassAudio } from "../../../test/helper/PassAudio.js";
import { Oscillator } from "../../source/oscillator/Oscillator.js";
import { getContext } from "../Global.js";
import { DestinationClass } from "./Destination.js";
2019-06-23 19:03:04 +00:00
describe("Destination", () => {
it("creates itself on the context", () => {
expect(getContext().destination).instanceOf(DestinationClass);
2019-06-23 19:03:04 +00:00
});
it("can be muted and unmuted", () => {
return Offline((context) => {
2019-06-23 19:03:04 +00:00
context.destination.mute = false;
expect(context.destination.mute).to.equal(false);
context.destination.mute = true;
expect(context.destination.mute).to.equal(true);
});
});
it("passes audio through", () => {
return PassAudio((input) => {
2019-06-23 19:03:04 +00:00
input.toDestination();
});
});
it("passes no audio when muted", () => {
return Offline((context) => {
new Oscillator().toDestination().start(0);
context.destination.mute = true;
}).then((buffer) => {
2019-06-23 19:03:04 +00:00
expect(buffer.isSilent()).to.equal(true);
});
});
it("has a master volume control", () => {
return Offline((context) => {
context.destination.volume.value = -20;
expect(context.destination.volume.value).to.be.closeTo(-20, 0.1);
});
});
2019-09-10 03:38:34 +00:00
it("warns when toMaster is called", () => {
warns(() => {
const osc = new Oscillator().toMaster();
osc.dispose();
});
});
2020-03-02 03:03:37 +00:00
it("can get the maxChannelCount", () => {
return Offline(
(context) => {
expect(context.destination.maxChannelCount).to.equal(4);
},
0.1,
4
);
2020-03-02 03:03:37 +00:00
});
it("can set the audio channel configuration", () => {
return Offline(
(context) => {
expect(context.destination.channelCount).to.equal(4);
context.destination.channelCountMode = "explicit";
context.destination.channelInterpretation = "discrete";
expect(context.destination.channelCountMode).to.equal(
"explicit"
);
expect(context.destination.channelInterpretation).to.equal(
"discrete"
);
},
0.1,
4
);
2020-03-02 03:03:37 +00:00
});
2019-06-23 19:03:04 +00:00
it("can pass audio through chained nodes", () => {
return PassAudio((input) => {
2019-06-23 19:03:04 +00:00
const gain = input.context.createGain();
input.connect(gain);
input.context.destination.chain(gain);
});
});
});