Advertisement
triclops200

Untitled

Jul 4th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2.  *
  3.  * welcome to wavepot
  4.  * ------------------
  5.  *
  6.  * this is a live editor. you create a function named `dsp`
  7.  * that accepts the parameter `t`, the coefficient of time,
  8.  * which you use to generate a single sample (range -1..1)
  9.  *
  10.  * below is the smallest example possible, a simple sine wave
  11.  * generator. check out more complex demos on the right ---->
  12.  *
  13.  * have fun!
  14.  *
  15.  */
  16.  
  17. tau = Math.PI*2
  18. function beat(t){
  19.   t = t%1;
  20.   if(t > .5 && t < .55){
  21.     return Math.random();
  22.   }
  23.   return 0;
  24. }
  25.  
  26. function triangle(t,m){
  27.   n = 1/m;
  28.   return n - Math.abs(t % (2*n) - n) * m + .5;
  29. }
  30.  
  31. function a_minor_arpegiator(t){
  32.   t = t%1;
  33.   if(t < 0.25){
  34.     return triangle(t,440)
  35.     //return Math.sin(tau*440*t);
  36.   } else if(t < .50) {
  37.     return triangle(t,523.25)
  38.  //   return Math.sin(tau*523.25*t);
  39.   } else if(t < .75) {
  40.     return triangle(t,659.25)
  41.    // return Math.sin(tau*659.25*t);
  42.   }
  43.   return triangle(t,523.25)
  44.  // return Math.sin(tau*523.25*t);
  45. }
  46.  
  47. function dsp(t) {
  48.   return 0.05 * Math.sin(tau*t*440)*(1-t%1)
  49.   + Math.sin(tau*t*220)*Math.sin(tau*t*2)*0.15
  50.   + beat(t)*0.1
  51.   + a_minor_arpegiator(t)*0.1;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement