2019-01-27 18:05:20 +00:00
|
|
|
import Analyser from "Tone/component/Analyser";
|
|
|
|
import Test from "helper/Test";
|
|
|
|
import Basic from "helper/Basic";
|
|
|
|
import Noise from "Tone/source/Noise";
|
2015-08-28 22:42:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
describe("Analyser", function(){
|
2015-08-28 22:42:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Basic(Analyser);
|
2015-08-28 22:42:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("handles input connection", function(){
|
|
|
|
var anl = new Analyser();
|
|
|
|
Test.connect(anl);
|
|
|
|
anl.dispose();
|
|
|
|
});
|
2015-08-28 22:42:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can get and set properties", function(){
|
|
|
|
var anl = new Analyser();
|
|
|
|
anl.set({
|
|
|
|
"size" : 32,
|
|
|
|
"smoothing" : 0.2
|
|
|
|
});
|
|
|
|
var values = anl.get();
|
|
|
|
expect(values.size).to.equal(32);
|
|
|
|
expect(values.smoothing).to.equal(0.2);
|
|
|
|
anl.dispose();
|
|
|
|
});
|
2017-08-30 18:42:50 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can correctly set the size", function(){
|
|
|
|
var anl = new Analyser("fft", 512);
|
|
|
|
expect(anl.size).to.equal(512);
|
|
|
|
anl.size = 1024;
|
|
|
|
expect(anl.size).to.equal(1024);
|
|
|
|
anl.dispose();
|
|
|
|
});
|
2015-08-28 22:42:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can run fft analysis", function(){
|
|
|
|
var anl = new Analyser("fft", 512);
|
|
|
|
var analysis = anl.getValue();
|
|
|
|
expect(analysis.length).to.equal(512);
|
|
|
|
for (var i = 0; i < analysis.length; i++){
|
|
|
|
expect(analysis[i]).is.lessThan(0);
|
|
|
|
}
|
|
|
|
anl.dispose();
|
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can run waveform analysis", function(done){
|
|
|
|
var noise = new Noise();
|
|
|
|
var anl = new Analyser("waveform", 256);
|
|
|
|
noise.connect(anl);
|
|
|
|
noise.start();
|
2017-07-08 15:21:39 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
var analysis = anl.getValue();
|
|
|
|
expect(analysis.length).to.equal(256);
|
|
|
|
for (var i = 0; i < analysis.length; i++){
|
|
|
|
expect(analysis[i]).is.within(-1, 1);
|
|
|
|
}
|
|
|
|
anl.dispose();
|
|
|
|
noise.dispose();
|
|
|
|
done();
|
|
|
|
}, 300);
|
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("throws an error if an invalid type is set", function(){
|
|
|
|
var anl = new Analyser("fft", 512);
|
|
|
|
expect(function(){
|
|
|
|
anl.type = "invalid";
|
|
|
|
}).to.throw(Error);
|
|
|
|
anl.dispose();
|
2015-08-28 22:42:08 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|