An open source library for audio playback and mixing.
Download dr_audio.h
dr_audio is an open source library for audio playback and mixing, released into the public domain. It's written in C in a single file with no dependencies except for the relevant back-ends (DirectSound, ALSA, etc.)
Features
  • Public domain.
  • Single file.
  • No dependencies except for back-ends (DirectSound, ALSA, etc.) and the standard library.
  • Written in C for maximum compatibility.
  • Can seamlessly make use of dr_wav, dr_flac and stb_vorbis by #including them before dr_audio. See example to the right.
  • Includes a layered API to simplify certain things, while still providing plenty of flexibility at a low level. The example to the right demonstrates dr_audio's high level APIs.
  • Multi-channel mixing (stereo to 5.1, etc.) (See limitations below.)
  • Runtime sample rate conversion. (See limitations below.)
  • Submixing.
Limitations and Future Plans
  • dr_audio is still very early in development. Expect a lot of missing features and bugs.
  • Multi-channel mixing is very basic. In all cases except for mono, unused channels are simply dropped.
  • Sample rate conversion is extremely low quality at the moment.
  • dr_audio is not currently optimized.
  • Recording is not currently supported, but is planned.
  • Effects and 3D spatialization are not currently supported, but are planned.
  • Only Windows (DirectSound) and Linux (ALSA) are currently supported. Support for more platforms and back-ends is planned.
  • dr_audio is not currently fully thread-safe, however thread-safety is one of the key planned features.
Examples
Example 1: This example demonstrates some of dr_audio's high level APIs. dr_audio can optionally depend on dr_flac by simply placing the #include "dr_audio.h" line after dr_flac, as shown below. The dra_voice_create_from_file function is a high level helper for loading a file using one of the supported decoders and then creating a voice containing the entire decoded file.
#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"

#define DR_AUDIO_IMPLEMENTATION
#include "dr_audio.h"

int main()
{
    dra_device* pDevice;
    dra_result result = dra_device_create(NULL, dra_device_type_playback, &pDevice);
    if (result != DRA_RESULT_SUCCESS) {
        return -1;
    }

    dra_voice* pVoice;
    result = dra_voice_create_from_file(pDevice, "my_song.flac", &pVoice);
    if (result != DRA_RESULT_SUCCESS) {
        return -1;
    }

    dra_voice_play(pVoice, false);

    printf("Press Enter to quit...\n");
    getchar();

    dra_voice_delete(pVoice);
    dra_device_delete(pDevice);
    return 0;
}
Developed by David Reid - mackron@gmail.com