2017-10-26 04:42:51 +00:00
|
|
|
define(["helper/OutputAudio", "Tone/source/Source", "helper/OutputAudioStereo",
|
2018-05-18 16:07:20 +00:00
|
|
|
"helper/Test", "helper/Offline", "helper/APITest"],
|
|
|
|
function(OutputAudio, Source, OutputAudioStereo, Test, Offline, APITest){
|
2015-08-21 21:03:48 +00:00
|
|
|
|
|
|
|
return function(Constr, args){
|
|
|
|
|
|
|
|
context("Source Tests", function(){
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("extends Tone.Source", function(){
|
2015-08-21 21:03:48 +00:00
|
|
|
var instance = new Constr(args);
|
|
|
|
expect(instance).to.be.an.instanceof(Source);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can connect the output", function(){
|
2015-08-21 21:03:48 +00:00
|
|
|
var instance = new Constr(args);
|
|
|
|
instance.connect(Test);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("starts and stops", function(){
|
|
|
|
return Offline(function(){
|
2016-03-03 06:37:44 +00:00
|
|
|
var instance = new Constr(args);
|
2015-08-21 21:03:48 +00:00
|
|
|
expect(instance.state).to.equal("stopped");
|
2016-03-03 06:37:44 +00:00
|
|
|
instance.start(0).stop(0.2);
|
2017-02-20 19:06:44 +00:00
|
|
|
return function(time){
|
2016-03-03 06:37:44 +00:00
|
|
|
if (time >= 0 && time < 0.2){
|
|
|
|
expect(instance.state).to.equal("started");
|
|
|
|
} else if (time > 0.2){
|
|
|
|
expect(instance.state).to.equal("stopped");
|
|
|
|
}
|
2017-02-20 19:06:44 +00:00
|
|
|
};
|
2016-03-03 06:37:44 +00:00
|
|
|
}, 0.3);
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("makes a sound", function(){
|
|
|
|
return OutputAudio(function(){
|
|
|
|
var instance = new Constr(args);
|
|
|
|
instance.toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
instance.start();
|
|
|
|
});
|
2017-10-26 04:42:51 +00:00
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("produces sound in both channels", function(){
|
|
|
|
return OutputAudioStereo(function(){
|
|
|
|
var instance = new Constr(args);
|
|
|
|
instance.toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
instance.start();
|
|
|
|
});
|
2017-10-26 04:42:51 +00:00
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("be scheduled to start in the future", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var instance = new Constr(args).toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
instance.start(0.1);
|
2017-02-20 19:06:44 +00:00
|
|
|
}, 0.3).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample, time){
|
|
|
|
if (sample > 0){
|
|
|
|
expect(time).to.be.at.least(0.099);
|
|
|
|
}
|
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("makes no sound if it is started and then stopped with a time at or before the start time", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var instance = new Constr(args).toMaster();
|
|
|
|
instance.start(0.1).stop(0.05);
|
|
|
|
}, 0.3).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
2016-03-03 18:04:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("can be muted", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var instance = new Constr(args).toMaster();
|
2016-05-14 21:21:36 +00:00
|
|
|
instance.start(0);
|
|
|
|
instance.mute = true;
|
2017-02-20 19:06:44 +00:00
|
|
|
}, 0.3).then(function(buffer){
|
|
|
|
expect(buffer.isSilent()).to.be.true;
|
2016-05-14 21:21:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it("be scheduled to stop in the future", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var instance = new Constr(args).toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
instance.start(0).stop(0.2);
|
2017-02-20 19:06:44 +00:00
|
|
|
}, 0.3).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample, time){
|
|
|
|
if (time > 0.2){
|
|
|
|
expect(sample).to.equal(0);
|
|
|
|
}
|
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-09-26 01:36:32 +00:00
|
|
|
context("Source API", function(){
|
2017-10-26 04:42:51 +00:00
|
|
|
APITest.method(Constr, "start", ["Time=", "Time=", "Time="], args);
|
|
|
|
APITest.method(Constr, "stop", ["Time="], args);
|
2016-09-26 01:36:32 +00:00
|
|
|
});
|
|
|
|
|
2015-08-21 21:03:48 +00:00
|
|
|
};
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|