aboutsummaryrefslogtreecommitdiff
path: root/mwe/audio/miniaudio
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-03 11:23:54 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-03 11:23:54 +0100
commit75cf0b8e72aff7072c25ab015ce5c9c64eb3ecc5 (patch)
treedd459130f169a924db0637146d31ed20aaa10d74 /mwe/audio/miniaudio
parented8534e2d150428bcbc4a6df8940323ae8db2925 (diff)
parent6aa8fdd04728b6a499f526de727514ae3d0490b4 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/events-poc
Diffstat (limited to 'mwe/audio/miniaudio')
-rw-r--r--mwe/audio/miniaudio/CMakeLists.txt19
-rw-r--r--mwe/audio/miniaudio/main.cpp46
2 files changed, 65 insertions, 0 deletions
diff --git a/mwe/audio/miniaudio/CMakeLists.txt b/mwe/audio/miniaudio/CMakeLists.txt
new file mode 100644
index 0000000..6dd0191
--- /dev/null
+++ b/mwe/audio/miniaudio/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.28)
+
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
+set(CMAKE_BUILD_TYPE Debug)
+
+add_subdirectory(../../../lib/miniaudio miniaudio)
+
+project(poc C CXX)
+
+add_executable(main
+ main.cpp
+)
+
+target_link_libraries(main
+ miniaudio
+)
+
diff --git a/mwe/audio/miniaudio/main.cpp b/mwe/audio/miniaudio/main.cpp
new file mode 100644
index 0000000..bf31898
--- /dev/null
+++ b/mwe/audio/miniaudio/main.cpp
@@ -0,0 +1,46 @@
+#include <miniaudio.h>
+
+#include <chrono>
+#include <thread>
+
+using namespace std;
+using namespace std::chrono_literals;
+
+int main() {
+ ma_engine engine;
+ ma_engine_init(NULL, &engine);
+
+ // 1. load background track (ogg vorbis)
+ ma_sound bgm;
+ ma_sound_init_from_file(&engine, "../bgm.ogg", 0, NULL, NULL, &bgm);
+
+ // 2. load samples (wav)
+ ma_sound sfx[3];
+ ma_sound_init_from_file(&engine, "../sfx1.wav", 0, NULL, NULL, &sfx[0]);
+ ma_sound_init_from_file(&engine, "../sfx2.wav", 0, NULL, NULL, &sfx[1]);
+ ma_sound_init_from_file(&engine, "../sfx3.wav", 0, NULL, NULL, &sfx[2]);
+
+ // 3. start the background track
+ ma_sound_start(&bgm);
+
+ // 4. play samples sequentially while controlling the background track
+ this_thread::sleep_for(500ms);
+ ma_sound_start(&sfx[0]);
+ this_thread::sleep_for(500ms);
+ ma_sound_start(&sfx[1]);
+ ma_sound_stop(&bgm);
+ this_thread::sleep_for(500ms);
+ ma_sound_start(&sfx[2]);
+ ma_sound_start(&bgm); // this actually resumes now
+ this_thread::sleep_for(500ms);
+ for (unsigned i = 0; i < 3; i++)
+ ma_sound_seek_to_pcm_frame(&sfx[i], 0);
+
+ // 5. play all samples simultaniously
+ for (unsigned i = 0; i < 3; i++)
+ ma_sound_start(&sfx[i]);
+ this_thread::sleep_for(1000ms);
+
+ ma_engine_uninit(&engine);
+ return 0;
+}