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 AudioDeviceBase;
124
125// Forward decl
126struct AudioDevice;
127
129using AudioDeviceID = SDL_AudioDeviceID;
130
137
138// Forward decl
139struct AudioStreamBase;
140
141// Forward decl
142struct AudioStream;
143
145using AudioStreamRaw = SDL_AudioStream*;
146
153
154// Forward decl
155struct AudioStreamLock;
156
164constexpr Uint32 AUDIO_MASK_BITSIZE = SDL_AUDIO_MASK_BITSIZE;
165
173constexpr Uint32 AUDIO_MASK_FLOAT = SDL_AUDIO_MASK_FLOAT;
174
183constexpr Uint32 AUDIO_MASK_BIG_ENDIAN = SDL_AUDIO_MASK_BIG_ENDIAN;
184
192constexpr Uint32 AUDIO_MASK_SIGNED = SDL_AUDIO_MASK_SIGNED;
193
201using AudioSpec = SDL_AudioSpec;
202
218{
219 AudioFormatRaw m_audioFormat;
220
221public:
227 constexpr AudioFormat(AudioFormatRaw audioFormat = {}) noexcept
228 : m_audioFormat(audioFormat)
229 {
230 }
231
255 constexpr AudioFormat(bool sign, bool bigendian, bool flt, Uint16 size);
256
262 constexpr operator AudioFormatRaw() const noexcept { return m_audioFormat; }
263
275 constexpr Uint16 GetBitSize() const;
276
288 constexpr Uint16 GetByteSize() const;
289
301 constexpr bool IsFloat() const;
302
314 constexpr bool IsBigEndian() const;
315
327 constexpr bool IsLittleEndian() const;
328
340 constexpr bool IsSigned() const;
341
353 constexpr bool IsInt() const;
354
366 constexpr bool IsUnsigned() const;
367
378 const char* GetName() const;
379
392 int GetSilenceValue() const;
393};
394
395// Unfortunate name clash with SDL_oldnames.h
396#undef AUDIO_U8
397#undef AUDIO_S8
398#undef AUDIO_S16
399#undef AUDIO_S32
400#undef AUDIO_F32
401
403 SDL_AUDIO_UNKNOWN;
404
405constexpr AudioFormat AUDIO_U8 = SDL_AUDIO_U8;
406
407constexpr AudioFormat AUDIO_S8 = SDL_AUDIO_S8;
408
409constexpr AudioFormat AUDIO_S16LE = SDL_AUDIO_S16LE;
410
412 SDL_AUDIO_S16BE;
413
414constexpr AudioFormat AUDIO_S32LE = SDL_AUDIO_S32LE;
415
417 SDL_AUDIO_S32BE;
418
420 SDL_AUDIO_F32LE;
421
423 SDL_AUDIO_F32BE;
424
425constexpr AudioFormat AUDIO_S16 = SDL_AUDIO_S16;
426
427constexpr AudioFormat AUDIO_S32 = SDL_AUDIO_S32;
428
429constexpr AudioFormat AUDIO_F32 = SDL_AUDIO_F32;
430
454constexpr AudioFormat DefineAudioFormat(bool sign,
455 bool bigendian,
456 bool flt,
457 Uint16 size)
458{
459 return AudioFormat(sign, bigendian, flt, size);
460}
461
462constexpr AudioFormat::AudioFormat(bool sign,
463 bool bigendian,
464 bool flt,
465 Uint16 size)
466 : m_audioFormat(
467 AudioFormatRaw(SDL_DEFINE_AUDIO_FORMAT(sign, bigendian, flt, size)))
468{
469}
470
483constexpr Uint16 AudioBitSize(AudioFormatRaw x) { return SDL_AUDIO_BITSIZE(x); }
484
486{
487 return SDL::AudioBitSize(m_audioFormat);
488}
489
503{
504 return SDL_AUDIO_BYTESIZE(x);
505}
506
508{
509 return SDL::AudioByteSize(m_audioFormat);
510}
511
524constexpr bool IsAudioFloat(AudioFormatRaw x) { return SDL_AUDIO_ISFLOAT(x); }
525
526constexpr bool AudioFormat::IsFloat() const
527{
528 return SDL::IsAudioFloat(m_audioFormat);
529}
530
544{
545 return SDL_AUDIO_ISBIGENDIAN(x);
546}
547
548constexpr bool AudioFormat::IsBigEndian() const
549{
550 return SDL::IsAudioBigENDIAN(m_audioFormat);
551}
552
566{
567 return SDL_AUDIO_ISLITTLEENDIAN(x);
568}
569
570constexpr bool AudioFormat::IsLittleEndian() const
571{
572 return SDL::IsAudioLittleEndian(m_audioFormat);
573}
574
587constexpr bool IsAudioSigned(AudioFormatRaw x) { return SDL_AUDIO_ISSIGNED(x); }
588
589constexpr bool AudioFormat::IsSigned() const
590{
591 return SDL::IsAudioSigned(m_audioFormat);
592}
593
606constexpr bool IsAudioInt(AudioFormatRaw x) { return SDL_AUDIO_ISINT(x); }
607
608constexpr bool AudioFormat::IsInt() const
609{
610 return SDL::IsAudioInt(m_audioFormat);
611}
612
626{
627 return SDL_AUDIO_ISUNSIGNED(x);
628}
629
630constexpr bool AudioFormat::IsUnsigned() const
631{
632 return SDL::IsAudioUnsigned(m_audioFormat);
633}
634
670using AudioPostmixCallback = void(SDLCALL*)(void* userdata,
671 const AudioSpec* spec,
672 float* buffer,
673 int buflen);
674
710 MakeFrontCallback<void(const AudioSpec* spec, float* buffer, int buflen)>;
711
753using AudioStreamCallback = void(SDLCALL*)(void* userdata,
754 AudioStreamRaw stream,
755 int additional_amount,
756 int total_amount);
757
800 void(AudioStreamRaw stream, int additional_amount, int total_amount)>;
801
807struct AudioDeviceBase : ResourceBaseT<AudioDeviceID>
808{
810
827 void Close();
828
851 const char* GetName() const;
852
884 AudioSpec GetFormat(int* sample_frames = nullptr) const;
885
905
928 bool IsPhysical() const;
929
941 bool IsPlayback() const;
942
970 void Pause();
971
995 void Resume();
996
1016 bool Paused() const;
1017
1038 float GetGain() const;
1039
1071 void SetGain(float gain);
1072
1108 void BindAudioStreams(std::span<AudioStreamRef> streams);
1109
1127 void BindAudioStream(AudioStreamRef stream);
1128
1179 void SetPostmixCallback(AudioPostmixCallback callback, void* userdata);
1180
1230 void SetPostmixCallback(AudioPostmixCB callback);
1231
1288 AudioStreamCallback callback,
1289 void* userdata);
1290
1343 AudioStreamCB callback);
1344};
1345
1356{
1357 using AudioDeviceBase::AudioDeviceBase;
1358
1366 constexpr explicit AudioDevice(AudioDeviceID resource) noexcept
1367 : AudioDeviceBase(resource)
1368 {
1369 }
1370
1372 constexpr AudioDevice(AudioDevice&& other) noexcept
1373 : AudioDevice(other.release())
1374 {
1375 }
1376
1449
1451 ~AudioDevice() { SDL_CloseAudioDevice(get()); }
1452
1454 constexpr AudioDevice& operator=(AudioDevice&& other) noexcept
1455 {
1456 swap(*this, other);
1457 return *this;
1458 }
1459};
1460
1471 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1472
1483 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1484
1500constexpr int AudioFrameSize(const AudioSpec& x)
1501{
1502 return SDL_AUDIO_FRAMESIZE(x);
1503}
1504
1505#if SDL_VERSION_ATLEAST(3, 4, 0)
1506
1533using AudioStreamDataCompleteCallback = void(SDLCALL*)(void* userdata,
1534 const void* buf,
1535 int buflen);
1536
1564 std::function<void(const void* buf, int buflen)>;
1565
1566#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1567
1573struct AudioStreamBase : ResourceBaseT<AudioStreamRaw>
1574{
1576
1594 void Destroy();
1595
1618
1633 {
1634 AudioSpec spec;
1635 GetFormat(&spec, nullptr);
1636 return spec;
1637 }
1638
1653 {
1654 AudioSpec spec;
1655 GetFormat(nullptr, &spec);
1656 return spec;
1657 }
1658
1673 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
1674
1705 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
1706
1737 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
1738
1777
1791 float GetFrequencyRatio() const;
1792
1817 void SetFrequencyRatio(float ratio);
1818
1837 float GetGain() const;
1838
1860 void SetGain(float gain);
1861
1882
1903
1959 void SetInputChannelMap(std::span<int> chmap);
1960
2014 void SetOutputChannelMap(std::span<int> chmap);
2015
2041 void PutData(SourceBytes buf);
2042
2043#if SDL_VERSION_ATLEAST(3, 4, 0)
2044
2087 void PutDataNoCopy(SourceBytes buf,
2089 void* userdata);
2090
2132
2133#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2134
2161 int GetData(TargetBytes buf);
2162
2186 int GetAvailable() const;
2187
2223 int GetQueued() const;
2224
2241 void Flush();
2242
2260 void Clear();
2261
2282 void PauseDevice();
2283
2303 void ResumeDevice();
2304
2321 bool DevicePaused() const;
2322
2358
2373 void Unlock(AudioStreamLock&& lock);
2374
2417 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2418
2459 void SetGetCallback(AudioStreamCB callback);
2460
2506 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2507
2551 void SetPutCallback(AudioStreamCB callback);
2552
2565 void Unbind();
2566
2585 AudioDeviceRef GetDevice() const;
2586
2587#if SDL_VERSION_ATLEAST(3, 4, 0)
2588
2637 void PutPlanarData(const void* const* channel_buffers,
2638 int num_channels,
2639 int num_samples);
2640
2641#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2642};
2643
2672{
2673 using AudioStreamBase::AudioStreamBase;
2674
2682 constexpr explicit AudioStream(AudioStreamRaw resource) noexcept
2683 : AudioStreamBase(resource)
2684 {
2685 }
2686
2688 constexpr AudioStream(AudioStream&& other) noexcept
2689 : AudioStream(other.release())
2690 {
2691 }
2692
2722
2781 OptionalRef<const AudioSpec> spec = std::nullopt,
2782 AudioStreamCallback callback = nullptr,
2783 void* userdata = nullptr);
2784
2840 AudioStreamCB callback);
2841
2843 ~AudioStream() { SDL_DestroyAudioStream(get()); }
2844
2846 constexpr AudioStream& operator=(AudioStream&& other) noexcept
2847 {
2848 swap(*this, other);
2849 return *this;
2850 }
2851};
2852
2883{
2884 AudioStreamRef m_lock;
2885
2886public:
2924
2926 AudioStreamLock(const AudioStreamLock& other) = delete;
2927
2930 : m_lock(std::move(other.m_lock))
2931 {
2932 }
2933
2947 {
2948 if (!m_lock) return;
2949 SDL_UnlockAudioStream(m_lock);
2950 }
2951
2952 AudioStreamLock& operator=(const AudioStreamLock& other) = delete;
2953
2956 {
2957 std::swap(m_lock, other.m_lock);
2958 return *this;
2959 }
2960
2962 constexpr operator bool() const { return bool(m_lock); }
2963
2978 void reset();
2979
2981 AudioStreamRef resource() const { return m_lock; }
2982
2984 void release() { m_lock.release(); }
2985};
2986
3008inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
3009
3032inline const char* GetAudioDriver(int index)
3033{
3034 return SDL_GetAudioDriver(index);
3035}
3036
3051inline const char* GetCurrentAudioDriver()
3052{
3053 return SDL_GetCurrentAudioDriver();
3054}
3055
3081{
3082 int count;
3083 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3084 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3085 size_t(count)};
3086}
3087
3113{
3114 int count;
3115 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3116 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3117 size_t(count)};
3118}
3119
3143inline const char* GetAudioDeviceName(AudioDeviceRef devid)
3144{
3145 return CheckError(SDL_GetAudioDeviceName(devid));
3146}
3147
3148inline const char* AudioDeviceBase::GetName() const
3149{
3150 return SDL::GetAudioDeviceName(get());
3151}
3152
3184 int* sample_frames = nullptr)
3185{
3186 AudioSpec spec;
3187 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3188 return spec;
3189}
3190
3191inline AudioSpec AudioDeviceBase::GetFormat(int* sample_frames) const
3192{
3193 return SDL::GetAudioDeviceFormat(get(), sample_frames);
3194}
3195
3216{
3217 int count;
3218 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3219 return OwnArray<int>{data, size_t(count)};
3220}
3221
3226
3299{
3300 return AudioDevice(devid, spec);
3301}
3302
3305 : AudioDevice(CheckError(SDL_OpenAudioDevice(devid, spec)))
3306{
3307}
3308
3333{
3334 return SDL_IsAudioDevicePhysical(devid);
3335}
3336
3338{
3340}
3341
3355{
3356 return SDL_IsAudioDevicePlayback(devid);
3357}
3358
3360{
3362}
3363
3393{
3394 CheckError(SDL_PauseAudioDevice(devid));
3395}
3396
3398
3424{
3425 CheckError(SDL_ResumeAudioDevice(devid));
3426}
3427
3429
3451{
3452 return SDL_AudioDevicePaused(devid);
3453}
3454
3455inline bool AudioDeviceBase::Paused() const
3456{
3457 return SDL::AudioDevicePaused(get());
3458}
3459
3482{
3483 return SDL_GetAudioDeviceGain(devid);
3484}
3485
3486inline float AudioDeviceBase::GetGain() const
3487{
3488 return SDL::GetAudioDeviceGain(get());
3489}
3490
3523inline void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
3524{
3525 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3526}
3527
3528inline void AudioDeviceBase::SetGain(float gain)
3529{
3531}
3532
3552{
3553 SDL_CloseAudioDevice(devid);
3554}
3555
3557
3595 std::span<AudioStreamRef> streams)
3596{
3597 CheckError(SDL_BindAudioStreams(
3598 devid,
3599 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3600 narrowS32(streams.size())));
3601}
3602
3603inline void AudioDeviceBase::BindAudioStreams(std::span<AudioStreamRef> streams)
3604{
3605 SDL::BindAudioStreams(get(), streams);
3606}
3607
3627{
3628 CheckError(SDL_BindAudioStream(devid, stream));
3629}
3630
3632{
3633 SDL::BindAudioStream(get(), stream);
3634}
3635
3654inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3655{
3656 SDL_UnbindAudioStreams(
3657 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3658 narrowS32(streams.size()));
3659}
3660
3676{
3677 SDL_UnbindAudioStream(stream);
3678}
3679
3681
3701{
3702 return SDL_GetAudioStreamDevice(stream);
3703}
3704
3709
3739{
3740 return AudioStream(src_spec, dst_spec);
3741}
3742
3745 : AudioStream(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
3746{
3747}
3748
3751 AudioStreamCallback callback,
3752 void* userdata)
3753 : AudioStream(
3754 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
3755{
3756}
3757
3760 AudioStreamCB callback)
3761 : AudioStream(devid, spec)
3762{
3763 if (IsAudioDevicePlayback(devid)) {
3764 SetGetCallback(std::move(callback));
3765 } else {
3766 SetPutCallback(std::move(callback));
3767 }
3768}
3769
3792{
3793 return CheckError(SDL_GetAudioStreamProperties(stream));
3794}
3795
3800
3801#if SDL_VERSION_ATLEAST(3, 4, 0)
3802
3816
3817constexpr auto AUTO_CLEANUP_BOOLEAN =
3818 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3819
3820} // namespace prop::AudioStream
3821
3822#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3823
3840 AudioSpec* src_spec,
3841 AudioSpec* dst_spec)
3842{
3843 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3844}
3845
3847 AudioSpec* dst_spec) const
3848{
3849 SDL::GetAudioStreamFormat(get(), src_spec, dst_spec);
3850}
3851
3892{
3893 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3894}
3895
3898{
3899 SDL::SetAudioStreamFormat(get(), src_spec, dst_spec);
3900}
3901
3917{
3918 return SDL_GetAudioStreamFrequencyRatio(stream);
3919}
3920
3922{
3924}
3925
3951inline void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
3952{
3953 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3954}
3955
3957{
3959}
3960
3981{
3982 return SDL_GetAudioStreamGain(stream);
3983}
3984
3985inline float AudioStreamBase::GetGain() const
3986{
3987 return SDL::GetAudioStreamGain(get());
3988}
3989
4012inline void SetAudioStreamGain(AudioStreamRef stream, float gain)
4013{
4014 CheckError(SDL_SetAudioStreamGain(stream, gain));
4015}
4016
4017inline void AudioStreamBase::SetGain(float gain)
4018{
4020}
4021
4043{
4044 int count;
4045 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4046 if (!data) return {};
4047 return OwnArray<int>{data, size_t(count)};
4048}
4049
4054
4076{
4077 int count;
4078 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4079 if (!data) return {};
4080 return OwnArray<int>{data, size_t(count)};
4081}
4082
4087
4145 std::span<int> chmap)
4146{
4147 CheckError(SDL_SetAudioStreamInputChannelMap(
4148 stream, chmap.data(), narrowS32(chmap.size())));
4149}
4150
4151inline void AudioStreamBase::SetInputChannelMap(std::span<int> chmap)
4152{
4154}
4155
4211 std::span<int> chmap)
4212{
4213 CheckError(SDL_SetAudioStreamOutputChannelMap(
4214 stream, chmap.data(), narrowS32(chmap.size())));
4215}
4216
4217inline void AudioStreamBase::SetOutputChannelMap(std::span<int> chmap)
4218{
4220}
4221
4249{
4250 CheckError(
4251 SDL_PutAudioStreamData(stream, buf.data(), narrowS32(buf.size_bytes())));
4252}
4253
4255{
4256 SDL::PutAudioStreamData(get(), std::move(buf));
4257}
4258
4259#if SDL_VERSION_ATLEAST(3, 4, 0)
4260
4305 SourceBytes buf,
4307 void* userdata)
4308{
4309 CheckError(SDL_PutAudioStreamDataNoCopy(
4310 stream, buf.data(), narrowS32(buf.size_bytes()), callback, userdata));
4311}
4312
4355 SourceBytes buf,
4357{
4360 std::move(buf),
4361 &Wrapper::CallOnce,
4362 Wrapper::Wrap(std::move(callback)));
4363}
4364
4366 SourceBytes buf,
4368 void* userdata)
4369{
4370 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), callback, userdata);
4371}
4372
4375{
4376 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), std::move(callback));
4377}
4378
4428 const void* const* channel_buffers,
4429 int num_channels,
4430 int num_samples)
4431{
4432 CheckError(SDL_PutAudioStreamPlanarData(
4433 stream, channel_buffers, num_channels, num_samples));
4434}
4435
4436inline void AudioStreamBase::PutPlanarData(const void* const* channel_buffers,
4437 int num_channels,
4438 int num_samples)
4439{
4441 get(), channel_buffers, num_channels, num_samples);
4442}
4443
4444#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4445
4474{
4475 return SDL_GetAudioStreamData(
4476 stream, buf.data(), narrowS32(buf.size_bytes()));
4477}
4478
4480{
4481 return SDL::GetAudioStreamData(get(), std::move(buf));
4482}
4483
4508{
4509 return SDL_GetAudioStreamAvailable(stream);
4510}
4511
4513{
4515}
4516
4553{
4554 return SDL_GetAudioStreamQueued(stream);
4555}
4556
4558{
4560}
4561
4580{
4581 CheckError(SDL_FlushAudioStream(stream));
4582}
4583
4585
4605{
4606 CheckError(SDL_ClearAudioStream(stream));
4607}
4608
4610
4633{
4634 CheckError(SDL_PauseAudioStreamDevice(stream));
4635}
4636
4641
4663{
4664 CheckError(SDL_ResumeAudioStreamDevice(stream));
4665}
4666
4671
4690{
4691 return SDL_AudioStreamDevicePaused(stream);
4692}
4693
4695{
4697}
4698
4735{
4736 CheckError(SDL_LockAudioStream(stream));
4737}
4738
4740{
4741 return {AudioStreamRef(*this)};
4742}
4743
4745 : m_lock(std::move(resource))
4746{
4747 LockAudioStream(m_lock);
4748}
4749
4766{
4767 CheckError(SDL_UnlockAudioStream(stream));
4768}
4769
4771{
4772 SDL_assert_paranoid(lock.resource() == *this);
4773 std::move(lock).reset();
4774}
4775
4777{
4778 if (!m_lock) return;
4779 UnlockAudioStream(m_lock);
4780 m_lock = {};
4781}
4782
4825 AudioStreamCallback callback,
4826 void* userdata)
4827{
4828 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4829}
4830
4871 AudioStreamCB callback)
4872{
4873 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4874}
4875
4877 void* userdata)
4878{
4879 SDL::SetAudioStreamGetCallback(get(), callback, userdata);
4880}
4881
4883{
4885}
4886
4933 AudioStreamCallback callback,
4934 void* userdata)
4935{
4936 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4937}
4938
4983 AudioStreamCB callback)
4984{
4985 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
4986}
4987
4989 void* userdata)
4990{
4991 SDL::SetAudioStreamPutCallback(get(), callback, userdata);
4992}
4993
4995{
4997}
4998
5018{
5019 SDL_DestroyAudioStream(stream);
5020}
5021
5023
5083 AudioStreamCallback callback = nullptr,
5084 void* userdata = nullptr)
5085{
5086 return AudioStream(devid, spec, callback, userdata);
5087}
5088
5144 AudioStreamCB callback)
5145{
5146 return AudioStream(devid, spec, callback);
5147}
5148
5151 AudioStreamCallback callback,
5152 void* userdata)
5153{
5154 return AudioStream(get(), spec, callback, userdata);
5155}
5156
5159 AudioStreamCB callback)
5160{
5161 return SDL::OpenAudioDeviceStream(get(), spec, callback);
5162}
5163
5216 AudioPostmixCallback callback,
5217 void* userdata)
5218{
5219 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5220}
5221
5273 AudioPostmixCB callback)
5274{
5275 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5276}
5277
5279 void* userdata)
5280{
5281 SDL::SetAudioPostmixCallback(get(), callback, userdata);
5282}
5283
5285{
5286 SDL::SetAudioPostmixCallback(get(), callback);
5287}
5288
5360{
5361 Uint8* buf;
5362 Uint32 len;
5363 if (!SDL_LoadWAV_IO(src.stream, src.closeio, spec, &buf, &len)) return {};
5364 return OwnArray<Uint8>{buf, size_t(len)};
5365}
5366
5397{
5398 Uint8* buf;
5399 Uint32 len;
5400 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5401 return OwnArray<Uint8>{buf, size_t(len)};
5402}
5403
5435inline void MixAudio(Uint8* dst,
5436 SourceBytes src,
5437 AudioFormat format,
5438 float volume)
5439{
5440 CheckError(SDL_MixAudio(
5441 dst, src.data_as<Uint8>(), format, narrowS32(src.size_bytes()), volume));
5442}
5443
5475inline void MixAudio(TargetBytes dst,
5476 SourceBytes src,
5477 AudioFormat format,
5478 float volume)
5479{
5480 if (dst.size_bytes() < src.size_bytes()) {
5481 MixAudio(dst.data_as<Uint8>(),
5482 SourceBytes{src.data(), dst.size_bytes()},
5483 format,
5484 volume);
5485 } else
5486 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5487}
5488
5512 SourceBytes src_data,
5513 const AudioSpec& dst_spec)
5514{
5515 Uint8* buf;
5516 int len;
5517 CheckError(SDL_ConvertAudioSamples(&src_spec,
5518 src_data.data_as<Uint8>(),
5519 narrowS32(src_data.size_bytes()),
5520 &dst_spec,
5521 &buf,
5522 &len));
5523 return OwnArray<Uint8>{buf, size_t(len)};
5524}
5525
5537inline const char* GetAudioFormatName(AudioFormatRaw format)
5538{
5539 return SDL_GetAudioFormatName(format);
5540}
5541
5542inline const char* AudioFormat::GetName() const
5543{
5544 return SDL::GetAudioFormatName(m_audioFormat);
5545}
5546
5561{
5562 return SDL_GetSilenceValueForFormat(format);
5563}
5564
5566{
5567 return SDL::GetSilenceValueForFormat(m_audioFormat);
5568}
5569
5571
5572} // namespace SDL
5573
5574#endif /* SDL3PP_AUDIO_H_ */
Audio format.
Definition SDL3pp_audio.h:218
constexpr AudioFormat(AudioFormatRaw audioFormat={}) noexcept
Wraps AudioFormat.
Definition SDL3pp_audio.h:227
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:2883
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2955
void release()
Releases the lock without unlocking.
Definition SDL3pp_audio.h:2984
AudioStreamRef resource() const
Get the reference to locked resource.
Definition SDL3pp_audio.h:2981
AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2929
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:2946
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Source byte stream.
Definition SDL3pp_strings.h:246
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:310
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:313
constexpr const T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:320
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
Target byte stream.
Definition SDL3pp_strings.h:332
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:418
constexpr T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:422
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:415
#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:524
void SetAudioStreamInputChannelMap(AudioStreamRef stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4144
void PutAudioStreamData(AudioStreamRef stream, SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4248
constexpr AudioFormat AUDIO_UNKNOWN
Unspecified audio format.
Definition SDL3pp_audio.h:402
void SetAudioStreamOutputChannelMap(AudioStreamRef stream, std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4210
constexpr bool IsLittleEndian() const
Determine if an AudioFormat represents littleendian data.
Definition SDL3pp_audio.h:570
constexpr bool IsBigEndian() const
Determine if an AudioFormat represents bigendian data.
Definition SDL3pp_audio.h:548
constexpr bool IsAudioInt(AudioFormatRaw x)
Determine if an AudioFormat represents integer data.
Definition SDL3pp_audio.h:606
bool IsAudioDevicePlayback(AudioDeviceRef devid)
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3354
bool AudioDevicePaused(AudioDeviceRef devid)
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3450
void BindAudioStreams(AudioDeviceRef devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3594
AudioDevice OpenAudioDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition SDL3pp_audio.h:3297
constexpr Uint32 AUDIO_MASK_SIGNED
Mask of bits in an AudioFormat that contain the signed data flag.
Definition SDL3pp_audio.h:192
constexpr Uint32 AUDIO_MASK_BITSIZE
Mask of bits in an AudioFormat that contains the format bit size.
Definition SDL3pp_audio.h:164
void BindAudioStream(AudioDeviceRef devid, AudioStreamRef stream)
Bind a single audio stream to an audio device.
Definition SDL3pp_audio.h:3626
void PutData(SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4254
constexpr AudioFormat AUDIO_S8
Signed 8-bit samples.
Definition SDL3pp_audio.h:407
constexpr Uint32 AUDIO_MASK_FLOAT
Mask of bits in an AudioFormat that contain the floating point flag.
Definition SDL3pp_audio.h:173
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:5511
float GetGain() const
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3985
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:670
AudioStreamLock(AudioStreamRef resource)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4744
void GetAudioStreamFormat(AudioStreamRef stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3839
constexpr bool IsAudioUnsigned(AudioFormatRaw x)
Determine if an AudioFormat represents unsigned data.
Definition SDL3pp_audio.h:625
int GetSilenceValueForFormat(AudioFormatRaw format)
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5560
void Pause()
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3397
constexpr AudioFormat AUDIO_S16
AUDIO_S16.
Definition SDL3pp_audio.h:425
int GetData(TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4479
bool IsAudioDevicePhysical(AudioDeviceRef devid)
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3332
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition SDL3pp_audio.h:419
OwnArray< Uint8 > LoadWAV_IO(IOStreamParam src, AudioSpec *spec)
Load the audio data of a WAVE file into memory.
Definition SDL3pp_audio.h:5359
std::function< void(const void *buf, int buflen)> AudioStreamDataCompleteCB
A callback that fires for completed PutAudioStreamDataNoCopy() data.
Definition SDL3pp_audio.h:1563
void Clear()
Clear any pending data in the stream.
Definition SDL3pp_audio.h:4609
constexpr Uint16 GetByteSize() const
Retrieve the size, in bytes, from an AudioFormat.
Definition SDL3pp_audio.h:507
void PauseAudioStreamDevice(AudioStreamRef stream)
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4632
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition SDL3pp_audio.h:3051
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3603
float GetAudioDeviceGain(AudioDeviceRef devid)
Get the gain of an audio device.
Definition SDL3pp_audio.h:3481
float GetAudioStreamGain(AudioStreamRef stream)
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3980
constexpr bool IsAudioSigned(AudioFormatRaw x)
Determine if an AudioFormat represents signed data.
Definition SDL3pp_audio.h:587
void ResumeAudioStreamDevice(AudioStreamRef stream)
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4662
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:3889
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5537
const char * GetAudioDeviceName(AudioDeviceRef devid)
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3143
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4151
void UnlockAudioStream(AudioStreamRef stream)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4765
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:4604
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3222
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition SDL3pp_audio.h:5149
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3705
constexpr AudioFormat AUDIO_U8
Unsigned 8-bit samples.
Definition SDL3pp_audio.h:405
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:3896
int GetQueued() const
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4557
constexpr Uint16 AudioBitSize(AudioFormatRaw x)
Retrieve the size, in bits, from an AudioFormat.
Definition SDL3pp_audio.h:483
constexpr AudioFormat AUDIO_S32
AUDIO_S32.
Definition SDL3pp_audio.h:427
OwnArray< int > GetInputChannelMap() const
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4050
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3148
void Close()
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3556
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5565
constexpr bool IsAudioLittleEndian(AudioFormatRaw x)
Determine if an AudioFormat represents littleendian data.
Definition SDL3pp_audio.h:565
constexpr AudioFormat AUDIO_S16LE
Signed 16-bit samples.
Definition SDL3pp_audio.h:409
void SetGain(float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:4017
constexpr Uint32 AUDIO_MASK_BIG_ENDIAN
Mask of bits in an AudioFormat that contain the bigendian flag.
Definition SDL3pp_audio.h:183
float GetAudioStreamFrequencyRatio(AudioStreamRef stream)
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3916
void SetAudioStreamGain(AudioStreamRef stream, float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:4012
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:4579
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:4427
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:753
void BindAudioStream(AudioStreamRef stream)
Bind a single audio stream to an audio device.
Definition SDL3pp_audio.h:3631
PropertiesRef GetAudioStreamProperties(AudioStreamRef stream)
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3791
void UnbindAudioStream(AudioStreamRef stream)
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3675
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition SDL3pp_audio.h:3112
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3846
void SetGain(float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3528
void PauseAudioDevice(AudioDeviceRef devid)
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3392
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:709
void reset()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4776
SDL_AudioSpec AudioSpec
Format specifier for audio data.
Definition SDL3pp_audio.h:201
constexpr AudioFormat AUDIO_S32BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:416
void SetGetCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is requested from an audio stream.
Definition SDL3pp_audio.h:4876
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4584
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition SDL3pp_audio.h:3032
bool Paused() const
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3455
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:5215
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition SDL3pp_audio.h:1482
void Resume()
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3428
constexpr AudioFormat DefineAudioFormat(bool sign, bool bigendian, bool flt, Uint16 size)
Define an AudioFormat value.
Definition SDL3pp_audio.h:454
AudioDeviceRef GetAudioStreamDevice(AudioStreamRef stream)
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3700
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition SDL3pp_audio.h:1470
constexpr AudioFormat AUDIO_S32LE
32-bit integer samples
Definition SDL3pp_audio.h:414
void PutDataNoCopy(SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4365
constexpr bool IsInt() const
Determine if an AudioFormat represents integer data.
Definition SDL3pp_audio.h:608
int GetAudioStreamQueued(AudioStreamRef stream)
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4552
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition SDL3pp_audio.h:5435
AudioSpec GetAudioDeviceFormat(AudioDeviceRef devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3183
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed PutAudioStreamDataNoCopy() data.
Definition SDL3pp_audio.h:1533
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4083
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition SDL3pp_audio.h:3737
OwnArray< Uint8 > LoadWAV(StringParam path, AudioSpec *spec)
Loads a WAV from a file path.
Definition SDL3pp_audio.h:5396
constexpr bool IsFloat() const
Determine if an AudioFormat represents floating point data.
Definition SDL3pp_audio.h:526
PropertiesRef GetProperties() const
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3796
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3921
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:5278
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3956
void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3523
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3359
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:4932
constexpr AudioFormat AUDIO_F32BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:422
constexpr AudioFormat AUDIO_F32
AUDIO_F32.
Definition SDL3pp_audio.h:429
int GetNumAudioDrivers()
Use this function to get the number of built-in audio drivers.
Definition SDL3pp_audio.h:3008
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3337
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition SDL3pp_audio.h:3654
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:5081
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:4436
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceRef devid)
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3215
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:4988
ResourceRefT< AudioStreamBase > AudioStreamRef
Reference for AudioStream.
Definition SDL3pp_audio.h:152
void ResumeDevice()
Use this function to unpause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4667
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4217
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition SDL3pp_audio.h:5017
constexpr bool IsSigned() const
Determine if an AudioFormat represents signed data.
Definition SDL3pp_audio.h:589
SDL_AudioDeviceID AudioDeviceID
Alias to raw representation for AudioDevice.
Definition SDL3pp_audio.h:129
constexpr bool IsAudioBigENDIAN(AudioFormatRaw x)
Determine if an AudioFormat represents bigendian data.
Definition SDL3pp_audio.h:543
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:799
void Unbind()
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3680
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4694
constexpr AudioFormat AUDIO_S16BE
As above, but big-endian byte order.
Definition SDL3pp_audio.h:411
OwnArray< int > GetAudioStreamOutputChannelMap(AudioStreamRef stream)
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4075
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition SDL3pp_audio.h:3080
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamRef stream)
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4042
ResourceRefT< AudioDeviceBase > AudioDeviceRef
Reference for AudioDevice.
Definition SDL3pp_audio.h:136
int GetAudioStreamAvailable(AudioStreamRef stream)
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4507
void Destroy()
Free an audio stream.
Definition SDL3pp_audio.h:5022
constexpr Uint16 AudioByteSize(AudioFormatRaw x)
Retrieve the size, in bytes, from an AudioFormat.
Definition SDL3pp_audio.h:502
SDL_AudioStream * AudioStreamRaw
Alias to raw representation for AudioStream.
Definition SDL3pp_audio.h:145
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:4824
bool AudioStreamDevicePaused(AudioStreamRef stream)
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4689
void ResumeAudioDevice(AudioDeviceRef devid)
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3423
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4739
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4770
void PutAudioStreamDataNoCopy(AudioStreamRef stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4304
float GetGain() const
Get the gain of an audio device.
Definition SDL3pp_audio.h:3486
const char * GetName() const
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5542
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3191
void LockAudioStream(AudioStreamRef stream)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4734
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4512
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3551
void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3951
constexpr Uint16 GetBitSize() const
Retrieve the size, in bits, from an AudioFormat.
Definition SDL3pp_audio.h:485
void PauseDevice()
Use this function to pause audio playback on the audio device associated with an audio stream.
Definition SDL3pp_audio.h:4637
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition SDL3pp_audio.h:1500
int GetAudioStreamData(AudioStreamRef stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4473
constexpr bool IsUnsigned() const
Determine if an AudioFormat represents unsigned data.
Definition SDL3pp_audio.h:630
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:56
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:270
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
Properties for AudioStream.
Definition SDL3pp_audio.h:3815
constexpr auto AUTO_CLEANUP_BOOLEAN
Auto cleanup enabled.
Definition SDL3pp_audio.h:3817
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6262
Base class to AudioDevice.
Definition SDL3pp_audio.h:808
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
SDL Audio Device instance IDs.
Definition SDL3pp_audio.h:1356
~AudioDevice()
Destructor.
Definition SDL3pp_audio.h:1451
constexpr AudioDevice(AudioDeviceID resource) noexcept
Constructs from raw AudioDevice.
Definition SDL3pp_audio.h:1366
constexpr AudioDevice & operator=(AudioDevice &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:1454
constexpr AudioDevice(AudioDevice &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:1372
Base class to AudioStream.
Definition SDL3pp_audio.h:1574
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition SDL3pp_audio.h:1652
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition SDL3pp_audio.h:1737
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition SDL3pp_audio.h:1705
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition SDL3pp_audio.h:1632
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The opaque handle that represents an audio stream.
Definition SDL3pp_audio.h:2672
~AudioStream()
Destructor.
Definition SDL3pp_audio.h:2843
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2688
constexpr AudioStream(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:2682
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2846
Definition SDL3pp_callbackWrapper.h:20
Wrapper to be used as parameter to LoadFile_IO() and SaveFile_IO() and similar.
Definition SDL3pp_iostream.h:2243
IOStreamRef stream
The IOStream to read from or write to.
Definition SDL3pp_iostream.h:2244
bool closeio
Whether to close the IOStream after the operation.
Definition SDL3pp_iostream.h:2245
Definition SDL3pp_callbackWrapper.h:169
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93