Oscillators (wave functions)
function sin(l){
val = Math.sin(l * Math.PI/180);
return val;
}
function tri(l){
p = 360; // period
l = l + 90;
val = (2 * Math.abs(2 * ((l/p) - Math.floor((l/p) + (1/2)))) - 1);
return val;
}
function saw(l){
p = 360;
val = 2 * ((l/p) - Math.floor((1/2) + (l/p)));
return val;
}
function squ(l){
val = Math.sign(Math.sin(l * Math.PI/180));
return val;
}
Smart object
function osc(type){
this.type = type;
if(type == "sin"){
this.calc = sin;
}else if(type == "tri"){
this.calc = tri;
}else if(type == "squ"){
this.calc = squ;
}else if(type == "saw"){
this.calc = saw;
}else if(type == "non"){
this.calc = non;
}
this.updateOscType = updateOscType;
}
function updateOscType(type){
if(type == "sin"){
this.calc = sin;
}else if(type == "tri"){
this.calc = tri;
}else if(type == "squ"){
this.calc = squ;
}else if(type == "saw"){
this.calc = saw;
}else if(type == "non"){
this.calc = non;
}
}
function non(l){
return 1;
}
function sin(l){
val = Math.sin(l * Math.PI/180);
return val;
}
function tri(l){
p = 360; // period
l = l + 90;
val = (2 * Math.abs(2 * ((l/p) - Math.floor((l/p) + (1/2)))) - 1);
return val;
}
function saw(l){
p = 360;
val = 2 * ((l/p) - Math.floor((1/2) + (l/p)));
return val;
}
function squ(l){
val = Math.sign(Math.sin(l * Math.PI/180));// (2*Math.floor(p*l) - Math.floor(2*p*l))+1;
return val;
}