2017-10-26 04:49:42 +00:00
|
|
|
define(["helper/Basic", "Tone/source/PulseOscillator", "helper/Offline", "helper/SourceTests", "helper/OscillatorTests"],
|
2015-08-21 21:03:48 +00:00
|
|
|
function (BasicTests, PulseOscillator, Offline, SourceTests, OscillatorTests) {
|
|
|
|
|
|
|
|
describe("PulseOscillator", function(){
|
|
|
|
|
|
|
|
//run the common tests
|
|
|
|
BasicTests(PulseOscillator);
|
|
|
|
SourceTests(PulseOscillator);
|
|
|
|
OscillatorTests(PulseOscillator);
|
|
|
|
|
|
|
|
context("Phase Rotation", function(){
|
2017-02-20 19:06:44 +00:00
|
|
|
it ("can change the phase to 90", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new PulseOscillator({
|
2015-08-21 21:03:48 +00:00
|
|
|
"phase" : 90,
|
|
|
|
"frequency" : 1
|
|
|
|
});
|
2017-02-20 19:06:44 +00:00
|
|
|
osc.toMaster();
|
|
|
|
osc.start(0);
|
|
|
|
}, 1).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample, time){
|
|
|
|
if (time < 0.25){
|
|
|
|
expect(sample).to.be.within(-1, 0);
|
2017-10-26 04:49:42 +00:00
|
|
|
} else if (time > 0.25 && time < 0.5){
|
2017-02-20 19:06:44 +00:00
|
|
|
expect(sample).to.be.within(0, 1);
|
|
|
|
}
|
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it ("can change the phase to -90", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new PulseOscillator({
|
2015-08-21 21:03:48 +00:00
|
|
|
"phase" : 270,
|
|
|
|
"frequency" : 1
|
|
|
|
});
|
2017-02-20 19:06:44 +00:00
|
|
|
osc.toMaster();
|
|
|
|
osc.start(0);
|
|
|
|
}, 1).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample, time){
|
|
|
|
if (time < 0.25){
|
|
|
|
expect(sample).to.be.within(0, 1);
|
2017-10-26 04:49:42 +00:00
|
|
|
} else if (time > 0.25 && time < 0.5){
|
2017-02-20 19:06:44 +00:00
|
|
|
expect(sample).to.be.within(-1, 0);
|
|
|
|
}
|
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-26 04:49:42 +00:00
|
|
|
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
context("Width", function(){
|
|
|
|
|
|
|
|
it ("can set the width", function(){
|
|
|
|
var osc = new PulseOscillator({
|
|
|
|
"width" : 0.2,
|
|
|
|
});
|
|
|
|
expect(osc.width.value).to.be.closeTo(0.2, 0.001);
|
|
|
|
osc.dispose();
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it ("outputs correctly with a width of 0", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new PulseOscillator({
|
2015-08-21 21:03:48 +00:00
|
|
|
"width" : 0,
|
|
|
|
"frequency" : 1
|
|
|
|
});
|
2017-02-20 19:06:44 +00:00
|
|
|
osc.toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
osc.start(0);
|
2017-10-26 04:49:42 +00:00
|
|
|
}, 0.9).then(function(buffer){
|
2017-02-20 19:06:44 +00:00
|
|
|
buffer.forEach(function(sample, time){
|
2017-10-26 04:49:42 +00:00
|
|
|
if (time > 0.51){
|
2017-02-20 19:06:44 +00:00
|
|
|
expect(sample).to.be.within(-1, 0);
|
2017-10-26 04:49:42 +00:00
|
|
|
}
|
2017-02-20 19:06:44 +00:00
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-20 19:06:44 +00:00
|
|
|
it ("outputs correctly with a width of 0.5", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var osc = new PulseOscillator({
|
2015-08-21 21:03:48 +00:00
|
|
|
"width" : 0.5,
|
|
|
|
"frequency" : 1
|
|
|
|
});
|
2017-02-20 19:06:44 +00:00
|
|
|
osc.toMaster();
|
2015-08-21 21:03:48 +00:00
|
|
|
osc.start(0);
|
2017-02-20 19:06:44 +00:00
|
|
|
}, 1).then(function(buffer){
|
|
|
|
buffer.forEach(function(sample, time){
|
|
|
|
if (time <= 0.5){
|
|
|
|
expect(sample).to.be.within(0, 1);
|
|
|
|
} else if (time >= 0.51 && time <= 0.7){
|
|
|
|
expect(sample).to.be.within(-1, 0);
|
|
|
|
} else if (time > 0.71){
|
|
|
|
expect(sample).to.be.within(0, 1);
|
|
|
|
}
|
|
|
|
});
|
2015-08-21 21:03:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2017-10-26 04:49:42 +00:00
|
|
|
});
|