]> git.sesse.net Git - audiosync/commitdiff
Add a simple sine generator.
authorsgunderson@bigfoot.com <>
Thu, 28 Dec 2006 01:40:12 +0000 (02:40 +0100)
committersgunderson@bigfoot.com <>
Thu, 28 Dec 2006 01:40:12 +0000 (02:40 +0100)
gen-sine.c [new file with mode: 0644]

diff --git a/gen-sine.c b/gen-sine.c
new file mode 100644 (file)
index 0000000..86a0caf
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+       unsigned num_samples = atoi(argv[1]);
+       double freq = atof(argv[2]);
+       
+       for (unsigned i = 0; i < num_samples; ++i) {
+               double y = cos(freq * 2.0 * M_PI * (double)(i) / 48000);
+               short ys = (short)(16384.0 * y);
+
+               fwrite(&ys, sizeof(short), 1, stdout);
+       }
+}