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
1498constexpr int AudioFrameSize(const AudioSpec& x)
1499{
1500 return SDL_AUDIO_FRAMESIZE(x);
1501}
1502
1503#if SDL_VERSION_ATLEAST(3, 4, 0)
1504
1531using AudioStreamDataCompleteCallback = void(SDLCALL*)(void* userdata,
1532 const void* buf,
1533 int buflen);
1534
1562 std::function<void(const void* buf, int buflen)>;
1563
1564#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1565
1571struct AudioStreamBase : ResourceBaseT<AudioStreamRaw>
1572{
1574
1592 void Destroy();
1593
1616
1631 {
1632 AudioSpec spec;
1633 GetFormat(&spec, nullptr);
1634 return spec;
1635 }
1636
1651 {
1652 AudioSpec spec;
1653 GetFormat(nullptr, &spec);
1654 return spec;
1655 }
1656
1671 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
1672
1703 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
1704
1735 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
1736
1775
1789 float GetFrequencyRatio() const;
1790
1815 void SetFrequencyRatio(float ratio);
1816
1835 float GetGain() const;
1836
1858 void SetGain(float gain);
1859
1880
1901
1957 void SetInputChannelMap(std::span<int> chmap);
1958
2012 void SetOutputChannelMap(std::span<int> chmap);
2013
2039 void PutData(SourceBytes buf);
2040
2041#if SDL_VERSION_ATLEAST(3, 4, 0)
2042
2085 void PutDataNoCopy(SourceBytes buf,
2087 void* userdata);
2088
2130
2131#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2132
2159 int GetData(TargetBytes buf);
2160
2184 int GetAvailable() const;
2185
2221 int GetQueued() const;
2222
2239 void Flush();
2240
2258 void Clear();
2259
2280 void PauseDevice();
2281
2301 void ResumeDevice();
2302
2319 bool DevicePaused() const;
2320
2346
2361 void Unlock(AudioStreamLock&& lock);
2362
2405 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2406
2447 void SetGetCallback(AudioStreamCB callback);
2448
2494 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2495
2539 void SetPutCallback(AudioStreamCB callback);
2540
2553 void Unbind();
2554
2573 AudioDeviceRef GetDevice() const;
2574
2575#if SDL_VERSION_ATLEAST(3, 4, 0)
2576
2625 void PutPlanarData(const void* const* channel_buffers,
2626 int num_channels,
2627 int num_samples);
2628
2629#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2630};
2631
2660{
2661 using AudioStreamBase::AudioStreamBase;
2662
2670 constexpr explicit AudioStream(AudioStreamRaw resource) noexcept
2671 : AudioStreamBase(resource)
2672 {
2673 }
2674
2676 constexpr AudioStream(AudioStream&& other) noexcept
2677 : AudioStream(other.release())
2678 {
2679 }
2680
2710
2769 OptionalRef<const AudioSpec> spec = std::nullopt,
2770 AudioStreamCallback callback = nullptr,
2771 void* userdata = nullptr);
2772
2828 AudioStreamCB callback);
2829
2831 ~AudioStream() { SDL_DestroyAudioStream(get()); }
2832
2834 constexpr AudioStream& operator=(AudioStream&& other) noexcept
2835 {
2836 swap(*this, other);
2837 return *this;
2838 }
2839};
2840
2860{
2861 AudioStreamRef m_lock;
2862
2863public:
2891
2893 AudioStreamLock(const AudioStreamLock& other) = delete;
2894
2897 : m_lock(std::move(other.m_lock))
2898 {
2899 }
2900
2914 {
2915 if (!m_lock) return;
2916 SDL_UnlockAudioStream(m_lock);
2917 }
2918
2919 AudioStreamLock& operator=(const AudioStreamLock& other) = delete;
2920
2923 {
2924 std::swap(m_lock, other.m_lock);
2925 return *this;
2926 }
2927
2929 constexpr operator bool() const { return bool(m_lock); }
2930
2945 void reset();
2946
2948 AudioStreamRef resource() const { return m_lock; }
2949
2951 void release() { m_lock.release(); }
2952};
2953
2975inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
2976
2999inline const char* GetAudioDriver(int index)
3000{
3001 return SDL_GetAudioDriver(index);
3002}
3003
3018inline const char* GetCurrentAudioDriver()
3019{
3020 return SDL_GetCurrentAudioDriver();
3021}
3022
3048{
3049 int count;
3050 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3051 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3052 size_t(count)};
3053}
3054
3080{
3081 int count;
3082 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3083 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3084 size_t(count)};
3085}
3086
3110inline const char* GetAudioDeviceName(AudioDeviceRef devid)
3111{
3112 return CheckError(SDL_GetAudioDeviceName(devid));
3113}
3114
3115inline const char* AudioDeviceBase::GetName() const
3116{
3117 return SDL::GetAudioDeviceName(get());
3118}
3119
3151 int* sample_frames = nullptr)
3152{
3153 AudioSpec spec;
3154 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3155 return spec;
3156}
3157
3158inline AudioSpec AudioDeviceBase::GetFormat(int* sample_frames) const
3159{
3160 return SDL::GetAudioDeviceFormat(get(), sample_frames);
3161}
3162
3183{
3184 int count;
3185 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3186 return OwnArray<int>{data, size_t(count)};
3187}
3188
3193
3266{
3267 return AudioDevice(devid, spec);
3268}
3269
3272 : AudioDevice(CheckError(SDL_OpenAudioDevice(devid, spec)))
3273{
3274}
3275
3300{
3301 return SDL_IsAudioDevicePhysical(devid);
3302}
3303
3305{
3307}
3308
3322{
3323 return SDL_IsAudioDevicePlayback(devid);
3324}
3325
3327{
3329}
3330
3360{
3361 CheckError(SDL_PauseAudioDevice(devid));
3362}
3363
3365
3391{
3392 CheckError(SDL_ResumeAudioDevice(devid));
3393}
3394
3396
3418{
3419 return SDL_AudioDevicePaused(devid);
3420}
3421
3422inline bool AudioDeviceBase::Paused() const
3423{
3424 return SDL::AudioDevicePaused(get());
3425}
3426
3449{
3450 return SDL_GetAudioDeviceGain(devid);
3451}
3452
3453inline float AudioDeviceBase::GetGain() const
3454{
3455 return SDL::GetAudioDeviceGain(get());
3456}
3457
3490inline void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
3491{
3492 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3493}
3494
3495inline void AudioDeviceBase::SetGain(float gain)
3496{
3498}
3499
3519{
3520 SDL_CloseAudioDevice(devid);
3521}
3522
3524
3562 std::span<AudioStreamRef> streams)
3563{
3564 CheckError(SDL_BindAudioStreams(
3565 devid,
3566 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3567 narrowS32(streams.size())));
3568}
3569
3570inline void AudioDeviceBase::BindAudioStreams(std::span<AudioStreamRef> streams)
3571{
3572 SDL::BindAudioStreams(get(), streams);
3573}
3574
3594{
3595 CheckError(SDL_BindAudioStream(devid, stream));
3596}
3597
3599{
3600 SDL::BindAudioStream(get(), stream);
3601}
3602
3621inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3622{
3623 SDL_UnbindAudioStreams(
3624 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3625 narrowS32(streams.size()));
3626}
3627
3643{
3644 SDL_UnbindAudioStream(stream);
3645}
3646
3648
3668{
3669 return SDL_GetAudioStreamDevice(stream);
3670}
3671
3676
3706{
3707 return AudioStream(src_spec, dst_spec);
3708}
3709
3712 : AudioStream(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
3713{
3714}
3715
3718 AudioStreamCallback callback,
3719 void* userdata)
3720 : AudioStream(
3721 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
3722{
3723}
3724
3727 AudioStreamCB callback)
3728 : AudioStream(devid, spec)
3729{
3730 if (IsAudioDevicePlayback(devid)) {
3731 SetGetCallback(std::move(callback));
3732 } else {
3733 SetPutCallback(std::move(callback));
3734 }
3735}
3736
3759{
3760 return CheckError(SDL_GetAudioStreamProperties(stream));
3761}
3762
3767
3768#if SDL_VERSION_ATLEAST(3, 4, 0)
3769
3783
3784constexpr auto AUTO_CLEANUP_BOOLEAN =
3785 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3786
3787} // namespace prop::AudioStream
3788
3789#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3790
3807 AudioSpec* src_spec,
3808 AudioSpec* dst_spec)
3809{
3810 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3811}
3812
3814 AudioSpec* dst_spec) const
3815{
3816 SDL::GetAudioStreamFormat(get(), src_spec, dst_spec);
3817}
3818
3859{
3860 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3861}
3862
3865{
3866 SDL::SetAudioStreamFormat(get(), src_spec, dst_spec);
3867}
3868
3884{
3885 return SDL_GetAudioStreamFrequencyRatio(stream);
3886}
3887
3889{
3891}
3892
3918inline void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
3919{
3920 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3921}
3922
3924{
3926}
3927
3948{
3949 return SDL_GetAudioStreamGain(stream);
3950}
3951
3952inline float AudioStreamBase::GetGain() const
3953{
3954 return SDL::GetAudioStreamGain(get());
3955}
3956
3979inline void SetAudioStreamGain(AudioStreamRef stream, float gain)
3980{
3981 CheckError(SDL_SetAudioStreamGain(stream, gain));
3982}
3983
3984inline void AudioStreamBase::SetGain(float gain)
3985{
3987}
3988
4010{
4011 int count;
4012 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4013 if (!data) return {};
4014 return OwnArray<int>{data, size_t(count)};
4015}
4016
4021
4043{
4044 int count;
4045 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4046 if (!data) return {};
4047 return OwnArray<int>{data, size_t(count)};
4048}
4049
4054
4112 std::span<int> chmap)
4113{
4114 CheckError(SDL_SetAudioStreamInputChannelMap(
4115 stream, chmap.data(), narrowS32(chmap.size())));
4116}
4117
4118inline void AudioStreamBase::SetInputChannelMap(std::span<int> chmap)
4119{
4121}
4122
4178 std::span<int> chmap)
4179{
4180 CheckError(SDL_SetAudioStreamOutputChannelMap(
4181 stream, chmap.data(), narrowS32(chmap.size())));
4182}
4183
4184inline void AudioStreamBase::SetOutputChannelMap(std::span<int> chmap)
4185{
4187}
4188
4216{
4217 CheckError(
4218 SDL_PutAudioStreamData(stream, buf.data(), narrowS32(buf.size_bytes())));
4219}
4220
4222{
4223 SDL::PutAudioStreamData(get(), std::move(buf));
4224}
4225
4226#if SDL_VERSION_ATLEAST(3, 4, 0)
4227
4272 SourceBytes buf,
4274 void* userdata)
4275{
4276 CheckError(SDL_PutAudioStreamDataNoCopy(
4277 stream, buf.data(), narrowS32(buf.size_bytes()), callback, userdata));
4278}
4279
4322 SourceBytes buf,
4324{
4327 std::move(buf),
4328 &Wrapper::CallOnce,
4329 Wrapper::Wrap(std::move(callback)));
4330}
4331
4333 SourceBytes buf,
4335 void* userdata)
4336{
4337 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), callback, userdata);
4338}
4339
4342{
4343 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), std::move(callback));
4344}
4345
4395 const void* const* channel_buffers,
4396 int num_channels,
4397 int num_samples)
4398{
4399 CheckError(SDL_PutAudioStreamPlanarData(
4400 stream, channel_buffers, num_channels, num_samples));
4401}
4402
4403inline void AudioStreamBase::PutPlanarData(const void* const* channel_buffers,
4404 int num_channels,
4405 int num_samples)
4406{
4408 get(), channel_buffers, num_channels, num_samples);
4409}
4410
4411#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4412
4441{
4442 return SDL_GetAudioStreamData(
4443 stream, buf.data(), narrowS32(buf.size_bytes()));
4444}
4445
4447{
4448 return SDL::GetAudioStreamData(get(), std::move(buf));
4449}
4450
4475{
4476 return SDL_GetAudioStreamAvailable(stream);
4477}
4478
4480{
4482}
4483
4520{
4521 return SDL_GetAudioStreamQueued(stream);
4522}
4523
4525{
4527}
4528
4547{
4548 CheckError(SDL_FlushAudioStream(stream));
4549}
4550
4552
4572{
4573 CheckError(SDL_ClearAudioStream(stream));
4574}
4575
4577
4600{
4601 CheckError(SDL_PauseAudioStreamDevice(stream));
4602}
4603
4608
4630{
4631 CheckError(SDL_ResumeAudioStreamDevice(stream));
4632}
4633
4638
4657{
4658 return SDL_AudioStreamDevicePaused(stream);
4659}
4660
4662{
4664}
4665
4692{
4693 CheckError(SDL_LockAudioStream(stream));
4694}
4695
4697{
4698 return {AudioStreamRef(*this)};
4699}
4700
4702 : m_lock(std::move(resource))
4703{
4704 LockAudioStream(m_lock);
4705}
4706
4723{
4724 CheckError(SDL_UnlockAudioStream(stream));
4725}
4726
4728{
4729 SDL_assert_paranoid(lock.resource() == *this);
4730 std::move(lock).reset();
4731}
4732
4734{
4735 if (!m_lock) return;
4736 UnlockAudioStream(m_lock);
4737 m_lock = {};
4738}
4739
4782 AudioStreamCallback callback,
4783 void* userdata)
4784{
4785 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4786}
4787
4828 AudioStreamCB callback)
4829{
4830 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4831}
4832
4834 void* userdata)
4835{
4836 SDL::SetAudioStreamGetCallback(get(), callback, userdata);
4837}
4838
4840{
4842}
4843
4890 AudioStreamCallback callback,
4891 void* userdata)
4892{
4893 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4894}
4895
4940 AudioStreamCB callback)
4941{
4942 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
4943}
4944
4946 void* userdata)
4947{
4948 SDL::SetAudioStreamPutCallback(get(), callback, userdata);
4949}
4950
4952{
4954}
4955
4975{
4976 SDL_DestroyAudioStream(stream);
4977}
4978
4980
5040 AudioStreamCallback callback = nullptr,
5041 void* userdata = nullptr)
5042{
5043 return AudioStream(devid, spec, callback, userdata);
5044}
5045
5101 AudioStreamCB callback)
5102{
5103 return AudioStream(devid, spec, callback);
5104}
5105
5108 AudioStreamCallback callback,
5109 void* userdata)
5110{
5111 return AudioStream(get(), spec, callback, userdata);
5112}
5113
5116 AudioStreamCB callback)
5117{
5118 return SDL::OpenAudioDeviceStream(get(), spec, callback);
5119}
5120
5173 AudioPostmixCallback callback,
5174 void* userdata)
5175{
5176 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5177}
5178
5230 AudioPostmixCB callback)
5231{
5232 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5233}
5234
5236 void* userdata)
5237{
5238 SDL::SetAudioPostmixCallback(get(), callback, userdata);
5239}
5240
5242{
5243 SDL::SetAudioPostmixCallback(get(), callback);
5244}
5245
5314 AudioSpec* spec,
5315 bool closeio = false)
5316{
5317 Uint8* buf;
5318 Uint32 len;
5319 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
5320 return OwnArray<Uint8>{buf, size_t(len)};
5321}
5322
5348{
5349 Uint8* buf;
5350 Uint32 len;
5351 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5352 return OwnArray<Uint8>{buf, size_t(len)};
5353}
5354
5386inline void MixAudio(Uint8* dst,
5387 SourceBytes src,
5388 AudioFormat format,
5389 float volume)
5390{
5391 CheckError(SDL_MixAudio(
5392 dst, src.data_as<Uint8>(), format, narrowS32(src.size_bytes()), volume));
5393}
5394
5426inline void MixAudio(TargetBytes dst,
5427 SourceBytes src,
5428 AudioFormat format,
5429 float volume)
5430{
5431 if (dst.size_bytes() < src.size_bytes()) {
5432 MixAudio(dst.data_as<Uint8>(),
5433 SourceBytes{src.data(), dst.size_bytes()},
5434 format,
5435 volume);
5436 } else
5437 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5438}
5439
5463 SourceBytes src_data,
5464 const AudioSpec& dst_spec)
5465{
5466 Uint8* buf;
5467 int len;
5468 CheckError(SDL_ConvertAudioSamples(&src_spec,
5469 src_data.data_as<Uint8>(),
5470 narrowS32(src_data.size_bytes()),
5471 &dst_spec,
5472 &buf,
5473 &len));
5474 return OwnArray<Uint8>{buf, size_t(len)};
5475}
5476
5488inline const char* GetAudioFormatName(AudioFormatRaw format)
5489{
5490 return SDL_GetAudioFormatName(format);
5491}
5492
5493inline const char* AudioFormat::GetName() const
5494{
5495 return SDL::GetAudioFormatName(m_audioFormat);
5496}
5497
5512{
5513 return SDL_GetSilenceValueForFormat(format);
5514}
5515
5517{
5518 return SDL::GetSilenceValueForFormat(m_audioFormat);
5519}
5520
5522
5523} // namespace SDL
5524
5525#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:2860
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2922
void release()
Releases the lock without unlocking.
Definition SDL3pp_audio.h:2951
AudioStreamRef resource() const
Get the reference to locked resource.
Definition SDL3pp_audio.h:2948
AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2896
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:2913
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:4111
void PutAudioStreamData(AudioStreamRef stream, SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4215
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:4177
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:3321
bool AudioDevicePaused(AudioDeviceRef devid)
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3417
void BindAudioStreams(AudioDeviceRef devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3561
AudioDevice OpenAudioDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition SDL3pp_audio.h:3264
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:3593
void PutData(SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4221
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:5462
float GetGain() const
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3952
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:4701
void GetAudioStreamFormat(AudioStreamRef stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3806
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:5511
void Pause()
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3364
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:4446
bool IsAudioDevicePhysical(AudioDeviceRef devid)
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3299
constexpr AudioFormat AUDIO_F32LE
32-bit floating point samples
Definition SDL3pp_audio.h:419
std::function< void(const void *buf, int buflen)> AudioStreamDataCompleteCB
A callback that fires for completed PutAudioStreamDataNoCopy() data.
Definition SDL3pp_audio.h:1561
void Clear()
Clear any pending data in the stream.
Definition SDL3pp_audio.h:4576
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:4599
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition SDL3pp_audio.h:3018
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3570
float GetAudioDeviceGain(AudioDeviceRef devid)
Get the gain of an audio device.
Definition SDL3pp_audio.h:3448
float GetAudioStreamGain(AudioStreamRef stream)
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3947
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:4629
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:3856
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5488
const char * GetAudioDeviceName(AudioDeviceRef devid)
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3110
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4118
void UnlockAudioStream(AudioStreamRef stream)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4722
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:4571
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3189
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition SDL3pp_audio.h:5106
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3672
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:3863
int GetQueued() const
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4524
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:4017
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3115
void Close()
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3523
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5516
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:3984
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:3883
void SetAudioStreamGain(AudioStreamRef stream, float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:3979
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:4546
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:4394
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:3598
PropertiesRef GetAudioStreamProperties(AudioStreamRef stream)
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3758
void UnbindAudioStream(AudioStreamRef stream)
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3642
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition SDL3pp_audio.h:3079
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3813
void SetGain(float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3495
void PauseAudioDevice(AudioDeviceRef devid)
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3359
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:4733
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:4833
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4551
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition SDL3pp_audio.h:2999
bool Paused() const
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3422
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:5172
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:3395
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:3667
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:5313
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:4332
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:4519
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition SDL3pp_audio.h:5386
AudioSpec GetAudioDeviceFormat(AudioDeviceRef devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3150
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed PutAudioStreamDataNoCopy() data.
Definition SDL3pp_audio.h:1531
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4050
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition SDL3pp_audio.h:3704
OwnArray< Uint8 > LoadWAV(StringParam path, AudioSpec *spec)
Loads a WAV from a file path.
Definition SDL3pp_audio.h:5347
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:3763
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3888
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:5235
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3923
void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3490
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3326
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:4889
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:2975
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3304
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition SDL3pp_audio.h:3621
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:5038
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:4403
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceRef devid)
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3182
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:4945
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:4634
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4184
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition SDL3pp_audio.h:4974
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:3647
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4661
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:4042
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition SDL3pp_audio.h:3047
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamRef stream)
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4009
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:4474
void Destroy()
Free an audio stream.
Definition SDL3pp_audio.h:4979
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:4781
bool AudioStreamDevicePaused(AudioStreamRef stream)
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4656
void ResumeAudioDevice(AudioDeviceRef devid)
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3390
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4696
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4727
void PutAudioStreamDataNoCopy(AudioStreamRef stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4271
float GetGain() const
Get the gain of an audio device.
Definition SDL3pp_audio.h:3453
const char * GetName() const
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5493
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3158
void LockAudioStream(AudioStreamRef stream)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4691
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4479
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3518
void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3918
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:4604
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition SDL3pp_audio.h:1498
int GetAudioStreamData(AudioStreamRef stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4440
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< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:55
::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:3782
constexpr auto AUTO_CLEANUP_BOOLEAN
Auto cleanup enabled.
Definition SDL3pp_audio.h:3784
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:1572
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition SDL3pp_audio.h:1650
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition SDL3pp_audio.h:1735
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition SDL3pp_audio.h:1703
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition SDL3pp_audio.h:1630
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The opaque handle that represents an audio stream.
Definition SDL3pp_audio.h:2660
~AudioStream()
Destructor.
Definition SDL3pp_audio.h:2831
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2676
constexpr AudioStream(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:2670
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2834
Definition SDL3pp_callbackWrapper.h:20
Definition SDL3pp_callbackWrapper.h:169
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93