2024-05-03 18:31:14 +00:00
|
|
|
import { PitchShift } from "./PitchShift.js";
|
|
|
|
import { BasicTests } from "../../test/helper/Basic.js";
|
|
|
|
import { EffectTests } from "../../test/helper/EffectTests.js";
|
2019-11-05 03:28:51 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { Oscillator } from "../source/oscillator/Oscillator.js";
|
|
|
|
import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
2019-11-05 03:28:51 +00:00
|
|
|
|
|
|
|
describe("PitchShift", () => {
|
|
|
|
BasicTests(PitchShift);
|
|
|
|
EffectTests(PitchShift);
|
|
|
|
|
|
|
|
it("matches a file", () => {
|
2024-05-03 18:31:14 +00:00
|
|
|
return CompareToFile(
|
|
|
|
() => {
|
|
|
|
const pitchShift = new PitchShift(4).toDestination();
|
|
|
|
const osc = new Oscillator()
|
|
|
|
.toDestination()
|
|
|
|
.connect(pitchShift);
|
|
|
|
osc.start(0);
|
|
|
|
},
|
|
|
|
"pitchShift.wav",
|
|
|
|
0.3
|
|
|
|
);
|
2019-11-05 03:28:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
context("API", () => {
|
|
|
|
it("can pass in options in the constructor", () => {
|
|
|
|
const pitchShift = new PitchShift({
|
|
|
|
windowSize: 0.2,
|
2024-05-03 18:31:14 +00:00
|
|
|
pitch: 2,
|
2019-11-05 03:28:51 +00:00
|
|
|
});
|
|
|
|
expect(pitchShift.windowSize).to.be.closeTo(0.2, 0.01);
|
|
|
|
expect(pitchShift.pitch).to.be.closeTo(2, 0.01);
|
|
|
|
pitchShift.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set positive and negative pitches", () => {
|
|
|
|
const pitchShift = new PitchShift();
|
|
|
|
pitchShift.pitch = 2;
|
|
|
|
expect(pitchShift.pitch).to.be.equal(2);
|
|
|
|
pitchShift.pitch = -2;
|
|
|
|
expect(pitchShift.pitch).to.be.equal(-2);
|
|
|
|
pitchShift.pitch = -4.5;
|
|
|
|
expect(pitchShift.pitch).to.be.equal(-4.5);
|
|
|
|
pitchShift.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can get/set the options", () => {
|
|
|
|
const pitchShift = new PitchShift();
|
|
|
|
pitchShift.set({
|
|
|
|
windowSize: 0.4,
|
|
|
|
});
|
|
|
|
expect(pitchShift.get().windowSize).to.be.closeTo(0.4, 0.01);
|
|
|
|
pitchShift.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set set the feedback and delay times", () => {
|
|
|
|
const pitchShift = new PitchShift({
|
|
|
|
delayTime: "4n",
|
2024-05-03 18:31:14 +00:00
|
|
|
feedback: 0.3,
|
2019-11-05 03:28:51 +00:00
|
|
|
});
|
2024-05-03 18:31:14 +00:00
|
|
|
expect(pitchShift.delayTime.value).to.be.closeTo(
|
|
|
|
pitchShift.toSeconds("4n"),
|
|
|
|
0.01
|
|
|
|
);
|
2019-11-05 03:28:51 +00:00
|
|
|
expect(pitchShift.feedback.value).to.be.closeTo(0.3, 0.01);
|
|
|
|
pitchShift.delayTime.value = 0.2;
|
|
|
|
expect(pitchShift.delayTime.value).to.be.closeTo(0.2, 0.01);
|
|
|
|
pitchShift.dispose();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|