2017-02-20 21:40:41 +00:00
|
|
|
define(["helper/ConstantOutput", "Tone/signal/Normalize", "helper/Basic",
|
|
|
|
"Test", "Tone/source/Oscillator", "Tone/signal/Signal", "helper/Offline"],
|
|
|
|
function (ConstantOutput, Normalize, Basic, Test, Oscillator, Signal, Offline) {
|
2015-08-24 21:29:19 +00:00
|
|
|
|
|
|
|
describe("Normalize", function(){
|
|
|
|
|
|
|
|
Basic(Normalize);
|
|
|
|
|
|
|
|
context("Normalizing", function(){
|
|
|
|
|
|
|
|
it("handles input and output connections", function(){
|
|
|
|
var norm = new Normalize();
|
|
|
|
Test.connect(norm);
|
|
|
|
norm.connect(Test);
|
|
|
|
norm.dispose();
|
|
|
|
});
|
|
|
|
|
2017-02-20 21:40:41 +00:00
|
|
|
it("normalizes an oscillator to 0,1", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new Oscillator(1000);
|
|
|
|
var norm = new Normalize(-1, 1);
|
2015-08-24 21:29:19 +00:00
|
|
|
osc.connect(norm);
|
2017-02-20 21:40:41 +00:00
|
|
|
norm.toMaster();
|
|
|
|
}).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample){
|
|
|
|
expect(sample).to.be.within(0, 1);
|
|
|
|
});
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 21:40:41 +00:00
|
|
|
it("normalizes an input at the max range to 1", function(){
|
|
|
|
return ConstantOutput(function(){
|
|
|
|
var sig = new Signal(1000);
|
|
|
|
var norm = new Normalize(0, 1000);
|
2015-08-24 21:29:19 +00:00
|
|
|
sig.connect(norm);
|
2017-02-20 21:40:41 +00:00
|
|
|
norm.toMaster();
|
|
|
|
}, 1);
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
|
2017-02-20 21:40:41 +00:00
|
|
|
it("normalizes an input at the min range to 0", function(){
|
|
|
|
return ConstantOutput(function(){
|
|
|
|
var sig = new Signal(-10);
|
|
|
|
var norm = new Normalize(-10, 1000);
|
2015-08-24 21:29:19 +00:00
|
|
|
sig.connect(norm);
|
2017-02-20 21:40:41 +00:00
|
|
|
norm.toMaster();
|
|
|
|
}, 0);
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
|
2017-02-20 21:40:41 +00:00
|
|
|
it("can set the min and max", function(){
|
|
|
|
return ConstantOutput(function(){
|
|
|
|
var sig = new Signal(10);
|
|
|
|
var norm = new Normalize(0, 1);
|
2015-08-24 21:29:19 +00:00
|
|
|
norm.min = 5;
|
|
|
|
norm.max = 15;
|
2017-05-08 15:48:47 +00:00
|
|
|
expect(norm.min).to.be.closeTo(5, 0.1);
|
|
|
|
expect(norm.max).to.be.closeTo(15, 0.1);
|
2015-08-24 21:29:19 +00:00
|
|
|
sig.connect(norm);
|
2017-02-20 21:40:41 +00:00
|
|
|
norm.toMaster();
|
|
|
|
}, 0.5);
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|