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
115
117using AudioFormatRaw = SDL_AudioFormat;
118
119// Forward decl
120struct AudioFormat;
121
122// Forward decl
123struct AudioDevice;
124
126using AudioDeviceID = SDL_AudioDeviceID;
127
128// Forward decl
129struct AudioDeviceRef;
130
131// Forward decl
132struct AudioStream;
133
135using AudioStreamRaw = SDL_AudioStream*;
136
137// Forward decl
138struct AudioStreamRef;
139
140// Forward decl
141struct AudioStreamLock;
142
151constexpr Uint32 AUDIO_MASK_BITSIZE = SDL_AUDIO_MASK_BITSIZE;
152
161constexpr Uint32 AUDIO_MASK_FLOAT = SDL_AUDIO_MASK_FLOAT;
162
171constexpr Uint32 AUDIO_MASK_BIG_ENDIAN = SDL_AUDIO_MASK_BIG_ENDIAN;
172
181constexpr Uint32 AUDIO_MASK_SIGNED = SDL_AUDIO_MASK_SIGNED;
182
190using AudioSpec = SDL_AudioSpec;
191
207{
208 AudioFormatRaw m_audioFormat;
209
210public:
216 constexpr AudioFormat(AudioFormatRaw audioFormat = {}) noexcept
217 : m_audioFormat(audioFormat)
218 {
219 }
220
244 constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size);
245
251 constexpr operator AudioFormatRaw() const noexcept { return m_audioFormat; }
252
264 constexpr Uint16 GetBitSize() const;
265
277 constexpr Uint16 GetByteSize() const;
278
290 constexpr bool IsFloat() const;
291
303 constexpr bool IsBigEndian() const;
304
316 constexpr bool IsLittleEndian() const;
317
329 constexpr bool IsSigned() const;
330
342 constexpr bool IsInt() const;
343
355 constexpr bool IsUnsigned() const;
356
367 const char* GetName() const;
368
381 int GetSilenceValue() const;
382};
383
384// Unfortunate name clash with SDL_oldnames.h
385#undef AUDIO_U8
386#undef AUDIO_S8
387#undef AUDIO_S16
388#undef AUDIO_S32
389#undef AUDIO_F32
390
392 SDL_AUDIO_UNKNOWN;
393
394constexpr AudioFormat AUDIO_U8 = SDL_AUDIO_U8;
395
396constexpr AudioFormat AUDIO_S8 = SDL_AUDIO_S8;
397
398constexpr AudioFormat AUDIO_S16LE = SDL_AUDIO_S16LE;
399
401 SDL_AUDIO_S16BE;
402
403constexpr AudioFormat AUDIO_S32LE = SDL_AUDIO_S32LE;
404
406 SDL_AUDIO_S32BE;
407
409 SDL_AUDIO_F32LE;
410
412 SDL_AUDIO_F32BE;
413
414constexpr AudioFormat AUDIO_S16 = SDL_AUDIO_S16;
415
416constexpr AudioFormat AUDIO_S32 = SDL_AUDIO_S32;
417
418constexpr AudioFormat AUDIO_F32 = SDL_AUDIO_F32;
419
443constexpr AudioFormat DefineAudioFormat(bool sign,
444 bool bigendian,
445 bool flt,
446 Uint16 size)
447{
448 return AudioFormat(sign, bigendian, flt, size);
449}
450
451constexpr AudioFormat::AudioFormat(bool sign,
452 bool bigendian,
453 bool flt,
454 Uint16 size)
455 : m_audioFormat(
456 AudioFormatRaw(SDL_DEFINE_AUDIO_FORMAT(sign, bigendian, flt, size)))
457{
458}
459
472constexpr Uint16 AudioBitSize(AudioFormatRaw x) { return SDL_AUDIO_BITSIZE(x); }
473
475{
476 return SDL::AudioBitSize(m_audioFormat);
477}
478
492{
493 return SDL_AUDIO_BYTESIZE(x);
494}
495
497{
498 return SDL::AudioByteSize(m_audioFormat);
499}
500
513constexpr bool IsAudioFloat(AudioFormatRaw x) { return SDL_AUDIO_ISFLOAT(x); }
514
515constexpr bool AudioFormat::IsFloat() const
516{
517 return SDL::IsAudioFloat(m_audioFormat);
518}
519
533{
534 return SDL_AUDIO_ISBIGENDIAN(x);
535}
536
537constexpr bool AudioFormat::IsBigEndian() const
538{
539 return SDL::IsAudioBigENDIAN(m_audioFormat);
540}
541
555{
556 return SDL_AUDIO_ISLITTLEENDIAN(x);
557}
558
559constexpr bool AudioFormat::IsLittleEndian() const
560{
561 return SDL::IsAudioLittleEndian(m_audioFormat);
562}
563
576constexpr bool IsAudioSigned(AudioFormatRaw x) { return SDL_AUDIO_ISSIGNED(x); }
577
578constexpr bool AudioFormat::IsSigned() const
579{
580 return SDL::IsAudioSigned(m_audioFormat);
581}
582
595constexpr bool IsAudioInt(AudioFormatRaw x) { return SDL_AUDIO_ISINT(x); }
596
597constexpr bool AudioFormat::IsInt() const
598{
599 return SDL::IsAudioInt(m_audioFormat);
600}
601
615{
616 return SDL_AUDIO_ISUNSIGNED(x);
617}
618
619constexpr bool AudioFormat::IsUnsigned() const
620{
621 return SDL::IsAudioUnsigned(m_audioFormat);
622}
623
659using AudioPostmixCallback = void(SDLCALL*)(void* userdata,
660 const AudioSpec* spec,
661 float* buffer,
662 int buflen);
663
699 MakeFrontCallback<void(const AudioSpec* spec, float* buffer, int buflen)>;
700
740using AudioStreamCallback = void(SDLCALL*)(void* userdata,
741 AudioStreamRaw stream,
742 int additional_amount,
743 int total_amount);
744
785 void(AudioStreamRaw stream, int additional_amount, int total_amount)>;
786
797{
798 AudioDeviceID m_resource = 0;
799
800public:
802 constexpr AudioDevice(std::nullptr_t = nullptr) noexcept
803 : m_resource(0)
804 {
805 }
806
814 constexpr explicit AudioDevice(AudioDeviceID resource) noexcept
815 : m_resource(resource)
816 {
817 }
818
820 constexpr AudioDevice(const AudioDevice& other) noexcept = delete;
821
823 constexpr AudioDevice(AudioDevice&& other) noexcept
824 : AudioDevice(other.release())
825 {
826 }
827
828 constexpr AudioDevice(const AudioDeviceRef& other) = delete;
829
830 constexpr AudioDevice(AudioDeviceRef&& other) = delete;
831
904
906 ~AudioDevice() { SDL_CloseAudioDevice(m_resource); }
907
909 constexpr AudioDevice& operator=(AudioDevice&& other) noexcept
910 {
911 std::swap(m_resource, other.m_resource);
912 return *this;
913 }
914
916 AudioDevice& operator=(const AudioDevice& other) = delete;
917
919 constexpr AudioDeviceID get() const noexcept { return m_resource; }
920
922 constexpr AudioDeviceID release() noexcept
923 {
924 auto r = m_resource;
925 m_resource = 0;
926 return r;
927 }
928
930 constexpr auto operator<=>(const AudioDevice& other) const noexcept = default;
931
933 constexpr explicit operator bool() const noexcept { return !!m_resource; }
934
951 void Close();
952
975 const char* GetName() const;
976
1008 AudioSpec GetFormat(int* sample_frames = nullptr) const;
1009
1029
1052 bool IsPhysical() const;
1053
1065 bool IsPlayback() const;
1066
1094 void Pause();
1095
1119 void Resume();
1120
1140 bool Paused() const;
1141
1162 float GetGain() const;
1163
1195 void SetGain(float gain);
1196
1232 void BindAudioStreams(std::span<AudioStreamRef> streams);
1233
1251 void BindAudioStream(AudioStreamRef stream);
1252
1303 void SetPostmixCallback(AudioPostmixCallback callback, void* userdata);
1304
1354 void SetPostmixCallback(AudioPostmixCB callback);
1355
1412 AudioStreamCallback callback,
1413 void* userdata);
1414
1467 AudioStreamCB callback);
1468};
1469
1476{
1478
1486 constexpr AudioDeviceRef(AudioDeviceID resource) noexcept
1487 : AudioDevice(resource)
1488 {
1489 }
1490
1498 constexpr AudioDeviceRef(const AudioDevice& resource) noexcept
1499 : AudioDevice(resource.get())
1500 {
1501 }
1502
1510 constexpr AudioDeviceRef(AudioDevice&& resource) noexcept
1511 : AudioDevice(std::move(resource).release())
1512 {
1513 }
1514
1516 constexpr AudioDeviceRef(const AudioDeviceRef& other) noexcept
1517 : AudioDevice(other.get())
1518 {
1519 }
1520
1522 constexpr AudioDeviceRef(AudioDeviceRef&& other) noexcept
1523 : AudioDevice(other.get())
1524 {
1525 }
1526
1529
1532 {
1533 release();
1534 AudioDevice::operator=(AudioDevice(other.get()));
1535 return *this;
1536 }
1537
1539 constexpr operator AudioDeviceID() const noexcept { return get(); }
1540};
1541
1552 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1553
1564 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1565
1579constexpr int AudioFrameSize(const AudioSpec& x)
1580{
1581 return SDL_AUDIO_FRAMESIZE(x);
1582}
1583
1584#if SDL_VERSION_ATLEAST(3, 4, 0)
1585
1612using AudioStreamDataCompleteCallback = void(SDLCALL*)(void* userdata,
1613 const void* buf,
1614 int buflen);
1615
1643 std::function<void(const void* buf, int buflen)>;
1644
1645#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1646
1674{
1675 AudioStreamRaw m_resource = nullptr;
1676
1677public:
1679 constexpr AudioStream(std::nullptr_t = nullptr) noexcept
1680 : m_resource(nullptr)
1681 {
1682 }
1683
1691 constexpr explicit AudioStream(AudioStreamRaw resource) noexcept
1692 : m_resource(resource)
1693 {
1694 }
1695
1697 constexpr AudioStream(const AudioStream& other) noexcept = delete;
1698
1700 constexpr AudioStream(AudioStream&& other) noexcept
1701 : AudioStream(other.release())
1702 {
1703 }
1704
1705 constexpr AudioStream(const AudioStreamRef& other) = delete;
1706
1707 constexpr AudioStream(AudioStreamRef&& other) = delete;
1708
1731
1790 OptionalRef<const AudioSpec> spec = std::nullopt,
1791 AudioStreamCallback callback = nullptr,
1792 void* userdata = nullptr);
1793
1849 AudioStreamCB callback);
1850
1852 ~AudioStream() { SDL_DestroyAudioStream(m_resource); }
1853
1855 constexpr AudioStream& operator=(AudioStream&& other) noexcept
1856 {
1857 std::swap(m_resource, other.m_resource);
1858 return *this;
1859 }
1860
1862 AudioStream& operator=(const AudioStream& other) = delete;
1863
1865 constexpr AudioStreamRaw get() const noexcept { return m_resource; }
1866
1868 constexpr AudioStreamRaw release() noexcept
1869 {
1870 auto r = m_resource;
1871 m_resource = nullptr;
1872 return r;
1873 }
1874
1876 constexpr auto operator<=>(const AudioStream& other) const noexcept = default;
1877
1879 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1880
1898 void Destroy();
1899
1922
1937 {
1938 AudioSpec spec;
1939 GetFormat(&spec, nullptr);
1940 return spec;
1941 }
1942
1957 {
1958 AudioSpec spec;
1959 GetFormat(nullptr, &spec);
1960 return spec;
1961 }
1962
1977 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
1978
2009 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
2010
2041 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
2042
2078
2092 float GetFrequencyRatio() const;
2093
2118 void SetFrequencyRatio(float ratio);
2119
2138 float GetGain() const;
2139
2161 void SetGain(float gain);
2162
2183
2204
2260 void SetInputChannelMap(std::span<int> chmap);
2261
2315 void SetOutputChannelMap(std::span<int> chmap);
2316
2342 void PutData(SourceBytes buf);
2343
2344#if SDL_VERSION_ATLEAST(3, 4, 0)
2345
2388 void PutDataNoCopy(SourceBytes buf,
2390 void* userdata);
2391
2433
2434#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2435
2462 int GetData(TargetBytes buf);
2463
2487 int GetAvailable() const;
2488
2524 int GetQueued() const;
2525
2542 void Flush();
2543
2561 void Clear();
2562
2583 void PauseDevice();
2584
2604 void ResumeDevice();
2605
2622 bool DevicePaused() const;
2623
2649
2664 void Unlock(AudioStreamLock&& lock);
2665
2708 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2709
2750 void SetGetCallback(AudioStreamCB callback);
2751
2797 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2798
2842 void SetPutCallback(AudioStreamCB callback);
2843
2856 void Unbind();
2857
2876 AudioDeviceRef GetDevice() const;
2877
2878#if SDL_VERSION_ATLEAST(3, 4, 0)
2879
2928 void PutPlanarData(const void* const* channel_buffers,
2929 int num_channels,
2930 int num_samples);
2931
2932#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2933};
2934
2941{
2943
2951 constexpr AudioStreamRef(AudioStreamRaw resource) noexcept
2952 : AudioStream(resource)
2953 {
2954 }
2955
2963 constexpr AudioStreamRef(const AudioStream& resource) noexcept
2964 : AudioStream(resource.get())
2965 {
2966 }
2967
2975 constexpr AudioStreamRef(AudioStream&& resource) noexcept
2976 : AudioStream(std::move(resource).release())
2977 {
2978 }
2979
2981 constexpr AudioStreamRef(const AudioStreamRef& other) noexcept
2982 : AudioStream(other.get())
2983 {
2984 }
2985
2987 constexpr AudioStreamRef(AudioStreamRef&& other) noexcept
2988 : AudioStream(other.get())
2989 {
2990 }
2991
2994
2997 {
2998 release();
2999 AudioStream::operator=(AudioStream(other.get()));
3000 return *this;
3001 }
3002
3004 constexpr operator AudioStreamRaw() const noexcept { return get(); }
3005};
3006
3026{
3027 AudioStreamRef m_lock;
3028
3029public:
3057
3059 AudioStreamLock(const AudioStreamLock& other) = delete;
3060
3063 : m_lock(std::move(other.m_lock))
3064 {
3065 }
3066
3080 {
3081 if (!m_lock) return;
3082 SDL_UnlockAudioStream(m_lock);
3083 }
3084
3085 AudioStreamLock& operator=(const AudioStreamLock& other) = delete;
3086
3089 {
3090 std::swap(m_lock, other.m_lock);
3091 return *this;
3092 }
3093
3095 constexpr operator bool() const { return bool(m_lock); }
3096
3111 void reset();
3112
3114 AudioStreamRef resource() const { return m_lock; }
3115
3117 void release() { m_lock.release(); }
3118};
3119
3141inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
3142
3165inline const char* GetAudioDriver(int index)
3166{
3167 return SDL_GetAudioDriver(index);
3168}
3169
3184inline const char* GetCurrentAudioDriver()
3185{
3186 return SDL_GetCurrentAudioDriver();
3187}
3188
3214{
3215 int count;
3216 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3217 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3218 size_t(count)};
3219}
3220
3246{
3247 int count;
3248 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3249 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3250 size_t(count)};
3251}
3252
3276inline const char* GetAudioDeviceName(AudioDeviceRef devid)
3277{
3278 return CheckError(SDL_GetAudioDeviceName(devid));
3279}
3280
3281inline const char* AudioDevice::GetName() const
3282{
3283 return SDL::GetAudioDeviceName(m_resource);
3284}
3285
3317 int* sample_frames = nullptr)
3318{
3319 AudioSpec spec;
3320 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3321 return spec;
3322}
3323
3324inline AudioSpec AudioDevice::GetFormat(int* sample_frames) const
3325{
3326 return SDL::GetAudioDeviceFormat(m_resource, sample_frames);
3327}
3328
3349{
3350 int count;
3351 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3352 return OwnArray<int>{data, size_t(count)};
3353}
3354
3356{
3357 return SDL::GetAudioDeviceChannelMap(m_resource);
3358}
3359
3432{
3433 return AudioDevice(devid, spec);
3434}
3435
3438 : m_resource(CheckError(SDL_OpenAudioDevice(devid, spec)))
3439{
3440}
3441
3466{
3467 return SDL_IsAudioDevicePhysical(devid);
3468}
3469
3470inline bool AudioDevice::IsPhysical() const
3471{
3472 return SDL::IsAudioDevicePhysical(m_resource);
3473}
3474
3488{
3489 return SDL_IsAudioDevicePlayback(devid);
3490}
3491
3492inline bool AudioDevice::IsPlayback() const
3493{
3494 return SDL::IsAudioDevicePlayback(m_resource);
3495}
3496
3526{
3527 CheckError(SDL_PauseAudioDevice(devid));
3528}
3529
3530inline void AudioDevice::Pause() { SDL::PauseAudioDevice(m_resource); }
3531
3557{
3558 CheckError(SDL_ResumeAudioDevice(devid));
3559}
3560
3561inline void AudioDevice::Resume() { SDL::ResumeAudioDevice(m_resource); }
3562
3584{
3585 return SDL_AudioDevicePaused(devid);
3586}
3587
3588inline bool AudioDevice::Paused() const
3589{
3590 return SDL::AudioDevicePaused(m_resource);
3591}
3592
3615{
3616 return SDL_GetAudioDeviceGain(devid);
3617}
3618
3619inline float AudioDevice::GetGain() const
3620{
3621 return SDL::GetAudioDeviceGain(m_resource);
3622}
3623
3656inline void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
3657{
3658 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3659}
3660
3661inline void AudioDevice::SetGain(float gain)
3662{
3663 SDL::SetAudioDeviceGain(m_resource, gain);
3664}
3665
3685{
3686 SDL_CloseAudioDevice(devid);
3687}
3688
3690
3728 std::span<AudioStreamRef> streams)
3729{
3730 CheckError(SDL_BindAudioStreams(
3731 devid,
3732 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3733 narrowS32(streams.size())));
3734}
3735
3736inline void AudioDevice::BindAudioStreams(std::span<AudioStreamRef> streams)
3737{
3738 SDL::BindAudioStreams(m_resource, streams);
3739}
3740
3760{
3761 CheckError(SDL_BindAudioStream(devid, stream));
3762}
3763
3765{
3766 SDL::BindAudioStream(m_resource, stream);
3767}
3768
3787inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3788{
3789 SDL_UnbindAudioStreams(
3790 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3791 narrowS32(streams.size()));
3792}
3793
3809{
3810 SDL_UnbindAudioStream(stream);
3811}
3812
3813inline void AudioStream::Unbind() { SDL::UnbindAudioStream(m_resource); }
3814
3834{
3835 return {SDL_GetAudioStreamDevice(stream)};
3836}
3837
3839{
3840 return SDL::GetAudioStreamDevice(m_resource);
3841}
3842
3865{
3866 return AudioStream(src_spec, dst_spec);
3867}
3868
3871 : m_resource(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
3872{
3873}
3874
3877 AudioStreamCallback callback,
3878 void* userdata)
3879 : m_resource(
3880 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
3881{
3882}
3883
3886 AudioStreamCB callback)
3887 : AudioStream(devid, spec)
3888{
3889 if (IsAudioDevicePlayback(devid)) {
3890 SetGetCallback(std::move(callback));
3891 } else {
3892 SetPutCallback(std::move(callback));
3893 }
3894}
3895
3919{
3920 return {CheckError(SDL_GetAudioStreamProperties(stream))};
3921}
3922
3924{
3925 return SDL::GetAudioStreamProperties(m_resource);
3926}
3927
3928#if SDL_VERSION_ATLEAST(3, 4, 0)
3929
3930namespace prop::AudioStream {
3931
3932constexpr auto _AUTO_CLEANUP_BOOLEAN =
3933 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3934
3935} // namespace prop::AudioStream
3936
3937#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3938
3955 AudioSpec* src_spec,
3956 AudioSpec* dst_spec)
3957{
3958 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3959}
3960
3961inline void AudioStream::GetFormat(AudioSpec* src_spec,
3962 AudioSpec* dst_spec) const
3963{
3964 SDL::GetAudioStreamFormat(m_resource, src_spec, dst_spec);
3965}
3966
4004{
4005 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
4006}
4007
4010{
4011 SDL::SetAudioStreamFormat(m_resource, src_spec, dst_spec);
4012}
4013
4029{
4030 return SDL_GetAudioStreamFrequencyRatio(stream);
4031}
4032
4034{
4035 return SDL::GetAudioStreamFrequencyRatio(m_resource);
4036}
4037
4063inline void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
4064{
4065 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
4066}
4067
4068inline void AudioStream::SetFrequencyRatio(float ratio)
4069{
4070 SDL::SetAudioStreamFrequencyRatio(m_resource, ratio);
4071}
4072
4093{
4094 return SDL_GetAudioStreamGain(stream);
4095}
4096
4097inline float AudioStream::GetGain() const
4098{
4099 return SDL::GetAudioStreamGain(m_resource);
4100}
4101
4124inline void SetAudioStreamGain(AudioStreamRef stream, float gain)
4125{
4126 CheckError(SDL_SetAudioStreamGain(stream, gain));
4127}
4128
4129inline void AudioStream::SetGain(float gain)
4130{
4131 SDL::SetAudioStreamGain(m_resource, gain);
4132}
4133
4155{
4156 int count;
4157 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4158 if (!data) return {};
4159 return OwnArray<int>{data, size_t(count)};
4160}
4161
4166
4188{
4189 int count;
4190 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4191 if (!data) return {};
4192 return OwnArray<int>{data, size_t(count)};
4193}
4194
4199
4257 std::span<int> chmap)
4258{
4259 CheckError(SDL_SetAudioStreamInputChannelMap(
4260 stream, chmap.data(), narrowS32(chmap.size())));
4261}
4262
4263inline void AudioStream::SetInputChannelMap(std::span<int> chmap)
4264{
4265 SDL::SetAudioStreamInputChannelMap(m_resource, chmap);
4266}
4267
4323 std::span<int> chmap)
4324{
4325 CheckError(SDL_SetAudioStreamOutputChannelMap(
4326 stream, chmap.data(), narrowS32(chmap.size())));
4327}
4328
4329inline void AudioStream::SetOutputChannelMap(std::span<int> chmap)
4330{
4331 SDL::SetAudioStreamOutputChannelMap(m_resource, chmap);
4332}
4333
4361{
4362 CheckError(
4363 SDL_PutAudioStreamData(stream, buf.data(), narrowS32(buf.size_bytes())));
4364}
4365
4367{
4368 SDL::PutAudioStreamData(m_resource, std::move(buf));
4369}
4370
4371#if SDL_VERSION_ATLEAST(3, 4, 0)
4372
4417 SourceBytes buf,
4419 void* userdata)
4420{
4421 CheckError(SDL_PutAudioStreamDataNoCopy(
4422 stream, buf.data(), narrowS32(buf.size_bytes()), callback, userdata));
4423}
4424
4467 SourceBytes buf,
4469{
4472 std::move(buf),
4473 &Wrapper::CallOnce,
4474 Wrapper::Wrap(std::move(callback)));
4475}
4476
4479 void* userdata)
4480{
4481 SDL::PutAudioStreamDataNoCopy(m_resource, std::move(buf), callback, userdata);
4482}
4483
4486{
4488 m_resource, std::move(buf), std::move(callback));
4489}
4490
4540 const void* const* channel_buffers,
4541 int num_channels,
4542 int num_samples)
4543{
4544 CheckError(SDL_PutAudioStreamPlanarData(
4545 stream, channel_buffers, num_channels, num_samples));
4546}
4547
4548inline void AudioStream::PutPlanarData(const void* const* channel_buffers,
4549 int num_channels,
4550 int num_samples)
4551{
4553 m_resource, channel_buffers, num_channels, num_samples);
4554}
4555
4556#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4557
4586{
4587 return SDL_GetAudioStreamData(
4588 stream, buf.data(), narrowS32(buf.size_bytes()));
4589}
4590
4592{
4593 return SDL::GetAudioStreamData(m_resource, std::move(buf));
4594}
4595
4620{
4621 return SDL_GetAudioStreamAvailable(stream);
4622}
4623
4625{
4626 return SDL::GetAudioStreamAvailable(m_resource);
4627}
4628
4665{
4666 return SDL_GetAudioStreamQueued(stream);
4667}
4668
4669inline int AudioStream::GetQueued() const
4670{
4671 return SDL::GetAudioStreamQueued(m_resource);
4672}
4673
4692{
4693 CheckError(SDL_FlushAudioStream(stream));
4694}
4695
4696inline void AudioStream::Flush() { SDL::FlushAudioStream(m_resource); }
4697
4717{
4718 CheckError(SDL_ClearAudioStream(stream));
4719}
4720
4721inline void AudioStream::Clear() { SDL::ClearAudioStream(m_resource); }
4722
4745{
4746 CheckError(SDL_PauseAudioStreamDevice(stream));
4747}
4748
4750{
4751 SDL::PauseAudioStreamDevice(m_resource);
4752}
4753
4775{
4776 CheckError(SDL_ResumeAudioStreamDevice(stream));
4777}
4778
4780{
4781 SDL::ResumeAudioStreamDevice(m_resource);
4782}
4783
4802{
4803 return SDL_AudioStreamDevicePaused(stream);
4804}
4805
4806inline bool AudioStream::DevicePaused() const
4807{
4808 return SDL::AudioStreamDevicePaused(m_resource);
4809}
4810
4837{
4838 CheckError(SDL_LockAudioStream(stream));
4839}
4840
4842
4844 : m_lock(std::move(resource))
4845{
4846 LockAudioStream(m_lock);
4847}
4848
4865{
4866 CheckError(SDL_UnlockAudioStream(stream));
4867}
4868
4870{
4871 SDL_assert_paranoid(lock.resource() == *this);
4872 std::move(lock).reset();
4873}
4874
4876{
4877 if (!m_lock) return;
4878 UnlockAudioStream(m_lock);
4879 m_lock = {};
4880}
4881
4924 AudioStreamCallback callback,
4925 void* userdata)
4926{
4927 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4928}
4929
4970 AudioStreamCB callback)
4971{
4972 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4973}
4974
4976 void* userdata)
4977{
4978 SDL::SetAudioStreamGetCallback(m_resource, callback, userdata);
4979}
4980
4982{
4983 SDL::SetAudioStreamGetCallback(m_resource, callback);
4984}
4985
5032 AudioStreamCallback callback,
5033 void* userdata)
5034{
5035 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
5036}
5037
5082 AudioStreamCB callback)
5083{
5084 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
5085}
5086
5088 void* userdata)
5089{
5090 SDL::SetAudioStreamPutCallback(m_resource, callback, userdata);
5091}
5092
5094{
5095 SDL::SetAudioStreamPutCallback(m_resource, callback);
5096}
5097
5117{
5118 SDL_DestroyAudioStream(stream);
5119}
5120
5122
5182 AudioStreamCallback callback = nullptr,
5183 void* userdata = nullptr)
5184{
5185 return AudioStream(devid, spec, callback, userdata);
5186}
5187
5243 AudioStreamCB callback)
5244{
5245 return AudioStream(devid, spec, callback);
5246}
5247
5249 AudioStreamCallback callback,
5250 void* userdata)
5251{
5252 return AudioStream(m_resource, spec, callback, userdata);
5253}
5254
5256 AudioStreamCB callback)
5257{
5258 return AudioStream(m_resource, spec, callback);
5259}
5260
5313 AudioPostmixCallback callback,
5314 void* userdata)
5315{
5316 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5317}
5318
5370 AudioPostmixCB callback)
5371{
5372 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5373}
5374
5376 void* userdata)
5377{
5378 SDL::SetAudioPostmixCallback(m_resource, callback, userdata);
5379}
5380
5382{
5383 SDL::SetAudioPostmixCallback(m_resource, callback);
5384}
5385
5454 AudioSpec* spec,
5455 bool closeio = false)
5456{
5457 Uint8* buf;
5458 Uint32 len;
5459 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
5460 return OwnArray<Uint8>{buf, size_t(len)};
5461}
5462
5488{
5489 Uint8* buf;
5490 Uint32 len;
5491 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5492 return OwnArray<Uint8>{buf, size_t(len)};
5493}
5494
5526inline void MixAudio(Uint8* dst,
5527 SourceBytes src,
5528 AudioFormat format,
5529 float volume)
5530{
5531 CheckError(SDL_MixAudio(
5532 dst, src.data_as<Uint8>(), format, narrowS32(src.size_bytes()), volume));
5533}
5534
5566inline void MixAudio(TargetBytes dst,
5567 SourceBytes src,
5568 AudioFormat format,
5569 float volume)
5570{
5571 if (dst.size_bytes() < src.size_bytes()) {
5572 MixAudio(dst.data_as<Uint8>(),
5573 SourceBytes{src.data(), dst.size_bytes()},
5574 format,
5575 volume);
5576 } else
5577 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5578}
5579
5603 SourceBytes src_data,
5604 const AudioSpec& dst_spec)
5605{
5606 Uint8* buf;
5607 int len;
5608 CheckError(SDL_ConvertAudioSamples(&src_spec,
5609 src_data.data_as<Uint8>(),
5610 narrowS32(src_data.size_bytes()),
5611 &dst_spec,
5612 &buf,
5613 &len));
5614 return OwnArray<Uint8>{buf, size_t(len)};
5615}
5616
5628inline const char* GetAudioFormatName(AudioFormatRaw format)
5629{
5630 return SDL_GetAudioFormatName(format);
5631}
5632
5633inline const char* AudioFormat::GetName() const
5634{
5635 return SDL::GetAudioFormatName(m_audioFormat);
5636}
5637
5652{
5653 return SDL_GetSilenceValueForFormat(format);
5654}
5655
5657{
5658 return SDL::GetSilenceValueForFormat(m_audioFormat);
5659}
5660
5662
5663} // namespace SDL
5664
5665#endif /* SDL3PP_AUDIO_H_ */
SDL Audio Device instance IDs.
Definition SDL3pp_audio.h:797
constexpr AudioDeviceID get() const noexcept
Retrieves underlying AudioDeviceID.
Definition SDL3pp_audio.h:919
constexpr AudioDeviceID release() noexcept
Retrieves underlying AudioDeviceID and clear this.
Definition SDL3pp_audio.h:922
~AudioDevice()
Destructor.
Definition SDL3pp_audio.h:906
constexpr AudioDevice(AudioDeviceID resource) noexcept
Constructs from raw AudioDevice.
Definition SDL3pp_audio.h:814
constexpr AudioDevice(const AudioDevice &other) noexcept=delete
Copy constructor.
constexpr AudioDevice(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_audio.h:802
AudioDevice & operator=(const AudioDevice &other)=delete
Assignment operator.
constexpr auto operator<=>(const AudioDevice &other) const noexcept=default
Comparison.
constexpr AudioDevice & operator=(AudioDevice &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:909
constexpr AudioDevice(AudioDevice &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:823
Audio format.
Definition SDL3pp_audio.h:207
constexpr AudioFormat(AudioFormatRaw audioFormat={}) noexcept
Wraps AudioFormat.
Definition SDL3pp_audio.h:216
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:3026
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:3088
void release()
Releases the lock without unlocking.
Definition SDL3pp_audio.h:3117
AudioStreamRef resource() const
Get the reference to locked resource.
Definition SDL3pp_audio.h:3114
AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:3062
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:3079
The opaque handle that represents an audio stream.
Definition SDL3pp_audio.h:1674
AudioStream & operator=(const AudioStream &other)=delete
Assignment operator.
constexpr auto operator<=>(const AudioStream &other) const noexcept=default
Comparison.
~AudioStream()
Destructor.
Definition SDL3pp_audio.h:1852
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition SDL3pp_audio.h:1956
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition SDL3pp_audio.h:2041
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:1700
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition SDL3pp_audio.h:2009
constexpr AudioStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_audio.h:1679
constexpr AudioStreamRaw get() const noexcept
Retrieves underlying AudioStreamRaw.
Definition SDL3pp_audio.h:1865
constexpr AudioStream(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:1691
constexpr AudioStreamRaw release() noexcept
Retrieves underlying AudioStreamRaw and clear this.
Definition SDL3pp_audio.h:1868
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition SDL3pp_audio.h:1936
constexpr AudioStream(const AudioStream &other) noexcept=delete
Copy constructor.
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:1855
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:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
constexpr const T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:311
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Target byte stream.
Definition SDL3pp_strings.h:323
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:409
constexpr T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:413
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:406
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
constexpr bool IsAudioFloat(AudioFormatRaw x)
Determine if an AudioFormat represents floating point data.
Definition SDL3pp_audio.h:513
void SetAudioStreamInputChannelMap(AudioStreamRef stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4256
void Pause()
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3530
void PutAudioStreamData(AudioStreamRef stream, SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4360
constexpr AudioFormat AUDIO_UNKNOWN
Unspecified audio format.
Definition SDL3pp_audio.h:391
void SetAudioStreamOutputChannelMap(AudioStreamRef stream, std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4322
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition SDL3pp_audio.h:5248
void Resume()
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3561
constexpr bool IsLittleEndian() const
Determine if an AudioFormat represents littleendian data.
Definition SDL3pp_audio.h:559
constexpr bool IsBigEndian() const
Determine if an AudioFormat represents bigendian data.
Definition SDL3pp_audio.h:537
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3736
constexpr bool IsAudioInt(AudioFormatRaw x)
Determine if an AudioFormat represents integer data.
Definition SDL3pp_audio.h:595
bool IsAudioDevicePlayback(AudioDeviceRef devid)
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3487
bool AudioDevicePaused(AudioDeviceRef devid)
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3583
void BindAudioStreams(AudioDeviceRef devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3727
AudioDevice OpenAudioDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition SDL3pp_audio.h:3430
constexpr Uint32 AUDIO_MASK_SIGNED
Mask of bits in an AudioFormat that contain the signed data flag.
Definition SDL3pp_audio.h:181
constexpr Uint32 AUDIO_MASK_BITSIZE
Mask of bits in an AudioFormat that contains the format bit size.
Definition SDL3pp_audio.h:151
void BindAudioStream(AudioDeviceRef devid, AudioStreamRef stream)
Bind a single audio stream to an audio device.
Definition SDL3pp_audio.h:3759
void PauseDevice()
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4749
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3961
constexpr AudioFormat AUDIO_S8
Signed 8-bit samples.
Definition SDL3pp_audio.h:396
constexpr Uint32 AUDIO_MASK_FLOAT
Mask of bits in an AudioFormat that contain the floating point flag.
Definition SDL3pp_audio.h:161
OwnArray< int > GetInputChannelMap() const
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4162
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:5602
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:4068
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:659
AudioStreamLock(AudioStreamRef resource)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4843
void GetAudioStreamFormat(AudioStreamRef stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3954
constexpr bool IsAudioUnsigned(AudioFormatRaw x)
Determine if an AudioFormat represents unsigned data.
Definition SDL3pp_audio.h:614
int GetSilenceValueForFormat(AudioFormatRaw format)
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5651
int GetData(TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4591
constexpr AudioFormat AUDIO_S16
AUDIO_S16.
Definition SDL3pp_audio.h:414
bool IsAudioDevicePhysical(AudioDeviceRef devid)
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3465
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition SDL3pp_audio.h:408
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:5087
std::function< void(const void *buf, int buflen)> AudioStreamDataCompleteCB
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition SDL3pp_audio.h:1642
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4195
constexpr Uint16 GetByteSize() const
Retrieve the size, in bytes, from an AudioFormat.
Definition SDL3pp_audio.h:496
void BindAudioStream(AudioStreamRef stream)
Bind a single audio stream to an audio device.
Definition SDL3pp_audio.h:3764
void PauseAudioStreamDevice(AudioStreamRef stream)
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4744
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition SDL3pp_audio.h:3184
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3355
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4624
float GetAudioDeviceGain(AudioDeviceRef devid)
Get the gain of an audio device.
Definition SDL3pp_audio.h:3614
float GetAudioStreamGain(AudioStreamRef stream)
Get the gain of an audio stream.
Definition SDL3pp_audio.h:4092
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:4033
constexpr bool IsAudioSigned(AudioFormatRaw x)
Determine if an AudioFormat represents signed data.
Definition SDL3pp_audio.h:576
void ResumeAudioStreamDevice(AudioStreamRef stream)
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4774
void ResumeDevice()
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4779
void SetAudioStreamFormat(AudioStreamRef 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:4001
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5628
const char * GetAudioDeviceName(AudioDeviceRef devid)
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3276
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4841
bool Paused() const
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3588
void UnlockAudioStream(AudioStreamRef stream)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4864
SDL_AudioFormat AudioFormatRaw
Alias to raw representation for AudioFormat.
Definition SDL3pp_audio.h:117
void ClearAudioStream(AudioStreamRef stream)
Clear any pending data in the stream.
Definition SDL3pp_audio.h:4716
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:4548
constexpr AudioFormat AUDIO_U8
Unsigned 8-bit samples.
Definition SDL3pp_audio.h:394
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:4008
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4806
constexpr Uint16 AudioBitSize(AudioFormatRaw x)
Retrieve the size, in bits, from an AudioFormat.
Definition SDL3pp_audio.h:472
constexpr AudioFormat AUDIO_S32
AUDIO_S32.
Definition SDL3pp_audio.h:416
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5656
constexpr bool IsAudioLittleEndian(AudioFormatRaw x)
Determine if an AudioFormat represents littleendian data.
Definition SDL3pp_audio.h:554
constexpr AudioFormat AUDIO_S16LE
Signed 16-bit samples.
Definition SDL3pp_audio.h:398
constexpr Uint32 AUDIO_MASK_BIG_ENDIAN
Mask of bits in an AudioFormat that contain the bigendian flag.
Definition SDL3pp_audio.h:171
float GetAudioStreamFrequencyRatio(AudioStreamRef stream)
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:4028
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3324
void SetAudioStreamGain(AudioStreamRef stream, float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:4124
PropertiesRef GetProperties() const
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3923
void FlushAudioStream(AudioStreamRef stream)
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4691
void PutAudioStreamPlanarData(AudioStreamRef 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:4539
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:740
float GetGain() const
Get the gain of an audio stream.
Definition SDL3pp_audio.h:4097
PropertiesRef GetAudioStreamProperties(AudioStreamRef stream)
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3918
void UnbindAudioStream(AudioStreamRef stream)
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3808
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition SDL3pp_audio.h:3245
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4329
void PauseAudioDevice(AudioDeviceRef devid)
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3525
MakeFrontCallback< void(const AudioSpec *spec, float *buffer, int buflen)> AudioPostmixCB
A callback that fires when data is about to be fed to an audio device.
Definition SDL3pp_audio.h:698
void reset()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4875
void SetGetCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition SDL3pp_audio.h:4975
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3838
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition SDL3pp_audio.h:190
constexpr AudioFormat AUDIO_S32BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:405
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition SDL3pp_audio.h:3165
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3492
void SetAudioPostmixCallback(AudioDeviceRef 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:5312
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition SDL3pp_audio.h:1563
constexpr AudioFormat DefineAudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition SDL3pp_audio.h:443
AudioDeviceRef GetAudioStreamDevice(AudioStreamRef stream)
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3833
OwnArray< Uint8 > LoadWAV_IO(IOStreamRef src, AudioSpec *spec, bool closeio=false)
Load the audio data of a WAVE file into memory.
Definition SDL3pp_audio.h:5453
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition SDL3pp_audio.h:1551
constexpr AudioFormat AUDIO_S32LE
32-bit integer samples
Definition SDL3pp_audio.h:403
void Close()
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3689
constexpr bool IsInt() const
Determine if an AudioFormat represents integer data.
Definition SDL3pp_audio.h:597
int GetAudioStreamQueued(AudioStreamRef stream)
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4664
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition SDL3pp_audio.h:5526
AudioSpec GetAudioDeviceFormat(AudioDeviceRef devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3316
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed AudioStream.PutDataNoCopy() data.
Definition SDL3pp_audio.h:1612
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition SDL3pp_audio.h:3863
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4263
void Unbind()
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3813
OwnArray< Uint8 > LoadWAV(StringParam path, AudioSpec *spec)
Loads a WAV from a file path.
Definition SDL3pp_audio.h:5487
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3281
constexpr bool IsFloat() const
Determine if an AudioFormat represents floating point data.
Definition SDL3pp_audio.h:515
void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3656
void SetAudioStreamPutCallback(AudioStreamRef stream, AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:5031
constexpr AudioFormat AUDIO_F32BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:411
constexpr AudioFormat AUDIO_F32
AUDIO_F32.
Definition SDL3pp_audio.h:418
int GetNumAudioDrivers()
Use this function to get the number of built-in audio drivers.
Definition SDL3pp_audio.h:3141
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition SDL3pp_audio.h:3787
AudioStream OpenAudioDeviceStream(AudioDeviceRef 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:5180
int GetQueued() const
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4669
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceRef devid)
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3348
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:5375
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3470
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition SDL3pp_audio.h:5116
constexpr bool IsSigned() const
Determine if an AudioFormat represents signed data.
Definition SDL3pp_audio.h:578
SDL_AudioDeviceID AudioDeviceID
Alias to raw representation for AudioDevice.
Definition SDL3pp_audio.h:126
constexpr bool IsAudioBigENDIAN(AudioFormatRaw x)
Determine if an AudioFormat represents bigendian data.
Definition SDL3pp_audio.h:532
MakeFrontCallback< void(AudioStreamRaw stream, int additional_amount, int total_amount)> AudioStreamCB
A callback that fires when data passes through an AudioStream.
Definition SDL3pp_audio.h:784
void SetGain(float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3661
constexpr AudioFormat AUDIO_S16BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:400
void PutData(SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4366
OwnArray< int > GetAudioStreamOutputChannelMap(AudioStreamRef stream)
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4187
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition SDL3pp_audio.h:3213
float GetGain() const
Get the gain of an audio device.
Definition SDL3pp_audio.h:3619
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamRef stream)
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4154
int GetAudioStreamAvailable(AudioStreamRef stream)
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4619
constexpr Uint16 AudioByteSize(AudioFormatRaw x)
Retrieve the size, in bytes, from an AudioFormat.
Definition SDL3pp_audio.h:491
void PutDataNoCopy(SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4477
void Clear()
Clear any pending data in the stream.
Definition SDL3pp_audio.h:4721
SDL_AudioStream * AudioStreamRaw
Alias to raw representation for AudioStream.
Definition SDL3pp_audio.h:135
void SetAudioStreamGetCallback(AudioStreamRef stream, AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition SDL3pp_audio.h:4923
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4696
bool AudioStreamDevicePaused(AudioStreamRef stream)
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4801
void ResumeAudioDevice(AudioDeviceRef devid)
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3556
void SetGain(float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:4129
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4869
void PutAudioStreamDataNoCopy(AudioStreamRef stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4416
const char * GetName() const
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5633
void LockAudioStream(AudioStreamRef stream)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4836
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3684
void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:4063
constexpr Uint16 GetBitSize() const
Retrieve the size, in bits, from an AudioFormat.
Definition SDL3pp_audio.h:474
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition SDL3pp_audio.h:1579
int GetAudioStreamData(AudioStreamRef stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4585
void Destroy()
Free an audio stream.
Definition SDL3pp_audio.h:5121
constexpr bool IsUnsigned() const
Determine if an AudioFormat represents unsigned data.
Definition SDL3pp_audio.h:619
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:255
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:281
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:229
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6425
Reference for AudioDevice.
Definition SDL3pp_audio.h:1476
constexpr AudioDeviceRef(AudioDeviceID resource) noexcept
Constructs from raw AudioDevice.
Definition SDL3pp_audio.h:1486
AudioDeviceRef & operator=(const AudioDeviceRef &other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:1531
constexpr AudioDeviceRef(AudioDeviceRef &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:1522
constexpr AudioDevice(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_audio.h:802
constexpr AudioDeviceRef(AudioDevice &&resource) noexcept
Constructs from AudioDevice.
Definition SDL3pp_audio.h:1510
constexpr AudioDeviceRef(const AudioDeviceRef &other) noexcept
Copy constructor.
Definition SDL3pp_audio.h:1516
~AudioDeviceRef()
Destructor.
Definition SDL3pp_audio.h:1528
constexpr AudioDeviceRef(const AudioDevice &resource) noexcept
Constructs from AudioDevice.
Definition SDL3pp_audio.h:1498
Reference for AudioStream.
Definition SDL3pp_audio.h:2941
constexpr AudioStreamRef(const AudioStream &resource) noexcept
Constructs from AudioStream.
Definition SDL3pp_audio.h:2963
constexpr AudioStreamRef(const AudioStreamRef &other) noexcept
Copy constructor.
Definition SDL3pp_audio.h:2981
AudioStreamRef & operator=(const AudioStreamRef &other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2996
~AudioStreamRef()
Destructor.
Definition SDL3pp_audio.h:2993
constexpr AudioStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_audio.h:1679
constexpr AudioStreamRef(AudioStreamRef &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2987
constexpr AudioStreamRef(AudioStream &&resource) noexcept
Constructs from AudioStream.
Definition SDL3pp_audio.h:2975
constexpr AudioStreamRef(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:2951
Definition SDL3pp_callbackWrapper.h:20
Reference for IOStream.
Definition SDL3pp_iostream.h:1627
Definition SDL3pp_callbackWrapper.h:169
Reference for Properties.
Definition SDL3pp_properties.h:687