Scroll To Top
Yofiel menu
Welcome, Guest

TOPIC: Code for antialiased saw oscillators

Code for antialiased saw oscillators 2 years 2 months ago #1

Here is the complete gen code for the variable width triangle/saw oscillator with antialiased saw. Thanks to DaveyC on the Cycling74 forums for providing the original source for this algorithm.
Hide LIne Numbers
  1. History zr1(0); History zr2(0); History zt(0); 
  2. Param fb(0); Param fm(0); Param f2(440); 
  3. D=0; fc=440; dx1 = 0; w2 = 0; d1 = 0; fc=440;
  4. sel = in1; osc = in2;  fc = in3; snc = in4; w1= in5; 
  5. rsr = in6 ; sr  = in7; sr3d3 = in8; srx3 = in9 ;
  6. m13 = -1/3; p13 = 1/3; p23 = 2/3;
  7. fc += fm *osc + fb *zr2;
  8. inc = rsr * fc;
  9. r1 = accum(inc, snc, max=1, resetmode="post"); 
  10. dx1 = delta(r1);  
  11. out2 = triangle(r1, w1) *2 -1; // for FM modulation of other oscillators
  12. if (w1 < .01) {  // falling saw
  13.     if (r1<inc) out1 = neg(pow(r1/fc,3) *sr3d3 +r1 *fc *rsr + 1);
  14.     else if (r1 < inc *2){
  15.         D = r1 *sr /fc;    
  16.         out1 = neg(D *D *D *p23 -D *D *3 +r1 *srx3/fc +r1 *2);        
  17.     } else if(r1 <inc *3) {
  18.         D = r1 *sr /fc;    
  19.         out1 = neg(D *D *D *m13 + D *D *3 + D * inc *2 - D *9 +8);    
  20.     } else out1 = out2;
  21. } else if (w1>.99)  {  // rising saw
  22.     if (r1<inc)out1 = pow(r1/fc,3) *sr3d3 +r1 *fc *rsr + 1;
  23.     else if(r1 <inc *2){
  24.         D = r1 *sr /fc;    
  25.         out1 = D *D *D *p23 -D *D *3 +r1 *srx3/fc +r1 *2;        
  26.     } else if(r1 <inc *3) {
  27.         D = r1 *sr /fc;    
  28.         out1 = D *D *D *m13 + D *D *3 + D *inc *2 - D *9 +8;    
  29.     } else out1 = out2;
  30. } else {  // variable slope
  31.     out1 = triwave(out2, r1, zr1, w1);
  32.     out1 = out2;
  33. }
  34. zr1 = r1; 
  35. zr2 = out2;    
  36. out1 = dcblock(out1);
  37. out3 = rsr;
Ernest
Last Edit: 2 years 2 months ago by ernestm.
The administrator has disabled public write access.