4#include <SDL3/SDL_audio.h>
5#include "SDL3pp_iostream.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
148 constexpr explicit operator bool()
const {
return !!
value; }
184 constexpr explicit operator bool()
const {
return !!
value; }
194struct AudioStreamLock;
270 : m_audioFormat(audioFormat)
299 AudioFormatRaw(SDL_DEFINE_AUDIO_FORMAT(sign, bigendian, flt, size)))
347 constexpr bool IsFloat()
const;
399 constexpr bool IsInt()
const;
541 return SDL_AUDIO_BYTESIZE(x);
582 return SDL_AUDIO_ISBIGENDIAN(x);
604 return SDL_AUDIO_ISLITTLEENDIAN(x);
664 return SDL_AUDIO_ISUNSIGNED(x);
790 int additional_amount,
833 void(
AudioStreamRaw stream,
int additional_amount,
int total_amount)>;
863 : m_resource(resource)
954 : m_resource(
CheckError(SDL_OpenAudioDevice(devid, spec)))
964 std::swap(m_resource, other.m_resource);
988 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
1574 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1586 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1603 return SDL_AUDIO_FRAMESIZE(x);
1606#if SDL_VERSION_ATLEAST(3, 4, 0)
1665 std::function<void(
const void* buf,
int buflen)>;
1714 : m_resource(resource)
1755 : m_resource(
CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
1819 void* userdata =
nullptr)
1821 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
1888 std::swap(m_resource, other.m_resource);
1903 auto r = m_resource;
1904 m_resource =
nullptr;
1912 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
2380#if SDL_VERSION_ATLEAST(3, 4, 0)
2914#if SDL_VERSION_ATLEAST(3, 4, 0)
3063 : m_lock(other.m_lock)
3087 std::swap(m_lock, other.m_lock);
3092 constexpr operator bool()
const {
return bool(m_lock); }
3164 return SDL_GetAudioDriver(index);
3183 return SDL_GetCurrentAudioDriver();
3213 auto data =
CheckError(SDL_GetAudioPlaybackDevices(&count));
3245 auto data =
CheckError(SDL_GetAudioRecordingDevices(&count));
3275 return CheckError(SDL_GetAudioDeviceName(devid));
3314 int* sample_frames =
nullptr)
3317 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3348 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3458 return SDL_IsAudioDevicePhysical(devid);
3480 return SDL_IsAudioDevicePlayback(devid);
3576 return SDL_AudioDevicePaused(devid);
3607 return SDL_GetAudioDeviceGain(devid);
3649 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3678 SDL_CloseAudioDevice(devid);
3720 std::span<AudioStreamRef> streams)
3724 reinterpret_cast<SDL_AudioStream* const*
>(streams.data()),
3753 CheckError(SDL_BindAudioStream(devid, stream));
3781 SDL_UnbindAudioStreams(
3782 reinterpret_cast<SDL_AudioStream* const*
>(streams.data()), streams.size());
3801 SDL_UnbindAudioStream(stream);
3826 return {SDL_GetAudioStreamDevice(stream)};
3884 return {
CheckError(SDL_GetAudioStreamProperties(stream))};
3892#if SDL_VERSION_ATLEAST(3, 4, 0)
3894namespace prop::AudioStream {
3896constexpr auto _AUTO_CLEANUP_BOOLEAN =
3897 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3922 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3969 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3994 return SDL_GetAudioStreamFrequencyRatio(stream);
4029 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
4058 return SDL_GetAudioStreamGain(stream);
4090 CheckError(SDL_SetAudioStreamGain(stream, gain));
4121 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4122 if (!data)
return {};
4154 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4155 if (!data)
return {};
4221 std::span<int> chmap)
4224 SDL_SetAudioStreamInputChannelMap(stream, chmap.data(), chmap.size()));
4287 std::span<int> chmap)
4290 SDL_SetAudioStreamOutputChannelMap(stream, chmap.data(), chmap.size()));
4334#if SDL_VERSION_ATLEAST(3, 4, 0)
4437 Wrapper::Wrap(std::move(callback)));
4502 const void*
const* channel_buffers,
4507 stream, channel_buffers, num_channels, num_samples));
4515 m_resource, channel_buffers, num_channels, num_samples);
4549 return SDL_GetAudioStreamData(stream, buf.
data(), buf.
size_bytes());
4582 return SDL_GetAudioStreamAvailable(stream);
4627 return SDL_GetAudioStreamQueued(stream);
4707 CheckError(SDL_PauseAudioStreamDevice(stream));
4737 CheckError(SDL_ResumeAudioStreamDevice(stream));
4764 return SDL_AudioStreamDevicePaused(stream);
4805 : m_lock(std::move(resource))
4838 if (!m_lock)
return;
4888 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4996 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
5079 SDL_DestroyAudioStream(stream);
5144 void* userdata =
nullptr)
5146 return AudioStream(devid, spec, callback, userdata);
5213 return AudioStream(m_resource, spec, callback, userdata);
5289 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5427 bool closeio =
false)
5431 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len))
return {};
5462 if (!SDL_LoadWAV(path, spec, &buf, &len))
return {};
5579 CheckError(SDL_ConvertAudioSamples(&src_spec,
5601 return SDL_GetAudioFormatName(format);
5624 return SDL_GetSilenceValueForFormat(format);
SDL Audio Device instance IDs.
Definition: SDL3pp_audio.h:845
constexpr AudioDeviceID get() const noexcept
Retrieves underlying AudioDeviceID.
Definition: SDL3pp_audio.h:974
constexpr AudioDevice & operator=(const AudioDevice &other) noexcept=default
Assignment operator.
constexpr AudioDeviceID release() noexcept
Retrieves underlying AudioDeviceID and clear this.
Definition: SDL3pp_audio.h:977
~AudioDevice()
Destructor.
Definition: SDL3pp_audio.h:959
AudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:953
constexpr AudioDevice(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_audio.h:850
constexpr AudioDevice(const AudioDeviceID resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:862
constexpr auto operator<=>(const AudioDevice &other) const noexcept=default
Comparison.
constexpr AudioDevice(const AudioDevice &other) noexcept=default
Copy constructor.
constexpr AudioDevice & operator=(AudioDevice &&other) noexcept
Assignment operator.
Definition: SDL3pp_audio.h:962
constexpr AudioDevice(AudioDevice &&other) noexcept
Move constructor.
Definition: SDL3pp_audio.h:873
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:3026
AudioStreamRef get()
Get the reference to locked resource.
Definition: SDL3pp_audio.h:3111
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_audio.h:3085
void release()
Releases the lock without unlocking.
Definition: SDL3pp_audio.h:3114
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:3080
constexpr AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition: SDL3pp_audio.h:3062
The opaque handle that represents an audio stream.
Definition: SDL3pp_audio.h:1696
constexpr auto operator<=>(const AudioStream &other) const noexcept=default
Comparison.
~AudioStream()
Destructor.
Definition: SDL3pp_audio.h:1883
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition: SDL3pp_audio.h:1992
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition: SDL3pp_audio.h:2077
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition: SDL3pp_audio.h:1724
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition: SDL3pp_audio.h:2045
constexpr AudioStream(const AudioStreamRaw resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:1713
AudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:1753
constexpr AudioStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_audio.h:1701
constexpr AudioStreamRaw get() const noexcept
Retrieves underlying AudioStreamRaw.
Definition: SDL3pp_audio.h:1898
constexpr AudioStreamRaw release() noexcept
Retrieves underlying AudioStreamRaw and clear this.
Definition: SDL3pp_audio.h:1901
constexpr AudioStream(const AudioStream &other) noexcept=default
Copy constructor.
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition: SDL3pp_audio.h:1972
AudioStream(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec=std::nullopt, AudioStreamCallback callback=nullptr, void *userdata=nullptr)
Convenience function for straightforward audio init for the common case.
Definition: SDL3pp_audio.h:1816
constexpr AudioStream & operator=(const AudioStream &other) noexcept=default
Assignment operator.
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition: SDL3pp_audio.h:1886
Optional-like shim for references.
Definition: SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
Source byte stream.
Definition: SDL3pp_strings.h:240
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:304
constexpr const char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:307
constexpr const T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:314
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:326
constexpr char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:412
constexpr T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:416
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:409
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition: SDL3pp_assert.h:383
constexpr bool IsAudioFloat(AudioFormatRaw x)
Determine if an AudioFormat represents floating point data.
Definition: SDL3pp_audio.h:561
void Pause()
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3521
constexpr AudioFormat AUDIO_UNKNOWN
Unspecified audio format.
Definition: SDL3pp_audio.h:448
bool IsAudioDevicePlayback(AudioDeviceParam devid)
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3478
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition: SDL3pp_audio.h:5209
void Resume()
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3552
constexpr bool IsLittleEndian() const
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:607
void SetAudioPostmixCallback(AudioDeviceParam devid, AudioPostmixCallback callback, void *userdata)
Set a callback that fires when data is about to be fed to an audio device.
Definition: SDL3pp_audio.h:5285
const char * GetAudioDeviceName(AudioDeviceParam devid)
Get the human-readable name of a specific audio device.
Definition: SDL3pp_audio.h:3273
void GetAudioStreamFormat(AudioStreamParam stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3918
constexpr bool IsBigEndian() const
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:585
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3728
constexpr bool IsAudioInt(AudioFormatRaw x)
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:643
void LockAudioStream(AudioStreamParam stream)
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4797
constexpr Uint32 AUDIO_MASK_SIGNED
Mask of bits in an AudioFormat that contain the signed data flag.
Definition: SDL3pp_audio.h:234
constexpr Uint32 AUDIO_MASK_BITSIZE
Mask of bits in an AudioFormat that contains the format bit size.
Definition: SDL3pp_audio.h:204
bool AudioDevicePaused(AudioDeviceParam devid)
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3574
void PauseDevice()
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4710
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3925
constexpr AudioFormat AUDIO_S8
Signed 8-bit samples.
Definition: SDL3pp_audio.h:453
AudioDeviceRef GetAudioStreamDevice(AudioStreamParam stream)
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3824
constexpr Uint32 AUDIO_MASK_FLOAT
Mask of bits in an AudioFormat that contain the floating point flag.
Definition: SDL3pp_audio.h:214
SDL_AudioFormat AudioFormatRaw
Alias to raw representation for AudioFormat.
Definition: SDL3pp_audio.h:116
OwnArray< int > GetInputChannelMap() const
Get the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4126
OwnArray< Uint8 > ConvertAudioSamples(const AudioSpec &src_spec, SourceBytes src_data, const AudioSpec &dst_spec)
Convert some audio data of one format to another format.
Definition: SDL3pp_audio.h:5573
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:4032
AudioStreamLock(AudioStreamRef resource)
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4804
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition: SDL3pp_audio.h:243
OwnArray< int > GetAudioStreamOutputChannelMap(AudioStreamParam stream)
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4151
constexpr bool IsAudioUnsigned(AudioFormatRaw x)
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:662
int GetSilenceValueForFormat(AudioFormatRaw format)
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5622
int GetData(TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:4552
OwnArray< Uint8 > LoadWAV(IOStreamParam src, AudioSpec *spec, bool closeio=false)
Load the audio data of a WAVE file into memory.
Definition: SDL3pp_audio.h:5425
int GetAudioStreamQueued(AudioStreamParam stream)
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4625
constexpr AudioFormat AUDIO_S16
AUDIO_S16.
Definition: SDL3pp_audio.h:471
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition: SDL3pp_audio.h:465
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition: SDL3pp_audio.h:5048
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4159
float GetAudioDeviceGain(AudioDeviceParam devid)
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3605
constexpr Uint16 GetByteSize() const
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:544
void(SDLCALL *)(void *userdata, const AudioSpec *spec, float *buffer, int buflen) AudioPostmixCallback
A callback that fires when data is about to be fed to an audio device.
Definition: SDL3pp_audio.h:710
void ClearAudioStream(AudioStreamParam stream)
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4677
void SetAudioStreamGain(AudioStreamParam stream, float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:4088
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition: SDL3pp_audio.h:3181
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition: SDL3pp_audio.h:1636
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:3352
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:4585
float GetAudioStreamGain(AudioStreamParam stream)
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:4056
void PutAudioStreamData(AudioStreamParam stream, SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:4324
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3997
void SetAudioStreamGetCallback(AudioStreamParam stream, AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition: SDL3pp_audio.h:4884
constexpr bool IsAudioSigned(AudioFormatRaw x)
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:624
void ResumeDevice()
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4740
void SetAudioStreamOutputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4286
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5599
AudioDevice OpenAudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:3427
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4802
bool IsAudioDevicePhysical(AudioDeviceParam devid)
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3456
bool Paused() const
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3579
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamParam stream)
Get the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4118
void BindAudioStream(AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3756
void PutPlanarData(const void *const *channel_buffers, int num_channels, int num_samples)
Add data to the stream with each channel in a separate array.
Definition: SDL3pp_audio.h:4510
void SetAudioDeviceGain(AudioDeviceParam devid, float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3647
constexpr AudioFormat AUDIO_U8
Unsigned 8-bit samples.
Definition: SDL3pp_audio.h:451
void SetFormat(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Change the input and output formats of an audio stream.
Definition: SDL3pp_audio.h:3972
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4767
int GetAudioStreamAvailable(AudioStreamParam stream)
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:4580
SDL_AudioDeviceID AudioDeviceID
Alias to raw representation for AudioDevice.
Definition: SDL3pp_audio.h:125
constexpr Uint16 AudioBitSize(AudioFormatRaw x)
Retrieve the size, in bits, from an AudioFormat.
Definition: SDL3pp_audio.h:520
constexpr AudioFormat AUDIO_S32
AUDIO_S32.
Definition: SDL3pp_audio.h:473
void SetAudioStreamPutCallback(AudioStreamParam stream, AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition: SDL3pp_audio.h:4992
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5627
constexpr bool IsAudioLittleEndian(AudioFormatRaw x)
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:602
constexpr AudioFormat AUDIO_S16LE
Signed 16-bit samples.
Definition: SDL3pp_audio.h:455
constexpr Uint32 AUDIO_MASK_BIG_ENDIAN
Mask of bits in an AudioFormat that contain the bigendian flag.
Definition: SDL3pp_audio.h:224
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:3321
PropertiesRef GetProperties() const
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3887
float GetGain() const
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:4061
void SetAudioStreamFrequencyRatio(AudioStreamParam stream, float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:4027
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition: SDL3pp_audio.h:3242
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4293
void PutAudioStreamDataNoCopy(AudioStreamParam stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition: SDL3pp_audio.h:4379
void reset()
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4836
void SetGetCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition: SDL3pp_audio.h:4936
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3829
bool AudioStreamDevicePaused(AudioStreamParam stream)
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4762
constexpr AudioFormat AUDIO_S32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:462
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition: SDL3pp_audio.h:3162
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3483
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition: SDL3pp_audio.h:1585
AudioStream OpenAudioDeviceStream(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec, AudioStreamCallback callback=nullptr, void *userdata=nullptr)
Convenience function for straightforward audio init for the common case.
Definition: SDL3pp_audio.h:5141
constexpr AudioFormat DefineAudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition: SDL3pp_audio.h:500
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition: SDL3pp_audio.h:1573
constexpr AudioFormat AUDIO_S32LE
32-bit integer samples
Definition: SDL3pp_audio.h:460
void SetAudioStreamFormat(AudioStreamParam stream, OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Change the input and output formats of an audio stream.
Definition: SDL3pp_audio.h:3965
void Close()
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3681
constexpr bool IsInt() const
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:645
void BindAudioStream(AudioDeviceParam devid, AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3751
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceParam devid)
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:3345
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition: SDL3pp_audio.h:5497
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:3854
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4227
void Unbind()
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3804
SDL_AudioStream * AudioStreamRaw
Alias to raw representation for AudioStream.
Definition: SDL3pp_audio.h:161
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition: SDL3pp_audio.h:3278
constexpr bool IsFloat() const
Determine if an AudioFormat represents floating point data.
Definition: SDL3pp_audio.h:563
constexpr AudioFormat AUDIO_F32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:468
constexpr AudioFormat AUDIO_F32
AUDIO_F32.
Definition: SDL3pp_audio.h:475
int GetNumAudioDrivers()
Use this function to get the number of built-in audio drivers.
Definition: SDL3pp_audio.h:3138
void BindAudioStreams(AudioDeviceParam devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3719
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition: SDL3pp_audio.h:3779
void SetAudioStreamInputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4220
int GetQueued() const
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4630
int GetAudioStreamData(AudioStreamParam stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:4547
void UnbindAudioStream(AudioStreamParam stream)
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3799
void SetPostmixCallback(AudioPostmixCallback callback, void *userdata)
Set a callback that fires when data is about to be fed to an audio device.
Definition: SDL3pp_audio.h:5348
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3461
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition: SDL3pp_audio.h:5077
constexpr bool IsSigned() const
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:626
constexpr bool IsAudioBigENDIAN(AudioFormatRaw x)
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:580
void SetGain(float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3652
void UnlockAudioStream(AudioStreamParam stream)
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4825
constexpr AudioFormat AUDIO_S16BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:457
void PutData(SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:4329
void PauseAudioStreamDevice(AudioStreamParam stream)
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4705
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition: SDL3pp_audio.h:3210
float GetGain() const
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3610
AudioSpec GetAudioDeviceFormat(AudioDeviceParam devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:3313
PropertiesRef GetAudioStreamProperties(AudioStreamParam stream)
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3882
void FlushAudioStream(AudioStreamParam stream)
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition: SDL3pp_audio.h:4652
void(SDLCALL *)(void *userdata, AudioStreamRaw stream, int additional_amount, int total_amount) AudioStreamCallback
A callback that fires when data passes through an AudioStream.
Definition: SDL3pp_audio.h:791
constexpr Uint16 AudioByteSize(AudioFormatRaw x)
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:539
void PutDataNoCopy(SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition: SDL3pp_audio.h:4440
void Clear()
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4682
float GetAudioStreamFrequencyRatio(AudioStreamParam stream)
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3992
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition: SDL3pp_audio.h:4657
void PauseAudioDevice(AudioDeviceParam devid)
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3516
void ResumeAudioDevice(AudioDeviceParam devid)
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3547
void SetGain(float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:4093
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4830
const char * GetName() const
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5604
void PutAudioStreamPlanarData(AudioStreamParam stream, const void *const *channel_buffers, int num_channels, int num_samples)
Add data to the stream with each channel in a separate array.
Definition: SDL3pp_audio.h:4501
void ResumeAudioStreamDevice(AudioStreamParam stream)
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4735
std::function< void(const void *buf, int buflen)> AudioStreamDataCompleteCB
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition: SDL3pp_audio.h:1665
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3676
constexpr Uint16 GetBitSize() const
Retrieve the size, in bits, from an AudioFormat.
Definition: SDL3pp_audio.h:522
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition: SDL3pp_audio.h:1601
void Destroy()
Free an audio stream.
Definition: SDL3pp_audio.h:5082
constexpr bool IsUnsigned() const
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:667
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:315
Main include header for the SDL3pp library.
Safely wrap AudioDevice for non owning parameters.
Definition: SDL3pp_audio.h:132
AudioDeviceID value
parameter's AudioDeviceID
Definition: SDL3pp_audio.h:133
constexpr AudioDeviceParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_audio.h:142
constexpr auto operator<=>(const AudioDeviceParam &other) const =default
Comparison.
constexpr AudioDeviceParam(AudioDeviceID value)
Constructs from AudioDeviceID.
Definition: SDL3pp_audio.h:136
Semi-safe reference for AudioDevice.
Definition: SDL3pp_audio.h:1530
constexpr AudioDeviceRef(const AudioDeviceRef &other) noexcept=default
Copy constructor.
AudioDeviceRef(AudioDeviceID resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:1552
AudioDeviceRef(AudioDeviceParam resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:1540
~AudioDeviceRef()
Destructor.
Definition: SDL3pp_audio.h:1561
Safely wrap AudioStream for non owning parameters.
Definition: SDL3pp_audio.h:168
AudioStreamRaw value
parameter's AudioStreamRaw
Definition: SDL3pp_audio.h:169
constexpr auto operator<=>(const AudioStreamParam &other) const =default
Comparison.
constexpr AudioStreamParam(AudioStreamRaw value)
Constructs from AudioStreamRaw.
Definition: SDL3pp_audio.h:172
constexpr AudioStreamParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_audio.h:178
Semi-safe reference for AudioStream.
Definition: SDL3pp_audio.h:2973
constexpr AudioStreamRef(const AudioStreamRef &other) noexcept=default
Copy constructor.
~AudioStreamRef()
Destructor.
Definition: SDL3pp_audio.h:3004
AudioStreamRef(AudioStreamParam resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:2983
AudioStreamRef(AudioStreamRaw resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:2995
Definition: SDL3pp_callbackWrapper.h:20
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
Definition: SDL3pp_callbackWrapper.h:169
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716