Tone.js/test/component/Meter.js

70 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-08-28 22:42:44 +00:00
define(["Tone/component/Meter", "helper/Basic", "helper/Offline", "Test",
"Tone/signal/Signal", "helper/PassAudio", "Tone/type/Type",
"Tone/component/Merge", "Tone/source/Oscillator"],
function (Meter, Basic, Offline, Test, Signal, PassAudio, Tone, Merge, Oscillator) {
2015-08-28 22:42:44 +00:00
describe("Meter", function(){
Basic(Meter);
context("Metering", function(){
it("handles input and output connections", function(){
var meter = new Meter();
Test.connect(meter);
meter.connect(Test);
meter.dispose();
});
it("handles getter/setter as Object", function(){
var meter = new Meter();
var values = {
"type" : "signal",
"smoothing" : 0.2
2015-08-28 22:42:44 +00:00
};
meter.set(values);
expect(meter.get().type).to.equal("signal");
expect(meter.get().smoothing).to.equal(0.2);
2015-08-28 22:42:44 +00:00
meter.dispose();
});
it("can be constructed with an object", function(){
var meter = new Meter({
"smoothing" : 0.3
});
expect(meter.smoothing).to.equal(0.3);
meter.dispose();
});
it("passes the audio through", function(){
2015-08-28 22:42:44 +00:00
var meter;
return PassAudio(function(input){
meter = new Meter();
input.chain(meter, Tone.Master);
2015-08-28 22:42:44 +00:00
});
});
it("measures the incoming signal", function(done){
var meter = new Meter("signal");
var signal = new Signal(1).connect(meter);
2015-08-28 22:42:44 +00:00
setTimeout(function(){
expect(meter.value).to.be.closeTo(1, 0.05);
2015-08-28 22:42:44 +00:00
meter.dispose();
signal.dispose();
done();
}, 400);
});
it("can get the level of the incoming signal", function(done){
2015-08-28 22:42:44 +00:00
var meter = new Meter();
var osc = new Oscillator().connect(meter).start();
2016-05-18 01:27:08 +00:00
osc.volume.value = -6;
2015-08-28 22:42:44 +00:00
setTimeout(function(){
2016-05-18 01:27:08 +00:00
expect(meter.value).to.be.closeTo(1, 0.1);
2015-08-28 22:42:44 +00:00
meter.dispose();
osc.dispose();
2015-08-28 22:42:44 +00:00
done();
}, 400);
});
});
});
});