2017-02-20 04:55:55 +00:00
|
|
|
define(["Tone/component/Volume", "helper/Basic", "helper/Offline", "Test",
|
2015-08-28 22:42:44 +00:00
|
|
|
"Tone/signal/Signal", "helper/PassAudio", "helper/PassAudioStereo"],
|
2017-02-20 04:55:55 +00:00
|
|
|
function (Volume, Basic, Offline, Test, Signal, PassAudio, PassAudioStereo) {
|
2015-08-28 22:42:44 +00:00
|
|
|
describe("Volume", function(){
|
|
|
|
|
|
|
|
Basic(Volume);
|
|
|
|
|
|
|
|
context("Volume", function(){
|
|
|
|
|
|
|
|
it("handles input and output connections", function(){
|
2015-11-01 22:50:14 +00:00
|
|
|
var vol = new Volume();
|
|
|
|
Test.connect(vol);
|
|
|
|
vol.connect(Test);
|
|
|
|
vol.dispose();
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
|
2015-11-01 22:50:14 +00:00
|
|
|
it("can be constructed with volume value", function(){
|
|
|
|
var vol = new Volume(-12);
|
|
|
|
expect(vol.volume.value).to.be.closeTo(-12, 0.1);
|
|
|
|
vol.dispose();
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("can be constructed with an options object", function(){
|
2015-11-01 22:50:14 +00:00
|
|
|
var vol = new Volume({
|
|
|
|
"volume" : 2
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2015-11-01 22:50:14 +00:00
|
|
|
expect(vol.volume.value).to.be.closeTo(2, 0.1);
|
|
|
|
vol.dispose();
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
|
2016-05-14 21:46:21 +00:00
|
|
|
it("can be constructed with an options object and muted", function(){
|
|
|
|
var vol = new Volume({
|
|
|
|
"mute" : true
|
|
|
|
});
|
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
vol.dispose();
|
|
|
|
});
|
|
|
|
|
2015-08-28 22:42:44 +00:00
|
|
|
it("can set/get with an object", function(){
|
2015-11-01 22:50:14 +00:00
|
|
|
var vol = new Volume();
|
|
|
|
vol.set({
|
|
|
|
"volume" : -10
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2015-11-01 22:50:14 +00:00
|
|
|
expect(vol.get().volume).to.be.closeTo(-10, 0.1);
|
|
|
|
vol.dispose();
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
|
2016-05-14 21:34:23 +00:00
|
|
|
it("unmuting returns to previous volume", function(){
|
|
|
|
var vol = new Volume(-10);
|
|
|
|
vol.mute = true;
|
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
expect(vol.volume.value).to.equal(-Infinity);
|
|
|
|
vol.mute = false;
|
|
|
|
//returns the volume to what it was
|
|
|
|
expect(vol.volume.value).to.be.closeTo(-10, 0.1);
|
|
|
|
vol.dispose();
|
|
|
|
});
|
|
|
|
|
2017-02-20 04:55:55 +00:00
|
|
|
it("passes the incoming signal through", function(){
|
|
|
|
return PassAudio(function(input){
|
|
|
|
var vol = new Volume().toMaster();
|
2015-11-01 22:50:14 +00:00
|
|
|
input.connect(vol);
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 04:55:55 +00:00
|
|
|
it("passes the incoming stereo signal through", function(){
|
|
|
|
return PassAudioStereo(function(input){
|
|
|
|
var vol = new Volume().toMaster();
|
2015-11-01 22:50:14 +00:00
|
|
|
input.connect(vol);
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 04:55:55 +00:00
|
|
|
it("can lower the volume", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var vol = new Volume(-10).toMaster();
|
|
|
|
new Signal(1).connect(vol);
|
|
|
|
}).then(function(buffer){
|
|
|
|
buffer.getRMS().forEach(function(level){
|
|
|
|
expect(level).to.be.closeTo(0.315, 0.01);
|
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 04:55:55 +00:00
|
|
|
it("can mute the volume", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var vol = new Volume(0).toMaster();
|
|
|
|
new Signal(1).connect(vol);
|
2016-05-14 21:34:23 +00:00
|
|
|
vol.mute = true;
|
2017-02-20 04:55:55 +00:00
|
|
|
}).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
2016-05-14 21:34:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-26 20:42:35 +00:00
|
|
|
it("muted when volume is set to -Infinity", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var vol = new Volume(-Infinity).toMaster();
|
|
|
|
new Signal(1).connect(vol);
|
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
}).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-24 21:27:40 +00:00
|
|
|
it("setting the volume unmutes it and reports itself as unmuted", function(){
|
|
|
|
var vol = new Volume(0).toMaster();
|
|
|
|
vol.mute = true;
|
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
vol.volume.value = 0
|
|
|
|
expect(vol.mute).to.be.false;
|
|
|
|
vol.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("multiple calls to mute still return the vol to the original", function(){
|
|
|
|
var vol = new Volume(-20);
|
|
|
|
vol.mute = true;
|
|
|
|
vol.mute = true;
|
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
expect(vol.volume.value).to.equal(-Infinity);
|
|
|
|
vol.mute = false;
|
|
|
|
vol.mute = false;
|
|
|
|
expect(vol.volume.value).to.be.closeTo(-20, 0.5);
|
|
|
|
vol.dispose();
|
|
|
|
});
|
|
|
|
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|