2019-09-09 22:24:07 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
import { BasicTests } from "test/helper/Basic";
|
2019-09-09 23:27:45 +00:00
|
|
|
import { ONLINE_TESTING } from "test/helper/Supports";
|
2019-09-09 22:24:07 +00:00
|
|
|
import { Noise } from "Tone/source/Noise";
|
|
|
|
import { FFT } from "./FFT";
|
|
|
|
|
|
|
|
describe("FFT", () => {
|
|
|
|
|
|
|
|
BasicTests(FFT);
|
|
|
|
|
|
|
|
it("can get and set properties", () => {
|
|
|
|
const fft = new FFT();
|
|
|
|
fft.set({
|
2019-09-16 03:32:40 +00:00
|
|
|
size: 128,
|
2019-09-09 22:24:07 +00:00
|
|
|
smoothing: 0.4,
|
|
|
|
});
|
|
|
|
const values = fft.get();
|
|
|
|
expect(values.size).to.equal(128);
|
|
|
|
expect(values.smoothing).to.equal(0.4);
|
|
|
|
fft.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can correctly set the size", () => {
|
|
|
|
const fft = new FFT(512);
|
|
|
|
expect(fft.size).to.equal(512);
|
|
|
|
fft.size = 1024;
|
|
|
|
expect(fft.size).to.equal(1024);
|
|
|
|
fft.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can set the smoothing", () => {
|
|
|
|
const fft = new FFT(512);
|
|
|
|
fft.smoothing = 0.2;
|
|
|
|
expect(fft.smoothing).to.equal(0.2);
|
|
|
|
fft.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can run waveform analysis", (done) => {
|
|
|
|
const noise = new Noise();
|
|
|
|
const fft = new FFT(256);
|
|
|
|
noise.connect(fft);
|
|
|
|
noise.start();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const analysis = fft.getValue();
|
|
|
|
expect(analysis.length).to.equal(256);
|
|
|
|
analysis.forEach(value => {
|
|
|
|
expect(value).is.within(-Infinity, 0);
|
|
|
|
});
|
|
|
|
fft.dispose();
|
|
|
|
noise.dispose();
|
|
|
|
done();
|
|
|
|
}, 300);
|
|
|
|
});
|
2019-09-09 22:30:53 +00:00
|
|
|
|
2019-09-09 23:27:45 +00:00
|
|
|
if (ONLINE_TESTING) {
|
|
|
|
it("outputs a normal range", (done) => {
|
|
|
|
const noise = new Noise();
|
|
|
|
const fft = new FFT({
|
2019-09-16 03:32:40 +00:00
|
|
|
normalRange: true,
|
2019-09-09 22:30:53 +00:00
|
|
|
});
|
2019-09-09 23:27:45 +00:00
|
|
|
noise.connect(fft);
|
|
|
|
noise.start();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const analysis = fft.getValue();
|
|
|
|
analysis.forEach(value => {
|
|
|
|
expect(value).is.within(0, 1);
|
|
|
|
});
|
|
|
|
fft.dispose();
|
|
|
|
noise.dispose();
|
|
|
|
done();
|
|
|
|
}, 300);
|
|
|
|
});
|
|
|
|
}
|
2019-09-09 22:24:07 +00:00
|
|
|
});
|