Tone.js/test/component/Volume.js

85 lines
2 KiB
JavaScript
Raw Normal View History

2015-08-28 22:42:44 +00:00
define(["Tone/component/Volume", "helper/Basic", "helper/Meter", "Test",
"Tone/signal/Signal", "helper/PassAudio", "helper/PassAudioStereo"],
function (Volume, Basic, Meter, Test, Signal, PassAudio, PassAudioStereo) {
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
});
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
});
it("passes the incoming signal through", function(done){
2015-11-01 22:50:14 +00:00
var vol;
2015-08-28 22:42:44 +00:00
PassAudio(function(input, output){
2015-11-01 22:50:14 +00:00
vol = new Volume();
input.connect(vol);
vol.connect(output);
2015-08-28 22:42:44 +00:00
}, function(){
2015-11-01 22:50:14 +00:00
vol.dispose();
2015-08-28 22:42:44 +00:00
done();
});
});
it("passes the incoming stereo signal through", function(done){
2015-11-01 22:50:14 +00:00
var vol;
2015-08-28 22:42:44 +00:00
PassAudioStereo(function(input, output){
2015-11-01 22:50:14 +00:00
vol = new Volume();
input.connect(vol);
vol.connect(output);
2015-08-28 22:42:44 +00:00
}, function(){
2015-11-01 22:50:14 +00:00
vol.dispose();
2015-08-28 22:42:44 +00:00
done();
});
});
it("can lower the volume", function(done){
2015-11-01 22:50:14 +00:00
var vol;
2015-08-28 22:42:44 +00:00
var signal;
var meter = new Meter();
meter.before(function(output){
2015-11-01 22:50:14 +00:00
vol = new Volume(-10).connect(output);
signal = new Signal(1).connect(vol);
2015-08-28 22:42:44 +00:00
});
meter.test(function(level){
2015-11-01 22:50:14 +00:00
expect(level).to.be.closeTo(vol.dbToGain(-10), 0.01);
2015-08-28 22:42:44 +00:00
});
meter.after(function(){
2015-11-01 22:50:14 +00:00
vol.dispose();
2015-08-28 22:42:44 +00:00
signal.dispose();
done();
});
meter.run();
});
});
});
});