summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mossrose.c70
-rw-r--r--src/mossrose.h12
2 files changed, 82 insertions, 0 deletions
diff --git a/src/mossrose.c b/src/mossrose.c
new file mode 100644
index 0000000..fdaa10c
--- /dev/null
+++ b/src/mossrose.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <portaudio.h>
+#include "mossrose.h"
+
+
+PaStream *stream;
+
+
+struct audio_output_t {
+ float l;
+ float r;
+};
+
+
+static int callback(
+ const void *input,
+ void *output,
+ unsigned long frame_count,
+ const PaStreamCallbackTimeInfo *time_info,
+ void *userdata)
+{
+ static float left = 0;
+ static float right = 0;
+
+ struct audio_output_t *out = output;
+ for (int i=0; i<frame_count; i++) {
+ out[i].l = left;
+ out[i].r = right;
+ left += 0.01;
+ right += 0.03;
+ if (left > 1) left -= 2;
+ if (right > 1) right -= 2;
+ }
+ return 0;
+}
+
+
+int mr_init(double sample_rate, int n_channels)
+{
+ PaError err;
+
+ err = Pa_Initialize();
+ if (err != paNoError) {
+ fprintf(stderr, "failed to initialize PortAudio!\n");
+ return 1;
+ }
+
+ err = Pa_OpenDefaultStream(&stream, 0, 2, paFloat32, sample_rate, 0, callback, NULL);
+ if (err != paNoError) {
+ fprintf(stderr, "failed to open audio stream!\n");
+ return 1;
+ }
+
+ err = Pa_StartStream(stream);
+ if (err != paNoError) {
+ fprintf(stderr, "failed to start audio stream!\n");
+ return 1;
+ }
+
+ return 0;
+};
+
+
+int mr_terminate(double sample_rate, int n_channels)
+{
+ Pa_AbortStream(stream);
+ Pa_CloseStream(stream);
+ Pa_Terminate();
+ return 0;
+}
diff --git a/src/mossrose.h b/src/mossrose.h
new file mode 100644
index 0000000..3d5bcd5
--- /dev/null
+++ b/src/mossrose.h
@@ -0,0 +1,12 @@
+#ifndef MOSSROSE_H
+#define MOSSROSE_H
+
+#include <stddef.h>
+
+int mr_init(double sample_rate, int n_channels);
+
+int mr_terminate();
+
+int mr_play(float *left, float *right, size_t n_samples, int channel);
+
+#endif