SDL_audiolib 0.0.0
An audio decoding, resampling and mixing library
SDL_audiolib

With SDL_audiolib, you can play many forms of audio files in your programs. It uses SDL to access the audio hardware, and uses existing libraries to handle the decoding of various audio formats.

Only mono and stereo output are supported.

As of right now, only a C++ API is provided, and is not finalized yet. That means if you use this, expect API breaking changes every day. A C API will hopefully also be provided in the future.

The provided decoders are:

If the decoded audio does not match the output sample rate with which the library was initialized, it is resampled using one of the available resamplers:

Usage of the library is fairly simple. To play a music.ogg file containing Vorbis audio and having the audio automatically resampled by the internal resampler to the sample rate that the audio device is opened with (in this case 44.1kHz,) you would do:

#include <Aulib/DecoderVorbis.h>
#include <Aulib/ResamplerSpeex.h>
#include <Aulib/Stream.h>
#include <SDL.h>
#include <iostream>
int main()
{
// The library uses std::chrono for durations, seeking and fading.
using namespace std::chrono_literals;
// Initialize the SDL_audiolib library. Set the output sample rate to
// 44.1kHz, the audio format to 16-bit signed, use 2 output channels
// (stereo), and an 8kB output buffer.
if (Aulib::init(44100, AUDIO_S16SYS, 2, 8192) != 0) {
std::cerr << "Couldn't initialize audio: " << SDL_GetError() << '\n';
return EXIT_FAILURE;
}
// Create an audio stream that will play our Vorbis file using a Vorbis
// decoder and a Speex resampler.
Aulib::Stream music("music.ogg",
std::make_unique<Aulib::DecoderVorbis>(),
std::make_unique<Aulib::ResamplerSpeex>());
// Play it once with a fade-in of 700 milliseconds.
music.play(1, 700ms);
// Wait while the music is still playing.
while (music.isPlaying()) {
SDL_Delay(200);
}
// Shut down and clean up. Calling this manually is optional, since the
// library will call this automatically when the program exits.
}
A Stream handles playback for audio produced by a Decoder.
Definition: Stream.h:36
auto init(int freq, AudioFormat format, int channels, int frameSize, const std::string &device={}) -> bool
Initializes the audio system.
void quit()
Shuts down the SDL_audiolib library.