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
120using AudioFormatRaw = SDL_AudioFormat;
121
122// Forward decl
123struct AudioFormat;
124
125// Forward decl
126struct AudioDevice;
127
129using AudioDeviceID = SDL_AudioDeviceID;
130
131// Forward decl
132struct AudioDeviceRef;
133
136{
138
141 : value(value)
142 {
143 }
144
146 constexpr AudioDeviceParam(std::nullptr_t _ = nullptr)
147 : value(0)
148 {
149 }
150
152 constexpr explicit operator bool() const { return !!value; }
153
155 constexpr auto operator<=>(const AudioDeviceParam& other) const = default;
156
158 constexpr operator AudioDeviceID() const { return value; }
159};
160
161// Forward decl
162struct AudioStream;
163
165using AudioStreamRaw = SDL_AudioStream*;
166
167// Forward decl
168struct AudioStreamRef;
169
172{
174
177 : value(value)
178 {
179 }
180
182 constexpr AudioStreamParam(std::nullptr_t _ = nullptr)
183 : value(nullptr)
184 {
185 }
186
188 constexpr explicit operator bool() const { return !!value; }
189
191 constexpr auto operator<=>(const AudioStreamParam& other) const = default;
192
194 constexpr operator AudioStreamRaw() const { return value; }
195};
196
205constexpr Uint32 AUDIO_MASK_BITSIZE = SDL_AUDIO_MASK_BITSIZE;
206
215constexpr Uint32 AUDIO_MASK_FLOAT = SDL_AUDIO_MASK_FLOAT;
216
225constexpr Uint32 AUDIO_MASK_BIG_ENDIAN = SDL_AUDIO_MASK_BIG_ENDIAN;
226
235constexpr Uint32 AUDIO_MASK_SIGNED = SDL_AUDIO_MASK_SIGNED;
236
244using AudioSpec = SDL_AudioSpec;
245
261{
262 AudioFormatRaw m_audioFormat;
263
264public:
270 constexpr AudioFormat(AudioFormatRaw audioFormat = {})
271 : m_audioFormat(audioFormat)
272 {
273 }
274
298 constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
299 : m_audioFormat(
300 AudioFormatRaw(SDL_DEFINE_AUDIO_FORMAT(sign, bigendian, flt, size)))
301 {
302 }
303
309 constexpr operator AudioFormatRaw() const { return m_audioFormat; }
310
322 constexpr Uint16 GetBitSize() const;
323
335 constexpr Uint16 GetByteSize() const;
336
348 constexpr bool IsFloat() const;
349
361 constexpr bool IsBigEndian() const;
362
374 constexpr bool IsLittleEndian() const;
375
387 constexpr bool IsSigned() const;
388
400 constexpr bool IsInt() const;
401
413 constexpr bool IsUnsigned() const;
414
425 const char* GetName() const;
426
440 int GetSilenceValue() const;
441};
442
443// Unfortunate name clash with SDL_oldnames.h
444#undef AUDIO_U8
445#undef AUDIO_S8
446#undef AUDIO_S16
447#undef AUDIO_S32
448#undef AUDIO_F32
449
451 SDL_AUDIO_UNKNOWN;
452
453constexpr AudioFormat AUDIO_U8 = SDL_AUDIO_U8;
454
455constexpr AudioFormat AUDIO_S8 = SDL_AUDIO_S8;
456
457constexpr AudioFormat AUDIO_S16LE = SDL_AUDIO_S16LE;
458
460 SDL_AUDIO_S16BE;
461
462constexpr AudioFormat AUDIO_S32LE = SDL_AUDIO_S32LE;
463
465 SDL_AUDIO_S32BE;
466
468 SDL_AUDIO_F32LE;
469
471 SDL_AUDIO_F32BE;
472
473constexpr AudioFormat AUDIO_S16 = SDL_AUDIO_S16;
474
475constexpr AudioFormat AUDIO_S32 = SDL_AUDIO_S32;
476
477constexpr AudioFormat AUDIO_F32 = SDL_AUDIO_F32;
478
502constexpr AudioFormat DefineAudioFormat(bool sign,
503 bool bigendian,
504 bool flt,
505 Uint16 size)
506{
507 return AudioFormat(sign, bigendian, flt, size);
508}
509
522constexpr Uint16 AudioBitSize(AudioFormatRaw x) { return SDL_AUDIO_BITSIZE(x); }
523
525{
526 return SDL::AudioBitSize(m_audioFormat);
527}
528
542{
543 return SDL_AUDIO_BYTESIZE(x);
544}
545
547{
548 return SDL::AudioByteSize(m_audioFormat);
549}
550
563constexpr bool IsAudioFloat(AudioFormatRaw x) { return SDL_AUDIO_ISFLOAT(x); }
564
565constexpr bool AudioFormat::IsFloat() const
566{
567 return SDL::IsAudioFloat(m_audioFormat);
568}
569
583{
584 return SDL_AUDIO_ISBIGENDIAN(x);
585}
586
587constexpr bool AudioFormat::IsBigEndian() const
588{
589 return SDL::IsAudioBigENDIAN(m_audioFormat);
590}
591
605{
606 return SDL_AUDIO_ISLITTLEENDIAN(x);
607}
608
609constexpr bool AudioFormat::IsLittleEndian() const
610{
611 return SDL::IsAudioLittleEndian(m_audioFormat);
612}
613
626constexpr bool IsAudioSigned(AudioFormatRaw x) { return SDL_AUDIO_ISSIGNED(x); }
627
628constexpr bool AudioFormat::IsSigned() const
629{
630 return SDL::IsAudioSigned(m_audioFormat);
631}
632
645constexpr bool IsAudioInt(AudioFormatRaw x) { return SDL_AUDIO_ISINT(x); }
646
647constexpr bool AudioFormat::IsInt() const
648{
649 return SDL::IsAudioInt(m_audioFormat);
650}
651
665{
666 return SDL_AUDIO_ISUNSIGNED(x);
667}
668
669constexpr bool AudioFormat::IsUnsigned() const
670{
671 return SDL::IsAudioUnsigned(m_audioFormat);
672}
673
709using AudioPostmixCallback = SDL_AudioPostmixCallback;
710
745 std::function<void(const AudioSpec& spec, std::span<float> buffer)>;
746
787using AudioStreamCallback = SDL_AudioStreamCallback;
788
828using AudioStreamCB = std::function<
829 void(AudioStreamRef stream, int additional_amount, int total_amount)>;
830
841{
842 AudioDeviceID m_resource = 0;
843
844public:
846 constexpr AudioDevice() = default;
847
855 constexpr explicit AudioDevice(const AudioDeviceID resource)
856 : m_resource(resource)
857 {
858 }
859
861 constexpr AudioDevice(const AudioDevice& other) = delete;
862
864 constexpr AudioDevice(AudioDevice&& other)
865 : AudioDevice(other.release())
866 {
867 }
868
869 constexpr AudioDevice(const AudioDeviceRef& other) = delete;
870
871 constexpr AudioDevice(AudioDeviceRef&& other) = delete;
872
948 : m_resource(CheckError(SDL_OpenAudioDevice(devid, spec)))
949 {
950 }
951
953 ~AudioDevice() { SDL_CloseAudioDevice(m_resource); }
954
957 {
958 std::swap(m_resource, other.m_resource);
959 return *this;
960 }
961
963 constexpr AudioDeviceID get() const { return m_resource; }
964
967 {
968 auto r = m_resource;
969 m_resource = 0;
970 return r;
971 }
972
974 constexpr auto operator<=>(const AudioDevice& other) const = default;
975
977 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
978
980 constexpr explicit operator bool() const { return !!m_resource; }
981
983 constexpr operator AudioDeviceParam() const { return {m_resource}; }
984
1001 void Close();
1002
1016 const char* GetName() const;
1017
1049 AudioSpec GetFormat(int* sample_frames = nullptr) const;
1050
1070
1093 bool IsPhysical() const;
1094
1106 bool IsPlayback() const;
1107
1135 void Pause();
1136
1161 void Resume();
1162
1182 bool Paused() const;
1183
1204 float GetGain() const;
1205
1237 void SetGain(float gain);
1238
1274 void BindAudioStreams(std::span<AudioStreamRef> streams);
1275
1293 void BindAudioStream(AudioStreamParam stream);
1294
1345 void SetPostmixCallback(AudioPostmixCallback callback, void* userdata);
1346
1396 void SetPostmixCallback(AudioPostmixCB callback);
1397
1454 AudioStreamCallback callback,
1455 void* userdata);
1456
1509 AudioStreamCB callback);
1510};
1511
1514{
1523 : AudioDevice(resource.value)
1524 {
1525 }
1526
1529 : AudioDevice(other.get())
1530 {
1531 }
1532
1535};
1536
1547 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1548
1559 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1560
1574constexpr int AudioFrameSize(const AudioSpec& x)
1575{
1576 return SDL_AUDIO_FRAMESIZE(x);
1577}
1578
1606{
1607 AudioStreamRaw m_resource = nullptr;
1608
1609public:
1611 constexpr AudioStream() = default;
1612
1620 constexpr explicit AudioStream(const AudioStreamRaw resource)
1621 : m_resource(resource)
1622 {
1623 }
1624
1626 constexpr AudioStream(const AudioStream& other) = delete;
1627
1629 constexpr AudioStream(AudioStream&& other)
1630 : AudioStream(other.release())
1631 {
1632 }
1633
1634 constexpr AudioStream(const AudioStreamRef& other) = delete;
1635
1636 constexpr AudioStream(AudioStreamRef&& other) = delete;
1637
1660 : m_resource(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
1661 {
1662 }
1663
1722 OptionalRef<const AudioSpec> spec = std::nullopt,
1723 AudioStreamCallback callback = nullptr,
1724 void* userdata = nullptr)
1725 : m_resource(
1726 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
1727 {
1728 }
1729
1785 AudioStreamCB callback);
1786
1788 ~AudioStream() { SDL_DestroyAudioStream(m_resource); }
1789
1792 {
1793 std::swap(m_resource, other.m_resource);
1794 return *this;
1795 }
1796
1798 constexpr AudioStreamRaw get() const { return m_resource; }
1799
1802 {
1803 auto r = m_resource;
1804 m_resource = nullptr;
1805 return r;
1806 }
1807
1809 constexpr auto operator<=>(const AudioStream& other) const = default;
1810
1812 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
1813
1815 constexpr explicit operator bool() const { return !!m_resource; }
1816
1818 constexpr operator AudioStreamParam() const { return {m_resource}; }
1819
1837 void Destroy();
1838
1850
1865 {
1866 AudioSpec spec;
1867 GetFormat(&spec, nullptr);
1868 return spec;
1869 }
1870
1885 {
1886 AudioSpec spec;
1887 GetFormat(nullptr, &spec);
1888 return spec;
1889 }
1890
1905 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
1906
1937 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
1938
1969 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
1970
2006
2020 float GetFrequencyRatio() const;
2021
2046 void SetFrequencyRatio(float ratio);
2047
2066 float GetGain() const;
2067
2089 void SetGain(float gain);
2090
2111
2132
2188 void SetInputChannelMap(std::span<int> chmap);
2189
2243 void SetOutputChannelMap(std::span<int> chmap);
2244
2270 void PutData(SourceBytes buf);
2271
2298 int GetData(TargetBytes buf);
2299
2323 int GetAvailable() const;
2324
2360 int GetQueued() const;
2361
2378 void Flush();
2379
2397 void Clear();
2398
2419 void PauseDevice();
2420
2440 void ResumeDevice();
2441
2458 bool DevicePaused() const;
2459
2484 void Lock();
2485
2500 void Unlock();
2501
2544 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2545
2586 void SetGetCallback(AudioStreamCB callback);
2587
2633 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2634
2678 void SetPutCallback(AudioStreamCB callback);
2679
2693 void Unbind();
2694
2713 AudioDeviceRef GetDevice() const;
2714};
2715
2718{
2727 : AudioStream(resource.value)
2728 {
2729 }
2730
2733 : AudioStream(other.get())
2734 {
2735 }
2736
2739};
2740
2762inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
2763
2786inline const char* GetAudioDriver(int index)
2787{
2788 return SDL_GetAudioDriver(index);
2789}
2790
2805inline const char* GetCurrentAudioDriver()
2806{
2807 return SDL_GetCurrentAudioDriver();
2808}
2809
2835{
2836 int count;
2837 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
2838 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
2839 size_t(count)};
2840}
2841
2867{
2868 int count;
2869 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
2870 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
2871 size_t(count)};
2872}
2873
2888inline const char* GetAudioDeviceName(AudioDeviceParam devid)
2889{
2890 return CheckError(SDL_GetAudioDeviceName(devid));
2891}
2892
2893inline const char* AudioDevice::GetName() const
2894{
2895 return SDL::GetAudioDeviceName(m_resource);
2896}
2897
2930 int* sample_frames = nullptr)
2931{
2932 AudioSpec spec;
2933 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
2934 return spec;
2935}
2936
2937inline AudioSpec AudioDevice::GetFormat(int* sample_frames) const
2938{
2939 return SDL::GetAudioDeviceFormat(m_resource, sample_frames);
2940}
2941
2962{
2963 int count;
2964 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
2965 return OwnArray<int>{data, size_t(count)};
2966}
2967
2969{
2970 return SDL::GetAudioDeviceChannelMap(m_resource);
2971}
2972
3049{
3050 return AudioDevice(devid, spec);
3051}
3052
3077{
3078 return SDL_IsAudioDevicePhysical(devid);
3079}
3080
3081inline bool AudioDevice::IsPhysical() const
3082{
3083 return SDL::IsAudioDevicePhysical(m_resource);
3084}
3085
3099{
3100 return SDL_IsAudioDevicePlayback(devid);
3101}
3102
3103inline bool AudioDevice::IsPlayback() const
3104{
3105 return SDL::IsAudioDevicePlayback(m_resource);
3106}
3107
3137{
3138 CheckError(SDL_PauseAudioDevice(devid));
3139}
3140
3141inline void AudioDevice::Pause() { SDL::PauseAudioDevice(m_resource); }
3142
3169{
3170 CheckError(SDL_ResumeAudioDevice(devid));
3171}
3172
3173inline void AudioDevice::Resume() { SDL::ResumeAudioDevice(m_resource); }
3174
3196{
3197 return SDL_AudioDevicePaused(devid);
3198}
3199
3200inline bool AudioDevice::Paused() const
3201{
3202 return SDL::AudioDevicePaused(m_resource);
3203}
3204
3227{
3228 return SDL_GetAudioDeviceGain(devid);
3229}
3230
3231inline float AudioDevice::GetGain() const
3232{
3233 return SDL::GetAudioDeviceGain(m_resource);
3234}
3235
3268inline void SetAudioDeviceGain(AudioDeviceParam devid, float gain)
3269{
3270 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3271}
3272
3273inline void AudioDevice::SetGain(float gain)
3274{
3275 SDL::SetAudioDeviceGain(m_resource, gain);
3276}
3277
3298{
3299 SDL_CloseAudioDevice(devid);
3300}
3301
3303
3341 std::span<AudioStreamRef> streams)
3342{
3343 CheckError(SDL_BindAudioStreams(
3344 devid,
3345 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3346 streams.size()));
3347}
3348
3349inline void AudioDevice::BindAudioStreams(std::span<AudioStreamRef> streams)
3350{
3351 SDL::BindAudioStreams(m_resource, streams);
3352}
3353
3373{
3374 CheckError(SDL_BindAudioStream(devid, stream));
3375}
3376
3378{
3379 SDL::BindAudioStream(m_resource, stream);
3380}
3381
3400inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3401{
3402 SDL_UnbindAudioStreams(
3403 reinterpret_cast<SDL_AudioStream* const*>(streams.data()), streams.size());
3404}
3405
3421{
3422 SDL_UnbindAudioStream(stream);
3423}
3424
3425inline void AudioStream::Unbind() { SDL::UnbindAudioStream(m_resource); }
3426
3447{
3448 return {SDL_GetAudioStreamDevice(stream)};
3449}
3450
3452{
3453 return SDL::GetAudioStreamDevice(m_resource);
3454}
3455
3478{
3479 return AudioStream(src_spec, dst_spec);
3480}
3481
3494{
3495 return {CheckError(SDL_GetAudioStreamProperties(stream))};
3496}
3497
3499{
3500 return SDL::GetAudioStreamProperties(m_resource);
3501}
3502
3519 AudioSpec* src_spec,
3520 AudioSpec* dst_spec)
3521{
3522 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3523}
3524
3525inline void AudioStream::GetFormat(AudioSpec* src_spec,
3526 AudioSpec* dst_spec) const
3527{
3528 SDL::GetAudioStreamFormat(m_resource, src_spec, dst_spec);
3529}
3530
3568{
3569 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3570}
3571
3574{
3575 SDL::SetAudioStreamFormat(m_resource, src_spec, dst_spec);
3576}
3577
3593{
3594 return SDL_GetAudioStreamFrequencyRatio(stream);
3595}
3596
3598{
3599 return SDL::GetAudioStreamFrequencyRatio(m_resource);
3600}
3601
3627inline void SetAudioStreamFrequencyRatio(AudioStreamParam stream, float ratio)
3628{
3629 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3630}
3631
3632inline void AudioStream::SetFrequencyRatio(float ratio)
3633{
3634 SDL::SetAudioStreamFrequencyRatio(m_resource, ratio);
3635}
3636
3657{
3658 return SDL_GetAudioStreamGain(stream);
3659}
3660
3661inline float AudioStream::GetGain() const
3662{
3663 return SDL::GetAudioStreamGain(m_resource);
3664}
3665
3688inline void SetAudioStreamGain(AudioStreamParam stream, float gain)
3689{
3690 CheckError(SDL_SetAudioStreamGain(stream, gain));
3691}
3692
3693inline void AudioStream::SetGain(float gain)
3694{
3695 SDL::SetAudioStreamGain(m_resource, gain);
3696}
3697
3719{
3720 int count;
3721 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
3722 if (!data) return {};
3723 return OwnArray<int>{data, size_t(count)};
3724}
3725
3727{
3728 return SDL::GetAudioStreamInputChannelMap(m_resource);
3729}
3730
3752{
3753 int count;
3754 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
3755 if (!data) return {};
3756 return OwnArray<int>{data, size_t(count)};
3757}
3758
3760{
3761 return SDL::GetAudioStreamOutputChannelMap(m_resource);
3762}
3763
3821 std::span<int> chmap)
3822{
3823 CheckError(
3824 SDL_SetAudioStreamInputChannelMap(stream, chmap.data(), chmap.size()));
3825}
3826
3827inline void AudioStream::SetInputChannelMap(std::span<int> chmap)
3828{
3829 SDL::SetAudioStreamInputChannelMap(m_resource, chmap);
3830}
3831
3887 std::span<int> chmap)
3888{
3889 CheckError(
3890 SDL_SetAudioStreamOutputChannelMap(stream, chmap.data(), chmap.size()));
3891}
3892
3893inline void AudioStream::SetOutputChannelMap(std::span<int> chmap)
3894{
3895 SDL::SetAudioStreamOutputChannelMap(m_resource, chmap);
3896}
3897
3925{
3926 CheckError(SDL_PutAudioStreamData(stream, buf.data(), buf.size_bytes()));
3927}
3928
3930{
3931 SDL::PutAudioStreamData(m_resource, std::move(buf));
3932}
3933
3962{
3963 return SDL_GetAudioStreamData(stream, buf.data(), buf.size_bytes());
3964}
3965
3967{
3968 return SDL::GetAudioStreamData(m_resource, std::move(buf));
3969}
3970
3996{
3997 return SDL_GetAudioStreamAvailable(stream);
3998}
3999
4001{
4002 return SDL::GetAudioStreamAvailable(m_resource);
4003}
4004
4042{
4043 return SDL_GetAudioStreamQueued(stream);
4044}
4045
4046inline int AudioStream::GetQueued() const
4047{
4048 return SDL::GetAudioStreamQueued(m_resource);
4049}
4050
4069{
4070 CheckError(SDL_FlushAudioStream(stream));
4071}
4072
4073inline void AudioStream::Flush() { SDL::FlushAudioStream(m_resource); }
4074
4094{
4095 CheckError(SDL_ClearAudioStream(stream));
4096}
4097
4098inline void AudioStream::Clear() { SDL::ClearAudioStream(m_resource); }
4099
4122{
4123 CheckError(SDL_PauseAudioStreamDevice(stream));
4124}
4125
4127{
4128 SDL::PauseAudioStreamDevice(m_resource);
4129}
4130
4152{
4153 CheckError(SDL_ResumeAudioStreamDevice(stream));
4154}
4155
4157{
4158 SDL::ResumeAudioStreamDevice(m_resource);
4159}
4160
4179{
4180 return SDL_AudioStreamDevicePaused(stream);
4181}
4182
4183inline bool AudioStream::DevicePaused() const
4184{
4185 return SDL::AudioStreamDevicePaused(m_resource);
4186}
4187
4214{
4215 CheckError(SDL_LockAudioStream(stream));
4216}
4217
4218inline void AudioStream::Lock() { SDL::LockAudioStream(m_resource); }
4219
4236{
4237 CheckError(SDL_UnlockAudioStream(stream));
4238}
4239
4240inline void AudioStream::Unlock() { SDL::UnlockAudioStream(m_resource); }
4241
4286 AudioStreamCallback callback,
4287 void* userdata)
4288{
4290 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4291}
4292
4335 AudioStreamCB callback)
4336{
4338 if (!SDL_SetAudioStreamGetCallback(
4339 stream,
4340 [](void* userdata,
4341 SDL_AudioStream* stream,
4342 int additional_amount,
4343 int total_amount) {
4344 Wrapper::Call(userdata, {stream}, additional_amount, total_amount);
4345 },
4346 Wrapper::Wrap(stream, std::move(callback)))) {
4347 Wrapper::release(stream);
4348 throw Error{};
4349 }
4350}
4351
4353 void* userdata)
4354{
4355 SDL::SetAudioStreamGetCallback(m_resource, callback, userdata);
4356}
4357
4359{
4360 SDL::SetAudioStreamGetCallback(m_resource, callback);
4361}
4362
4410 AudioStreamCallback callback,
4411 void* userdata)
4412{
4414 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4415}
4416
4462 AudioStreamCB callback)
4463{
4465 if (!SDL_SetAudioStreamPutCallback(
4466 stream,
4467 [](void* userdata,
4468 SDL_AudioStream* stream,
4469 int additional_amount,
4470 int total_amount) {
4471 Wrapper::Call(userdata, {stream}, additional_amount, total_amount);
4472 },
4473 Wrapper::Wrap(stream, std::move(callback)))) {
4474 Wrapper::release(stream);
4475 throw Error{};
4476 }
4477}
4478
4480 void* userdata)
4481{
4482 SDL::SetAudioStreamPutCallback(m_resource, callback, userdata);
4483}
4484
4486{
4487 SDL::SetAudioStreamPutCallback(m_resource, callback);
4488}
4489
4510{
4511 SDL_DestroyAudioStream(stream);
4512}
4513
4515
4576 AudioStreamCallback callback = nullptr,
4577 void* userdata = nullptr)
4578{
4579 return AudioStream(devid, spec, callback, userdata);
4580}
4581
4637 AudioStreamCB callback)
4638{
4639 return AudioStream(devid, spec, callback);
4640}
4641
4643 AudioStreamCallback callback,
4644 void* userdata)
4645{
4646 return AudioStream(m_resource, spec, callback, userdata);
4647}
4648
4650 AudioStreamCB callback)
4651{
4652 return AudioStream(m_resource, spec, callback);
4653}
4654
4657 AudioStreamCB callback)
4658 : AudioStream(devid, spec)
4659{
4660 if (IsAudioDevicePlayback(devid)) {
4661 SetGetCallback(std::move(callback));
4662 } else {
4663 SetPutCallback(std::move(callback));
4664 }
4665}
4666
4719 AudioPostmixCallback callback,
4720 void* userdata)
4721{
4723 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
4724}
4725
4777 AudioPostmixCB callback)
4778{
4780 if (!SDL_SetAudioPostmixCallback(
4781 devid,
4782 [](void* userdata,
4783 const SDL_AudioSpec* spec,
4784 float* buffer,
4785 int buflen) {
4786 Wrapper::Call(
4787 userdata, *spec, std::span<float>(buffer, size_t(buflen)));
4788 },
4789 Wrapper::Wrap(devid, std::move(callback)))) {
4790 Wrapper::release(devid);
4791 throw Error{};
4792 }
4793}
4794
4796 void* userdata)
4797{
4798 SDL::SetAudioPostmixCallback(m_resource, callback, userdata);
4799}
4800
4802{
4803 SDL::SetAudioPostmixCallback(m_resource, callback);
4804}
4805
4874 AudioSpec* spec,
4875 bool closeio = false)
4876{
4877 Uint8* buf;
4878 Uint32 len;
4879 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
4880 return OwnArray<Uint8>{buf, size_t(len)};
4881}
4882
4907{
4908 Uint8* buf;
4909 Uint32 len;
4910 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
4911 return OwnArray<Uint8>{buf, size_t(len)};
4912}
4913
4946inline void MixAudio(Uint8* dst,
4947 SourceBytes src,
4948 AudioFormat format,
4949 float volume)
4950{
4951 CheckError(
4952 SDL_MixAudio(dst, src.data_as<Uint8>(), format, src.size_bytes(), volume));
4953}
4954
4987inline void MixAudio(TargetBytes dst,
4988 SourceBytes src,
4989 AudioFormat format,
4990 float volume)
4991{
4992 if (dst.size_bytes() < src.size_bytes()) {
4993 MixAudio(dst.data_as<Uint8>(),
4994 SourceBytes{src.data(), dst.size_bytes()},
4995 format,
4996 volume);
4997 } else
4998 MixAudio(dst.data_as<Uint8>(), src, format, volume);
4999}
5000
5024 SourceBytes src_data,
5025 const AudioSpec& dst_spec)
5026{
5027 Uint8* buf;
5028 int len;
5029 CheckError(SDL_ConvertAudioSamples(&src_spec,
5030 src_data.data_as<Uint8>(),
5031 src_data.size_bytes(),
5032 &dst_spec,
5033 &buf,
5034 &len));
5035 return OwnArray<Uint8>{buf, size_t(len)};
5036}
5037
5049inline const char* GetAudioFormatName(AudioFormatRaw format)
5050{
5051 return SDL_GetAudioFormatName(format);
5052}
5053
5054inline const char* AudioFormat::GetName() const
5055{
5056 return SDL::GetAudioFormatName(m_audioFormat);
5057}
5058
5074{
5075 return SDL_GetSilenceValueForFormat(format);
5076}
5077
5079{
5080 return SDL::GetSilenceValueForFormat(m_audioFormat);
5081}
5082
5084
5085} // namespace SDL
5086
5087#endif /* SDL3PP_AUDIO_H_ */
SDL Audio Device instance IDs.
Definition: SDL3pp_audio.h:841
constexpr AudioDevice(const AudioDevice &other)=delete
Copy constructor.
AudioDevice & operator=(AudioDevice other)
Assignment operator.
Definition: SDL3pp_audio.h:956
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_audio.h:977
constexpr AudioDevice(AudioDevice &&other)
Move constructor.
Definition: SDL3pp_audio.h:864
~AudioDevice()
Destructor.
Definition: SDL3pp_audio.h:953
constexpr auto operator<=>(const AudioDevice &other) const =default
Comparison.
AudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:947
constexpr AudioDevice(const AudioDeviceID resource)
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:855
constexpr AudioDeviceID release()
Retrieves underlying AudioDeviceID and clear this.
Definition: SDL3pp_audio.h:966
constexpr AudioDevice()=default
Default ctor.
constexpr AudioDeviceID get() const
Retrieves underlying AudioDeviceID.
Definition: SDL3pp_audio.h:963
Audio format.
Definition: SDL3pp_audio.h:261
constexpr AudioFormat(AudioFormatRaw audioFormat={})
Wraps AudioFormat.
Definition: SDL3pp_audio.h:270
constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition: SDL3pp_audio.h:298
The opaque handle that represents an audio stream.
Definition: SDL3pp_audio.h:1606
~AudioStream()
Destructor.
Definition: SDL3pp_audio.h:1788
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition: SDL3pp_audio.h:1884
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition: SDL3pp_audio.h:1969
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition: SDL3pp_audio.h:1937
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_audio.h:1812
AudioStream & operator=(AudioStream other)
Assignment operator.
Definition: SDL3pp_audio.h:1791
constexpr auto operator<=>(const AudioStream &other) const =default
Comparison.
AudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:1658
constexpr AudioStreamRaw release()
Retrieves underlying AudioStreamRaw and clear this.
Definition: SDL3pp_audio.h:1801
constexpr AudioStreamRaw get() const
Retrieves underlying AudioStreamRaw.
Definition: SDL3pp_audio.h:1798
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition: SDL3pp_audio.h:1864
constexpr AudioStream(const AudioStream &other)=delete
Copy constructor.
constexpr AudioStream(const AudioStreamRaw resource)
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:1620
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:1721
constexpr AudioStream()=default
Default ctor.
constexpr AudioStream(AudioStream &&other)
Move constructor.
Definition: SDL3pp_audio.h:1629
An exception that returns GetError()
Definition: SDL3pp_error.h:165
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:563
void Pause()
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3141
constexpr AudioFormat AUDIO_UNKNOWN
Unspecified audio format.
Definition: SDL3pp_audio.h:450
bool IsAudioDevicePlayback(AudioDeviceParam devid)
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3098
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition: SDL3pp_audio.h:4642
void Resume()
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3173
constexpr bool IsLittleEndian() const
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:609
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:4718
const char * GetAudioDeviceName(AudioDeviceParam devid)
Get the human-readable name of a specific audio device.
Definition: SDL3pp_audio.h:2888
void GetAudioStreamFormat(AudioStreamParam stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3518
constexpr bool IsBigEndian() const
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:587
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3349
constexpr bool IsAudioInt(AudioFormatRaw x)
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:645
void LockAudioStream(AudioStreamParam stream)
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4213
void Lock()
Lock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4218
constexpr Uint32 AUDIO_MASK_SIGNED
Mask of bits in an AudioFormat that contain the signed data flag.
Definition: SDL3pp_audio.h:235
constexpr Uint32 AUDIO_MASK_BITSIZE
Mask of bits in an AudioFormat that contains the format bit size.
Definition: SDL3pp_audio.h:205
bool AudioDevicePaused(AudioDeviceParam devid)
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3195
void PauseDevice()
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4126
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition: SDL3pp_audio.h:3525
constexpr AudioFormat AUDIO_S8
Signed 8-bit samples.
Definition: SDL3pp_audio.h:455
AudioDeviceRef GetAudioStreamDevice(AudioStreamParam stream)
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3446
constexpr Uint32 AUDIO_MASK_FLOAT
Mask of bits in an AudioFormat that contain the floating point flag.
Definition: SDL3pp_audio.h:215
SDL_AudioFormat AudioFormatRaw
Alias to raw representation for AudioFormat.
Definition: SDL3pp_audio.h:120
OwnArray< int > GetInputChannelMap() const
Get the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:3726
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:5023
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3632
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition: SDL3pp_audio.h:244
OwnArray< int > GetAudioStreamOutputChannelMap(AudioStreamParam stream)
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:3751
constexpr bool IsAudioUnsigned(AudioFormatRaw x)
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:664
int GetSilenceValueForFormat(AudioFormatRaw format)
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5073
int GetData(TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:3966
OwnArray< Uint8 > LoadWAV(IOStreamParam src, AudioSpec *spec, bool closeio=false)
Load the audio data of a WAVE file into memory.
Definition: SDL3pp_audio.h:4873
int GetAudioStreamQueued(AudioStreamParam stream)
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4041
SDL_AudioPostmixCallback AudioPostmixCallback
A callback that fires when data is about to be fed to an audio device.
Definition: SDL3pp_audio.h:709
constexpr AudioFormat AUDIO_S16
AUDIO_S16.
Definition: SDL3pp_audio.h:473
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition: SDL3pp_audio.h:467
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition: SDL3pp_audio.h:4479
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:3759
float GetAudioDeviceGain(AudioDeviceParam devid)
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3226
constexpr Uint16 GetByteSize() const
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:546
void ClearAudioStream(AudioStreamParam stream)
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4093
void SetAudioStreamGain(AudioStreamParam stream, float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:3688
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition: SDL3pp_audio.h:2805
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:2968
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:4000
float GetAudioStreamGain(AudioStreamParam stream)
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:3656
void PutAudioStreamData(AudioStreamParam stream, SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:3924
void Unlock()
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4240
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3597
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:4285
constexpr bool IsAudioSigned(AudioFormatRaw x)
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:626
void ResumeDevice()
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4156
void SetAudioStreamOutputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:3886
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5049
AudioDevice OpenAudioDevice(AudioDeviceParam devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition: SDL3pp_audio.h:3047
bool IsAudioDevicePhysical(AudioDeviceParam devid)
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3076
bool Paused() const
Use this function to query if an audio device is paused.
Definition: SDL3pp_audio.h:3200
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamParam stream)
Get the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:3718
void BindAudioStream(AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3377
void SetAudioDeviceGain(AudioDeviceParam devid, float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3268
constexpr AudioFormat AUDIO_U8
Unsigned 8-bit samples.
Definition: SDL3pp_audio.h:453
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:3572
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4183
int GetAudioStreamAvailable(AudioStreamParam stream)
Get the number of converted/resampled bytes available.
Definition: SDL3pp_audio.h:3995
SDL_AudioDeviceID AudioDeviceID
Alias to raw representation for AudioDevice.
Definition: SDL3pp_audio.h:129
constexpr Uint16 AudioBitSize(AudioFormatRaw x)
Retrieve the size, in bits, from an AudioFormat.
Definition: SDL3pp_audio.h:522
constexpr AudioFormat AUDIO_S32
AUDIO_S32.
Definition: SDL3pp_audio.h:475
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:4409
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition: SDL3pp_audio.h:5078
std::function< void(AudioStreamRef stream, int additional_amount, int total_amount)> AudioStreamCB
A callback that fires when data passes through an AudioStream.
Definition: SDL3pp_audio.h:829
constexpr bool IsAudioLittleEndian(AudioFormatRaw x)
Determine if an AudioFormat represents littleendian data.
Definition: SDL3pp_audio.h:604
constexpr AudioFormat AUDIO_S16LE
Signed 16-bit samples.
Definition: SDL3pp_audio.h:457
constexpr Uint32 AUDIO_MASK_BIG_ENDIAN
Mask of bits in an AudioFormat that contain the bigendian flag.
Definition: SDL3pp_audio.h:225
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:2937
PropertiesRef GetProperties() const
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3498
float GetGain() const
Get the gain of an audio stream.
Definition: SDL3pp_audio.h:3661
void SetAudioStreamFrequencyRatio(AudioStreamParam stream, float ratio)
Change the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3627
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition: SDL3pp_audio.h:2866
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition: SDL3pp_audio.h:3893
void SetGetCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition: SDL3pp_audio.h:4352
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition: SDL3pp_audio.h:3451
bool AudioStreamDevicePaused(AudioStreamParam stream)
Use this function to query if an audio device associated with a stream is paused.
Definition: SDL3pp_audio.h:4178
constexpr AudioFormat AUDIO_S32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:464
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition: SDL3pp_audio.h:2786
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition: SDL3pp_audio.h:3103
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition: SDL3pp_audio.h:1558
std::function< void(const AudioSpec &spec, std::span< float > buffer)> AudioPostmixCB
A callback that fires when data is about to be fed to an audio device.
Definition: SDL3pp_audio.h:745
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:4574
constexpr AudioFormat DefineAudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition: SDL3pp_audio.h:502
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition: SDL3pp_audio.h:1546
constexpr AudioFormat AUDIO_S32LE
32-bit integer samples
Definition: SDL3pp_audio.h:462
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:3565
void Close()
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3302
constexpr bool IsInt() const
Determine if an AudioFormat represents integer data.
Definition: SDL3pp_audio.h:647
void BindAudioStream(AudioDeviceParam devid, AudioStreamParam stream)
Bind a single audio stream to an audio device.
Definition: SDL3pp_audio.h:3372
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceParam devid)
Get the current channel map of an audio device.
Definition: SDL3pp_audio.h:2961
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition: SDL3pp_audio.h:4946
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition: SDL3pp_audio.h:3476
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:3827
void Unbind()
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3425
SDL_AudioStream * AudioStreamRaw
Alias to raw representation for AudioStream.
Definition: SDL3pp_audio.h:165
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition: SDL3pp_audio.h:2893
constexpr bool IsFloat() const
Determine if an AudioFormat represents floating point data.
Definition: SDL3pp_audio.h:565
constexpr AudioFormat AUDIO_F32BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:470
constexpr AudioFormat AUDIO_F32
AUDIO_F32.
Definition: SDL3pp_audio.h:477
int GetNumAudioDrivers()
Use this function to get the number of built-in audio drivers.
Definition: SDL3pp_audio.h:2762
void BindAudioStreams(AudioDeviceParam devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition: SDL3pp_audio.h:3340
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition: SDL3pp_audio.h:3400
void SetAudioStreamInputChannelMap(AudioStreamParam stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition: SDL3pp_audio.h:3820
int GetQueued() const
Get the number of bytes currently queued.
Definition: SDL3pp_audio.h:4046
int GetAudioStreamData(AudioStreamParam stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition: SDL3pp_audio.h:3961
void UnbindAudioStream(AudioStreamParam stream)
Unbind a single audio stream from its audio device.
Definition: SDL3pp_audio.h:3420
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:4795
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition: SDL3pp_audio.h:3081
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition: SDL3pp_audio.h:4509
constexpr bool IsSigned() const
Determine if an AudioFormat represents signed data.
Definition: SDL3pp_audio.h:628
constexpr bool IsAudioBigENDIAN(AudioFormatRaw x)
Determine if an AudioFormat represents bigendian data.
Definition: SDL3pp_audio.h:582
void SetGain(float gain)
Change the gain of an audio device.
Definition: SDL3pp_audio.h:3273
void UnlockAudioStream(AudioStreamParam stream)
Unlock an audio stream for serialized access.
Definition: SDL3pp_audio.h:4235
constexpr AudioFormat AUDIO_S16BE
As above, but big-endian byte order.
Definition: SDL3pp_audio.h:459
void PutData(SourceBytes buf)
Add data to the stream.
Definition: SDL3pp_audio.h:3929
void PauseAudioStreamDevice(AudioStreamParam stream)
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4121
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition: SDL3pp_audio.h:2834
float GetGain() const
Get the gain of an audio device.
Definition: SDL3pp_audio.h:3231
AudioSpec GetAudioDeviceFormat(AudioDeviceParam devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition: SDL3pp_audio.h:2929
PropertiesRef GetAudioStreamProperties(AudioStreamParam stream)
Get the properties associated with an audio stream.
Definition: SDL3pp_audio.h:3493
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:4068
constexpr Uint16 AudioByteSize(AudioFormatRaw x)
Retrieve the size, in bytes, from an AudioFormat.
Definition: SDL3pp_audio.h:541
void Clear()
Clear any pending data in the stream.
Definition: SDL3pp_audio.h:4098
float GetAudioStreamFrequencyRatio(AudioStreamParam stream)
Get the frequency ratio of an audio stream.
Definition: SDL3pp_audio.h:3592
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition: SDL3pp_audio.h:4073
void PauseAudioDevice(AudioDeviceParam devid)
Use this function to pause audio playback on a specified device.
Definition: SDL3pp_audio.h:3136
void ResumeAudioDevice(AudioDeviceParam devid)
Use this function to unpause audio playback on a specified device.
Definition: SDL3pp_audio.h:3168
void SetGain(float gain)
Change the gain of an audio stream.
Definition: SDL3pp_audio.h:3693
SDL_AudioStreamCallback AudioStreamCallback
A callback that fires when data passes through an AudioStream.
Definition: SDL3pp_audio.h:787
const char * GetName() const
Get the human readable name of an audio format.
Definition: SDL3pp_audio.h:5054
void ResumeAudioStreamDevice(AudioStreamParam stream)
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition: SDL3pp_audio.h:4151
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition: SDL3pp_audio.h:3297
constexpr Uint16 GetBitSize() const
Retrieve the size, in bits, from an AudioFormat.
Definition: SDL3pp_audio.h:524
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition: SDL3pp_audio.h:1574
void Destroy()
Free an audio stream.
Definition: SDL3pp_audio.h:4514
constexpr bool IsUnsigned() const
Determine if an AudioFormat represents unsigned data.
Definition: SDL3pp_audio.h:669
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:310
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:258
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:284
Main include header for the SDL3pp library.
Safely wrap AudioDevice for non owning parameters.
Definition: SDL3pp_audio.h:136
AudioDeviceID value
parameter's AudioDeviceID
Definition: SDL3pp_audio.h:137
constexpr AudioDeviceParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_audio.h:146
constexpr auto operator<=>(const AudioDeviceParam &other) const =default
Comparison.
constexpr AudioDeviceParam(AudioDeviceID value)
Constructs from AudioDeviceID.
Definition: SDL3pp_audio.h:140
Semi-safe reference for AudioDevice.
Definition: SDL3pp_audio.h:1514
AudioDeviceRef(AudioDeviceParam resource)
Constructs from AudioDeviceParam.
Definition: SDL3pp_audio.h:1522
~AudioDeviceRef()
Destructor.
Definition: SDL3pp_audio.h:1534
AudioDeviceRef(const AudioDeviceRef &other)
Copy constructor.
Definition: SDL3pp_audio.h:1528
Safely wrap AudioStream for non owning parameters.
Definition: SDL3pp_audio.h:172
AudioStreamRaw value
parameter's AudioStreamRaw
Definition: SDL3pp_audio.h:173
constexpr auto operator<=>(const AudioStreamParam &other) const =default
Comparison.
constexpr AudioStreamParam(AudioStreamRaw value)
Constructs from AudioStreamRaw.
Definition: SDL3pp_audio.h:176
constexpr AudioStreamParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_audio.h:182
Semi-safe reference for AudioStream.
Definition: SDL3pp_audio.h:2718
AudioStreamRef(AudioStreamParam resource)
Constructs from AudioStreamParam.
Definition: SDL3pp_audio.h:2726
~AudioStreamRef()
Destructor.
Definition: SDL3pp_audio.h:2738
AudioStreamRef(const AudioStreamRef &other)
Copy constructor.
Definition: SDL3pp_audio.h:2732
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
Store callbacks by key.
Definition: SDL3pp_callbackWrapper.h:222
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:701