]> git.sesse.net Git - audiosync/commitdiff
Make a square generator.
authorsgunderson@bigfoot.com <>
Thu, 28 Dec 2006 17:58:43 +0000 (18:58 +0100)
committersgunderson@bigfoot.com <>
Thu, 28 Dec 2006 17:58:43 +0000 (18:58 +0100)
gen-square.c [new file with mode: 0644]

diff --git a/gen-square.c b/gen-square.c
new file mode 100644 (file)
index 0000000..72c32cd
--- /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 = (y > 0) ? 16384.0 : -16384.0;
+
+               fwrite(&ys, sizeof(short), 1, stdout);
+       }
+}