summaryrefslogtreecommitdiff
path: root/examples
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
parenta416cfb6881b8ff99c29ba87c1d940d6143e44b1 (diff)
add looping
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt5
-rw-r--r--examples/example.c6
-rw-r--r--examples/loop.c40
-rw-r--r--examples/panning.c2
4 files changed, 49 insertions, 4 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 46e02d4..7fe2030 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -8,3 +8,8 @@ add_dependencies(examples example)
add_executable(panning ${CMAKE_CURRENT_LIST_DIR}/panning.c)
target_link_libraries(panning mossrose)
add_dependencies(examples panning)
+
+
+add_executable(loop ${CMAKE_CURRENT_LIST_DIR}/loop.c)
+target_link_libraries(loop mossrose)
+add_dependencies(examples loop)
diff --git a/examples/example.c b/examples/example.c
index 5e65d82..eefc41d 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -35,17 +35,17 @@ int main()
Pa_Sleep(500);
printf("play 1\n");
- mossrose_play(&sound_512, -1);
+ mossrose_play(&sound_512, -1, 1);
printf("wait\n");
Pa_Sleep(1000);
printf("play 2\n");
- mossrose_play(&sound_440, -1);
+ mossrose_play(&sound_440, -1, 1);
printf("wait\n");
Pa_Sleep(500);
printf("play 3\n");
- mossrose_play(&sound_512, -1);
+ mossrose_play(&sound_512, -1, 1);
printf("wait\n");
Pa_Sleep(1000);
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;
+}
diff --git a/examples/panning.c b/examples/panning.c
index 485833a..b63727b 100644
--- a/examples/panning.c
+++ b/examples/panning.c
@@ -28,7 +28,7 @@ int main()
Pa_Sleep(500);
- int chan = mossrose_play(&sound, -1);
+ int chan = mossrose_play(&sound, -1, 1);
for (int i=0; i<8000; i++) {
float time = ((float)i)/1000;