2019-01-27 18:05:20 +00:00
|
|
|
import Volume from "Tone/component/Volume";
|
|
|
|
import Basic from "helper/Basic";
|
|
|
|
import Offline from "helper/Offline";
|
|
|
|
import Test from "helper/Test";
|
|
|
|
import Signal from "Tone/signal/Signal";
|
|
|
|
import PassAudio from "helper/PassAudio";
|
|
|
|
import PassAudioStereo from "helper/PassAudioStereo";
|
|
|
|
describe("Volume", function(){
|
|
|
|
|
|
|
|
Basic(Volume);
|
|
|
|
|
|
|
|
context("Volume", function(){
|
|
|
|
|
|
|
|
it("handles input and output connections", function(){
|
|
|
|
var vol = new Volume();
|
|
|
|
Test.connect(vol);
|
|
|
|
vol.connect(Test);
|
|
|
|
vol.dispose();
|
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +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();
|
|
|
|
});
|
2016-05-14 21:46:21 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be constructed with an options object", function(){
|
|
|
|
var vol = new Volume({
|
|
|
|
"volume" : 2
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(vol.volume.value).to.be.closeTo(2, 0.1);
|
|
|
|
vol.dispose();
|
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be constructed with an options object and muted", function(){
|
|
|
|
var vol = new Volume({
|
|
|
|
"mute" : true
|
2016-05-14 21:34:23 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(vol.mute).to.be.true;
|
|
|
|
vol.dispose();
|
|
|
|
});
|
2016-05-14 21:34:23 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can set/get with an object", function(){
|
|
|
|
var vol = new Volume();
|
|
|
|
vol.set({
|
|
|
|
"volume" : -10
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(vol.get().volume).to.be.closeTo(-10, 0.1);
|
|
|
|
vol.dispose();
|
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +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();
|
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("passes the incoming signal through", function(){
|
|
|
|
return PassAudio(function(input){
|
|
|
|
var vol = new Volume().toMaster();
|
|
|
|
input.connect(vol);
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("passes the incoming stereo signal through", function(){
|
|
|
|
return PassAudioStereo(function(input){
|
|
|
|
var vol = new Volume().toMaster();
|
|
|
|
input.connect(vol);
|
2016-05-14 21:34:23 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-05-14 21:34:23 +00:00
|
|
|
|
2019-01-27 18:05:20 +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);
|
2017-03-26 20:42:35 +00:00
|
|
|
});
|
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2017-03-26 20:42:35 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can mute the volume", function(){
|
|
|
|
return Offline(function(){
|
2017-03-24 21:27:40 +00:00
|
|
|
var vol = new Volume(0).toMaster();
|
2019-01-27 18:05:20 +00:00
|
|
|
new Signal(1).connect(vol);
|
2017-03-24 21:27:40 +00:00
|
|
|
vol.mute = true;
|
2019-01-27 18:05:20 +00:00
|
|
|
}).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
2017-03-24 21:27:40 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2017-03-24 21:27:40 +00:00
|
|
|
|
2019-01-27 18:05:20 +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);
|
2017-03-24 21:27:40 +00:00
|
|
|
expect(vol.mute).to.be.true;
|
2019-01-27 18:05:20 +00:00
|
|
|
}).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
2017-03-24 21:27:40 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2017-03-24 21:27:40 +00:00
|
|
|
|
2019-01-27 18:05:20 +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();
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|
|
|
|
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
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|