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
751using AudioStreamCallback = void(SDLCALL*)(void* userdata,
752 AudioStreamRaw stream,
753 int additional_amount,
754 int total_amount);
755
796 void(AudioStreamRaw stream, int additional_amount, int total_amount)>;
797
803struct AudioDeviceBase : ResourceBaseT<AudioDeviceID>
804{
806
823 void Close();
824
847 const char* GetName() const;
848
880 AudioSpec GetFormat(int* sample_frames = nullptr) const;
881
901
924 bool IsPhysical() const;
925
937 bool IsPlayback() const;
938
966 void Pause();
967
991 void Resume();
992
1012 bool Paused() const;
1013
1034 float GetGain() const;
1035
1067 void SetGain(float gain);
1068
1104 void BindAudioStreams(std::span<AudioStreamRef> streams);
1105
1123 void BindAudioStream(AudioStreamRef stream);
1124
1175 void SetPostmixCallback(AudioPostmixCallback callback, void* userdata);
1176
1226 void SetPostmixCallback(AudioPostmixCB callback);
1227
1284 AudioStreamCallback callback,
1285 void* userdata);
1286
1339 AudioStreamCB callback);
1340};
1341
1352{
1353 using AudioDeviceBase::AudioDeviceBase;
1354
1362 constexpr explicit AudioDevice(AudioDeviceID resource) noexcept
1363 : AudioDeviceBase(resource)
1364 {
1365 }
1366
1368 constexpr AudioDevice(AudioDevice&& other) noexcept
1369 : AudioDevice(other.release())
1370 {
1371 }
1372
1445
1447 ~AudioDevice() { SDL_CloseAudioDevice(get()); }
1448
1450 constexpr AudioDevice& operator=(AudioDevice&& other) noexcept
1451 {
1452 swap(*this, other);
1453 return *this;
1454 }
1455};
1456
1467 SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
1468
1479 SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
1480
1494constexpr int AudioFrameSize(const AudioSpec& x)
1495{
1496 return SDL_AUDIO_FRAMESIZE(x);
1497}
1498
1499#if SDL_VERSION_ATLEAST(3, 4, 0)
1500
1527using AudioStreamDataCompleteCallback = void(SDLCALL*)(void* userdata,
1528 const void* buf,
1529 int buflen);
1530
1558 std::function<void(const void* buf, int buflen)>;
1559
1560#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1561
1567struct AudioStreamBase : ResourceBaseT<AudioStreamRaw>
1568{
1570
1588 void Destroy();
1589
1612
1627 {
1628 AudioSpec spec;
1629 GetFormat(&spec, nullptr);
1630 return spec;
1631 }
1632
1647 {
1648 AudioSpec spec;
1649 GetFormat(nullptr, &spec);
1650 return spec;
1651 }
1652
1667 void GetFormat(AudioSpec* src_spec, AudioSpec* dst_spec) const;
1668
1699 void SetInputFormat(const AudioSpec& spec) { SetFormat(spec, std::nullopt); }
1700
1731 void SetOutputFormat(const AudioSpec& spec) { SetFormat(std::nullopt, spec); }
1732
1771
1785 float GetFrequencyRatio() const;
1786
1811 void SetFrequencyRatio(float ratio);
1812
1831 float GetGain() const;
1832
1854 void SetGain(float gain);
1855
1876
1897
1953 void SetInputChannelMap(std::span<int> chmap);
1954
2008 void SetOutputChannelMap(std::span<int> chmap);
2009
2035 void PutData(SourceBytes buf);
2036
2037#if SDL_VERSION_ATLEAST(3, 4, 0)
2038
2081 void PutDataNoCopy(SourceBytes buf,
2083 void* userdata);
2084
2126
2127#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2128
2155 int GetData(TargetBytes buf);
2156
2180 int GetAvailable() const;
2181
2217 int GetQueued() const;
2218
2235 void Flush();
2236
2254 void Clear();
2255
2276 void PauseDevice();
2277
2297 void ResumeDevice();
2298
2315 bool DevicePaused() const;
2316
2342
2357 void Unlock(AudioStreamLock&& lock);
2358
2401 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2402
2443 void SetGetCallback(AudioStreamCB callback);
2444
2490 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2491
2535 void SetPutCallback(AudioStreamCB callback);
2536
2549 void Unbind();
2550
2569 AudioDeviceRef GetDevice() const;
2570
2571#if SDL_VERSION_ATLEAST(3, 4, 0)
2572
2621 void PutPlanarData(const void* const* channel_buffers,
2622 int num_channels,
2623 int num_samples);
2624
2625#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2626};
2627
2656{
2657 using AudioStreamBase::AudioStreamBase;
2658
2666 constexpr explicit AudioStream(AudioStreamRaw resource) noexcept
2667 : AudioStreamBase(resource)
2668 {
2669 }
2670
2672 constexpr AudioStream(AudioStream&& other) noexcept
2673 : AudioStream(other.release())
2674 {
2675 }
2676
2706
2765 OptionalRef<const AudioSpec> spec = std::nullopt,
2766 AudioStreamCallback callback = nullptr,
2767 void* userdata = nullptr);
2768
2824 AudioStreamCB callback);
2825
2827 ~AudioStream() { SDL_DestroyAudioStream(get()); }
2828
2830 constexpr AudioStream& operator=(AudioStream&& other) noexcept
2831 {
2832 swap(*this, other);
2833 return *this;
2834 }
2835};
2836
2856{
2857 AudioStreamRef m_lock;
2858
2859public:
2887
2889 AudioStreamLock(const AudioStreamLock& other) = delete;
2890
2893 : m_lock(std::move(other.m_lock))
2894 {
2895 }
2896
2910 {
2911 if (!m_lock) return;
2912 SDL_UnlockAudioStream(m_lock);
2913 }
2914
2915 AudioStreamLock& operator=(const AudioStreamLock& other) = delete;
2916
2919 {
2920 std::swap(m_lock, other.m_lock);
2921 return *this;
2922 }
2923
2925 constexpr operator bool() const { return bool(m_lock); }
2926
2941 void reset();
2942
2944 AudioStreamRef resource() const { return m_lock; }
2945
2947 void release() { m_lock.release(); }
2948};
2949
2971inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
2972
2995inline const char* GetAudioDriver(int index)
2996{
2997 return SDL_GetAudioDriver(index);
2998}
2999
3014inline const char* GetCurrentAudioDriver()
3015{
3016 return SDL_GetCurrentAudioDriver();
3017}
3018
3044{
3045 int count;
3046 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3047 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3048 size_t(count)};
3049}
3050
3076{
3077 int count;
3078 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3079 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3080 size_t(count)};
3081}
3082
3106inline const char* GetAudioDeviceName(AudioDeviceRef devid)
3107{
3108 return CheckError(SDL_GetAudioDeviceName(devid));
3109}
3110
3111inline const char* AudioDeviceBase::GetName() const
3112{
3113 return SDL::GetAudioDeviceName(get());
3114}
3115
3147 int* sample_frames = nullptr)
3148{
3149 AudioSpec spec;
3150 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3151 return spec;
3152}
3153
3154inline AudioSpec AudioDeviceBase::GetFormat(int* sample_frames) const
3155{
3156 return SDL::GetAudioDeviceFormat(get(), sample_frames);
3157}
3158
3179{
3180 int count;
3181 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3182 return OwnArray<int>{data, size_t(count)};
3183}
3184
3189
3262{
3263 return AudioDevice(devid, spec);
3264}
3265
3268 : AudioDevice(CheckError(SDL_OpenAudioDevice(devid, spec)))
3269{
3270}
3271
3296{
3297 return SDL_IsAudioDevicePhysical(devid);
3298}
3299
3301{
3303}
3304
3318{
3319 return SDL_IsAudioDevicePlayback(devid);
3320}
3321
3323{
3325}
3326
3356{
3357 CheckError(SDL_PauseAudioDevice(devid));
3358}
3359
3361
3387{
3388 CheckError(SDL_ResumeAudioDevice(devid));
3389}
3390
3392
3414{
3415 return SDL_AudioDevicePaused(devid);
3416}
3417
3418inline bool AudioDeviceBase::Paused() const
3419{
3420 return SDL::AudioDevicePaused(get());
3421}
3422
3445{
3446 return SDL_GetAudioDeviceGain(devid);
3447}
3448
3449inline float AudioDeviceBase::GetGain() const
3450{
3451 return SDL::GetAudioDeviceGain(get());
3452}
3453
3486inline void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
3487{
3488 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3489}
3490
3491inline void AudioDeviceBase::SetGain(float gain)
3492{
3494}
3495
3515{
3516 SDL_CloseAudioDevice(devid);
3517}
3518
3520
3558 std::span<AudioStreamRef> streams)
3559{
3560 CheckError(SDL_BindAudioStreams(
3561 devid,
3562 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3563 narrowS32(streams.size())));
3564}
3565
3566inline void AudioDeviceBase::BindAudioStreams(std::span<AudioStreamRef> streams)
3567{
3568 SDL::BindAudioStreams(get(), streams);
3569}
3570
3590{
3591 CheckError(SDL_BindAudioStream(devid, stream));
3592}
3593
3595{
3596 SDL::BindAudioStream(get(), stream);
3597}
3598
3617inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3618{
3619 SDL_UnbindAudioStreams(
3620 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3621 narrowS32(streams.size()));
3622}
3623
3639{
3640 SDL_UnbindAudioStream(stream);
3641}
3642
3644
3664{
3665 return SDL_GetAudioStreamDevice(stream);
3666}
3667
3672
3702{
3703 return AudioStream(src_spec, dst_spec);
3704}
3705
3708 : AudioStream(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
3709{
3710}
3711
3714 AudioStreamCallback callback,
3715 void* userdata)
3716 : AudioStream(
3717 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
3718{
3719}
3720
3723 AudioStreamCB callback)
3724 : AudioStream(devid, spec)
3725{
3726 if (IsAudioDevicePlayback(devid)) {
3727 SetGetCallback(std::move(callback));
3728 } else {
3729 SetPutCallback(std::move(callback));
3730 }
3731}
3732
3755{
3756 return CheckError(SDL_GetAudioStreamProperties(stream));
3757}
3758
3763
3764#if SDL_VERSION_ATLEAST(3, 4, 0)
3765
3779
3780constexpr auto AUTO_CLEANUP_BOOLEAN =
3781 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3782
3783} // namespace prop::AudioStream
3784
3785#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3786
3803 AudioSpec* src_spec,
3804 AudioSpec* dst_spec)
3805{
3806 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3807}
3808
3810 AudioSpec* dst_spec) const
3811{
3812 SDL::GetAudioStreamFormat(get(), src_spec, dst_spec);
3813}
3814
3855{
3856 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3857}
3858
3861{
3862 SDL::SetAudioStreamFormat(get(), src_spec, dst_spec);
3863}
3864
3880{
3881 return SDL_GetAudioStreamFrequencyRatio(stream);
3882}
3883
3885{
3887}
3888
3914inline void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
3915{
3916 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3917}
3918
3920{
3922}
3923
3944{
3945 return SDL_GetAudioStreamGain(stream);
3946}
3947
3948inline float AudioStreamBase::GetGain() const
3949{
3950 return SDL::GetAudioStreamGain(get());
3951}
3952
3975inline void SetAudioStreamGain(AudioStreamRef stream, float gain)
3976{
3977 CheckError(SDL_SetAudioStreamGain(stream, gain));
3978}
3979
3980inline void AudioStreamBase::SetGain(float gain)
3981{
3983}
3984
4006{
4007 int count;
4008 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
4009 if (!data) return {};
4010 return OwnArray<int>{data, size_t(count)};
4011}
4012
4017
4039{
4040 int count;
4041 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4042 if (!data) return {};
4043 return OwnArray<int>{data, size_t(count)};
4044}
4045
4050
4108 std::span<int> chmap)
4109{
4110 CheckError(SDL_SetAudioStreamInputChannelMap(
4111 stream, chmap.data(), narrowS32(chmap.size())));
4112}
4113
4114inline void AudioStreamBase::SetInputChannelMap(std::span<int> chmap)
4115{
4117}
4118
4174 std::span<int> chmap)
4175{
4176 CheckError(SDL_SetAudioStreamOutputChannelMap(
4177 stream, chmap.data(), narrowS32(chmap.size())));
4178}
4179
4180inline void AudioStreamBase::SetOutputChannelMap(std::span<int> chmap)
4181{
4183}
4184
4212{
4213 CheckError(
4214 SDL_PutAudioStreamData(stream, buf.data(), narrowS32(buf.size_bytes())));
4215}
4216
4218{
4219 SDL::PutAudioStreamData(get(), std::move(buf));
4220}
4221
4222#if SDL_VERSION_ATLEAST(3, 4, 0)
4223
4268 SourceBytes buf,
4270 void* userdata)
4271{
4272 CheckError(SDL_PutAudioStreamDataNoCopy(
4273 stream, buf.data(), narrowS32(buf.size_bytes()), callback, userdata));
4274}
4275
4318 SourceBytes buf,
4320{
4323 std::move(buf),
4324 &Wrapper::CallOnce,
4325 Wrapper::Wrap(std::move(callback)));
4326}
4327
4329 SourceBytes buf,
4331 void* userdata)
4332{
4333 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), callback, userdata);
4334}
4335
4338{
4339 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), std::move(callback));
4340}
4341
4391 const void* const* channel_buffers,
4392 int num_channels,
4393 int num_samples)
4394{
4395 CheckError(SDL_PutAudioStreamPlanarData(
4396 stream, channel_buffers, num_channels, num_samples));
4397}
4398
4399inline void AudioStreamBase::PutPlanarData(const void* const* channel_buffers,
4400 int num_channels,
4401 int num_samples)
4402{
4404 get(), channel_buffers, num_channels, num_samples);
4405}
4406
4407#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4408
4437{
4438 return SDL_GetAudioStreamData(
4439 stream, buf.data(), narrowS32(buf.size_bytes()));
4440}
4441
4443{
4444 return SDL::GetAudioStreamData(get(), std::move(buf));
4445}
4446
4471{
4472 return SDL_GetAudioStreamAvailable(stream);
4473}
4474
4476{
4478}
4479
4516{
4517 return SDL_GetAudioStreamQueued(stream);
4518}
4519
4521{
4523}
4524
4543{
4544 CheckError(SDL_FlushAudioStream(stream));
4545}
4546
4548
4568{
4569 CheckError(SDL_ClearAudioStream(stream));
4570}
4571
4573
4596{
4597 CheckError(SDL_PauseAudioStreamDevice(stream));
4598}
4599
4604
4626{
4627 CheckError(SDL_ResumeAudioStreamDevice(stream));
4628}
4629
4634
4653{
4654 return SDL_AudioStreamDevicePaused(stream);
4655}
4656
4658{
4660}
4661
4688{
4689 CheckError(SDL_LockAudioStream(stream));
4690}
4691
4693{
4694 return {AudioStreamRef(*this)};
4695}
4696
4698 : m_lock(std::move(resource))
4699{
4700 LockAudioStream(m_lock);
4701}
4702
4719{
4720 CheckError(SDL_UnlockAudioStream(stream));
4721}
4722
4724{
4725 SDL_assert_paranoid(lock.resource() == *this);
4726 std::move(lock).reset();
4727}
4728
4730{
4731 if (!m_lock) return;
4732 UnlockAudioStream(m_lock);
4733 m_lock = {};
4734}
4735
4778 AudioStreamCallback callback,
4779 void* userdata)
4780{
4781 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4782}
4783
4824 AudioStreamCB callback)
4825{
4826 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4827}
4828
4830 void* userdata)
4831{
4832 SDL::SetAudioStreamGetCallback(get(), callback, userdata);
4833}
4834
4836{
4838}
4839
4886 AudioStreamCallback callback,
4887 void* userdata)
4888{
4889 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4890}
4891
4936 AudioStreamCB callback)
4937{
4938 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
4939}
4940
4942 void* userdata)
4943{
4944 SDL::SetAudioStreamPutCallback(get(), callback, userdata);
4945}
4946
4948{
4950}
4951
4971{
4972 SDL_DestroyAudioStream(stream);
4973}
4974
4976
5036 AudioStreamCallback callback = nullptr,
5037 void* userdata = nullptr)
5038{
5039 return AudioStream(devid, spec, callback, userdata);
5040}
5041
5097 AudioStreamCB callback)
5098{
5099 return AudioStream(devid, spec, callback);
5100}
5101
5104 AudioStreamCallback callback,
5105 void* userdata)
5106{
5107 return AudioStream(get(), spec, callback, userdata);
5108}
5109
5112 AudioStreamCB callback)
5113{
5114 return SDL::OpenAudioDeviceStream(get(), spec, callback);
5115}
5116
5169 AudioPostmixCallback callback,
5170 void* userdata)
5171{
5172 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5173}
5174
5226 AudioPostmixCB callback)
5227{
5228 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5229}
5230
5232 void* userdata)
5233{
5234 SDL::SetAudioPostmixCallback(get(), callback, userdata);
5235}
5236
5238{
5239 SDL::SetAudioPostmixCallback(get(), callback);
5240}
5241
5310 AudioSpec* spec,
5311 bool closeio = false)
5312{
5313 Uint8* buf;
5314 Uint32 len;
5315 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
5316 return OwnArray<Uint8>{buf, size_t(len)};
5317}
5318
5344{
5345 Uint8* buf;
5346 Uint32 len;
5347 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5348 return OwnArray<Uint8>{buf, size_t(len)};
5349}
5350
5382inline void MixAudio(Uint8* dst,
5383 SourceBytes src,
5384 AudioFormat format,
5385 float volume)
5386{
5387 CheckError(SDL_MixAudio(
5388 dst, src.data_as<Uint8>(), format, narrowS32(src.size_bytes()), volume));
5389}
5390
5422inline void MixAudio(TargetBytes dst,
5423 SourceBytes src,
5424 AudioFormat format,
5425 float volume)
5426{
5427 if (dst.size_bytes() < src.size_bytes()) {
5428 MixAudio(dst.data_as<Uint8>(),
5429 SourceBytes{src.data(), dst.size_bytes()},
5430 format,
5431 volume);
5432 } else
5433 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5434}
5435
5459 SourceBytes src_data,
5460 const AudioSpec& dst_spec)
5461{
5462 Uint8* buf;
5463 int len;
5464 CheckError(SDL_ConvertAudioSamples(&src_spec,
5465 src_data.data_as<Uint8>(),
5466 narrowS32(src_data.size_bytes()),
5467 &dst_spec,
5468 &buf,
5469 &len));
5470 return OwnArray<Uint8>{buf, size_t(len)};
5471}
5472
5484inline const char* GetAudioFormatName(AudioFormatRaw format)
5485{
5486 return SDL_GetAudioFormatName(format);
5487}
5488
5489inline const char* AudioFormat::GetName() const
5490{
5491 return SDL::GetAudioFormatName(m_audioFormat);
5492}
5493
5508{
5509 return SDL_GetSilenceValueForFormat(format);
5510}
5511
5513{
5514 return SDL::GetSilenceValueForFormat(m_audioFormat);
5515}
5516
5518
5519} // namespace SDL
5520
5521#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:2856
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2918
void release()
Releases the lock without unlocking.
Definition SDL3pp_audio.h:2947
AudioStreamRef resource() const
Get the reference to locked resource.
Definition SDL3pp_audio.h:2944
AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2892
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:2909
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:4107
void PutAudioStreamData(AudioStreamRef stream, SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4211
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:4173
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:3317
bool AudioDevicePaused(AudioDeviceRef devid)
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3413
void BindAudioStreams(AudioDeviceRef devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3557
AudioDevice OpenAudioDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition SDL3pp_audio.h:3260
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:3589
void PutData(SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4217
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:5458
float GetGain() const
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3948
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:4697
void GetAudioStreamFormat(AudioStreamRef stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3802
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:5507
void Pause()
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3360
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:4442
bool IsAudioDevicePhysical(AudioDeviceRef devid)
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3295
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:1557
void Clear()
Clear any pending data in the stream.
Definition SDL3pp_audio.h:4572
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:4595
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition SDL3pp_audio.h:3014
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3566
float GetAudioDeviceGain(AudioDeviceRef devid)
Get the gain of an audio device.
Definition SDL3pp_audio.h:3444
float GetAudioStreamGain(AudioStreamRef stream)
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3943
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:4625
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:3852
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5484
const char * GetAudioDeviceName(AudioDeviceRef devid)
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3106
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4114
void UnlockAudioStream(AudioStreamRef stream)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4718
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:4567
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3185
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition SDL3pp_audio.h:5102
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3668
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:3859
int GetQueued() const
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4520
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:4013
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3111
void Close()
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3519
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5512
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:3980
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:3879
void SetAudioStreamGain(AudioStreamRef stream, float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:3975
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:4542
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:4390
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:751
void BindAudioStream(AudioStreamRef stream)
Bind a single audio stream to an audio device.
Definition SDL3pp_audio.h:3594
PropertiesRef GetAudioStreamProperties(AudioStreamRef stream)
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3754
void UnbindAudioStream(AudioStreamRef stream)
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3638
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition SDL3pp_audio.h:3075
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3809
void SetGain(float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3491
void PauseAudioDevice(AudioDeviceRef devid)
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3355
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:4729
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:4829
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4547
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition SDL3pp_audio.h:2995
bool Paused() const
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3418
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:5168
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_RECORDING
A value used to request a default recording audio device.
Definition SDL3pp_audio.h:1478
void Resume()
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3391
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:3663
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:5309
constexpr AudioDeviceID AUDIO_DEVICE_DEFAULT_PLAYBACK
A value used to request a default playback audio device.
Definition SDL3pp_audio.h:1466
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:4328
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:4515
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition SDL3pp_audio.h:5382
AudioSpec GetAudioDeviceFormat(AudioDeviceRef devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3146
void(SDLCALL *)(void *userdata, const void *buf, int buflen) AudioStreamDataCompleteCallback
A callback that fires for completed PutAudioStreamDataNoCopy() data.
Definition SDL3pp_audio.h:1527
OwnArray< int > GetOutputChannelMap() const
Get the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4046
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition SDL3pp_audio.h:3700
OwnArray< Uint8 > LoadWAV(StringParam path, AudioSpec *spec)
Loads a WAV from a file path.
Definition SDL3pp_audio.h:5343
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:3759
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3884
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:5231
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3919
void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3486
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3322
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:4885
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:2971
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3300
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition SDL3pp_audio.h:3617
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:5034
void PutPlanarData(const void *const *channel_buffers, int num_channels, int num_samples)
Add data to the stream with each channel in a separate array.
Definition SDL3pp_audio.h:4399
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceRef devid)
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3178
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:4941
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:4630
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4180
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition SDL3pp_audio.h:4970
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:795
void Unbind()
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3643
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4657
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:4038
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition SDL3pp_audio.h:3043
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamRef stream)
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4005
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:4470
void Destroy()
Free an audio stream.
Definition SDL3pp_audio.h:4975
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:4777
bool AudioStreamDevicePaused(AudioStreamRef stream)
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4652
void ResumeAudioDevice(AudioDeviceRef devid)
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3386
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4692
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4723
void PutAudioStreamDataNoCopy(AudioStreamRef stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4267
float GetGain() const
Get the gain of an audio device.
Definition SDL3pp_audio.h:3449
const char * GetName() const
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5489
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3154
void LockAudioStream(AudioStreamRef stream)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4687
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4475
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3514
void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3914
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:4600
constexpr int AudioFrameSize(const AudioSpec &x)
Calculate the size of each audio frame (in bytes) from an AudioSpec.
Definition SDL3pp_audio.h:1494
int GetAudioStreamData(AudioStreamRef stream, TargetBytes buf)
Get converted/resampled data from the stream.
Definition SDL3pp_audio.h:4436
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:3778
constexpr auto AUTO_CLEANUP_BOOLEAN
Auto cleanup enabled.
Definition SDL3pp_audio.h:3780
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:804
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
SDL Audio Device instance IDs.
Definition SDL3pp_audio.h:1352
~AudioDevice()
Destructor.
Definition SDL3pp_audio.h:1447
constexpr AudioDevice(AudioDeviceID resource) noexcept
Constructs from raw AudioDevice.
Definition SDL3pp_audio.h:1362
constexpr AudioDevice & operator=(AudioDevice &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:1450
constexpr AudioDevice(AudioDevice &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:1368
Base class to AudioStream.
Definition SDL3pp_audio.h:1568
AudioSpec GetOutputFormat() const
Query the current output format of an audio stream.
Definition SDL3pp_audio.h:1646
void SetOutputFormat(const AudioSpec &spec)
Change the output format of an audio stream.
Definition SDL3pp_audio.h:1731
void SetInputFormat(const AudioSpec &spec)
Change the input format of an audio stream.
Definition SDL3pp_audio.h:1699
AudioSpec GetInputFormat() const
Query the current input format of an audio stream.
Definition SDL3pp_audio.h:1626
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The opaque handle that represents an audio stream.
Definition SDL3pp_audio.h:2656
~AudioStream()
Destructor.
Definition SDL3pp_audio.h:2827
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2672
constexpr AudioStream(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:2666
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2830
Definition SDL3pp_callbackWrapper.h:20
Definition SDL3pp_callbackWrapper.h:169
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93