OpenALpp
December 24, 2023 ยท View on GitHub
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.
How to build
git clone https://github.com/Laguna1989/OpenALpp.git && cd OpenALppmkdir build && cd buildcmake ..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
Code Example
#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();
}
Common Pitfalls
Soundhas a dependency onSoundContext. You need to keep theSoundContextalive 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
SoundDatathat is passed in the constructor. You need to keep theSoundDataalive as long as anySoundmight access it.- You can bundle
SoundDataandSoundtogether in your implementation. - Alternatively you can write your own
SoundDataManagerto avoid creating multipleSoundDatas for the same file.
- You can bundle
- Your sound will stop after some seconds, even if the audio file contains a longer sound.
Sounds do not update themselves. You need to callupdate()regularly.
How to include OpenALpp in your project
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)
CMake Options
OALPP_ENABLE_UNIT_TESTS- Enable unit tests - defaultONOALPP_ENABLE_APPROVAL_TESTS- Enable approval tests - defaultONOALPP_ENABLE_INTEGRATION_TESTS- Enable integration test - defaultONOALPP_STATIC_LIBRARY- Build OpenALpp and dependencies as static library - defaultON
Compiler compatibility
- Microsoft Visual C++ 2019
- clang++ from version 8
- g++ from version 9
- emscripten g++ version 9
Dependencies
- CMake 3.19
- One of the compatible compilers
All other dependencies (openal-soft and libnyquist) are automatically fetched via CMake.