Advertisement
Guest User

fourier saw wave function

a guest
Feb 23rd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. float return_fsaw(int time, int osc_id)
  2. {  
  3.     float time_to_rad = ((float)time/ONESECOND)*(2*M_PI); //where ONESECOND is the number of pixels representing one second. the program draws the wave by looping through incrementing time by 1 to draw the wave form of one second.
  4.    
  5.     float value=0;
  6.     int i = 0;
  7.     for (i=1; i<=oscArray[osc_id]->fourier; i++)
  8.     {  
  9.         value += (pow(-1, i))*((sin(i*oscArray[osc_id]->freq*time_to_rad))/i);
  10.        
  11.     }
  12.    
  13.     value = (2/M_PI)*value;
  14.     if (value >1) printf("F.Saw: value exceeded 1. Value = %f, time = %d, time_to_rad = %f\n", value, time, time_to_rad);
  15.     return value;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement