← API Reference Class

asge::audio::AudioDevice

Owns SDL's audio subsystem, one physical playback device, and a fixed pool of up to 32 AudioStreams bound to it.

#include <AudioDevice.hpp>

Initialize() brings up SDL_INIT_AUDIO and opens the default playback device; CreateStream() then hands out a shared_ptr<AudioStream> per AudioSource wanting to play a clip, backed by a slot in the fixed m_Streams array. Callers keep that shared_ptr for as long as they're playing (see AudioSystem) — it stays valid regardless of which slot backs it, even across a DetachStream() call elsewhere that swap-removes and relocates a slot still in use. Shutdown() (also run from the destructor) tears both the streams and the device back down.

Static Private Attributes

#static constexpr std::size_t kMaxNofStreams = 32private

Private Attributes

#std::array< std::shared_ptr< AudioStream >, kMaxNofStreams > m_Streamsprivate
#SDL_AudioDeviceID m_DeviceId {0}private
#bool m_BackendInitialized {false}private
#std::size_t m_LastIndex {0}private

Public Member Functions

#~AudioDevice()
#BoolResult Initialize()

Initializes SDL's audio subsystem and opens the default playback device, resumed and ready.

#void Shutdown()
#std::size_t Size() const noexcept

Count of stream slots currently handed out (grows on CreateStream, shrinks on DetachStream).

#SDL_AudioDeviceID Id() const noexcept
#Result< std::shared_ptr< AudioStream > > CreateStream(media::AudioClip &inAudioClip) noexcept

Creates a new AudioStream matching inAudioClip's format, binds it to this device, and returns a shared handle into this device's stream pool that stays valid until DetachStream() releases it.

#BoolResult DetachStream(AudioStream &inStream) noexcept

Unbinds and releases a stream previously returned by CreateStream(), swap-removing its slot (relocating the trailing stream into it, if it wasn't already the trailing one) so the pool stays compact.

#BoolResult SetGain(float inVolume) noexcept

Sets the master playback gain for every stream on this device (1.0 = unchanged, 0.0 = silent).