mksine.c 617 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. mksine.c
  3. David Rowe
  4. 10 Nov 2010
  5. Creates a file of sine wave samples.
  6. */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <math.h>
  10. #define TWO_PI 6.283185307
  11. #define N 8000
  12. #define FS 8000.0
  13. #define AMP 1000.0
  14. int main(int argc, char *argv[]) {
  15. FILE *f;
  16. int i;
  17. float freq;
  18. short buf[N];
  19. if (argc != 3) {
  20. printf("usage: %s outputFile frequencyHz\n", argv[0]);
  21. exit(1);
  22. }
  23. f = fopen(argv[1] ,"wb");
  24. freq = atof(argv[2]);
  25. for(i=0; i<N; i++)
  26. buf[i] = AMP*cos(freq*i*(TWO_PI/FS));
  27. fwrite(buf, sizeof(short), N, f);
  28. return 0;
  29. }