Tone.js/test/signal/AudioToGain.js
2015-08-24 11:17:21 -04:00

100 lines
No EOL
2.3 KiB
JavaScript

define(["helper/Offline", "Tone/signal/AudioToGain", "helper/Basic",
"Test", "Tone/source/Oscillator", "Tone/signal/Signal"],
function (Offline, AudioToGain, Basic, Test, Oscillator, Signal) {
describe("AudioToGain", function(){
Basic(AudioToGain);
it("handles input and output connections", function(){
var a2g = new AudioToGain();
a2g.connect(Test);
Test.connect(a2g);
a2g.dispose();
});
it("normalizes an oscillator to 0,1", function(done){
//make an oscillator to drive the signal
var osc, a2g;
var offline = new Offline();
offline.before(function(dest){
osc = new Oscillator(1000);
a2g = new AudioToGain();
osc.connect(a2g);
a2g.connect(dest);
});
offline.test(function(sample){
expect(sample).to.be.within(0, 1);
});
offline.after(function(){
osc.dispose();
a2g.dispose();
done();
});
offline.run();
});
it("outputs 0.5 for an input value of 0", function(done){
//make an oscillator to drive the signal
var sig, a2g;
var offline = new Offline();
offline.before(function(dest){
sig = new Signal(0);
a2g = new AudioToGain();
sig.connect(a2g);
a2g.connect(dest);
});
offline.test(function(sample){
expect(sample).to.be.closeTo(0.5, 0.01);
});
offline.after(function(){
sig.dispose();
a2g.dispose();
done();
});
offline.run();
});
it("outputs 1 for an input value of 1", function(done){
//make an oscillator to drive the signal
var sig, a2g;
var offline = new Offline();
offline.before(function(dest){
sig = new Signal(1);
a2g = new AudioToGain();
sig.connect(a2g);
a2g.connect(dest);
});
offline.test(function(sample){
expect(sample).to.be.closeTo(1, 0.01);
});
offline.after(function(){
sig.dispose();
a2g.dispose();
done();
});
offline.run();
});
it("outputs 0 for an input value of -1", function(done){
//make an oscillator to drive the signal
var sig, a2g;
var offline = new Offline();
offline.before(function(dest){
sig = new Signal(-1);
a2g = new AudioToGain();
sig.connect(a2g);
a2g.connect(dest);
});
offline.test(function(sample){
expect(sample).to.be.closeTo(0, 0.01);
});
offline.after(function(){
sig.dispose();
a2g.dispose();
done();
});
offline.run();
});
});
});