Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- const int Dv = 2048;
- const float fa = 44100;
- const float fv = 6;
- const float nu = 0.2;
- const float f = 440;
- int main(void)
- {
- int i;
- float x[Dv];
- float tabv[Dv];
- int ii[(int)fa*2];
- int gv[(int)fa*2];
- float tv[(int)fa*2];
- float fi[(int)fa*2];
- float dD[(int)fa*2];
- float gi_f[(int)fa*2];
- int gi[(int)fa*2];
- float ti[(int)fa*2];
- float t[(int)fa*2];
- for (i = 0; i < Dv; i++) {
- x[i] = 2 * M_PI * (float)i / (float)Dv;
- tabv[i] = sin(x[i]);
- }
- for (i = 0; i < (int)fa*2; i++) {
- ii[i] = i;
- gv[i] = ii[i] * fv * (float)Dv / fa;
- tv[i] = tabv[gv[i]%Dv] * nu;
- fi[i] = f * pow(2, tv[i] / 12);
- dD[i] = fi[i] * (Dv / (float)fa);
- }
- gi_f[0] = dD[0];
- for (i = 1; i < (int)fa*2; i++) gi_f[i] = gi_f[i-1] + dD[i];
- for (i = 0; i < (int)fa*2; i++) {
- gi[i] = gi_f[i];
- gi[i] = gi[i] % Dv;
- }
- for (i = 0; i < (int)fa*2; i++) ti[i] = tabv[gi[i]];
- /* ff is 440 for all positions, we don't compute that */
- for (i = 0; i < (int)fa*2; i++) {
- gi_f[i] = ii[i] * (Dv / (float)fa) * 440;
- gi[i] = gi_f[i];
- gi[i] = gi[i] % Dv;
- }
- for (i = 0; i < (int)fa*2; i++) t[i] = tabv[gi[i]];
- for (i = 0; i < 44100*2; i++) fwrite(&ti[i], 4, 1, stdout);
- for (i = 0; i < 44100*2; i++) fwrite(&t[i], 4, 1, stdout);
- fflush(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement