diff options
| author | drowe67 <[email protected]> | 2023-07-20 08:59:48 +0930 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-20 08:59:48 +0930 |
| commit | 06d4c11e699b0351765f10398abb4f663a984f36 (patch) | |
| tree | 33e22af0814c5b6c3d676f096ae8c2ac8a3ed9f0 /unittest/mksine.c | |
| parent | 6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff) | |
| parent | 4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff) | |
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'unittest/mksine.c')
| -rw-r--r-- | unittest/mksine.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/unittest/mksine.c b/unittest/mksine.c index fb5f822..a77830c 100644 --- a/unittest/mksine.c +++ b/unittest/mksine.c @@ -7,48 +7,48 @@ */ #include <assert.h> -#include <stdlib.h> +#include <errno.h> +#include <math.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <math.h> -#include <errno.h> -#define TWO_PI 6.283185307 -#define FS 8000.0 +#define TWO_PI 6.283185307 +#define FS 8000.0 int main(int argc, char *argv[]) { - FILE *f; - int i,n; - float freq, length; - short *buf; - float amp = 1E4; - - if (argc < 4) { - printf("usage: %s outputFile frequencyHz lengthSecs [PeakAmp]\n", argv[0]); - exit(1); - } - - if (strcmp(argv[1], "-") == 0) { - f = stdout; - } else if ( (f = fopen(argv[1],"wb")) == NULL ) { - fprintf(stderr, "Error opening output file: %s: %s.\n", argv[3], strerror(errno)); - exit(1); - } - freq = atof(argv[2]); - length = atof(argv[3]); - if (argc == 5) amp = atof(argv[4]); - - n = length*FS; - buf = (short*)malloc(sizeof(short)*n); - assert(buf != NULL); - - for(i=0; i<n; i++) - buf[i] = amp*cos(freq*i*(TWO_PI/FS)); - - fwrite(buf, sizeof(short), n, f); - - fclose(f); - free(buf); - - return 0; + FILE *f; + int i, n; + float freq, length; + short *buf; + float amp = 1E4; + + if (argc < 4) { + printf("usage: %s outputFile frequencyHz lengthSecs [PeakAmp]\n", argv[0]); + exit(1); + } + + if (strcmp(argv[1], "-") == 0) { + f = stdout; + } else if ((f = fopen(argv[1], "wb")) == NULL) { + fprintf(stderr, "Error opening output file: %s: %s.\n", argv[3], + strerror(errno)); + exit(1); + } + freq = atof(argv[2]); + length = atof(argv[3]); + if (argc == 5) amp = atof(argv[4]); + + n = length * FS; + buf = (short *)malloc(sizeof(short) * n); + assert(buf != NULL); + + for (i = 0; i < n; i++) buf[i] = amp * cos(freq * i * (TWO_PI / FS)); + + fwrite(buf, sizeof(short), n, f); + + fclose(f); + free(buf); + + return 0; } |
