SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_audio.h
1#ifndef SDL3PP_AUDIO_H_
2#define SDL3PP_AUDIO_H_
3
4#include <SDL3/SDL_audio.h>
5#include "SDL3pp_iostream.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
8
9namespace SDL {
10
116using AudioFormatRaw = SDL_AudioFormat;
117
118// Forward decl
119struct AudioFormat;
120
121// Forward decl
122struct AudioDevice;
123
125using AudioDeviceID = SDL_AudioDeviceID;
126
127// Forward decl
128struct AudioDeviceRef;
129
132{
134
137 : value(value)
138 {
139 }
140
142 constexpr AudioDeviceParam(std::nullptr_t _ = nullptr)
143 : value(0)
144 {
145 }
146
148 constexpr explicit operator bool() const { return !!value; }
149
151 constexpr auto operator<=>(const AudioDeviceParam& other) const = default;
152
154 constexpr operator AudioDeviceID() const { return value; }
155};
156
157// Forward decl
158struct AudioStream;
159
161using AudioStreamRaw = SDL_AudioStream*;
162
163// Forward decl
164struct AudioStreamRef;
165
168{
170
173 : value(value)
174 {
175 }
176
178 constexpr AudioStreamParam(std::nullptr_t _ = nullptr)
179 : value(nullptr)
180 {
181 }
182
184 constexpr explicit operator bool() const { return !!value; }
185
187 constexpr auto operator<=>(const AudioStreamParam& other) const = default;
188
190 constexpr operator AudioStreamRaw() const { return value; }
191};
192
201constexpr Uint32 AUDIO_MASK_BITSIZE = SDL_AUDIO_MASK_BITSIZE;
202
211constexpr Uint32 AUDIO_MASK_FLOAT = SDL_AUDIO_MASK_FLOAT;
212
221constexpr Uint32 AUDIO_MASK_BIG_ENDIAN = SDL_AUDIO_MASK_BIG_ENDIAN;
222
231constexpr Uint32 AUDIO_MASK_SIGNED = SDL_AUDIO_MASK_SIGNED;
232
240using AudioSpec = SDL_AudioSpec;
241
257{
258 AudioFormatRaw m_audioFormat;
259
260public:
266 constexpr AudioFormat(AudioFormatRaw audioFormat = {}) noexcept
267 : m_audioFormat(audioFormat)
268 {
269 }
270
294 constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
295 : m_audioFormat(
296 AudioFormatRaw(SDL_DEFINE_AUDIO_FORMAT(sign, bigendian, flt, size)))
297 {
298 }
299
305 constexpr operator AudioFormatRaw() const noexcept { return m_audioFormat; }
306
318 constexpr Uint16 GetBitSize() const;
319
331 constexpr Uint16 GetByteSize() const;
332
344 constexpr bool IsFloat() const;
345
357 constexpr bool IsBigEndian() const;
358
370 constexpr bool IsLittleEndian() const;
371
383 constexpr bool IsSigned() const;
384
396 constexpr bool IsInt() const;
397
409 constexpr bool IsUnsigned() const;
410
421 const char* GetName() const;
422
435 int GetSilenceValue() const;
436};
437
438// Unfortunate name clash with SDL_oldnames.h
439#undef AUDIO_U8
440#undef AUDIO_S8
441#undef AUDIO_S16
442#undef AUDIO_S32
443#undef AUDIO_F32
444
446 SDL_AUDIO_UNKNOWN;
447
448constexpr AudioFormat AUDIO_U8 = SDL_AUDIO_U8;
449
450constexpr AudioFormat AUDIO_S8 = SDL_AUDIO_S8;
451
452constexpr AudioFormat AUDIO_S16LE = SDL_AUDIO_S16LE;
453
455 SDL_AUDIO_S16BE;
456
457constexpr AudioFormat AUDIO_S32LE = SDL_AUDIO_S32LE;
458
460 SDL_AUDIO_S32BE;
461
463 SDL_AUDIO_F32LE;
464
466 SDL_AUDIO_F32BE;
467
468constexpr AudioFormat AUDIO_S16 = SDL_AUDIO_S16;
469
470constexpr AudioFormat AUDIO_S32 = SDL_AUDIO_S32;
471
472constexpr AudioFormat AUDIO_F32 = SDL_AUDIO_F32;
473
497constexpr AudioFormat DefineAudioFormat(bool sign,
498 bool bigendian,
499 bool flt,
500 Uint16 size)
501{
502 return AudioFormat(sign, bigendian, flt, size);
503}
504
517constexpr Uint16 AudioBitSize(AudioFormatRaw x) { return SDL_AUDIO_BITSIZE(x); }
518
520{
521 return SDL::AudioBitSize(m_audioFormat);
522}
523
537{
538 return SDL_AUDIO_BYTESIZE(x);
539}
540
542{
543 return SDL::AudioByteSize(m_audioFormat);
544}
545
558constexpr bool IsAudioFloat(AudioFormatRaw x) { return SDL_AUDIO_ISFLOAT(x); }
559
560constexpr bool AudioFormat::IsFloat() const
561{
562 return SDL::IsAudioFloat(m_audioFormat);
563}
564
578{
579 return SDL_AUDIO_ISBIGENDIAN(x);
580}
581
582constexpr bool AudioFormat::IsBigEndian() const
583{
584 return SDL::IsAudioBigENDIAN(m_audioFormat);
585}
586
600{
601 return SDL_AUDIO_ISLITTLEENDIAN(x);
602}
603
604constexpr bool AudioFormat::IsLittleEndian() const
605{
606 return SDL::IsAudioLittleEndian(m_audioFormat);
607}
608
621constexpr bool IsAudioSigned(AudioFormatRaw x) { return SDL_AUDIO_ISSIGNED(x); }
622
623constexpr bool AudioFormat::IsSigned() const
624{
625 return SDL::IsAudioSigned(m_audioFormat);
626}
627
640constexpr bool IsAudioInt(AudioFormatRaw x) { return SDL_AUDIO_ISINT(x); }
641
642constexpr bool AudioFormat::IsInt() const
643{
644 return SDL::IsAudioInt(m_audioFormat);
645}
646
660{
661 return SDL_AUDIO_ISUNSIGNED(x);
662}
663
664constexpr bool AudioFormat::IsUnsigned() const
665{
666 return SDL::IsAudioUnsigned(m_audioFormat);
667}
668
704using AudioPostmixCallback = void(SDLCALL*)(void* userdata,
705 const AudioSpec* spec,
706 float* buffer,
707 int buflen);
708
744 MakeFrontCallback<void(const AudioSpec* spec, float* buffer, int buflen)>;
745
785using AudioStreamCallback = void(SDLCALL*)(void* userdata,
786 AudioStreamRaw stream,
787 int additional_amount,
788 int total_amount);
789
830 void(AudioStreamRaw stream, int additional_amount, int total_amount)>;
831
842{
843 AudioDeviceID m_resource = 0;
844
845public:
847 constexpr AudioDevice(std::nullptr_t = nullptr) noexcept
848 : m_resource(0)
849 {
850 }
851
859 constexpr explicit AudioDevice(const AudioDeviceID resource) noexcept
860 : m_resource(resource)
861 {
862 }
863
865 constexpr AudioDevice(const AudioDevice& other) = delete;
866
868 constexpr AudioDevice(AudioDevice&& other) noexcept
869 : AudioDevice(other.release())
870 {
871 }
872
873 constexpr AudioDevice(const AudioDeviceRef& other) = delete;
874
875 constexpr AudioDevice(AudioDeviceRef&& other) = delete;
876
949 : m_resource(CheckError(SDL_OpenAudioDevice(devid, spec)))
950 {
951 }
952
954 ~AudioDevice() { SDL_CloseAudioDevice(m_resource); }
955
957 constexpr AudioDevice& operator=(AudioDevice&& other) noexcept
958 {
959 std::swap(m_resource, other.m_resource);
960 return *this;
961 }
962
963protected:
965 constexpr AudioDevice& operator=(const AudioDevice& other) noexcept = default;
966
967public:
969 constexpr AudioDeviceID get() const noexcept { return m_resource; }
970
972 constexpr AudioDeviceID release() noexcept
973 {
974 auto r = m_resource;
975 m_resource = 0;
976 return r;
977 }
978
980 constexpr auto operator<=>(const AudioDevice& other) const noexcept = default;
981
983 constexpr explicit operator bool() const noexcept { return !!m_resource; }
984
986 constexpr operator AudioDeviceParam() const noexcept { return {m_resource}; }
987
1004 void Close();
1005
1028 const char* GetName() const;
1029
1061 AudioSpec GetFormat(int* sample_frames = nullptr) const;
1062
1082
1105 bool IsPhysical() const;
1106
1118 bool IsPlayback() const;
1119
1147 void Pause();
1148
1172 void Resume();
1173
1193 bool Paused() const;
1194
1215 float GetGain() const;
1216
1248 void SetGain(float gain);
1249
1285 void BindAudioStreams(std::span<AudioStreamRef> streams);
1286
1304 void BindAudioStream(AudioStreamParam stream);
1305
1356 void SetPostmixCallback(AudioPostmixCallback callback, void* userdata);
1357
1407 void SetPostmixCallback(AudioPostmixCB callback);
1408
1465 AudioStreamCallback callback,
1466 void* userdata);
1467
1520 AudioStreamCB callback);
1521};
1522
1525{
1527
1536 : AudioDevice(resource.value)
1537 {
1538 }
1539
1548 : AudioDevice(resource)
1549 {
1550 }
1551
1553 AudioDeviceRef(const AudioDeviceRef& other) noexcept
1554 : AudioDevice(other.get())
1555 {
1556 }
1557
1560};
1561
1572 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1573
1584 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1585
1599constexpr int AudioFrameSize(const AudioSpec& x)
1600{
1601 return SDL_AUDIO_FRAMESIZE(x);
1602}
1603
1604#if SDL_VERSION_ATLEAST(3, 3, 6)
1605
1632using AudioStreamDataCompleteCallback = void(SDLCALL*)(void* userdata,
1633 const void* buf,
1634 int buflen);
1635
1663 std::function<void(const void* buf, int buflen)>;
1664
1665#endif // SDL_VERSION_ATLEAST(3, 3, 6)
1666
1694{
1695 AudioStreamRaw m_resource = nullptr;
1696
1697public:
1699 constexpr AudioStream(std::nullptr_t = nullptr) noexcept
1700 : m_resource(0)
1701 {
1702 }
1703
1711 constexpr explicit AudioStream(const AudioStreamRaw resource) noexcept
1712 : m_resource(resource)
1713 {
1714 }
1715
1717 constexpr AudioStream(const AudioStream& other) = delete;
1718
1720 constexpr AudioStream(AudioStream&& other) noexcept
1721 : AudioStream(other.release())
1722 {
1723 }
1724
1725 constexpr AudioStream(const AudioStreamRef& other) = delete;
1726
1727 constexpr AudioStream(AudioStreamRef&& other) = delete;
1728
1751 : m_resource(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
1752 {
1753 }
1754
1813 OptionalRef<const AudioSpec> spec = std::nullopt,
1814 AudioStreamCallback callback = nullptr,
1815 void* userdata = nullptr)
1816 : m_resource(
1817 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
1818 {
1819 }
1820
1876 AudioStreamCB callback);
1877
1879 ~AudioStream() { SDL_DestroyAudioStream(m_resource); }
1880
1882 constexpr AudioStream& operator=(AudioStream&& other) noexcept
1883 {
1884 std::swap(m_resource, other.m_resource);
1885 return *this;
1886 }
1887
1888protected:
1890 constexpr AudioStream& operator=(const AudioStream& other) noexcept = default;
1891
1892public:
1894 constexpr AudioStreamRaw get() const noexcept { return m_resource; }
1895
1897 constexpr AudioStreamRaw release() noexcept
1898 {
1899 auto r = m_resource;
1900 m_resource = nullptr;
1901 return r;
1902 }
1903
1905 constexpr auto operator<=>(const AudioStream& other) const noexcept = default;
1906
1908 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1909
1911 constexpr operator AudioStreamParam() const noexcept { return {m_resource}; }
1912
1930 void Destroy();
1931
1954
1969 {
1970 AudioSpec spec;
1971 GetFormat(&spec, nullptr);
1972 return spec;
1973 }
1974
1989 {
1990 AudioSpec spec;
1991 GetFormat(nullptr, &spec);
1992 return spec;
1993 }
1994
2009 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
2010
2041 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
2042
2073 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
2074
2110
2124 float GetFrequencyRatio() const;
2125
2150 void SetFrequencyRatio(float ratio);
2151
2170 float GetGain() const;
2171
2193 void SetGain(float gain);
2194
2215
2236
2292 void SetInputChannelMap(std::span<int> chmap);
2293
2347 void SetOutputChannelMap(std::span<int> chmap);
2348
2374 void PutData(SourceBytes buf);
2375
2376#if SDL_VERSION_ATLEAST(3, 3, 6)
2377
2420 void PutDataNoCopy(SourceBytes buf,
2422 void* userdata);
2423
2465
2466#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2467
2494 int GetData(TargetBytes buf);
2495
2519 int GetAvailable() const;
2520
2556 int GetQueued() const;
2557
2574 void Flush();
2575
2593 void Clear();
2594
2615 void PauseDevice();
2616
2636 void ResumeDevice();
2637
2654 bool DevicePaused() const;
2655
2680 void Lock();
2681
2696 void Unlock();
2697
2740 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2741
2782 void SetGetCallback(AudioStreamCB callback);
2783
2829 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2830
2874 void SetPutCallback(AudioStreamCB callback);
2875
2888 void Unbind();
2889
2908 AudioDeviceRef GetDevice() const;
2909
2910#if SDL_VERSION_ATLEAST(3, 3, 6)
2911
2960 void PutPlanarData(const void* const* channel_buffers,
2961 int num_channels,
2962 int num_samples);
2963
2964#endif // SDL_VERSION_ATLEAST(3, 3, 6)
2965};
2966
2969{
2971
2980 : AudioStream(resource.value)
2981 {
2982 }
2983
2992 : AudioStream(resource)
2993 {
2994 }
2995
2997 AudioStreamRef(const AudioStreamRef& other) noexcept
2998 : AudioStream(other.get())
2999 {
3000 }
3001
3004};
3005
3027inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
3028
3051inline const char* GetAudioDriver(int index)
3052{
3053 return SDL_GetAudioDriver(index);
3054}
3055
3070inline const char* GetCurrentAudioDriver()
3071{
3072 return SDL_GetCurrentAudioDriver();
3073}
3074
3100{
3101 int count;
3102 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3103 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3104 size_t(count)};
3105}
3106
3132{
3133 int count;
3134 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3135 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3136 size_t(count)};
3137}
3138
3162inline const char* GetAudioDeviceName(AudioDeviceParam devid)
3163{
3164 return CheckError(SDL_GetAudioDeviceName(devid));
3165}
3166
3167inline const char* AudioDevice::GetName() const
3168{
3169 return SDL::GetAudioDeviceName(m_resource);
3170}
3171
3203 int* sample_frames = nullptr)
3204{
3205 AudioSpec spec;
3206 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3207 return spec;
3208}
3209
3210inline AudioSpec AudioDevice::GetFormat(int* sample_frames) const
3211{
3212 return SDL::GetAudioDeviceFormat(m_resource, sample_frames);
3213}
3214
3235{
3236 int count;
3237 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3238 return OwnArray<int>{data, size_t(count)};
3239}
3240
3242{
3243 return SDL::GetAudioDeviceChannelMap(m_resource);
3244}
3245
3318{
3319 return AudioDevice(devid, spec);
3320}
3321
3346{
3347 return SDL_IsAudioDevicePhysical(devid);
3348}
3349
3350inline bool AudioDevice::IsPhysical() const
3351{
3352 return SDL::IsAudioDevicePhysical(m_resource);
3353}
3354
3368{
3369 return SDL_IsAudioDevicePlayback(devid);
3370}
3371
3372inline bool AudioDevice::IsPlayback() const
3373{
3374 return SDL::IsAudioDevicePlayback(m_resource);
3375}
3376
3406{
3407 CheckError(SDL_PauseAudioDevice(devid));
3408}
3409
3410inline void AudioDevice::Pause() { SDL::PauseAudioDevice(m_resource); }
3411
3437{
3438 CheckError(SDL_ResumeAudioDevice(devid));
3439}
3440
3441inline void AudioDevice::Resume() { SDL::ResumeAudioDevice(m_resource); }
3442
3464{
3465 return SDL_AudioDevicePaused(devid);
3466}
3467
3468inline bool AudioDevice::Paused() const
3469{
3470 return SDL::AudioDevicePaused(m_resource);
3471}
3472
3495{
3496 return SDL_GetAudioDeviceGain(devid);
3497}
3498
3499inline float AudioDevice::GetGain() const
3500{
3501 return SDL::GetAudioDeviceGain(m_resource);
3502}
3503
3536inline void SetAudioDeviceGain(AudioDeviceParam devid, float gain)
3537{
3538 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3539}
3540
3541inline void AudioDevice::SetGain(float gain)
3542{
3543 SDL::SetAudioDeviceGain(m_resource, gain);
3544}
3545
3566{
3567 SDL_CloseAudioDevice(devid);
3568}
3569
3571
3609 std::span<AudioStreamRef> streams)
3610{
3611 CheckError(SDL_BindAudioStreams(
3612 devid,
3613 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3614 streams.size()));
3615}
3616
3617inline void AudioDevice::BindAudioStreams(std::span<AudioStreamRef> streams)
3618{
3619 SDL::BindAudioStreams(m_resource, streams);
3620}
3621
3641{
3642 CheckError(SDL_BindAudioStream(devid, stream));
3643}
3644
3646{
3647 SDL::BindAudioStream(m_resource, stream);
3648}
3649
3668inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3669{
3670 SDL_UnbindAudioStreams(
3671 reinterpret_cast<SDL_AudioStream* const*>(streams.data()), streams.size());
3672}
3673
3689{
3690 SDL_UnbindAudioStream(stream);
3691}
3692
3693inline void AudioStream::Unbind() { SDL::UnbindAudioStream(m_resource); }
3694
3714{
3715 return {SDL_GetAudioStreamDevice(stream)};
3716}
3717
3719{
3720 return SDL::GetAudioStreamDevice(m_resource);
3721}
3722
3745{
3746 return AudioStream(src_spec, dst_spec);
3747}
3748
3772{
3773 return {CheckError(SDL_GetAudioStreamProperties(stream))};
3774}
3775
3777{
3778 return SDL::GetAudioStreamProperties(m_resource);
3779}
3780
3781namespace prop::AudioStream {
3782
3783#if SDL_VERSION_ATLEAST(3, 3, 2)
3784
3785constexpr auto _AUTO_CLEANUP_BOOLEAN =
3786 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3787
3788#endif // SDL_VERSION_ATLEAST(3, 3, 2)
3789
3790} // namespace prop::AudioStream
3791
3808 AudioSpec* src_spec,
3809 AudioSpec* dst_spec)
3810{
3811 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3812}
3813
3814inline void AudioStream::GetFormat(AudioSpec* src_spec,
3815 AudioSpec* dst_spec) const
3816{
3817 SDL::GetAudioStreamFormat(m_resource, src_spec, dst_spec);
3818}
3819
3857{
3858 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3859}
3860
3863{
3864 SDL::SetAudioStreamFormat(m_resource, src_spec, dst_spec);
3865}
3866
3882{
3883 return SDL_GetAudioStreamFrequencyRatio(stream);
3884}
3885
3887{
3888 return SDL::GetAudioStreamFrequencyRatio(m_resource);
3889}
3890
3916inline void SetAudioStreamFrequencyRatio(AudioStreamParam stream, float ratio)
3917{
3918 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3919}
3920
3921inline void AudioStream::SetFrequencyRatio(float ratio)
3922{
3923 SDL::SetAudioStreamFrequencyRatio(m_resource, ratio);
3924}
3925
3946{
3947 return SDL_GetAudioStreamGain(stream);
3948}
3949
3950inline float AudioStream::GetGain() const
3951{
3952 return SDL::GetAudioStreamGain(m_resource);
3953}
3954
3977inline void SetAudioStreamGain(AudioStreamParam stream, float gain)
3978{
3979 CheckError(SDL_SetAudioStreamGain(stream, gain));
3980}
3981
3982inline void AudioStream::SetGain(float gain)
3983{
3984 SDL::SetAudioStreamGain(m_resource, gain);
3985}
3986
4008{
4009 int count;
4010 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4011 if (!data) return {};
4012 return OwnArray<int>{data, size_t(count)};
4013}
4014
4016{
4017 return SDL::GetAudioStreamInputChannelMap(m_resource);
4018}
4019
4041{
4042 int count;
4043 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4044 if (!data) return {};
4045 return OwnArray<int>{data, size_t(count)};
4046}
4047
4049{
4050 return SDL::GetAudioStreamOutputChannelMap(m_resource);
4051}
4052
4110 std::span<int> chmap)
4111{
4112 CheckError(
4113 SDL_SetAudioStreamInputChannelMap(stream, chmap.data(), chmap.size()));
4114}
4115
4116inline void AudioStream::SetInputChannelMap(std::span<int> chmap)
4117{
4118 SDL::SetAudioStreamInputChannelMap(m_resource, chmap);
4119}
4120
4176 std::span<int> chmap)
4177{
4178 CheckError(
4179 SDL_SetAudioStreamOutputChannelMap(stream, chmap.data(), chmap.size()));
4180}
4181
4182inline void AudioStream::SetOutputChannelMap(std::span<int> chmap)
4183{
4184 SDL::SetAudioStreamOutputChannelMap(m_resource, chmap);
4185}
4186
4214{
4215 CheckError(SDL_PutAudioStreamData(stream, buf.data(), buf.size_bytes()));
4216}
4217
4219{
4220 SDL::PutAudioStreamData(m_resource, std::move(buf));
4221}
4222
4223#if SDL_VERSION_ATLEAST(3, 3, 6)
4224
4269 SourceBytes buf,
4271 void* userdata)
4272{
4273 CheckError(SDL_PutAudioStreamDataNoCopy(
4274 stream, buf.data(), buf.size_bytes(), callback, userdata));
4275}
4276
4319 SourceBytes buf,
4321{
4324 std::move(buf),
4325 &Wrapper::CallOnce,
4326 Wrapper::Wrap(std::move(callback)));
4327}
4328
4331 void* userdata)
4332{
4333 SDL::PutAudioStreamDataNoCopy(m_resource, std::move(buf), callback, userdata);
4334}
4335
4338{
4339 SDL::PutAudioStreamDataNoCopy(m_resource, std::move(buf), callback);
4340}
4341
4391 const void* const* channel_buffers,
4392 int num_channels,
4393 int num_samples)
4394{
4395 CheckError(SDL_PutAudioStreamPlanarData(
4396 stream, channel_buffers, num_channels, num_samples));
4397}
4398
4399inline void AudioStream::PutPlanarData(const void* const* channel_buffers,
4400 int num_channels,
4401 int num_samples)
4402{
4404 m_resource, channel_buffers, num_channels, num_samples);
4405}
4406
4407#endif // SDL_VERSION_ATLEAST(3, 3, 6)
4408
4437{
4438 return SDL_GetAudioStreamData(stream, buf.data(), buf.size_bytes());
4439}
4440
4442{
4443 return SDL::GetAudioStreamData(m_resource, std::move(buf));
4444}
4445
4470{
4471 return SDL_GetAudioStreamAvailable(stream);
4472}
4473
4475{
4476 return SDL::GetAudioStreamAvailable(m_resource);
4477}
4478
4515{
4516 return SDL_GetAudioStreamQueued(stream);
4517}
4518
4519inline int AudioStream::GetQueued() const
4520{
4521 return SDL::GetAudioStreamQueued(m_resource);
4522}
4523
4542{
4543 CheckError(SDL_FlushAudioStream(stream));
4544}
4545
4546inline void AudioStream::Flush() { SDL::FlushAudioStream(m_resource); }
4547
4567{
4568 CheckError(SDL_ClearAudioStream(stream));
4569}
4570
4571inline void AudioStream::Clear() { SDL::ClearAudioStream(m_resource); }
4572
4595{
4596 CheckError(SDL_PauseAudioStreamDevice(stream));
4597}
4598
4600{
4601 SDL::PauseAudioStreamDevice(m_resource);
4602}
4603
4625{
4626 CheckError(SDL_ResumeAudioStreamDevice(stream));
4627}
4628
4630{
4631 SDL::ResumeAudioStreamDevice(m_resource);
4632}
4633
4652{
4653 return SDL_AudioStreamDevicePaused(stream);
4654}
4655
4656inline bool AudioStream::DevicePaused() const
4657{
4658 return SDL::AudioStreamDevicePaused(m_resource);
4659}
4660
4687{
4688 CheckError(SDL_LockAudioStream(stream));
4689}
4690
4691inline void AudioStream::Lock() { SDL::LockAudioStream(m_resource); }
4692
4709{
4710 CheckError(SDL_UnlockAudioStream(stream));
4711}
4712
4713inline void AudioStream::Unlock() { SDL::UnlockAudioStream(m_resource); }
4714
4757 AudioStreamCallback callback,
4758 void* userdata)
4759{
4760 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4761}
4762
4803 AudioStreamCB callback)
4804{
4805 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4806}
4807
4809 void* userdata)
4810{
4811 SDL::SetAudioStreamGetCallback(m_resource, callback, userdata);
4812}
4813
4815{
4816 SDL::SetAudioStreamGetCallback(m_resource, callback);
4817}
4818
4865 AudioStreamCallback callback,
4866 void* userdata)
4867{
4868 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4869}
4870
4915 AudioStreamCB callback)
4916{
4917 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
4918}
4919
4921 void* userdata)
4922{
4923 SDL::SetAudioStreamPutCallback(m_resource, callback, userdata);
4924}
4925
4927{
4928 SDL::SetAudioStreamPutCallback(m_resource, callback);
4929}
4930
4950{
4951 SDL_DestroyAudioStream(stream);
4952}
4953
4955
5015 AudioStreamCallback callback = nullptr,
5016 void* userdata = nullptr)
5017{
5018 return AudioStream(devid, spec, callback, userdata);
5019}
5020
5076 AudioStreamCB callback)
5077{
5078 return AudioStream(devid, spec, callback);
5079}
5080
5082 AudioStreamCallback callback,
5083 void* userdata)
5084{
5085 return AudioStream(m_resource, spec, callback, userdata);
5086}
5087
5089 AudioStreamCB callback)
5090{
5091 return AudioStream(m_resource, spec, callback);
5092}
5093
5096 AudioStreamCB callback)
5097 : AudioStream(devid, spec)
5098{
5099 if (IsAudioDevicePlayback(devid)) {
5100 SetGetCallback(std::move(callback));
5101 } else {
5102 SetPutCallback(std::move(callback));
5103 }
5104}
5105
5158 AudioPostmixCallback callback,
5159 void* userdata)
5160{
5161 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5162}
5163
5215 AudioPostmixCB callback)
5216{
5217 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5218}
5219
5221 void* userdata)
5222{
5223 SDL::SetAudioPostmixCallback(m_resource, callback, userdata);
5224}
5225
5227{
5228 SDL::SetAudioPostmixCallback(m_resource, callback);
5229}
5230
5298 AudioSpec* spec,
5299 bool closeio = false)
5300{
5301 Uint8* buf;
5302 Uint32 len;
5303 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
5304 return OwnArray<Uint8>{buf, size_t(len)};
5305}
5306
5331{
5332 Uint8* buf;
5333 Uint32 len;
5334 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5335 return OwnArray<Uint8>{buf, size_t(len)};
5336}
5337
5369inline void MixAudio(Uint8* dst,
5370 SourceBytes src,
5371 AudioFormat format,
5372 float volume)
5373{
5374 CheckError(
5375 SDL_MixAudio(dst, src.data_as<Uint8>(), format, src.size_bytes(), volume));
5376}
5377
5409inline void MixAudio(TargetBytes dst,
5410 SourceBytes src,
5411 AudioFormat format,
5412 float volume)
5413{
5414 if (dst.size_bytes() < src.size_bytes()) {
5415 MixAudio(dst.data_as<Uint8>(),
5416 SourceBytes{src.data(), dst.size_bytes()},
5417 format,
5418 volume);
5419 } else
5420 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5421}
5422
5446 SourceBytes src_data,
5447 const AudioSpec& dst_spec)
5448{
5449 Uint8* buf;
5450 int len;
5451 CheckError(SDL_ConvertAudioSamples(&src_spec,
5452 src_data.data_as<Uint8>(),
5453 src_data.size_bytes(),
5454 &dst_spec,
5455 &buf,
5456 &len));
5457 return OwnArray<Uint8>{buf, size_t(len)};
5458}
5459
5471inline const char* GetAudioFormatName(AudioFormatRaw format)
5472{
5473 return SDL_GetAudioFormatName(format);
5474}
5475
5476inline const char* AudioFormat::GetName() const
5477{
5478 return SDL::GetAudioFormatName(m_audioFormat);
5479}
5480
5495{
5496 return SDL_GetSilenceValueForFormat(format);
5497}
5498
5500{
5501 return SDL::GetSilenceValueForFormat(m_audioFormat);
5502}
5503
5505
5506} // namespace SDL
5507
5508#endif /* SDL3PP_AUDIO_H_ */
SDL Audio Device instance IDs.
Definition: SDL3pp_audio.h:842
constexpr AudioDevice(const AudioDevice &other)=delete
Copy constructor.
constexpr AudioDeviceID get() const noexcept
Retrieves underlying AudioDeviceID.
Definition: SDL3pp_audio.h:969
constexpr AudioDevice & operator=(const AudioDevice &other) noexcept=default
Assignment operator.
constexpr AudioDeviceID release() noexcept
Retrieves underlying AudioDeviceID and clear this.
Definition: SDL3pp_audio.h:972
~AudioDevice()
Destructor.
Definition: SDL3pp_audio.h:954
AudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:948
constexpr AudioDevice(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_audio.h:847
constexpr AudioDevice(const AudioDeviceID resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:859
constexpr auto operator<=>(const AudioDevice &other) const noexcept=default
Comparison.
constexpr AudioDevice & operator=(AudioDevice &&other) noexcept
Assignment operator.
Definition: SDL3pp_audio.h:957
constexpr AudioDevice(AudioDevice &&other) noexcept
Move constructor.
Definition: SDL3pp_audio.h:868
Audio format.
Definition: SDL3pp_audio.h:257
constexpr AudioFormat(AudioFormatRaw audioFormat={}) noexcept
Wraps AudioFormat.
Definition: SDL3pp_audio.h:266
constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition: SDL3pp_audio.h:294
The opaque handle that represents an audio stream.
Definition: SDL3pp_audio.h:1694
constexpr auto operator<=>(const AudioStream &other) const noexcept=default
Comparison.
~AudioStream()
Destructor.
Definition: SDL3pp_audio.h:1879
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition: SDL3pp_audio.h:1988
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition: SDL3pp_audio.h:2073
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition: SDL3pp_audio.h:1720
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition: SDL3pp_audio.h:2041
constexpr AudioStream(const AudioStreamRaw resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:1711
AudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:1749
constexpr AudioStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_audio.h:1699
constexpr AudioStreamRaw get() const noexcept
Retrieves underlying AudioStreamRaw.
Definition: SDL3pp_audio.h:1894
constexpr AudioStreamRaw release() noexcept
Retrieves underlying AudioStreamRaw and clear this.
Definition: SDL3pp_audio.h:1897
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition: SDL3pp_audio.h:1968
constexpr AudioStream(const AudioStream &other)=delete
Copy constructor.
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:1812
constexpr AudioStream & operator=(const AudioStream &other) noexcept=default
Assignment operator.
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition: SDL3pp_audio.h:1882
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:239
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:303
constexpr const char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:306
constexpr const T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:313
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:325
constexpr char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:411
constexpr T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:415
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:408
constexpr bool IsAudioFloat(AudioFormatRaw x)
Determine if an AudioFormat represents floating point data.
Definition: SDL3pp_audio.h:558
void Pause()
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3410
constexpr AudioFormat AUDIO_UNKNOWN
Unspecified audio format.
Definition: SDL3pp_audio.h:445
bool IsAudioDevicePlayback(AudioDeviceParam devid)
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3367
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition: SDL3pp_audio.h:5081
void Resume()
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3441
constexpr bool IsLittleEndian() const
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:604
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:5157
const char * GetAudioDeviceName(AudioDeviceParam devid)
Get the human-readable name of a specific audio device.
Definition: SDL3pp_audio.h:3162
void GetAudioStreamFormat(AudioStreamParam stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3807
constexpr bool IsBigEndian() const
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:582
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3617
constexpr bool IsAudioInt(AudioFormatRaw x)
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:640
void LockAudioStream(AudioStreamParam stream)
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4686
void Lock()
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4691
constexpr Uint32 AUDIO_MASK_SIGNED
Mask of bits in an AudioFormat that contain the signed data flag.
Definition: SDL3pp_audio.h:231
constexpr Uint32 AUDIO_MASK_BITSIZE
Mask of bits in an AudioFormat that contains the format bit size.
Definition: SDL3pp_audio.h:201
bool AudioDevicePaused(AudioDeviceParam devid)
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3463
void PauseDevice()
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4599
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3814
constexpr AudioFormat AUDIO_S8
Signed 8-bit samples.
Definition: SDL3pp_audio.h:450
AudioDeviceRef GetAudioStreamDevice(AudioStreamParam stream)
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3713
constexpr Uint32 AUDIO_MASK_FLOAT
Mask of bits in an AudioFormat that contain the floating point flag.
Definition: SDL3pp_audio.h:211
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:4015
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:5445
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3921
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition: SDL3pp_audio.h:240
OwnArray< int > GetAudioStreamOutputChannelMap(AudioStreamParam stream)
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4040
constexpr bool IsAudioUnsigned(AudioFormatRaw x)
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:659
int GetSilenceValueForFormat(AudioFormatRaw format)
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5494
int GetData(TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:4441
OwnArray< Uint8 > LoadWAV(IOStreamParam src, AudioSpec *spec, bool closeio=false)
Load the audio data of a WAVE file into memory.
Definition: SDL3pp_audio.h:5297
int GetAudioStreamQueued(AudioStreamParam stream)
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4514
constexpr AudioFormat AUDIO_S16
AUDIO_S16.
Definition: SDL3pp_audio.h:468
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition: SDL3pp_audio.h:462
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition: SDL3pp_audio.h:4920
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4048
float GetAudioDeviceGain(AudioDeviceParam devid)
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3494
constexpr Uint16 GetByteSize() const
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:541
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:707
void ClearAudioStream(AudioStreamParam stream)
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4566
void SetAudioStreamGain(AudioStreamParam stream, float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:3977
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition: SDL3pp_audio.h:3070
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition: SDL3pp_audio.h:1634
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:3241
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:4474
float GetAudioStreamGain(AudioStreamParam stream)
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:3945
void PutAudioStreamData(AudioStreamParam stream, SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:4213
void Unlock()
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4713
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3886
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:4756
constexpr bool IsAudioSigned(AudioFormatRaw x)
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:621
void ResumeDevice()
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4629
void SetAudioStreamOutputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4175
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5471
AudioDevice OpenAudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:3316
bool IsAudioDevicePhysical(AudioDeviceParam devid)
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3345
bool Paused() const
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3468
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamParam stream)
Get the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4007
void BindAudioStream(AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3645
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:4399
void SetAudioDeviceGain(AudioDeviceParam devid, float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3536
constexpr AudioFormat AUDIO_U8
Unsigned 8-bit samples.
Definition: SDL3pp_audio.h:448
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:3861
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4656
int GetAudioStreamAvailable(AudioStreamParam stream)
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:4469
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:517
constexpr AudioFormat AUDIO_S32
AUDIO_S32.
Definition: SDL3pp_audio.h:470
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:4864
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5499
constexpr bool IsAudioLittleEndian(AudioFormatRaw x)
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:599
constexpr AudioFormat AUDIO_S16LE
Signed 16-bit samples.
Definition: SDL3pp_audio.h:452
constexpr Uint32 AUDIO_MASK_BIG_ENDIAN
Mask of bits in an AudioFormat that contain the bigendian flag.
Definition: SDL3pp_audio.h:221
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:3210
PropertiesRef GetProperties() const
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3776
float GetGain() const
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:3950
void SetAudioStreamFrequencyRatio(AudioStreamParam stream, float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3916
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition: SDL3pp_audio.h:3131
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:4182
void PutAudioStreamDataNoCopy(AudioStreamParam stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition: SDL3pp_audio.h:4268
void SetGetCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition: SDL3pp_audio.h:4808
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3718
bool AudioStreamDevicePaused(AudioStreamParam stream)
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4651
constexpr AudioFormat AUDIO_S32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:459
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition: SDL3pp_audio.h:3051
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3372
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition: SDL3pp_audio.h:1583
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:5013
constexpr AudioFormat DefineAudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition: SDL3pp_audio.h:497
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition: SDL3pp_audio.h:1571
constexpr AudioFormat AUDIO_S32LE
32-bit integer samples
Definition: SDL3pp_audio.h:457
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:3854
void Close()
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3570
constexpr bool IsInt() const
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:642
void BindAudioStream(AudioDeviceParam devid, AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3640
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceParam devid)
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:3234
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition: SDL3pp_audio.h:5369
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:3743
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4116
void Unbind()
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3693
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:3167
constexpr bool IsFloat() const
Determine if an AudioFormat represents floating point data.
Definition: SDL3pp_audio.h:560
constexpr AudioFormat AUDIO_F32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:465
constexpr AudioFormat AUDIO_F32
AUDIO_F32.
Definition: SDL3pp_audio.h:472
int GetNumAudioDrivers()
Use this function to get the number of built-in audio drivers.
Definition: SDL3pp_audio.h:3027
void BindAudioStreams(AudioDeviceParam devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3608
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition: SDL3pp_audio.h:3668
void SetAudioStreamInputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:4109
int GetQueued() const
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4519
int GetAudioStreamData(AudioStreamParam stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:4436
void UnbindAudioStream(AudioStreamParam stream)
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3688
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:5220
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3350
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition: SDL3pp_audio.h:4949
constexpr bool IsSigned() const
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:623
constexpr bool IsAudioBigENDIAN(AudioFormatRaw x)
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:577
void SetGain(float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3541
void UnlockAudioStream(AudioStreamParam stream)
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4708
constexpr AudioFormat AUDIO_S16BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:454
void PutData(SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:4218
void PauseAudioStreamDevice(AudioStreamParam stream)
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4594
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition: SDL3pp_audio.h:3099
float GetGain() const
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3499
AudioSpec GetAudioDeviceFormat(AudioDeviceParam devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:3202
PropertiesRef GetAudioStreamProperties(AudioStreamParam stream)
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3771
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:4541
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:788
constexpr Uint16 AudioByteSize(AudioFormatRaw x)
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:536
void PutDataNoCopy(SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition: SDL3pp_audio.h:4329
void Clear()
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4571
float GetAudioStreamFrequencyRatio(AudioStreamParam stream)
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3881
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition: SDL3pp_audio.h:4546
void PauseAudioDevice(AudioDeviceParam devid)
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3405
void ResumeAudioDevice(AudioDeviceParam devid)
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3436
void SetGain(float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:3982
const char * GetName() const
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5476
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:4390
void ResumeAudioStreamDevice(AudioStreamParam stream)
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4624
std::function< void(const void *buf, int buflen)> AudioStreamDataCompleteCB
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition: SDL3pp_audio.h:1663
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3565
constexpr Uint16 GetBitSize() const
Retrieve the size, in bits, from an AudioFormat.
Definition: SDL3pp_audio.h:519
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition: SDL3pp_audio.h:1599
void Destroy()
Free an audio stream.
Definition: SDL3pp_audio.h:4954
constexpr bool IsUnsigned() const
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:664
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:1525
AudioDeviceRef(AudioDeviceID resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:1547
AudioDeviceRef(const AudioDeviceRef &other) noexcept
Copy constructor.
Definition: SDL3pp_audio.h:1553
AudioDeviceRef(AudioDeviceParam resource) noexcept
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:1535
~AudioDeviceRef()
Destructor.
Definition: SDL3pp_audio.h:1559
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:2969
~AudioStreamRef()
Destructor.
Definition: SDL3pp_audio.h:3003
AudioStreamRef(AudioStreamParam resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:2979
AudioStreamRef(AudioStreamRaw resource) noexcept
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:2991
AudioStreamRef(const AudioStreamRef &other) noexcept
Copy constructor.
Definition: SDL3pp_audio.h:2997
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:711