Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. const int Dv = 2048;
  5. const float fa = 44100;
  6. const float fv = 6;
  7. const float nu = 0.2;
  8. const float f = 440;
  9.  
  10. int main(void)
  11. {
  12.   int i;
  13.   float x[Dv];
  14.   float tabv[Dv];
  15.   int ii[(int)fa*2];
  16.   int gv[(int)fa*2];
  17.   float tv[(int)fa*2];
  18.   float fi[(int)fa*2];
  19.   float dD[(int)fa*2];
  20.   float gi_f[(int)fa*2];
  21.   int gi[(int)fa*2];
  22.   float ti[(int)fa*2];
  23.   float t[(int)fa*2];
  24.  
  25.   for (i = 0; i < Dv; i++) {
  26.     x[i] = 2  * M_PI * (float)i / (float)Dv;
  27.     tabv[i] = sin(x[i]);
  28.   }
  29.  
  30.   for (i = 0; i < (int)fa*2; i++) {
  31.     ii[i] = i;
  32.     gv[i] = ii[i] * fv * (float)Dv / fa;
  33.     tv[i] = tabv[gv[i]%Dv] * nu;
  34.     fi[i] = f * pow(2, tv[i] / 12);
  35.     dD[i] = fi[i] * (Dv / (float)fa);
  36.   }
  37.  
  38.   gi_f[0] = dD[0];
  39.   for (i = 1; i < (int)fa*2; i++) gi_f[i] = gi_f[i-1] + dD[i];
  40.   for (i = 0; i < (int)fa*2; i++) {
  41.     gi[i] = gi_f[i];
  42.     gi[i] = gi[i] % Dv;
  43.   }
  44.  
  45.   for (i = 0; i < (int)fa*2; i++) ti[i] = tabv[gi[i]];
  46.  
  47.   /* ff is 440 for all positions, we don't compute that */
  48.   for (i = 0; i < (int)fa*2; i++) {
  49.     gi_f[i] = ii[i] * (Dv / (float)fa) * 440;
  50.     gi[i] = gi_f[i];
  51.     gi[i] = gi[i] % Dv;
  52.   }
  53.  
  54.   for (i = 0; i < (int)fa*2; i++) t[i] = tabv[gi[i]];
  55.  
  56.   for (i = 0; i < 44100*2; i++) fwrite(&ti[i], 4, 1, stdout);
  57.   for (i = 0; i < 44100*2; i++) fwrite(&t[i], 4, 1, stdout);
  58.   fflush(stdout);
  59.   return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement