2018-05-18 16:07:20 +00:00
|
|
|
define(["Tone/component/Meter", "helper/Basic", "helper/Offline", "helper/Test",
|
2017-08-31 14:56:19 +00:00
|
|
|
"Tone/signal/Signal", "helper/PassAudio", "Tone/type/Type",
|
2017-11-29 20:05:12 +00:00
|
|
|
"Tone/component/Merge", "Tone/source/Oscillator", "helper/Supports"],
|
2018-05-18 16:07:20 +00:00
|
|
|
function(Meter, Basic, Offline, Test, Signal, PassAudio, Tone, Merge, Oscillator, Supports){
|
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 = {
|
2016-05-14 23:13:50 +00:00
|
|
|
"smoothing" : 0.2
|
2015-08-28 22:42:44 +00:00
|
|
|
};
|
|
|
|
meter.set(values);
|
2016-05-14 23:13:50 +00:00
|
|
|
expect(meter.get().smoothing).to.equal(0.2);
|
2015-08-28 22:42:44 +00:00
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
2018-05-17 15:40:59 +00:00
|
|
|
it("can be constructed with the smoothing", function(){
|
|
|
|
var meter = new Meter(0.5);
|
|
|
|
expect(meter.smoothing).to.equal(0.5);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
2015-08-28 22:42:44 +00:00
|
|
|
it("can be constructed with an object", function(){
|
|
|
|
var meter = new Meter({
|
|
|
|
"smoothing" : 0.3
|
|
|
|
});
|
|
|
|
expect(meter.smoothing).to.equal(0.3);
|
|
|
|
meter.dispose();
|
|
|
|
});
|
|
|
|
|
2017-02-20 04:55:55 +00:00
|
|
|
it("passes the audio through", function(){
|
2015-08-28 22:42:44 +00:00
|
|
|
var meter;
|
2017-02-20 04:55:55 +00:00
|
|
|
return PassAudio(function(input){
|
2016-05-14 23:13:50 +00:00
|
|
|
meter = new Meter();
|
2017-02-20 04:55:55 +00:00
|
|
|
input.chain(meter, Tone.Master);
|
2017-08-31 14:56:19 +00:00
|
|
|
});
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
2018-05-16 14:41:02 +00:00
|
|
|
|
2017-11-29 20:05:12 +00:00
|
|
|
if (Supports.ONLINE_TESTING){
|
2018-05-17 15:40:59 +00:00
|
|
|
|
2018-05-16 14:41:02 +00:00
|
|
|
it("measures the rms incoming signal", function(done){
|
2017-11-29 20:05:12 +00:00
|
|
|
var meter = new Meter();
|
|
|
|
var signal = new Signal(1).connect(meter);
|
|
|
|
setTimeout(function(){
|
|
|
|
expect(meter.getValue()).to.be.closeTo(1, 0.05);
|
|
|
|
meter.dispose();
|
|
|
|
signal.dispose();
|
|
|
|
done();
|
|
|
|
}, 400);
|
|
|
|
});
|
|
|
|
|
2018-05-16 14:41:02 +00:00
|
|
|
it("can get the rms level of the incoming signal", function(done){
|
2017-11-29 20:05:12 +00:00
|
|
|
var meter = new Meter();
|
|
|
|
var osc = new Oscillator().connect(meter).start();
|
|
|
|
osc.volume.value = -6;
|
|
|
|
setTimeout(function(){
|
2018-05-16 14:41:02 +00:00
|
|
|
expect(meter.getLevel()).to.be.closeTo(-9, 1);
|
2017-11-29 20:05:12 +00:00
|
|
|
meter.dispose();
|
|
|
|
osc.dispose();
|
|
|
|
done();
|
|
|
|
}, 400);
|
|
|
|
});
|
|
|
|
}
|
2015-08-28 22:42:44 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-31 14:56:19 +00:00
|
|
|
});
|