Tone.js/test/component/Follower.js

117 lines
4 KiB
JavaScript
Raw Normal View History

2018-05-18 16:07:20 +00:00
define(["Tone/component/Follower", "helper/Basic", "helper/Offline", "helper/Test",
2017-10-26 04:48:51 +00:00
"Tone/signal/Signal", "helper/PassAudio", "helper/PassAudioStereo"],
2018-05-18 16:07:20 +00:00
function(Follower, Basic, Offline, Test, Signal, PassAudio, PassAudioStereo){
2015-08-28 22:42:44 +00:00
describe("Follower", function(){
Basic(Follower);
context("Envelope Following", function(){
it("handles input and output connections", function(){
var follower = new Follower();
Test.connect(follower);
follower.connect(Test);
follower.dispose();
});
it("handles getter/setter as Object", function(){
var foll = new Follower();
var values = {
2018-06-06 02:14:46 +00:00
"smoothing" : 0.2,
2015-08-28 22:42:44 +00:00
};
foll.set(values);
2018-06-06 02:14:46 +00:00
expect(foll.get()).to.have.keys(["smoothing"]);
expect(foll.get().smoothing).to.be.closeTo(0.2, 0.001);
2015-08-28 22:42:44 +00:00
foll.dispose();
});
it("can be constructed with an object", function(){
var follower = new Follower({
2018-06-06 02:14:46 +00:00
"smoothing" : 0.5,
2015-08-28 22:42:44 +00:00
});
2018-06-06 02:14:46 +00:00
expect(follower.smoothing).to.be.closeTo(0.5, 0.001);
2015-08-28 22:42:44 +00:00
follower.dispose();
});
2018-06-06 02:14:46 +00:00
it("smoothes the incoming signal at 0.1", function(){
return Offline(function(){
2018-06-06 02:14:46 +00:00
var foll = new Follower(0.1).toMaster();
var sig = new Signal(0);
2015-08-28 22:42:44 +00:00
sig.connect(foll);
sig.setValueAtTime(1, 0.1);
2018-06-06 02:14:46 +00:00
sig.setValueAtTime(0, 0.3);
}, 0.41).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.0, 0.01);
expect(buffer.getValueAtTime(0.15)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.2)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.3)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.35)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.4)).to.be.closeTo(0, 0.2);
2015-08-28 22:42:44 +00:00
});
});
2018-06-06 02:14:46 +00:00
it("smoothes the incoming signal at 0.05", function(){
return Offline(function(){
var foll = new Follower(0.05).toMaster();
var sig = new Signal(0);
2015-08-28 22:42:44 +00:00
sig.connect(foll);
2018-06-06 02:14:46 +00:00
sig.setValueAtTime(1, 0.1);
sig.setValueAtTime(0, 0.3);
}, 0.41).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.0, 0.01);
expect(buffer.getValueAtTime(0.125)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.15)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.3)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.325)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.35)).to.be.closeTo(0, 0.2);
});
2018-06-06 02:14:46 +00:00
});
it("smoothes the incoming signal at 0.2", function(){
return Offline(function(){
var foll = new Follower(0.2).toMaster();
var sig = new Signal(0);
sig.connect(foll);
sig.setValueAtTime(1, 0.1);
sig.setValueAtTime(0, 0.3);
}, 0.51).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.0, 0.01);
expect(buffer.getValueAtTime(0.2)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.3)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.4)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.5)).to.be.closeTo(0, 0.2);
});
2018-06-06 02:14:46 +00:00
});
2018-06-06 03:03:37 +00:00
/*it("smoothes the incoming signal at 0.5", function(){
2018-06-06 02:14:46 +00:00
return Offline(function(){
var foll = new Follower(0.5).toMaster();
var sig = new Signal(0);
sig.connect(foll);
sig.setValueAtTime(1, 0.1);
sig.setValueAtTime(0, 0.6);
}, 1.11).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.01);
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.0, 0.01);
expect(buffer.getValueAtTime(0.35)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(0.6)).to.be.closeTo(1, 0.2);
expect(buffer.getValueAtTime(0.85)).to.be.closeTo(0.5, 0.2);
expect(buffer.getValueAtTime(1.1)).to.be.closeTo(0, 0.2);
2015-08-28 22:42:44 +00:00
});
2018-06-06 03:03:37 +00:00
});*/
2015-08-28 22:42:44 +00:00
it("passes the incoming signal through", function(){
var follower;
return PassAudio(function(input){
follower = new Follower().toMaster();
input.connect(follower);
2015-08-28 22:42:44 +00:00
});
});
2015-08-28 22:42:44 +00:00
});
});
});