summaryrefslogtreecommitdiff
path: root/examples/loop.c
diff options
context:
space:
mode:
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;
+}