Tone.js/test/component/Volume.js

132 lines
3.3 KiB
JavaScript
Raw Normal View History

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
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();
});
it("can be constructed with an options object", function(){
var vol = new Volume({
"volume" : 2
2015-08-28 22:42:44 +00:00
});
expect(vol.volume.value).to.be.closeTo(2, 0.1);
vol.dispose();
});
2015-08-28 22:42:44 +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
});
expect(vol.mute).to.be.true;
vol.dispose();
});
2016-05-14 21:34:23 +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
});
expect(vol.get().volume).to.be.closeTo(-10, 0.1);
vol.dispose();
});
2015-08-28 22:42:44 +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
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
});
});
2015-08-28 22:42:44 +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
});
});
2016-05-14 21:34:23 +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);
});
});
});
it("can mute the volume", function(){
return Offline(function(){
var vol = new Volume(0).toMaster();
new Signal(1).connect(vol);
vol.mute = true;
}).then(function(buffer){
expect(buffer.isSilent()).to.be.true;
});
});
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;
});
});
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
});
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
});