From b7df77d6cc26cb9ee46891d7108f01734b3104dd Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 22 Sep 2024 17:08:56 +0200 Subject: add miniaudio poc --- .gitmodules | 3 +++ lib/miniaudio/CMakeLists.txt | 10 ++++++++ lib/miniaudio/lib | 1 + lib/miniaudio/main.c | 2 ++ mwe/audio/bgm.ogg | Bin 0 -> 125020 bytes mwe/audio/miniaudio/CMakeLists.txt | 19 +++++++++++++++ mwe/audio/miniaudio/main.cpp | 46 +++++++++++++++++++++++++++++++++++++ mwe/audio/sfx1.wav | Bin 0 -> 44144 bytes mwe/audio/sfx2.wav | Bin 0 -> 44144 bytes mwe/audio/sfx3.wav | Bin 0 -> 44144 bytes 10 files changed, 81 insertions(+) create mode 100644 lib/miniaudio/CMakeLists.txt create mode 160000 lib/miniaudio/lib create mode 100644 lib/miniaudio/main.c create mode 100644 mwe/audio/bgm.ogg create mode 100644 mwe/audio/miniaudio/CMakeLists.txt create mode 100644 mwe/audio/miniaudio/main.cpp create mode 100644 mwe/audio/sfx1.wav create mode 100644 mwe/audio/sfx2.wav create mode 100644 mwe/audio/sfx3.wav diff --git a/.gitmodules b/.gitmodules index f8a9861..f93e48c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,3 +3,6 @@ url = https://github.com/google/googletest branch = v1.15.x shallow = true +[submodule "lib/miniaudio/lib"] + path = lib/miniaudio/lib + url = https://github.com/mackron/miniaudio diff --git a/lib/miniaudio/CMakeLists.txt b/lib/miniaudio/CMakeLists.txt new file mode 100644 index 0000000..65d416c --- /dev/null +++ b/lib/miniaudio/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.28) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) + +project(miniaudio C CXX) + +add_library(miniaudio STATIC main.c) +target_include_directories(miniaudio SYSTEM INTERFACE lib) + diff --git a/lib/miniaudio/lib b/lib/miniaudio/lib new file mode 160000 index 0000000..4a5b74b --- /dev/null +++ b/lib/miniaudio/lib @@ -0,0 +1 @@ +Subproject commit 4a5b74bef029b3592c54b6048650ee5f972c1a48 diff --git a/lib/miniaudio/main.c b/lib/miniaudio/main.c new file mode 100644 index 0000000..8d898f7 --- /dev/null +++ b/lib/miniaudio/main.c @@ -0,0 +1,2 @@ +#define MINIAUDIO_IMPLEMENTATION +#include "lib/miniaudio.h" diff --git a/mwe/audio/bgm.ogg b/mwe/audio/bgm.ogg new file mode 100644 index 0000000..d6397fb Binary files /dev/null and b/mwe/audio/bgm.ogg differ 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 + +#include +#include + +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; +} diff --git a/mwe/audio/sfx1.wav b/mwe/audio/sfx1.wav new file mode 100644 index 0000000..576377a Binary files /dev/null and b/mwe/audio/sfx1.wav differ diff --git a/mwe/audio/sfx2.wav b/mwe/audio/sfx2.wav new file mode 100644 index 0000000..908ec86 Binary files /dev/null and b/mwe/audio/sfx2.wav differ diff --git a/mwe/audio/sfx3.wav b/mwe/audio/sfx3.wav new file mode 100644 index 0000000..20b7c84 Binary files /dev/null and b/mwe/audio/sfx3.wav differ -- cgit v1.2.3