OpenALpp is a modern OOP C++20 audio library built on OpenAL Soft for Windows, macOS, Linux and web (emscripten). It supports loading of wav, mp3, FLAC and ogg files via libnyquist.
git clone https://github.com/Laguna1989/OpenALpp.git && cd OpenALpp
mkdir build && cd build
cmake ..
cmake --build . --target OpenALpp_Lib
How to measure Code Coverage with OpenCppCoverage
OpenCppCoverage.exe
--sources <absolute path>\OpenALpp\impl\
--excluded_sources <absolute path>\OpenALpp\test\
--excluded_sources <absolute path>\OpenALpp\ext*
--excluded_sources <absolute path>\OpenALpp\cmake-build-debug*
.\path\to\unit_tests\OpenALpp_UnitTests.exe
#include "oalpp/sound_context.hpp"
#include "oalpp/sound_data.hpp"
#include "oalpp/sound.hpp"
using namespace oalpp;
SoundContext ctx;
SoundData buffer { "audio.mp3" };
Sound snd { buffer };
snd.play();
while (snd.isPlaying()) {
snd.update();
}
Sound
has a dependency onSoundContext
. You need to keep theSoundContext
alive as long as you want to use sounds.- Note that this does not apply to
SoundData
, which can be created independently ofSoundContext
.
- Note that this does not apply to
- Sound has a dependency to the
SoundData
that is passed in the constructor. You need to keep theSoundData
alive as long as anySound
might access it.- You can bundle
SoundData
andSound
together in your implementation. - Alternatively you can write your own
SoundDataManager
to avoid creating multipleSoundData
s for the same file.
- You can bundle
- Your sound will stop after some seconds, even if the audio file contains a longer sound.
Sound
s do not update themselves. You need to callupdate()
regularly.
CMakeLists.txt
FetchContent_Declare(
openalpp
GIT_REPOSITORY https://github.com/Laguna1989/OpenALpp.git
GIT_TAG master
)
FetchContent_MakeAvailable(openalpp)
add_executable(MyProject main.cpp)
target_link_libraries(MyProject OpenALpp_Lib)
OALPP_ENABLE_UNIT_TESTS
- Enable unit tests - defaultON
OALPP_ENABLE_APPROVAL_TESTS
- Enable approval tests - defaultON
OALPP_ENABLE_INTEGRATION_TESTS
- Enable integration test - defaultON
OALPP_STATIC_LIBRARY
- Build OpenALpp and dependencies as static library - defaultON
- Microsoft Visual C++ 2019
- clang++ from version 8
- g++ from version 9
- emscripten g++ version 9
- CMake 3.19
- One of the compatible compilers
All other dependencies (openal-soft
and libnyquist
) are automatically fetched via CMake.