added length paramto mksine
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 3 Jun 2013 01:55:39 +0000 (01:55 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 3 Jun 2013 01:55:39 +0000 (01:55 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1307 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/unittest/mksine.c

index 3e5c551aadb574dc4b33062a11e3acbc137c0ef7..932d361aa71782452d56899b3a453f97034afa31 100644 (file)
@@ -6,33 +6,37 @@
   Creates a file of sine wave samples.
 */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
 
 #define TWO_PI     6.283185307
-#define N          8000
 #define FS         8000.0
 #define AMP        1000.0
 
 int main(int argc, char *argv[]) {
     FILE *f;
-    int   i;
-    float freq;
-    short buf[N];
+    int   i,n;
+    float freq, length;
+    short *buf;
 
-    if (argc != 3) {
-       printf("usage: %s outputFile frequencyHz\n", argv[0]);
+    if (argc != 4) {
+       printf("usage: %s outputFile frequencyHz lengthSecs\n", argv[0]);
        exit(1);
     }
 
     f = fopen(argv[1] ,"wb");
     freq = atof(argv[2]);
+    length = atof(argv[3]);
+    n = length*FS;
+    buf = (short*)malloc(sizeof(short)*n);
+    assert(buf != NULL);
 
-    for(i=0; i<N; i++)
+    for(i=0; i<n; i++)
        buf[i] = AMP*cos(freq*i*(TWO_PI/FS));
 
-    fwrite(buf, sizeof(short), N, f);
+    fwrite(buf, sizeof(short), n, f);
 
     return 0;
 }