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
1768
1782 float GetFrequencyRatio() const;
1783
1808 void SetFrequencyRatio(float ratio);
1809
1828 float GetGain() const;
1829
1851 void SetGain(float gain);
1852
1873
1894
1950 void SetInputChannelMap(std::span<int> chmap);
1951
2005 void SetOutputChannelMap(std::span<int> chmap);
2006
2032 void PutData(SourceBytes buf);
2033
2034#if SDL_VERSION_ATLEAST(3, 4, 0)
2035
2078 void PutDataNoCopy(SourceBytes buf,
2080 void* userdata);
2081
2123
2124#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2125
2152 int GetData(TargetBytes buf);
2153
2177 int GetAvailable() const;
2178
2214 int GetQueued() const;
2215
2232 void Flush();
2233
2251 void Clear();
2252
2273 void PauseDevice();
2274
2294 void ResumeDevice();
2295
2312 bool DevicePaused() const;
2313
2339
2354 void Unlock(AudioStreamLock&& lock);
2355
2398 void SetGetCallback(AudioStreamCallback callback, void* userdata);
2399
2440 void SetGetCallback(AudioStreamCB callback);
2441
2487 void SetPutCallback(AudioStreamCallback callback, void* userdata);
2488
2532 void SetPutCallback(AudioStreamCB callback);
2533
2546 void Unbind();
2547
2566 AudioDeviceRef GetDevice() const;
2567
2568#if SDL_VERSION_ATLEAST(3, 4, 0)
2569
2618 void PutPlanarData(const void* const* channel_buffers,
2619 int num_channels,
2620 int num_samples);
2621
2622#endif // SDL_VERSION_ATLEAST(3, 4, 0)
2623};
2624
2652{
2653 using AudioStreamBase::AudioStreamBase;
2654
2662 constexpr explicit AudioStream(AudioStreamRaw resource) noexcept
2663 : AudioStreamBase(resource)
2664 {
2665 }
2666
2668 constexpr AudioStream(AudioStream&& other) noexcept
2669 : AudioStream(other.release())
2670 {
2671 }
2672
2695
2754 OptionalRef<const AudioSpec> spec = std::nullopt,
2755 AudioStreamCallback callback = nullptr,
2756 void* userdata = nullptr);
2757
2813 AudioStreamCB callback);
2814
2816 ~AudioStream() { SDL_DestroyAudioStream(get()); }
2817
2819 constexpr AudioStream& operator=(AudioStream&& other) noexcept
2820 {
2821 swap(*this, other);
2822 return *this;
2823 }
2824};
2825
2845{
2846 AudioStreamRef m_lock;
2847
2848public:
2876
2878 AudioStreamLock(const AudioStreamLock& other) = delete;
2879
2882 : m_lock(std::move(other.m_lock))
2883 {
2884 }
2885
2899 {
2900 if (!m_lock) return;
2901 SDL_UnlockAudioStream(m_lock);
2902 }
2903
2904 AudioStreamLock& operator=(const AudioStreamLock& other) = delete;
2905
2908 {
2909 std::swap(m_lock, other.m_lock);
2910 return *this;
2911 }
2912
2914 constexpr operator bool() const { return bool(m_lock); }
2915
2930 void reset();
2931
2933 AudioStreamRef resource() const { return m_lock; }
2934
2936 void release() { m_lock.release(); }
2937};
2938
2960inline int GetNumAudioDrivers() { return SDL_GetNumAudioDrivers(); }
2961
2984inline const char* GetAudioDriver(int index)
2985{
2986 return SDL_GetAudioDriver(index);
2987}
2988
3003inline const char* GetCurrentAudioDriver()
3004{
3005 return SDL_GetCurrentAudioDriver();
3006}
3007
3033{
3034 int count;
3035 auto data = CheckError(SDL_GetAudioPlaybackDevices(&count));
3036 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3037 size_t(count)};
3038}
3039
3065{
3066 int count;
3067 auto data = CheckError(SDL_GetAudioRecordingDevices(&count));
3068 return OwnArray<AudioDeviceRef>{reinterpret_cast<AudioDeviceRef*>(data),
3069 size_t(count)};
3070}
3071
3095inline const char* GetAudioDeviceName(AudioDeviceRef devid)
3096{
3097 return CheckError(SDL_GetAudioDeviceName(devid));
3098}
3099
3100inline const char* AudioDeviceBase::GetName() const
3101{
3102 return SDL::GetAudioDeviceName(get());
3103}
3104
3136 int* sample_frames = nullptr)
3137{
3138 AudioSpec spec;
3139 CheckError(SDL_GetAudioDeviceFormat(devid, &spec, sample_frames));
3140 return spec;
3141}
3142
3143inline AudioSpec AudioDeviceBase::GetFormat(int* sample_frames) const
3144{
3145 return SDL::GetAudioDeviceFormat(get(), sample_frames);
3146}
3147
3168{
3169 int count;
3170 auto data = SDL_GetAudioDeviceChannelMap(devid, &count);
3171 return OwnArray<int>{data, size_t(count)};
3172}
3173
3178
3251{
3252 return AudioDevice(devid, spec);
3253}
3254
3257 : AudioDevice(CheckError(SDL_OpenAudioDevice(devid, spec)))
3258{
3259}
3260
3285{
3286 return SDL_IsAudioDevicePhysical(devid);
3287}
3288
3290{
3292}
3293
3307{
3308 return SDL_IsAudioDevicePlayback(devid);
3309}
3310
3312{
3314}
3315
3345{
3346 CheckError(SDL_PauseAudioDevice(devid));
3347}
3348
3350
3376{
3377 CheckError(SDL_ResumeAudioDevice(devid));
3378}
3379
3381
3403{
3404 return SDL_AudioDevicePaused(devid);
3405}
3406
3407inline bool AudioDeviceBase::Paused() const
3408{
3409 return SDL::AudioDevicePaused(get());
3410}
3411
3434{
3435 return SDL_GetAudioDeviceGain(devid);
3436}
3437
3438inline float AudioDeviceBase::GetGain() const
3439{
3440 return SDL::GetAudioDeviceGain(get());
3441}
3442
3475inline void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
3476{
3477 CheckError(SDL_SetAudioDeviceGain(devid, gain));
3478}
3479
3480inline void AudioDeviceBase::SetGain(float gain)
3481{
3483}
3484
3504{
3505 SDL_CloseAudioDevice(devid);
3506}
3507
3509
3547 std::span<AudioStreamRef> streams)
3548{
3549 CheckError(SDL_BindAudioStreams(
3550 devid,
3551 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3552 narrowS32(streams.size())));
3553}
3554
3555inline void AudioDeviceBase::BindAudioStreams(std::span<AudioStreamRef> streams)
3556{
3557 SDL::BindAudioStreams(get(), streams);
3558}
3559
3579{
3580 CheckError(SDL_BindAudioStream(devid, stream));
3581}
3582
3584{
3585 SDL::BindAudioStream(get(), stream);
3586}
3587
3606inline void UnbindAudioStreams(std::span<AudioStreamRef> streams)
3607{
3608 SDL_UnbindAudioStreams(
3609 reinterpret_cast<SDL_AudioStream* const*>(streams.data()),
3610 narrowS32(streams.size()));
3611}
3612
3628{
3629 SDL_UnbindAudioStream(stream);
3630}
3631
3633
3653{
3654 return SDL_GetAudioStreamDevice(stream);
3655}
3656
3661
3684{
3685 return AudioStream(src_spec, dst_spec);
3686}
3687
3690 : AudioStream(CheckError(SDL_CreateAudioStream(src_spec, dst_spec)))
3691{
3692}
3693
3696 AudioStreamCallback callback,
3697 void* userdata)
3698 : AudioStream(
3699 CheckError(SDL_OpenAudioDeviceStream(devid, spec, callback, userdata)))
3700{
3701}
3702
3705 AudioStreamCB callback)
3706 : AudioStream(devid, spec)
3707{
3708 if (IsAudioDevicePlayback(devid)) {
3709 SetGetCallback(std::move(callback));
3710 } else {
3711 SetPutCallback(std::move(callback));
3712 }
3713}
3714
3737{
3738 return CheckError(SDL_GetAudioStreamProperties(stream));
3739}
3740
3745
3746#if SDL_VERSION_ATLEAST(3, 4, 0)
3747
3761
3762constexpr auto AUTO_CLEANUP_BOOLEAN =
3763 SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN;
3764
3765} // namespace prop::AudioStream
3766
3767#endif // SDL_VERSION_ATLEAST(3, 4, 0)
3768
3785 AudioSpec* src_spec,
3786 AudioSpec* dst_spec)
3787{
3788 CheckError(SDL_GetAudioStreamFormat(stream, src_spec, dst_spec));
3789}
3790
3792 AudioSpec* dst_spec) const
3793{
3794 SDL::GetAudioStreamFormat(get(), src_spec, dst_spec);
3795}
3796
3834{
3835 CheckError(SDL_SetAudioStreamFormat(stream, src_spec, dst_spec));
3836}
3837
3840{
3841 SDL::SetAudioStreamFormat(get(), src_spec, dst_spec);
3842}
3843
3859{
3860 return SDL_GetAudioStreamFrequencyRatio(stream);
3861}
3862
3864{
3866}
3867
3893inline void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
3894{
3895 CheckError(SDL_SetAudioStreamFrequencyRatio(stream, ratio));
3896}
3897
3899{
3901}
3902
3923{
3924 return SDL_GetAudioStreamGain(stream);
3925}
3926
3927inline float AudioStreamBase::GetGain() const
3928{
3929 return SDL::GetAudioStreamGain(get());
3930}
3931
3954inline void SetAudioStreamGain(AudioStreamRef stream, float gain)
3955{
3956 CheckError(SDL_SetAudioStreamGain(stream, gain));
3957}
3958
3959inline void AudioStreamBase::SetGain(float gain)
3960{
3962}
3963
3985{
3986 int count;
3987 auto data = SDL_GetAudioStreamInputChannelMap(stream, &count);
3988 if (!data) return {};
3989 return OwnArray<int>{data, size_t(count)};
3990}
3991
3996
4018{
4019 int count;
4020 auto data = SDL_GetAudioStreamOutputChannelMap(stream, &count);
4021 if (!data) return {};
4022 return OwnArray<int>{data, size_t(count)};
4023}
4024
4029
4087 std::span<int> chmap)
4088{
4089 CheckError(SDL_SetAudioStreamInputChannelMap(
4090 stream, chmap.data(), narrowS32(chmap.size())));
4091}
4092
4093inline void AudioStreamBase::SetInputChannelMap(std::span<int> chmap)
4094{
4096}
4097
4153 std::span<int> chmap)
4154{
4155 CheckError(SDL_SetAudioStreamOutputChannelMap(
4156 stream, chmap.data(), narrowS32(chmap.size())));
4157}
4158
4159inline void AudioStreamBase::SetOutputChannelMap(std::span<int> chmap)
4160{
4162}
4163
4191{
4192 CheckError(
4193 SDL_PutAudioStreamData(stream, buf.data(), narrowS32(buf.size_bytes())));
4194}
4195
4197{
4198 SDL::PutAudioStreamData(get(), std::move(buf));
4199}
4200
4201#if SDL_VERSION_ATLEAST(3, 4, 0)
4202
4247 SourceBytes buf,
4249 void* userdata)
4250{
4251 CheckError(SDL_PutAudioStreamDataNoCopy(
4252 stream, buf.data(), narrowS32(buf.size_bytes()), callback, userdata));
4253}
4254
4297 SourceBytes buf,
4299{
4302 std::move(buf),
4303 &Wrapper::CallOnce,
4304 Wrapper::Wrap(std::move(callback)));
4305}
4306
4308 SourceBytes buf,
4310 void* userdata)
4311{
4312 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), callback, userdata);
4313}
4314
4317{
4318 SDL::PutAudioStreamDataNoCopy(get(), std::move(buf), std::move(callback));
4319}
4320
4370 const void* const* channel_buffers,
4371 int num_channels,
4372 int num_samples)
4373{
4374 CheckError(SDL_PutAudioStreamPlanarData(
4375 stream, channel_buffers, num_channels, num_samples));
4376}
4377
4378inline void AudioStreamBase::PutPlanarData(const void* const* channel_buffers,
4379 int num_channels,
4380 int num_samples)
4381{
4383 get(), channel_buffers, num_channels, num_samples);
4384}
4385
4386#endif // SDL_VERSION_ATLEAST(3, 4, 0)
4387
4416{
4417 return SDL_GetAudioStreamData(
4418 stream, buf.data(), narrowS32(buf.size_bytes()));
4419}
4420
4422{
4423 return SDL::GetAudioStreamData(get(), std::move(buf));
4424}
4425
4450{
4451 return SDL_GetAudioStreamAvailable(stream);
4452}
4453
4455{
4457}
4458
4495{
4496 return SDL_GetAudioStreamQueued(stream);
4497}
4498
4500{
4502}
4503
4522{
4523 CheckError(SDL_FlushAudioStream(stream));
4524}
4525
4527
4547{
4548 CheckError(SDL_ClearAudioStream(stream));
4549}
4550
4552
4575{
4576 CheckError(SDL_PauseAudioStreamDevice(stream));
4577}
4578
4583
4605{
4606 CheckError(SDL_ResumeAudioStreamDevice(stream));
4607}
4608
4613
4632{
4633 return SDL_AudioStreamDevicePaused(stream);
4634}
4635
4637{
4639}
4640
4667{
4668 CheckError(SDL_LockAudioStream(stream));
4669}
4670
4672{
4673 return {AudioStreamRef(*this)};
4674}
4675
4677 : m_lock(std::move(resource))
4678{
4679 LockAudioStream(m_lock);
4680}
4681
4698{
4699 CheckError(SDL_UnlockAudioStream(stream));
4700}
4701
4703{
4704 SDL_assert_paranoid(lock.resource() == *this);
4705 std::move(lock).reset();
4706}
4707
4709{
4710 if (!m_lock) return;
4711 UnlockAudioStream(m_lock);
4712 m_lock = {};
4713}
4714
4757 AudioStreamCallback callback,
4758 void* userdata)
4759{
4760 CheckError(SDL_SetAudioStreamGetCallback(stream, callback, userdata));
4761}
4762
4803 AudioStreamCB callback)
4804{
4805 SetAudioStreamGetCallback(stream, callback.wrapper, callback.data);
4806}
4807
4809 void* userdata)
4810{
4811 SDL::SetAudioStreamGetCallback(get(), callback, userdata);
4812}
4813
4815{
4817}
4818
4865 AudioStreamCallback callback,
4866 void* userdata)
4867{
4868 CheckError(SDL_SetAudioStreamPutCallback(stream, callback, userdata));
4869}
4870
4915 AudioStreamCB callback)
4916{
4917 SetAudioStreamPutCallback(stream, callback.wrapper, callback.data);
4918}
4919
4921 void* userdata)
4922{
4923 SDL::SetAudioStreamPutCallback(get(), callback, userdata);
4924}
4925
4927{
4929}
4930
4950{
4951 SDL_DestroyAudioStream(stream);
4952}
4953
4955
5015 AudioStreamCallback callback = nullptr,
5016 void* userdata = nullptr)
5017{
5018 return AudioStream(devid, spec, callback, userdata);
5019}
5020
5076 AudioStreamCB callback)
5077{
5078 return AudioStream(devid, spec, callback);
5079}
5080
5083 AudioStreamCallback callback,
5084 void* userdata)
5085{
5086 return AudioStream(get(), spec, callback, userdata);
5087}
5088
5091 AudioStreamCB callback)
5092{
5093 return SDL::OpenAudioDeviceStream(get(), spec, callback);
5094}
5095
5148 AudioPostmixCallback callback,
5149 void* userdata)
5150{
5151 CheckError(SDL_SetAudioPostmixCallback(devid, callback, userdata));
5152}
5153
5205 AudioPostmixCB callback)
5206{
5207 SetAudioPostmixCallback(devid, callback.wrapper, callback.data);
5208}
5209
5211 void* userdata)
5212{
5213 SDL::SetAudioPostmixCallback(get(), callback, userdata);
5214}
5215
5217{
5218 SDL::SetAudioPostmixCallback(get(), callback);
5219}
5220
5289 AudioSpec* spec,
5290 bool closeio = false)
5291{
5292 Uint8* buf;
5293 Uint32 len;
5294 if (!SDL_LoadWAV_IO(src, closeio, spec, &buf, &len)) return {};
5295 return OwnArray<Uint8>{buf, size_t(len)};
5296}
5297
5323{
5324 Uint8* buf;
5325 Uint32 len;
5326 if (!SDL_LoadWAV(path, spec, &buf, &len)) return {};
5327 return OwnArray<Uint8>{buf, size_t(len)};
5328}
5329
5361inline void MixAudio(Uint8* dst,
5362 SourceBytes src,
5363 AudioFormat format,
5364 float volume)
5365{
5366 CheckError(SDL_MixAudio(
5367 dst, src.data_as<Uint8>(), format, narrowS32(src.size_bytes()), volume));
5368}
5369
5401inline void MixAudio(TargetBytes dst,
5402 SourceBytes src,
5403 AudioFormat format,
5404 float volume)
5405{
5406 if (dst.size_bytes() < src.size_bytes()) {
5407 MixAudio(dst.data_as<Uint8>(),
5408 SourceBytes{src.data(), dst.size_bytes()},
5409 format,
5410 volume);
5411 } else
5412 MixAudio(dst.data_as<Uint8>(), src, format, volume);
5413}
5414
5438 SourceBytes src_data,
5439 const AudioSpec& dst_spec)
5440{
5441 Uint8* buf;
5442 int len;
5443 CheckError(SDL_ConvertAudioSamples(&src_spec,
5444 src_data.data_as<Uint8>(),
5445 narrowS32(src_data.size_bytes()),
5446 &dst_spec,
5447 &buf,
5448 &len));
5449 return OwnArray<Uint8>{buf, size_t(len)};
5450}
5451
5463inline const char* GetAudioFormatName(AudioFormatRaw format)
5464{
5465 return SDL_GetAudioFormatName(format);
5466}
5467
5468inline const char* AudioFormat::GetName() const
5469{
5470 return SDL::GetAudioFormatName(m_audioFormat);
5471}
5472
5487{
5488 return SDL_GetSilenceValueForFormat(format);
5489}
5490
5492{
5493 return SDL::GetSilenceValueForFormat(m_audioFormat);
5494}
5495
5497
5498} // namespace SDL
5499
5500#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:2845
AudioStreamLock & operator=(AudioStreamLock &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2907
void release()
Releases the lock without unlocking.
Definition SDL3pp_audio.h:2936
AudioStreamRef resource() const
Get the reference to locked resource.
Definition SDL3pp_audio.h:2933
AudioStreamLock(AudioStreamLock &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2881
AudioStreamLock(const AudioStreamLock &other)=delete
Copy constructor.
~AudioStreamLock()
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:2898
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:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
constexpr const T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:311
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Target byte stream.
Definition SDL3pp_strings.h:323
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:409
constexpr T * data_as() const
Retrieves contained data.
Definition SDL3pp_strings.h:413
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:406
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
constexpr bool IsAudioFloat(AudioFormatRaw x)
Determine if an AudioFormat represents floating point data.
Definition SDL3pp_audio.h:524
void SetAudioStreamInputChannelMap(AudioStreamRef stream, std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4086
void PutAudioStreamData(AudioStreamRef stream, SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4190
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:4152
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:3306
bool AudioDevicePaused(AudioDeviceRef devid)
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3402
void BindAudioStreams(AudioDeviceRef devid, std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3546
AudioDevice OpenAudioDevice(AudioDeviceRef devid, OptionalRef< const AudioSpec > spec)
Open a specific audio device.
Definition SDL3pp_audio.h:3249
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:3578
void PutData(SourceBytes buf)
Add data to the stream.
Definition SDL3pp_audio.h:4196
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:5437
float GetGain() const
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3927
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:4676
void GetAudioStreamFormat(AudioStreamRef stream, AudioSpec *src_spec, AudioSpec *dst_spec)
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3784
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:5486
void Pause()
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3349
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:4421
bool IsAudioDevicePhysical(AudioDeviceRef devid)
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3284
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:4551
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:4574
const char * GetCurrentAudioDriver()
Get the name of the current audio driver.
Definition SDL3pp_audio.h:3003
void BindAudioStreams(std::span< AudioStreamRef > streams)
Bind a list of audio streams to an audio device.
Definition SDL3pp_audio.h:3555
float GetAudioDeviceGain(AudioDeviceRef devid)
Get the gain of an audio device.
Definition SDL3pp_audio.h:3433
float GetAudioStreamGain(AudioStreamRef stream)
Get the gain of an audio stream.
Definition SDL3pp_audio.h:3922
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:4604
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:3831
const char * GetAudioFormatName(AudioFormatRaw format)
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5463
const char * GetAudioDeviceName(AudioDeviceRef devid)
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3095
void SetInputChannelMap(std::span< int > chmap)
Set the current input channel map of an audio stream.
Definition SDL3pp_audio.h:4093
void UnlockAudioStream(AudioStreamRef stream)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4697
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:4546
OwnArray< int > GetChannelMap() const
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3174
AudioStream OpenStream(OptionalRef< const AudioSpec > spec, AudioStreamCallback callback, void *userdata)
Convenience function for straightforward audio init for the common case.
Definition SDL3pp_audio.h:5081
AudioDeviceRef GetDevice() const
Query an audio stream for its currently-bound device.
Definition SDL3pp_audio.h:3657
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:3838
int GetQueued() const
Get the number of bytes currently queued.
Definition SDL3pp_audio.h:4499
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:3992
const char * GetName() const
Get the human-readable name of a specific audio device.
Definition SDL3pp_audio.h:3100
void Close()
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3508
int GetSilenceValue() const
Get the appropriate memset value for silencing an audio format.
Definition SDL3pp_audio.h:5491
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:3959
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:3858
void SetAudioStreamGain(AudioStreamRef stream, float gain)
Change the gain of an audio stream.
Definition SDL3pp_audio.h:3954
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:4521
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:4369
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:3583
PropertiesRef GetAudioStreamProperties(AudioStreamRef stream)
Get the properties associated with an audio stream.
Definition SDL3pp_audio.h:3736
void UnbindAudioStream(AudioStreamRef stream)
Unbind a single audio stream from its audio device.
Definition SDL3pp_audio.h:3627
OwnArray< AudioDeviceRef > GetAudioRecordingDevices()
Get a list of currently-connected audio recording devices.
Definition SDL3pp_audio.h:3064
void GetFormat(AudioSpec *src_spec, AudioSpec *dst_spec) const
Query the current format of an audio stream.
Definition SDL3pp_audio.h:3791
void SetGain(float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3480
void PauseAudioDevice(AudioDeviceRef devid)
Use this function to pause audio playback on a specified device.
Definition SDL3pp_audio.h:3344
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:4708
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:4808
void Flush()
Tell the stream that you're done sending data, and anything being buffered should be converted/resamp...
Definition SDL3pp_audio.h:4526
const char * GetAudioDriver(int index)
Use this function to get the name of a built in audio driver.
Definition SDL3pp_audio.h:2984
bool Paused() const
Use this function to query if an audio device is paused.
Definition SDL3pp_audio.h:3407
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:5147
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:3380
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:3652
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:5288
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:4307
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:4494
void MixAudio(Uint8 *dst, SourceBytes src, AudioFormat format, float volume)
Mix audio data in a specified format.
Definition SDL3pp_audio.h:5361
AudioSpec GetAudioDeviceFormat(AudioDeviceRef devid, int *sample_frames=nullptr)
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3135
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:4025
AudioStream CreateAudioStream(OptionalRef< const AudioSpec > src_spec, OptionalRef< const AudioSpec > dst_spec)
Create a new audio stream.
Definition SDL3pp_audio.h:3682
OwnArray< Uint8 > LoadWAV(StringParam path, AudioSpec *spec)
Loads a WAV from a file path.
Definition SDL3pp_audio.h:5322
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:3741
float GetFrequencyRatio() const
Get the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3863
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:5210
void SetFrequencyRatio(float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3898
void SetAudioDeviceGain(AudioDeviceRef devid, float gain)
Change the gain of an audio device.
Definition SDL3pp_audio.h:3475
bool IsPlayback() const
Determine if an audio device is a playback device (instead of recording).
Definition SDL3pp_audio.h:3311
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:4864
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:2960
bool IsPhysical() const
Determine if an audio device is physical (instead of logical).
Definition SDL3pp_audio.h:3289
void UnbindAudioStreams(std::span< AudioStreamRef > streams)
Unbind a list of audio streams from their audio devices.
Definition SDL3pp_audio.h:3606
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:5013
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:4378
OwnArray< int > GetAudioDeviceChannelMap(AudioDeviceRef devid)
Get the current channel map of an audio device.
Definition SDL3pp_audio.h:3167
void SetPutCallback(AudioStreamCallback callback, void *userdata)
Set a callback that runs when data is added to an audio stream.
Definition SDL3pp_audio.h:4920
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:4609
void SetOutputChannelMap(std::span< int > chmap)
Set the current output channel map of an audio stream.
Definition SDL3pp_audio.h:4159
void DestroyAudioStream(AudioStreamRaw stream)
Free an audio stream.
Definition SDL3pp_audio.h:4949
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:3632
bool DevicePaused() const
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4636
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:4017
OwnArray< AudioDeviceRef > GetAudioPlaybackDevices()
Get a list of currently-connected audio playback devices.
Definition SDL3pp_audio.h:3032
OwnArray< int > GetAudioStreamInputChannelMap(AudioStreamRef stream)
Get the current input channel map of an audio stream.
Definition SDL3pp_audio.h:3984
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:4449
void Destroy()
Free an audio stream.
Definition SDL3pp_audio.h:4954
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:4756
bool AudioStreamDevicePaused(AudioStreamRef stream)
Use this function to query if an audio device associated with a stream is paused.
Definition SDL3pp_audio.h:4631
void ResumeAudioDevice(AudioDeviceRef devid)
Use this function to unpause audio playback on a specified device.
Definition SDL3pp_audio.h:3375
AudioStreamLock Lock()
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4671
void Unlock(AudioStreamLock &&lock)
Unlock an audio stream for serialized access.
Definition SDL3pp_audio.h:4702
void PutAudioStreamDataNoCopy(AudioStreamRef stream, SourceBytes buf, AudioStreamDataCompleteCallback callback, void *userdata)
Add external data to an audio stream without copying it.
Definition SDL3pp_audio.h:4246
float GetGain() const
Get the gain of an audio device.
Definition SDL3pp_audio.h:3438
const char * GetName() const
Get the human readable name of an audio format.
Definition SDL3pp_audio.h:5468
AudioSpec GetFormat(int *sample_frames=nullptr) const
Get the current audio format of a specific audio device.
Definition SDL3pp_audio.h:3143
void LockAudioStream(AudioStreamRef stream)
Lock an audio stream for serialized access.
Definition SDL3pp_audio.h:4666
int GetAvailable() const
Get the number of converted/resampled bytes available.
Definition SDL3pp_audio.h:4454
void CloseAudioDevice(AudioDeviceID devid)
Close a previously-opened audio device.
Definition SDL3pp_audio.h:3503
void SetAudioStreamFrequencyRatio(AudioStreamRef stream, float ratio)
Change the frequency ratio of an audio stream.
Definition SDL3pp_audio.h:3893
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:4579
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:4415
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:53
::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:3760
constexpr auto AUTO_CLEANUP_BOOLEAN
Auto cleanup enabled.
Definition SDL3pp_audio.h:3762
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
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:2652
~AudioStream()
Destructor.
Definition SDL3pp_audio.h:2816
constexpr AudioStream(AudioStream &&other) noexcept
Move constructor.
Definition SDL3pp_audio.h:2668
constexpr AudioStream(AudioStreamRaw resource) noexcept
Constructs from raw AudioStream.
Definition SDL3pp_audio.h:2662
constexpr AudioStream & operator=(AudioStream &&other) noexcept
Assignment operator.
Definition SDL3pp_audio.h:2819
Definition SDL3pp_callbackWrapper.h:20
Definition SDL3pp_callbackWrapper.h:169
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93