2019-01-27 18:05:20 +00:00
|
|
|
import ConstantOutput from "helper/ConstantOutput";
|
|
|
|
import Normalize from "Tone/signal/Normalize";
|
|
|
|
import Basic from "helper/Basic";
|
|
|
|
import Test from "helper/Test";
|
|
|
|
import Oscillator from "Tone/source/Oscillator";
|
|
|
|
import Signal from "Tone/signal/Signal";
|
|
|
|
import Offline from "helper/Offline";
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
describe("Normalize", function(){
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Basic(Normalize);
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
context("Normalizing", function(){
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("handles input and output connections", function(){
|
|
|
|
var norm = new Normalize();
|
|
|
|
Test.connect(norm);
|
|
|
|
norm.connect(Test);
|
|
|
|
norm.dispose();
|
|
|
|
});
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("normalizes an oscillator to 0,1", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new Oscillator(1000);
|
|
|
|
var norm = new Normalize(-1, 1);
|
|
|
|
osc.connect(norm);
|
|
|
|
norm.toMaster();
|
|
|
|
}).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample){
|
|
|
|
expect(sample).to.be.within(0, 1);
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +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);
|
|
|
|
sig.connect(norm);
|
|
|
|
norm.toMaster();
|
|
|
|
}, 1);
|
|
|
|
});
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +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);
|
|
|
|
sig.connect(norm);
|
|
|
|
norm.toMaster();
|
|
|
|
}, 0);
|
|
|
|
});
|
2015-08-24 21:29:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can set the min and max", function(){
|
|
|
|
return ConstantOutput(function(){
|
|
|
|
var sig = new Signal(10);
|
|
|
|
var norm = new Normalize(0, 1);
|
|
|
|
norm.min = 5;
|
|
|
|
norm.max = 15;
|
|
|
|
expect(norm.min).to.be.closeTo(5, 0.1);
|
|
|
|
expect(norm.max).to.be.closeTo(15, 0.1);
|
|
|
|
sig.connect(norm);
|
|
|
|
norm.toMaster();
|
|
|
|
}, 0.5);
|
2015-08-24 21:29:19 +00:00
|
|
|
});
|
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|