summaryrefslogtreecommitdiff
path: root/examples/loop.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-09-03 21:32:25 -0500
committersanine <sanine.not@pm.me>2022-09-03 21:32:25 -0500
commit2cf000fb7cbe653c2e96e0b3b8f3c1425401d3fc (patch)
treee172ef67b253d1eaa0fb22186b5901edd4de793a /examples/loop.c
parenta416cfb6881b8ff99c29ba87c1d940d6143e44b1 (diff)
add looping
Diffstat (limited to 'examples/loop.c')
-rw-r--r--examples/loop.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/loop.c b/examples/loop.c
new file mode 100644
index 0000000..1be04a9
--- /dev/null
+++ b/examples/loop.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <math.h>
+#include <mossrose.h>
+#include <portaudio.h>
+
+#define PI 3.14159
+
+
+#define SAMPLE_RATE 44100
+#define N_CHANNELS 8
+
+float f(float t)
+{
+ const int f0 = 440;
+ const int f1 = 880;
+ return ( t*f1 ) + ( (1-t)*f0 );
+}
+
+int main()
+{
+ float data[SAMPLE_RATE];
+ for (long i=0; i<SAMPLE_RATE; i++) {
+ float time = ((float)i)/SAMPLE_RATE;
+ data[i] = sin(2*PI*f(time)*time);
+ }
+
+ struct mossrose_sound_t sound = {
+ .left = data, .right = NULL, .mono = true, .len = SAMPLE_RATE
+ };
+
+ int err = mossrose_init(SAMPLE_RATE, N_CHANNELS, true);
+ if (err != 0)
+ fprintf(stderr, "FAILED TO INITIALIZE MOSSROSE\n");
+
+ int chan = mossrose_play(&sound, -1, 5);
+ Pa_Sleep(5000);
+
+ mossrose_terminate();
+ return 0;
+}