SDL_audiolib 0.0.0
An audio decoding, resampling and mixing library
Aulib Namespace Reference

Classes

class  Decoder
 Abstract base class for audio decoders. More...
 
class  DecoderAdlmidi
 libADLMIDI decoder. More...
 
class  DecoderBassmidi
 BASSMIDI decoder. More...
 
class  DecoderDrflac
 dr_flac decoder. More...
 
class  DecoderDrmp3
 dr_mp3 decoder. More...
 
class  DecoderDrwav
 dr_wav decoder. More...
 
class  DecoderFlac
 libFLAC decoder. More...
 
class  DecoderFluidsynth
 FluidSynth decoder. More...
 
class  DecoderModplug
 ModPlug decoder. More...
 
class  DecoderMpg123
 mpg123 decoder. More...
 
class  DecoderMusepack
 libmpcdec decoder. More...
 
class  DecoderOpenmpt
 OpenMPT decoder. More...
 
class  DecoderOpus
 libopusfile decoder. More...
 
class  DecoderSndfile
 Libsndfile decoder. More...
 
class  DecoderVorbis
 libvorbisfile decoder. More...
 
class  DecoderWildmidi
 WildMIDI decoder. More...
 
class  DecoderXmp
 XMP decoder. More...
 
class  Processor
 Abstract base class for audio processors. More...
 
class  Resampler
 Abstract base class for audio resamplers. More...
 
class  ResamplerSdl
 SDL_AudioStream resampler. More...
 
class  ResamplerSox
 Sox resampler. More...
 
class  ResamplerSpeex
 Speex resampler. More...
 
class  ResamplerSrc
 SRC (libsamplerate) resampler. More...
 
class  Stream
 A Stream handles playback for audio produced by a Decoder. More...
 

Typedefs

using AudioFormat = Uint16
 

Functions

auto init (int freq, AudioFormat format, int channels, int frameSize, const std::string &device={}) -> bool
 Initializes the audio system. More...
 
auto initWithoutOutput (int freq, int channels) -> bool
 Initializes the library for decoding and resampling only. More...
 
void quit ()
 Shuts down the SDL_audiolib library. More...
 
auto sampleFormat () noexcept -> AudioFormat
 Sample format the audio device is actually using. More...
 
auto sampleRate () noexcept -> int
 Sample rate the audio device is actually using. More...
 
auto channelCount () noexcept -> int
 Number of output channels. More...
 
auto frameSize () noexcept -> int
 Number of frames (samples per channel) the audio device is actually using. More...
 

Typedef Documentation

◆ AudioFormat

using Aulib::AudioFormat = typedef Uint16

Function Documentation

◆ channelCount()

auto Aulib::channelCount ( ) -> int
noexcept

Number of output channels.

This always matches the amount of channels that was requested.

◆ frameSize()

auto Aulib::frameSize ( ) -> int
noexcept

Number of frames (samples per channel) the audio device is actually using.

This can be different than the frame size that was requested.

◆ init()

auto Aulib::init ( int  freq,
AudioFormat  format,
int  channels,
int  frameSize,
const std::string &  device = {} 
) -> bool

Initializes the audio system.

Parameters
freqSample rate that the audio device should be opened in. The sample rate that gets actually used might change though if the device does not support the requested rate. Use sampleRate() to find out the actual sample rate.
formatAudio sample format. The most common format is AUDIO_S16SYS. The formats are defined by SDL (SDL_audio.h). The actual format we end up using might be different than the one we request if the audio device does not support it. Use sampleFormat() to find out the actual sample format.
channelsAmount of output channels to use. Can either be 1 (mono) or 2 (stereo.) Lower or higher values will be adjusted. Unlike the other parameters, the channel count is enforced and will not change.
frameSizeSize in frames (samples per channel) of the internal buffer that is used to feed audio samples to SDL. Lower values provide lower latency on audio operations, at the cost of increased CPU usage and risk of audio drop-outs. A good value for 44.1kHz output for music players is 8192 bytes (8kB), while a game that needs to play sound effects without much latency would use something like 2048 instead. The actual frame size we end up using might be different. This depends on the audio device and output driver used by SDL. Use frameSize() to find out the actual frame size.
deviceA UTF-8 string reported by SDL_GetAudioDeviceName() or a driver-specific name as appropriate. An empty string requests the most reasonable default device.
Returns
Return values
trueThe audio system was initialized successfully.
falseThe audio system could not be initialized.

◆ initWithoutOutput()

auto Aulib::initWithoutOutput ( int  freq,
int  channels 
) -> bool

Initializes the library for decoding and resampling only.

Use this instead of the normal init function if you only want to decode and/or resample without actually playing any audio, or if you want to handle audio playback yourself.

SDL_InitSubSystem() will not be called and thus the SDL audio subsystem is left uninitialized.

You cannot use Aulib::Stream objects. Trying to do so will result in undefined behavior.

Parameters
freqTarget sample rate for decoders that generate audio themselves (like the MIDI and MOD decoders.)
channelsTarget channel count for decoders that generate audio themselves (like the MIDI and MOD decoders.)
Returns
Return values
trueThe library was initialized successfully.
falseThe library could not be initialized.

◆ quit()

void Aulib::quit ( )

Shuts down the SDL_audiolib library.

It is not required to call this function manually, as this happens automatically at program exit, but it is useful in cases where you want to shut down the audio system for some reason.

◆ sampleFormat()

auto Aulib::sampleFormat ( ) -> AudioFormat
noexcept

Sample format the audio device is actually using.

This can be different than the format that was requested.

◆ sampleRate()

auto Aulib::sampleRate ( ) -> int
noexcept

Sample rate the audio device is actually using.

This can be different than the sample rate that was requested.