Audio Library

A minimalistic audio library for games.
Play a sound in one line of C++ or C.

#include <Audio/Audio.hpp>

int main()
{
    Audio::Sound music { "music.ogg", Audio::Sound::Type::Music };
    music.setLooping( true );
    music.play();

    Audio::playSound( "coin.wav" );  // Fire and forget.
    ...
}

No audio device to set up or shut down. The library does that for you.

Play the demo

Brick Bounce is a minimal game that uses the Audio library. Every sound you hear in it is played by the Audio library. It's the same C++ code as the desktop version, compiled to WebAssembly so it runs in your browser. On the desktop, the game window is made with fenster, a tiny single-header library by Serge Zaitsev.

Click the game to start. Browsers only play sound after you click or tap the page.
Move: mouse or arrow keys · Launch: click or space · Pause: P
On a phone or tablet: drag your finger to move, tap to launch.
The buttons in the top-right corner of the game pause it and switch to fullscreen (or press F).

Streamed music

The background music is streamed from an OGG file. It fades down when you pause, and fades out when the game is over.

Panned effects

Every bounce is panned to where it happens. Hit bricks in a row and each one sounds a little higher.

Waveform jingles

The level-clear and game-over tunes are made with a Waveform, without any sound files.

Read the game's source code →

Features

Simple

Load a sound and play it. Copies of a sound share it, just like objects in C#, Java, Python or JavaScript.

Sounds and music

WAV, MP3, FLAC and OGG. Volume, panning, pitch, looping, fading and scheduled start and stop.

Spatial audio

Place sounds in 3D space around the player, with up to 4 listeners for split-screen games.

Retro waveforms

Generate sine, square, triangle and sawtooth tones for sound effects like early video games.

C++ and C

A header-only C++17 API on top of a stable C99 API. One library for both Debug and Release builds.

Runs everywhere

Windows, Linux and the web (Emscripten). Built on the excellent miniaudio.

Examples

Fire and forget, or load the sound for more control.

Audio::playSound( "explosion.wav" );  // Fire and forget.

Audio::Sound coin { "coin.wav" };
coin.setVolume( 0.5f );  // 0 is silent, 1 is 100%.
coin.setPan( -1.0f );    // -1 is left, 0 is centered, 1 is right.
coin.setPitch( 1.5f );   // Higher values sound higher.
coin.play();

More in the documentation →

Get the library

Your project needs C++17 or newer (or C99 for the C API).

Prebuilt package

For Visual Studio 2022 and newer. Download the static package from the Releases page, and follow the step-by-step guide.

CMake

Let CMake download and build it:

include(FetchContent)
FetchContent_Declare(Audio
    GIT_REPOSITORY https://github.com/3dgep/Audio.git
    GIT_TAG        v2.0.1)
FetchContent_MakeAvailable(Audio)

target_link_libraries(MyGame PRIVATE Audio::Audio)

vcpkg

Install the port from the repository's ports folder:

vcpkg install 3dgep-audio --overlay-ports=path/to/Audio/ports
find_package(Audio CONFIG REQUIRED)
target_link_libraries(MyGame PRIVATE Audio::Audio)

Questions? Ask on the 3dgep.com Discord server.