Tone.js/Tone/effect/FrequencyShifter.test.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-08-21 04:57:45 +00:00
import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { CompareToFile } from "test/helper/CompareToFile";
2019-08-21 05:23:01 +00:00
import { EffectTests } from "test/helper/EffectTests";
2019-08-21 04:57:45 +00:00
import { Offline } from "test/helper/Offline";
import { Oscillator } from "Tone/source/oscillator/Oscillator";
import { FrequencyShifter } from "./FrequencyShifter";
describe("FrequencyShifter", () => {
BasicTests(FrequencyShifter);
2019-08-21 05:23:01 +00:00
EffectTests(FrequencyShifter);
2019-08-21 04:57:45 +00:00
it("matches a file", () => {
return CompareToFile(() => {
const shifter = new FrequencyShifter().toDestination();
shifter.frequency.value = -60;
const osc = new Oscillator().connect(shifter);
osc.start(0);
}, "frequencyShifter.wav", 0.1);
});
context("API", () => {
it("can pass in options in the constructor", () => {
const shifter = new FrequencyShifter({
2019-09-14 22:12:44 +00:00
frequency: -20,
2019-08-21 04:57:45 +00:00
});
expect(shifter.frequency.value).to.be.closeTo(-20, 0.001);
shifter.dispose();
});
it("can get/set the options", () => {
const shifter = new FrequencyShifter();
shifter.set({
2019-09-14 22:12:44 +00:00
frequency: 40,
2019-08-21 04:57:45 +00:00
});
expect(shifter.get().frequency).to.be.closeTo(40, 0.001);
shifter.dispose();
});
it("passes audio from input to output", () => {
return Offline(() => {
const osc = new Oscillator();
osc.start(0).stop(0.1);
const shifter = new FrequencyShifter(0.2).toDestination();
osc.connect(shifter);
}, 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);
});
});
});
});