summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt7
-rw-r--r--examples/mp3.c31
-rw-r--r--examples/sine-mono.mp3bin0 -> 13199 bytes
-rw-r--r--examples/weird-stereo.mp3bin0 -> 21029 bytes
4 files changed, 38 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index aea5060..3797392 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -18,3 +18,10 @@ add_dependencies(examples loop)
add_executable(callback ${CMAKE_CURRENT_LIST_DIR}/callback.c)
target_link_libraries(callback mossrose)
add_dependencies(examples callback)
+
+
+add_executable(mp3 ${CMAKE_CURRENT_LIST_DIR}/mp3.c)
+target_link_libraries(mp3 mossrose)
+add_dependencies(examples mp3)
+file(COPY ${CMAKE_CURRENT_LIST_DIR}/sine-mono.mp3 DESTINATION .)
+file(COPY ${CMAKE_CURRENT_LIST_DIR}/weird-stereo.mp3 DESTINATION .)
diff --git a/examples/mp3.c b/examples/mp3.c
new file mode 100644
index 0000000..7560bf1
--- /dev/null
+++ b/examples/mp3.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <mossrose.h>
+#include <portaudio.h>
+
+#define SAMPLE_RATE 44100
+#define N_CHANNELS 8
+
+int main()
+{
+ int err = mossrose_init(SAMPLE_RATE, N_CHANNELS, true);
+ if (err != 0)
+ fprintf(stderr, "FAILED TO INITIALIZE MOSSROSE\n");
+
+ struct mossrose_sound_t *mono = mossrose_load_mp3("sine-mono.mp3");
+ struct mossrose_sound_t *stereo = mossrose_load_mp3("weird-stereo.mp3");
+
+ int chan = mossrose_play(mono, -1, 1);
+ Pa_Sleep(1000);
+ chan = mossrose_play(stereo, -1, 1);
+ Pa_Sleep(1000);
+
+ mossrose_terminate();
+ free(mono->left);
+ free(mono);
+ free(stereo->left);
+ free(stereo->right);
+ free(stereo);
+ return 0;
+}
diff --git a/examples/sine-mono.mp3 b/examples/sine-mono.mp3
new file mode 100644
index 0000000..6ea6991
--- /dev/null
+++ b/examples/sine-mono.mp3
Binary files differ
diff --git a/examples/weird-stereo.mp3 b/examples/weird-stereo.mp3
new file mode 100644
index 0000000..586fc60
--- /dev/null
+++ b/examples/weird-stereo.mp3
Binary files differ