Tone.js/test/core/Gain.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-02-19 20:29:01 +00:00
define(["Test", "Tone/core/Gain", "Tone/core/Tone", "helper/PassAudio"],
function (Test, Gain, Tone, PassAudio) {
2015-08-16 18:23:40 +00:00
describe("Gain", function(){
it ("can be created and disposed", function(){
var gain = new Gain();
gain.dispose();
Test.wasDisposed(gain);
});
it("handles input and output connections", function(){
var gain = new Gain();
gain.connect(Test);
Test.connect(gain);
Test.connect(gain.gain);
gain.dispose();
});
it("can set the gain value", function(){
var gain = new Gain();
gain.gain.value = 0.2;
expect(gain.gain.value).to.be.closeTo(0.2, 0.001);
gain.dispose();
});
it("can be constructed with options object", function(){
2015-10-21 14:55:56 +00:00
2015-08-16 18:23:40 +00:00
var gain = new Gain({
2015-11-01 22:50:14 +00:00
"gain" : 0.4
2015-08-16 18:23:40 +00:00
});
expect(gain.gain.value).to.be.closeTo(0.4, 0.001);
gain.dispose();
});
it("can be constructed with an initial value", function(){
var gain = new Gain(3);
expect(gain.gain.value).to.be.closeTo(3, 0.001);
gain.dispose();
});
2015-10-21 14:55:56 +00:00
it("can set the units", function(){
var gain = new Gain(0, Tone.Type.Decibels);
2015-11-01 22:50:14 +00:00
expect(gain.gain.value).to.be.closeTo(0, 0.001);
expect(gain.gain.units).to.equal(Tone.Type.Decibels);
2015-10-21 14:55:56 +00:00
gain.dispose();
});
2015-08-16 18:23:40 +00:00
it("can get the value using 'get'", function(){
var gain = new Gain(5);
var value = gain.get();
2015-11-01 22:50:14 +00:00
expect(value.gain).to.be.closeTo(5, 0.001);
2015-10-21 14:55:56 +00:00
gain.dispose();
});
it("can set the value using 'set'", function(){
var gain = new Gain(5);
2015-11-01 22:50:14 +00:00
gain.set("gain", 4);
2015-10-21 14:55:56 +00:00
expect(gain.gain.value).to.be.closeTo(4, 0.001);
2015-08-16 18:23:40 +00:00
gain.dispose();
});
2017-02-19 20:29:01 +00:00
it ("passes audio through", function(){
return PassAudio(function(input){
var gain = new Gain().toMaster();
input.connect(gain);
2015-08-16 18:23:40 +00:00
});
});
});
});