Skip to main content

sdl3_sys/generated/
audio.rs

1//! Audio functionality for the SDL library.
2//!
3//! All audio in SDL3 revolves around [`SDL_AudioStream`]. Whether you want to play
4//! or record audio, convert it, stream it, buffer it, or mix it, you're going
5//! to be passing it through an audio stream.
6//!
7//! Audio streams are quite flexible; they can accept any amount of data at a
8//! time, in any supported format, and output it as needed in any other format,
9//! even if the data format changes on either side halfway through.
10//!
11//! An app opens an audio device and binds any number of audio streams to it,
12//! feeding more data to the streams as available. When the device needs more
13//! data, it will pull it from all bound streams and mix them together for
14//! playback.
15//!
16//! Audio streams can also use an app-provided callback to supply data
17//! on-demand, which maps pretty closely to the SDL2 audio model.
18//!
19//! SDL also provides a simple .WAV loader in [`SDL_LoadWAV`] (and [`SDL_LoadWAV_IO`]
20//! if you aren't reading from a file) as a basic means to load sound data into
21//! your program.
22//!
23//! ## Logical audio devices
24//!
25//! In SDL3, opening a physical device (like a SoundBlaster 16 Pro) gives you a
26//! logical device ID that you can bind audio streams to. In almost all cases,
27//! logical devices can be used anywhere in the API that a physical device is
28//! normally used. However, since each device opening generates a new logical
29//! device, different parts of the program (say, a VoIP library, or
30//! text-to-speech framework, or maybe some other sort of mixer on top of SDL)
31//! can have their own device opens that do not interfere with each other; each
32//! logical device will mix its separate audio down to a single buffer, fed to
33//! the physical device, behind the scenes. As many logical devices as you like
34//! can come and go; SDL will only have to open the physical device at the OS
35//! level once, and will manage all the logical devices on top of it
36//! internally.
37//!
38//! One other benefit of logical devices: if you don't open a specific physical
39//! device, instead opting for the default, SDL can automatically migrate those
40//! logical devices to different hardware as circumstances change: a user
41//! plugged in headphones? The system default changed? SDL can transparently
42//! migrate the logical devices to the correct physical device seamlessly and
43//! keep playing; the app doesn't even have to know it happened if it doesn't
44//! want to.
45//!
46//! ## Simplified audio
47//!
48//! As a simplified model for when a single source of audio is all that's
49//! needed, an app can use [`SDL_OpenAudioDeviceStream`], which is a single
50//! function to open an audio device, create an audio stream, bind that stream
51//! to the newly-opened device, and (optionally) provide a callback for
52//! obtaining audio data. When using this function, the primary interface is
53//! the [`SDL_AudioStream`] and the device handle is mostly hidden away; destroying
54//! a stream created through this function will also close the device, stream
55//! bindings cannot be changed, etc. One other quirk of this is that the device
56//! is started in a _paused_ state and must be explicitly resumed; this is
57//! partially to offer a clean migration for SDL2 apps and partially because
58//! the app might have to do more setup before playback begins; in the
59//! non-simplified form, nothing will play until a stream is bound to a device,
60//! so they start _unpaused_.
61//!
62//! ## Channel layouts
63//!
64//! Audio data passing through SDL is uncompressed PCM data, interleaved. One
65//! can provide their own decompression through an MP3, etc, decoder, but SDL
66//! does not provide this directly. Each interleaved channel of data is meant
67//! to be in a specific order.
68//!
69//! Abbreviations:
70//!
71//! - FRONT = single mono speaker
72//! - FL = front left speaker
73//! - FR = front right speaker
74//! - FC = front center speaker
75//! - BL = back left speaker
76//! - BR = back right speaker
77//! - SR = surround right speaker
78//! - SL = surround left speaker
79//! - BC = back center speaker
80//! - LFE = low-frequency speaker
81//!
82//! These are listed in the order they are laid out in memory, so "FL, FR"
83//! means "the front left speaker is laid out in memory first, then the front
84//! right, then it repeats for the next audio frame".
85//!
86//! - 1 channel (mono) layout: FRONT
87//! - 2 channels (stereo) layout: FL, FR
88//! - 3 channels (2.1) layout: FL, FR, LFE
89//! - 4 channels (quad) layout: FL, FR, BL, BR
90//! - 5 channels (4.1) layout: FL, FR, LFE, BL, BR
91//! - 6 channels (5.1) layout: FL, FR, FC, LFE, BL, BR (last two can also be
92//!   SL, SR)
93//! - 7 channels (6.1) layout: FL, FR, FC, LFE, BC, SL, SR
94//! - 8 channels (7.1) layout: FL, FR, FC, LFE, BL, BR, SL, SR
95//!
96//! This is the same order as DirectSound expects, but applied to all
97//! platforms; SDL will swizzle the channels as necessary if a platform expects
98//! something different.
99//!
100//! [`SDL_AudioStream`] can also be provided channel maps to change this ordering
101//! to whatever is necessary, in other audio processing scenarios.
102
103use super::stdinc::*;
104
105use super::error::*;
106
107use super::mutex::*;
108
109use super::properties::*;
110
111use super::iostream::*;
112
113/// Mask of bits in an [`SDL_AudioFormat`] that contains the format bit size.
114///
115/// Generally one should use [`SDL_AUDIO_BITSIZE`] instead of this macro directly.
116///
117/// ## Availability
118/// This macro is available since SDL 3.2.0.
119pub const SDL_AUDIO_MASK_BITSIZE: ::core::primitive::u32 = 255_u32;
120
121/// Mask of bits in an [`SDL_AudioFormat`] that contain the floating point flag.
122///
123/// Generally one should use [`SDL_AUDIO_ISFLOAT`] instead of this macro directly.
124///
125/// ## Availability
126/// This macro is available since SDL 3.2.0.
127pub const SDL_AUDIO_MASK_FLOAT: ::core::primitive::u32 = 256_u32;
128
129/// Mask of bits in an [`SDL_AudioFormat`] that contain the bigendian flag.
130///
131/// Generally one should use [`SDL_AUDIO_ISBIGENDIAN`] or [`SDL_AUDIO_ISLITTLEENDIAN`]
132/// instead of this macro directly.
133///
134/// ## Availability
135/// This macro is available since SDL 3.2.0.
136pub const SDL_AUDIO_MASK_BIG_ENDIAN: ::core::primitive::u32 = 4096_u32;
137
138/// Mask of bits in an [`SDL_AudioFormat`] that contain the signed data flag.
139///
140/// Generally one should use [`SDL_AUDIO_ISSIGNED`] instead of this macro directly.
141///
142/// ## Availability
143/// This macro is available since SDL 3.2.0.
144pub const SDL_AUDIO_MASK_SIGNED: ::core::primitive::u32 = 32768_u32;
145
146/// Audio format.
147///
148/// ## Availability
149/// This enum is available since SDL 3.2.0.
150///
151/// ## See also
152/// - [`SDL_AUDIO_BITSIZE`]
153/// - [`SDL_AUDIO_BYTESIZE`]
154/// - [`SDL_AUDIO_ISINT`]
155/// - [`SDL_AUDIO_ISFLOAT`]
156/// - [`SDL_AUDIO_ISBIGENDIAN`]
157/// - [`SDL_AUDIO_ISLITTLEENDIAN`]
158/// - [`SDL_AUDIO_ISSIGNED`]
159/// - [`SDL_AUDIO_ISUNSIGNED`]
160///
161/// ## Known values (`sdl3-sys`)
162/// | Associated constant | Global constant | Description |
163/// | ------------------- | --------------- | ----------- |
164/// | [`UNKNOWN`](SDL_AudioFormat::UNKNOWN) | [`SDL_AUDIO_UNKNOWN`] | Unspecified audio format |
165/// | [`U8`](SDL_AudioFormat::U8) | [`SDL_AUDIO_U8`] | Unsigned 8-bit samples |
166/// | [`S8`](SDL_AudioFormat::S8) | [`SDL_AUDIO_S8`] | Signed 8-bit samples |
167/// | [`S16LE`](SDL_AudioFormat::S16LE) | [`SDL_AUDIO_S16LE`] | Signed 16-bit samples |
168/// | [`S16BE`](SDL_AudioFormat::S16BE) | [`SDL_AUDIO_S16BE`] | As above, but big-endian byte order |
169/// | [`S32LE`](SDL_AudioFormat::S32LE) | [`SDL_AUDIO_S32LE`] | 32-bit integer samples |
170/// | [`S32BE`](SDL_AudioFormat::S32BE) | [`SDL_AUDIO_S32BE`] | As above, but big-endian byte order |
171/// | [`F32LE`](SDL_AudioFormat::F32LE) | [`SDL_AUDIO_F32LE`] | 32-bit floating point samples |
172/// | [`F32BE`](SDL_AudioFormat::F32BE) | [`SDL_AUDIO_F32BE`] | As above, but big-endian byte order |
173/// | [`S16`](SDL_AudioFormat::S16) | [`SDL_AUDIO_S16`] | (target dependent) |
174/// | [`S32`](SDL_AudioFormat::S32) | [`SDL_AUDIO_S32`] | (target dependent) |
175/// | [`F32`](SDL_AudioFormat::F32) | [`SDL_AUDIO_F32`] | (target dependent) |
176#[repr(transparent)]
177#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
178pub struct SDL_AudioFormat(pub ::core::ffi::c_uint);
179
180impl ::core::cmp::PartialEq<::core::ffi::c_uint> for SDL_AudioFormat {
181    #[inline(always)]
182    fn eq(&self, other: &::core::ffi::c_uint) -> bool {
183        &self.0 == other
184    }
185}
186
187impl ::core::cmp::PartialEq<SDL_AudioFormat> for ::core::ffi::c_uint {
188    #[inline(always)]
189    fn eq(&self, other: &SDL_AudioFormat) -> bool {
190        self == &other.0
191    }
192}
193
194impl From<SDL_AudioFormat> for ::core::ffi::c_uint {
195    #[inline(always)]
196    fn from(value: SDL_AudioFormat) -> Self {
197        value.0
198    }
199}
200
201#[cfg(feature = "debug-impls")]
202impl ::core::fmt::Debug for SDL_AudioFormat {
203    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
204        #[allow(unreachable_patterns)]
205        f.write_str(match *self {
206            Self::UNKNOWN => "SDL_AUDIO_UNKNOWN",
207            Self::U8 => "SDL_AUDIO_U8",
208            Self::S8 => "SDL_AUDIO_S8",
209            Self::S16LE => "SDL_AUDIO_S16LE",
210            Self::S16BE => "SDL_AUDIO_S16BE",
211            Self::S32LE => "SDL_AUDIO_S32LE",
212            Self::S32BE => "SDL_AUDIO_S32BE",
213            Self::F32LE => "SDL_AUDIO_F32LE",
214            Self::F32BE => "SDL_AUDIO_F32BE",
215            Self::S16 => "SDL_AUDIO_S16",
216            Self::S32 => "SDL_AUDIO_S32",
217            Self::F32 => "SDL_AUDIO_F32",
218            Self::S16 => "SDL_AUDIO_S16",
219            Self::S32 => "SDL_AUDIO_S32",
220            Self::F32 => "SDL_AUDIO_F32",
221
222            _ => return write!(f, "SDL_AudioFormat({})", self.0),
223        })
224    }
225}
226
227impl SDL_AudioFormat {
228    /// Unspecified audio format
229    pub const UNKNOWN: Self = Self((0x0000 as ::core::ffi::c_uint));
230    /// Unsigned 8-bit samples
231    pub const U8: Self = Self((0x0008 as ::core::ffi::c_uint));
232    /// Signed 8-bit samples
233    pub const S8: Self = Self((0x8008 as ::core::ffi::c_uint));
234    /// Signed 16-bit samples
235    pub const S16LE: Self = Self((0x8010 as ::core::ffi::c_uint));
236    /// As above, but big-endian byte order
237    pub const S16BE: Self = Self((0x9010 as ::core::ffi::c_uint));
238    /// 32-bit integer samples
239    pub const S32LE: Self = Self((0x8020 as ::core::ffi::c_uint));
240    /// As above, but big-endian byte order
241    pub const S32BE: Self = Self((0x9020 as ::core::ffi::c_uint));
242    /// 32-bit floating point samples
243    pub const F32LE: Self = Self((0x8120 as ::core::ffi::c_uint));
244    /// As above, but big-endian byte order
245    pub const F32BE: Self = Self((0x9120 as ::core::ffi::c_uint));
246    #[cfg(target_endian = "little")]
247    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
248    pub const S16: Self = SDL_AUDIO_S16LE;
249    #[cfg(target_endian = "little")]
250    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
251    pub const S32: Self = SDL_AUDIO_S32LE;
252    #[cfg(target_endian = "little")]
253    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
254    pub const F32: Self = SDL_AUDIO_F32LE;
255    #[cfg(not(target_endian = "little"))]
256    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
257    pub const S16: Self = SDL_AUDIO_S16BE;
258    #[cfg(not(target_endian = "little"))]
259    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
260    pub const S32: Self = SDL_AUDIO_S32BE;
261    #[cfg(not(target_endian = "little"))]
262    #[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
263    pub const F32: Self = SDL_AUDIO_F32BE;
264}
265
266/// Unspecified audio format
267pub const SDL_AUDIO_UNKNOWN: SDL_AudioFormat = SDL_AudioFormat::UNKNOWN;
268/// Unsigned 8-bit samples
269pub const SDL_AUDIO_U8: SDL_AudioFormat = SDL_AudioFormat::U8;
270/// Signed 8-bit samples
271pub const SDL_AUDIO_S8: SDL_AudioFormat = SDL_AudioFormat::S8;
272/// Signed 16-bit samples
273pub const SDL_AUDIO_S16LE: SDL_AudioFormat = SDL_AudioFormat::S16LE;
274/// As above, but big-endian byte order
275pub const SDL_AUDIO_S16BE: SDL_AudioFormat = SDL_AudioFormat::S16BE;
276/// 32-bit integer samples
277pub const SDL_AUDIO_S32LE: SDL_AudioFormat = SDL_AudioFormat::S32LE;
278/// As above, but big-endian byte order
279pub const SDL_AUDIO_S32BE: SDL_AudioFormat = SDL_AudioFormat::S32BE;
280/// 32-bit floating point samples
281pub const SDL_AUDIO_F32LE: SDL_AudioFormat = SDL_AudioFormat::F32LE;
282/// As above, but big-endian byte order
283pub const SDL_AUDIO_F32BE: SDL_AudioFormat = SDL_AudioFormat::F32BE;
284#[cfg(target_endian = "little")]
285#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
286pub const SDL_AUDIO_S16: SDL_AudioFormat = SDL_AudioFormat::S16;
287#[cfg(target_endian = "little")]
288#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
289pub const SDL_AUDIO_S32: SDL_AudioFormat = SDL_AudioFormat::S32;
290#[cfg(target_endian = "little")]
291#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
292pub const SDL_AUDIO_F32: SDL_AudioFormat = SDL_AudioFormat::F32;
293#[cfg(not(target_endian = "little"))]
294#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
295pub const SDL_AUDIO_S16: SDL_AudioFormat = SDL_AudioFormat::S16;
296#[cfg(not(target_endian = "little"))]
297#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
298pub const SDL_AUDIO_S32: SDL_AudioFormat = SDL_AudioFormat::S32;
299#[cfg(not(target_endian = "little"))]
300#[cfg_attr(all(feature = "nightly", doc), doc(cfg(all())))]
301pub const SDL_AUDIO_F32: SDL_AudioFormat = SDL_AudioFormat::F32;
302
303impl SDL_AudioFormat {
304    /// Initialize a `SDL_AudioFormat` from a raw value.
305    #[inline(always)]
306    pub const fn new(value: ::core::ffi::c_uint) -> Self {
307        Self(value)
308    }
309}
310
311impl SDL_AudioFormat {
312    /// Get a copy of the inner raw value.
313    #[inline(always)]
314    pub const fn value(&self) -> ::core::ffi::c_uint {
315        self.0
316    }
317}
318
319#[cfg(feature = "metadata")]
320impl sdl3_sys::metadata::GroupMetadata for SDL_AudioFormat {
321    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
322        &crate::metadata::audio::METADATA_SDL_AudioFormat;
323}
324
325/// Define an [`SDL_AudioFormat`] value.
326///
327/// SDL does not support custom audio formats, so this macro is not of much use
328/// externally, but it can be illustrative as to what the various bits of an
329/// [`SDL_AudioFormat`] mean.
330///
331/// For example, [`SDL_AUDIO_S32LE`] looks like this:
332///
333/// ```c
334/// SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32)
335/// ```
336///
337/// ## Parameters
338/// - `signed`: 1 for signed data, 0 for unsigned data.
339/// - `bigendian`: 1 for bigendian data, 0 for littleendian data.
340/// - `flt`: 1 for floating point data, 0 for integer data.
341/// - `size`: number of bits per sample.
342///
343/// ## Return value
344/// Returns a format value in the style of [`SDL_AudioFormat`].
345///
346/// ## Thread safety
347/// It is safe to call this macro from any thread.
348///
349/// ## Availability
350/// This macro is available since SDL 3.2.0.
351#[inline(always)]
352pub const fn SDL_DEFINE_AUDIO_FORMAT(
353    signed_: ::core::primitive::bool,
354    bigendian: ::core::primitive::bool,
355    flt: ::core::primitive::bool,
356    size: ::core::primitive::u8,
357) -> SDL_AudioFormat {
358    SDL_AudioFormat(
359        ((((((((signed_) as Uint16) << 15) | (((bigendian) as Uint16) << 12))
360            | (((flt) as Uint16) << 8)) as ::core::primitive::u32)
361            | (((size as ::core::ffi::c_int) as ::core::primitive::u32) & SDL_AUDIO_MASK_BITSIZE))
362            as ::core::ffi::c_uint),
363    )
364}
365
366/// Retrieve the size, in bits, from an [`SDL_AudioFormat`].
367///
368/// For example, `SDL_AUDIO_BITSIZE(SDL_AUDIO_S16)` returns 16.
369///
370/// ## Parameters
371/// - `x`: an [`SDL_AudioFormat`] value.
372///
373/// ## Return value
374/// Returns data size in bits.
375///
376/// ## Thread safety
377/// It is safe to call this macro from any thread.
378///
379/// ## Availability
380/// This macro is available since SDL 3.2.0.
381#[inline(always)]
382pub const fn SDL_AUDIO_BITSIZE(x: SDL_AudioFormat) -> ::core::ffi::c_uint {
383    (x.0 & SDL_AUDIO_MASK_BITSIZE)
384}
385
386/// Retrieve the size, in bytes, from an [`SDL_AudioFormat`].
387///
388/// For example, `SDL_AUDIO_BYTESIZE(SDL_AUDIO_S16)` returns 2.
389///
390/// ## Parameters
391/// - `x`: an [`SDL_AudioFormat`] value.
392///
393/// ## Return value
394/// Returns data size in bytes.
395///
396/// ## Thread safety
397/// It is safe to call this macro from any thread.
398///
399/// ## Availability
400/// This macro is available since SDL 3.2.0.
401#[inline(always)]
402pub const fn SDL_AUDIO_BYTESIZE(x: SDL_AudioFormat) -> ::core::ffi::c_uint {
403    (SDL_AUDIO_BITSIZE(x) / 8_u32)
404}
405
406/// Determine if an [`SDL_AudioFormat`] represents floating point data.
407///
408/// For example, `SDL_AUDIO_ISFLOAT(SDL_AUDIO_S16)` returns 0.
409///
410/// ## Parameters
411/// - `x`: an [`SDL_AudioFormat`] value.
412///
413/// ## Return value
414/// Returns non-zero if format is floating point, zero otherwise.
415///
416/// ## Thread safety
417/// It is safe to call this macro from any thread.
418///
419/// ## Availability
420/// This macro is available since SDL 3.2.0.
421#[inline(always)]
422pub const fn SDL_AUDIO_ISFLOAT(x: SDL_AudioFormat) -> ::core::primitive::bool {
423    ((x.0 & SDL_AUDIO_MASK_FLOAT) != 0)
424}
425
426/// Determine if an [`SDL_AudioFormat`] represents bigendian data.
427///
428/// For example, `SDL_AUDIO_ISBIGENDIAN(SDL_AUDIO_S16LE)` returns 0.
429///
430/// ## Parameters
431/// - `x`: an [`SDL_AudioFormat`] value.
432///
433/// ## Return value
434/// Returns non-zero if format is bigendian, zero otherwise.
435///
436/// ## Thread safety
437/// It is safe to call this macro from any thread.
438///
439/// ## Availability
440/// This macro is available since SDL 3.2.0.
441#[inline(always)]
442pub const fn SDL_AUDIO_ISBIGENDIAN(x: SDL_AudioFormat) -> ::core::primitive::bool {
443    ((x.0 & SDL_AUDIO_MASK_BIG_ENDIAN) != 0)
444}
445
446/// Determine if an [`SDL_AudioFormat`] represents littleendian data.
447///
448/// For example, `SDL_AUDIO_ISLITTLEENDIAN(SDL_AUDIO_S16BE)` returns 0.
449///
450/// ## Parameters
451/// - `x`: an [`SDL_AudioFormat`] value.
452///
453/// ## Return value
454/// Returns non-zero if format is littleendian, zero otherwise.
455///
456/// ## Thread safety
457/// It is safe to call this macro from any thread.
458///
459/// ## Availability
460/// This macro is available since SDL 3.2.0.
461#[inline(always)]
462pub const fn SDL_AUDIO_ISLITTLEENDIAN(x: SDL_AudioFormat) -> ::core::primitive::bool {
463    !(SDL_AUDIO_ISBIGENDIAN(x))
464}
465
466/// Determine if an [`SDL_AudioFormat`] represents signed data.
467///
468/// For example, `SDL_AUDIO_ISSIGNED(SDL_AUDIO_U8)` returns 0.
469///
470/// ## Parameters
471/// - `x`: an [`SDL_AudioFormat`] value.
472///
473/// ## Return value
474/// Returns non-zero if format is signed, zero otherwise.
475///
476/// ## Thread safety
477/// It is safe to call this macro from any thread.
478///
479/// ## Availability
480/// This macro is available since SDL 3.2.0.
481#[inline(always)]
482pub const fn SDL_AUDIO_ISSIGNED(x: SDL_AudioFormat) -> ::core::primitive::bool {
483    ((x.0 & SDL_AUDIO_MASK_SIGNED) != 0)
484}
485
486/// Determine if an [`SDL_AudioFormat`] represents integer data.
487///
488/// For example, `SDL_AUDIO_ISINT(SDL_AUDIO_F32)` returns 0.
489///
490/// ## Parameters
491/// - `x`: an [`SDL_AudioFormat`] value.
492///
493/// ## Return value
494/// Returns non-zero if format is integer, zero otherwise.
495///
496/// ## Thread safety
497/// It is safe to call this macro from any thread.
498///
499/// ## Availability
500/// This macro is available since SDL 3.2.0.
501#[inline(always)]
502pub const fn SDL_AUDIO_ISINT(x: SDL_AudioFormat) -> ::core::primitive::bool {
503    !(SDL_AUDIO_ISFLOAT(x))
504}
505
506/// Determine if an [`SDL_AudioFormat`] represents unsigned data.
507///
508/// For example, `SDL_AUDIO_ISUNSIGNED(SDL_AUDIO_S16)` returns 0.
509///
510/// ## Parameters
511/// - `x`: an [`SDL_AudioFormat`] value.
512///
513/// ## Return value
514/// Returns non-zero if format is unsigned, zero otherwise.
515///
516/// ## Thread safety
517/// It is safe to call this macro from any thread.
518///
519/// ## Availability
520/// This macro is available since SDL 3.2.0.
521#[inline(always)]
522pub const fn SDL_AUDIO_ISUNSIGNED(x: SDL_AudioFormat) -> ::core::primitive::bool {
523    !(SDL_AUDIO_ISSIGNED(x))
524}
525
526/// SDL Audio Device instance IDs.
527///
528/// Zero is used to signify an invalid/null device.
529///
530/// ## Availability
531/// This datatype is available since SDL 3.2.0.
532///
533/// ## Known values (`sdl3-sys`)
534/// | Associated constant | Global constant | Description |
535/// | ------------------- | --------------- | ----------- |
536/// | [`DEFAULT_PLAYBACK`](SDL_AudioDeviceID::DEFAULT_PLAYBACK) | [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`] | A value used to request a default playback audio device.  Several functions that require an [`SDL_AudioDeviceID`] will accept this value to signify the app just wants the system to choose a default device instead of the app providing a specific one.  \since This macro is available since SDL 3.2.0. |
537/// | [`DEFAULT_RECORDING`](SDL_AudioDeviceID::DEFAULT_RECORDING) | [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`] | A value used to request a default recording audio device.  Several functions that require an [`SDL_AudioDeviceID`] will accept this value to signify the app just wants the system to choose a default device instead of the app providing a specific one.  \since This macro is available since SDL 3.2.0. |
538#[repr(transparent)]
539#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
540pub struct SDL_AudioDeviceID(pub Uint32);
541
542impl ::core::cmp::PartialEq<Uint32> for SDL_AudioDeviceID {
543    #[inline(always)]
544    fn eq(&self, other: &Uint32) -> bool {
545        &self.0 == other
546    }
547}
548
549impl ::core::cmp::PartialEq<SDL_AudioDeviceID> for Uint32 {
550    #[inline(always)]
551    fn eq(&self, other: &SDL_AudioDeviceID) -> bool {
552        self == &other.0
553    }
554}
555
556impl From<SDL_AudioDeviceID> for Uint32 {
557    #[inline(always)]
558    fn from(value: SDL_AudioDeviceID) -> Self {
559        value.0
560    }
561}
562
563#[cfg(feature = "display-impls")]
564impl ::core::fmt::Display for SDL_AudioDeviceID {
565    #[inline(always)]
566    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
567        <Uint32 as ::core::fmt::Display>::fmt(&self.0, f)
568    }
569}
570
571#[cfg(feature = "debug-impls")]
572impl ::core::fmt::Debug for SDL_AudioDeviceID {
573    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
574        #[allow(unreachable_patterns)]
575        f.write_str(match *self {
576            Self::DEFAULT_PLAYBACK => "SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK",
577            Self::DEFAULT_RECORDING => "SDL_AUDIO_DEVICE_DEFAULT_RECORDING",
578
579            _ => return write!(f, "SDL_AudioDeviceID({})", self.0),
580        })
581    }
582}
583
584impl SDL_AudioDeviceID {
585    /// A value used to request a default playback audio device.
586    ///
587    /// Several functions that require an [`SDL_AudioDeviceID`] will accept this value
588    /// to signify the app just wants the system to choose a default device instead
589    /// of the app providing a specific one.
590    ///
591    /// ## Availability
592    /// This macro is available since SDL 3.2.0.
593    pub const DEFAULT_PLAYBACK: Self = Self((0xffffffff as Uint32));
594    /// A value used to request a default recording audio device.
595    ///
596    /// Several functions that require an [`SDL_AudioDeviceID`] will accept this value
597    /// to signify the app just wants the system to choose a default device instead
598    /// of the app providing a specific one.
599    ///
600    /// ## Availability
601    /// This macro is available since SDL 3.2.0.
602    pub const DEFAULT_RECORDING: Self = Self((0xfffffffe as Uint32));
603}
604
605/// A value used to request a default playback audio device.
606///
607/// Several functions that require an [`SDL_AudioDeviceID`] will accept this value
608/// to signify the app just wants the system to choose a default device instead
609/// of the app providing a specific one.
610///
611/// ## Availability
612/// This macro is available since SDL 3.2.0.
613pub const SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK: SDL_AudioDeviceID =
614    SDL_AudioDeviceID::DEFAULT_PLAYBACK;
615/// A value used to request a default recording audio device.
616///
617/// Several functions that require an [`SDL_AudioDeviceID`] will accept this value
618/// to signify the app just wants the system to choose a default device instead
619/// of the app providing a specific one.
620///
621/// ## Availability
622/// This macro is available since SDL 3.2.0.
623pub const SDL_AUDIO_DEVICE_DEFAULT_RECORDING: SDL_AudioDeviceID =
624    SDL_AudioDeviceID::DEFAULT_RECORDING;
625
626impl SDL_AudioDeviceID {
627    /// Initialize a `SDL_AudioDeviceID` from a raw value.
628    #[inline(always)]
629    pub const fn new(value: Uint32) -> Self {
630        Self(value)
631    }
632}
633
634impl SDL_AudioDeviceID {
635    /// Get a copy of the inner raw value.
636    #[inline(always)]
637    pub const fn value(&self) -> Uint32 {
638        self.0
639    }
640}
641
642#[cfg(feature = "metadata")]
643impl sdl3_sys::metadata::GroupMetadata for SDL_AudioDeviceID {
644    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
645        &crate::metadata::audio::METADATA_SDL_AudioDeviceID;
646}
647
648/// Format specifier for audio data.
649///
650/// ## Availability
651/// This struct is available since SDL 3.2.0.
652///
653/// ## See also
654/// - [`SDL_AudioFormat`]
655#[repr(C)]
656#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
657#[cfg_attr(feature = "debug-impls", derive(Debug))]
658pub struct SDL_AudioSpec {
659    /// Audio data format
660    pub format: SDL_AudioFormat,
661    /// Number of channels: 1 mono, 2 stereo, etc
662    pub channels: ::core::ffi::c_int,
663    /// sample rate: sample frames per second
664    pub freq: ::core::ffi::c_int,
665}
666
667/// Calculate the size of each audio frame (in bytes) from an [`SDL_AudioSpec`].
668///
669/// This reports on the size of an audio sample frame: stereo Sint16 data (2
670/// channels of 2 bytes each) would be 4 bytes per frame, for example.
671///
672/// ## Parameters
673/// - `x`: an [`SDL_AudioSpec`] to query.
674///
675/// ## Return value
676/// Returns the number of bytes used per sample frame.
677///
678/// ## Thread safety
679/// It is safe to call this macro from any thread.
680///
681/// ## Availability
682/// This macro is available since SDL 3.2.0.
683#[inline(always)]
684pub const fn SDL_AUDIO_FRAMESIZE(x: SDL_AudioSpec) -> ::core::ffi::c_uint {
685    (SDL_AUDIO_BYTESIZE(x.format) * (x.channels as ::core::ffi::c_uint))
686}
687
688unsafe extern "C" {
689    /// Use this function to get the number of built-in audio drivers.
690    ///
691    /// This function returns a hardcoded number. This never returns a negative
692    /// value; if there are no drivers compiled into this build of SDL, this
693    /// function returns zero. The presence of a driver in this list does not mean
694    /// it will function, it just means SDL is capable of interacting with that
695    /// interface. For example, a build of SDL might have esound support, but if
696    /// there's no esound server available, SDL's esound driver would fail if used.
697    ///
698    /// By default, SDL tries all drivers, in its preferred order, until one is
699    /// found to be usable.
700    ///
701    /// ## Return value
702    /// Returns the number of built-in audio drivers.
703    ///
704    /// ## Thread safety
705    /// It is safe to call this function from any thread.
706    ///
707    /// ## Availability
708    /// This function is available since SDL 3.2.0.
709    ///
710    /// ## See also
711    /// - [`SDL_GetAudioDriver`]
712    pub fn SDL_GetNumAudioDrivers() -> ::core::ffi::c_int;
713}
714
715unsafe extern "C" {
716    /// Use this function to get the name of a built in audio driver.
717    ///
718    /// The list of audio drivers is given in the order that they are normally
719    /// initialized by default; the drivers that seem more reasonable to choose
720    /// first (as far as the SDL developers believe) are earlier in the list.
721    ///
722    /// The names of drivers are all simple, low-ASCII identifiers, like "alsa",
723    /// "coreaudio" or "wasapi". These never have Unicode characters, and are not
724    /// meant to be proper names.
725    ///
726    /// ## Parameters
727    /// - `index`: the index of the audio driver; the value ranges from 0 to
728    ///   [`SDL_GetNumAudioDrivers()`] - 1.
729    ///
730    /// ## Return value
731    /// Returns the name of the audio driver at the requested index, or NULL if an
732    ///   invalid index was specified.
733    ///
734    /// ## Thread safety
735    /// It is safe to call this function from any thread.
736    ///
737    /// ## Availability
738    /// This function is available since SDL 3.2.0.
739    ///
740    /// ## See also
741    /// - [`SDL_GetNumAudioDrivers`]
742    pub fn SDL_GetAudioDriver(index: ::core::ffi::c_int) -> *const ::core::ffi::c_char;
743}
744
745unsafe extern "C" {
746    /// Get the name of the current audio driver.
747    ///
748    /// The names of drivers are all simple, low-ASCII identifiers, like "alsa",
749    /// "coreaudio" or "wasapi". These never have Unicode characters, and are not
750    /// meant to be proper names.
751    ///
752    /// ## Return value
753    /// Returns the name of the current audio driver or NULL if no driver has been
754    ///   initialized.
755    ///
756    /// ## Thread safety
757    /// It is safe to call this function from any thread.
758    ///
759    /// ## Availability
760    /// This function is available since SDL 3.2.0.
761    pub fn SDL_GetCurrentAudioDriver() -> *const ::core::ffi::c_char;
762}
763
764unsafe extern "C" {
765    /// Get a list of currently-connected audio playback devices.
766    ///
767    /// This returns of list of available devices that play sound, perhaps to
768    /// speakers or headphones ("playback" devices). If you want devices that
769    /// record audio, like a microphone ("recording" devices), use
770    /// [`SDL_GetAudioRecordingDevices()`] instead.
771    ///
772    /// This only returns a list of physical devices; it will not have any device
773    /// IDs returned by [`SDL_OpenAudioDevice()`].
774    ///
775    /// If this function returns NULL, to signify an error, `*count` will be set to
776    /// zero.
777    ///
778    /// ## Parameters
779    /// - `count`: a pointer filled in with the number of devices returned, may
780    ///   be NULL.
781    ///
782    /// ## Return value
783    /// Returns a 0 terminated array of device instance IDs or NULL on error; call
784    ///   [`SDL_GetError()`] for more information. This should be freed with
785    ///   [`SDL_free()`] when it is no longer needed.
786    ///
787    /// ## Thread safety
788    /// It is safe to call this function from any thread.
789    ///
790    /// ## Availability
791    /// This function is available since SDL 3.2.0.
792    ///
793    /// ## See also
794    /// - [`SDL_OpenAudioDevice`]
795    /// - [`SDL_GetAudioRecordingDevices`]
796    pub fn SDL_GetAudioPlaybackDevices(count: *mut ::core::ffi::c_int) -> *mut SDL_AudioDeviceID;
797}
798
799unsafe extern "C" {
800    /// Get a list of currently-connected audio recording devices.
801    ///
802    /// This returns of list of available devices that record audio, like a
803    /// microphone ("recording" devices). If you want devices that play sound,
804    /// perhaps to speakers or headphones ("playback" devices), use
805    /// [`SDL_GetAudioPlaybackDevices()`] instead.
806    ///
807    /// This only returns a list of physical devices; it will not have any device
808    /// IDs returned by [`SDL_OpenAudioDevice()`].
809    ///
810    /// If this function returns NULL, to signify an error, `*count` will be set to
811    /// zero.
812    ///
813    /// ## Parameters
814    /// - `count`: a pointer filled in with the number of devices returned, may
815    ///   be NULL.
816    ///
817    /// ## Return value
818    /// Returns a 0 terminated array of device instance IDs, or NULL on failure;
819    ///   call [`SDL_GetError()`] for more information. This should be freed
820    ///   with [`SDL_free()`] when it is no longer needed.
821    ///
822    /// ## Thread safety
823    /// It is safe to call this function from any thread.
824    ///
825    /// ## Availability
826    /// This function is available since SDL 3.2.0.
827    ///
828    /// ## See also
829    /// - [`SDL_OpenAudioDevice`]
830    /// - [`SDL_GetAudioPlaybackDevices`]
831    pub fn SDL_GetAudioRecordingDevices(count: *mut ::core::ffi::c_int) -> *mut SDL_AudioDeviceID;
832}
833
834unsafe extern "C" {
835    /// Get the human-readable name of a specific audio device.
836    ///
837    /// **WARNING**: this function will work with [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`]
838    /// and [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`], returning the current default
839    /// physical devices' names. However, as the default device may change at any
840    /// time, it is likely better to show a generic name to the user, like "System
841    /// default audio device" or perhaps "default \[currently %s\]". Do not store
842    /// this name to disk to reidentify the device in a later run of the program,
843    /// as the default might change in general, and the string will be the name of
844    /// a specific device and not the abstract system default.
845    ///
846    /// ## Parameters
847    /// - `devid`: the instance ID of the device to query.
848    ///
849    /// ## Return value
850    /// Returns the name of the audio device, or NULL on failure; call
851    ///   [`SDL_GetError()`] for more information.
852    ///
853    /// ## Thread safety
854    /// It is safe to call this function from any thread.
855    ///
856    /// ## Availability
857    /// This function is available since SDL 3.2.0.
858    ///
859    /// ## See also
860    /// - [`SDL_GetAudioPlaybackDevices`]
861    /// - [`SDL_GetAudioRecordingDevices`]
862    pub fn SDL_GetAudioDeviceName(devid: SDL_AudioDeviceID) -> *const ::core::ffi::c_char;
863}
864
865unsafe extern "C" {
866    /// Get the current audio format of a specific audio device.
867    ///
868    /// For an opened device, this will report the format the device is currently
869    /// using. If the device isn't yet opened, this will report the device's
870    /// preferred format (or a reasonable default if this can't be determined).
871    ///
872    /// You may also specify [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`] or
873    /// [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`] here, which is useful for getting a
874    /// reasonable recommendation before opening the system-recommended default
875    /// device.
876    ///
877    /// You can also use this to request the current device buffer size. This is
878    /// specified in sample frames and represents the amount of data SDL will feed
879    /// to the physical hardware in each chunk. This can be converted to
880    /// milliseconds of audio with the following equation:
881    ///
882    /// `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);`
883    ///
884    /// Buffer size is only important if you need low-level control over the audio
885    /// playback timing. Most apps do not need this.
886    ///
887    /// ## Parameters
888    /// - `devid`: the instance ID of the device to query.
889    /// - `spec`: on return, will be filled with device details.
890    /// - `sample_frames`: pointer to store device buffer size, in sample frames.
891    ///   Can be NULL.
892    ///
893    /// ## Return value
894    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
895    ///   information.
896    ///
897    /// ## Thread safety
898    /// It is safe to call this function from any thread.
899    ///
900    /// ## Availability
901    /// This function is available since SDL 3.2.0.
902    pub fn SDL_GetAudioDeviceFormat(
903        devid: SDL_AudioDeviceID,
904        spec: *mut SDL_AudioSpec,
905        sample_frames: *mut ::core::ffi::c_int,
906    ) -> ::core::primitive::bool;
907}
908
909unsafe extern "C" {
910    /// Get the current channel map of an audio device.
911    ///
912    /// Channel maps are optional; most things do not need them, instead passing
913    /// data in the [order that SDL expects](CategoryAudio#channel-layouts).
914    ///
915    /// Audio devices usually have no remapping applied. This is represented by
916    /// returning NULL, and does not signify an error.
917    ///
918    /// ## Parameters
919    /// - `devid`: the instance ID of the device to query.
920    /// - `count`: On output, set to number of channels in the map. Can be NULL.
921    ///
922    /// ## Return value
923    /// Returns an array of the current channel mapping, with as many elements as
924    ///   the current output spec's channels, or NULL if default. This
925    ///   should be freed with [`SDL_free()`] when it is no longer needed.
926    ///
927    /// ## Thread safety
928    /// It is safe to call this function from any thread.
929    ///
930    /// ## Availability
931    /// This function is available since SDL 3.2.0.
932    ///
933    /// ## See also
934    /// - [`SDL_SetAudioStreamInputChannelMap`]
935    pub fn SDL_GetAudioDeviceChannelMap(
936        devid: SDL_AudioDeviceID,
937        count: *mut ::core::ffi::c_int,
938    ) -> *mut ::core::ffi::c_int;
939}
940
941unsafe extern "C" {
942    /// Open a specific audio device.
943    ///
944    /// You can open both playback and recording devices through this function.
945    /// Playback devices will take data from bound audio streams, mix it, and send
946    /// it to the hardware. Recording devices will feed any bound audio streams
947    /// with a copy of any incoming data.
948    ///
949    /// An opened audio device starts out with no audio streams bound. To start
950    /// audio playing, bind a stream and supply audio data to it. Unlike SDL2,
951    /// there is no audio callback; you only bind audio streams and make sure they
952    /// have data flowing into them (however, you can simulate SDL2's semantics
953    /// fairly closely by using [`SDL_OpenAudioDeviceStream`] instead of this
954    /// function).
955    ///
956    /// If you don't care about opening a specific device, pass a `devid` of either
957    /// [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`] or
958    /// [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`]. In this case, SDL will try to pick
959    /// the most reasonable default, and may also switch between physical devices
960    /// seamlessly later, if the most reasonable default changes during the
961    /// lifetime of this opened device (user changed the default in the OS's system
962    /// preferences, the default got unplugged so the system jumped to a new
963    /// default, the user plugged in headphones on a mobile device, etc). Unless
964    /// you have a good reason to choose a specific device, this is probably what
965    /// you want.
966    ///
967    /// You may request a specific format for the audio device, but there is no
968    /// promise the device will honor that request for several reasons. As such,
969    /// it's only meant to be a hint as to what data your app will provide. Audio
970    /// streams will accept data in whatever format you specify and manage
971    /// conversion for you as appropriate. [`SDL_GetAudioDeviceFormat`] can tell you
972    /// the preferred format for the device before opening and the actual format
973    /// the device is using after opening.
974    ///
975    /// It's legal to open the same device ID more than once; each successful open
976    /// will generate a new logical [`SDL_AudioDeviceID`] that is managed separately
977    /// from others on the same physical device. This allows libraries to open a
978    /// device separately from the main app and bind its own streams without
979    /// conflicting.
980    ///
981    /// It is also legal to open a device ID returned by a previous call to this
982    /// function; doing so just creates another logical device on the same physical
983    /// device. This may be useful for making logical groupings of audio streams.
984    ///
985    /// This function returns the opened device ID on success. This is a new,
986    /// unique [`SDL_AudioDeviceID`] that represents a logical device.
987    ///
988    /// Some backends might offer arbitrary devices (for example, a networked audio
989    /// protocol that can connect to an arbitrary server). For these, as a change
990    /// from SDL2, you should open a default device ID and use an SDL hint to
991    /// specify the target if you care, or otherwise let the backend figure out a
992    /// reasonable default. Most backends don't offer anything like this, and often
993    /// this would be an end user setting an environment variable for their custom
994    /// need, and not something an application should specifically manage.
995    ///
996    /// When done with an audio device, possibly at the end of the app's life, one
997    /// should call [`SDL_CloseAudioDevice()`] on the returned device id.
998    ///
999    /// ## Parameters
1000    /// - `devid`: the device instance id to open, or
1001    ///   [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`] or
1002    ///   [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`] for the most reasonable
1003    ///   default device.
1004    /// - `spec`: the requested device configuration. Can be NULL to use
1005    ///   reasonable defaults.
1006    ///
1007    /// ## Return value
1008    /// Returns the device ID on success or 0 on failure; call [`SDL_GetError()`] for
1009    ///   more information.
1010    ///
1011    /// ## Thread safety
1012    /// It is safe to call this function from any thread.
1013    ///
1014    /// ## Availability
1015    /// This function is available since SDL 3.2.0.
1016    ///
1017    /// ## See also
1018    /// - [`SDL_CloseAudioDevice`]
1019    /// - [`SDL_GetAudioDeviceFormat`]
1020    pub fn SDL_OpenAudioDevice(
1021        devid: SDL_AudioDeviceID,
1022        spec: *const SDL_AudioSpec,
1023    ) -> SDL_AudioDeviceID;
1024}
1025
1026unsafe extern "C" {
1027    /// Determine if an audio device is physical (instead of logical).
1028    ///
1029    /// An [`SDL_AudioDeviceID`] that represents physical hardware is a physical
1030    /// device; there is one for each piece of hardware that SDL can see. Logical
1031    /// devices are created by calling [`SDL_OpenAudioDevice`] or
1032    /// [`SDL_OpenAudioDeviceStream`], and while each is associated with a physical
1033    /// device, there can be any number of logical devices on one physical device.
1034    ///
1035    /// For the most part, logical and physical IDs are interchangeable--if you try
1036    /// to open a logical device, SDL understands to assign that effort to the
1037    /// underlying physical device, etc. However, it might be useful to know if an
1038    /// arbitrary device ID is physical or logical. This function reports which.
1039    ///
1040    /// This function may return either true or false for invalid device IDs.
1041    ///
1042    /// ## Parameters
1043    /// - `devid`: the device ID to query.
1044    ///
1045    /// ## Return value
1046    /// Returns true if devid is a physical device, false if it is logical.
1047    ///
1048    /// ## Thread safety
1049    /// It is safe to call this function from any thread.
1050    ///
1051    /// ## Availability
1052    /// This function is available since SDL 3.2.0.
1053    pub safe fn SDL_IsAudioDevicePhysical(devid: SDL_AudioDeviceID) -> ::core::primitive::bool;
1054}
1055
1056unsafe extern "C" {
1057    /// Determine if an audio device is a playback device (instead of recording).
1058    ///
1059    /// This function may return either true or false for invalid device IDs.
1060    ///
1061    /// ## Parameters
1062    /// - `devid`: the device ID to query.
1063    ///
1064    /// ## Return value
1065    /// Returns true if devid is a playback device, false if it is recording.
1066    ///
1067    /// ## Thread safety
1068    /// It is safe to call this function from any thread.
1069    ///
1070    /// ## Availability
1071    /// This function is available since SDL 3.2.0.
1072    pub safe fn SDL_IsAudioDevicePlayback(devid: SDL_AudioDeviceID) -> ::core::primitive::bool;
1073}
1074
1075unsafe extern "C" {
1076    /// Use this function to pause audio playback on a specified device.
1077    ///
1078    /// This function pauses audio processing for a given device. Any bound audio
1079    /// streams will not progress, and no audio will be generated. Pausing one
1080    /// device does not prevent other unpaused devices from running.
1081    ///
1082    /// Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
1083    /// has to bind a stream before any audio will flow. Pausing a paused device is
1084    /// a legal no-op.
1085    ///
1086    /// Pausing a device can be useful to halt all audio without unbinding all the
1087    /// audio streams. This might be useful while a game is paused, or a level is
1088    /// loading, etc.
1089    ///
1090    /// Physical devices can not be paused or unpaused, only logical devices
1091    /// created through [`SDL_OpenAudioDevice()`] can be.
1092    ///
1093    /// ## Parameters
1094    /// - `devid`: a device opened by [`SDL_OpenAudioDevice()`].
1095    ///
1096    /// ## Return value
1097    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1098    ///   information.
1099    ///
1100    /// ## Thread safety
1101    /// It is safe to call this function from any thread.
1102    ///
1103    /// ## Availability
1104    /// This function is available since SDL 3.2.0.
1105    ///
1106    /// ## See also
1107    /// - [`SDL_ResumeAudioDevice`]
1108    /// - [`SDL_AudioDevicePaused`]
1109    pub fn SDL_PauseAudioDevice(devid: SDL_AudioDeviceID) -> ::core::primitive::bool;
1110}
1111
1112unsafe extern "C" {
1113    /// Use this function to unpause audio playback on a specified device.
1114    ///
1115    /// This function unpauses audio processing for a given device that has
1116    /// previously been paused with [`SDL_PauseAudioDevice()`]. Once unpaused, any
1117    /// bound audio streams will begin to progress again, and audio can be
1118    /// generated.
1119    ///
1120    /// Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
1121    /// has to bind a stream before any audio will flow. Unpausing an unpaused
1122    /// device is a legal no-op.
1123    ///
1124    /// Physical devices can not be paused or unpaused, only logical devices
1125    /// created through [`SDL_OpenAudioDevice()`] can be.
1126    ///
1127    /// ## Parameters
1128    /// - `devid`: a device opened by [`SDL_OpenAudioDevice()`].
1129    ///
1130    /// ## Return value
1131    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1132    ///   information.
1133    ///
1134    /// ## Thread safety
1135    /// It is safe to call this function from any thread.
1136    ///
1137    /// ## Availability
1138    /// This function is available since SDL 3.2.0.
1139    ///
1140    /// ## See also
1141    /// - [`SDL_AudioDevicePaused`]
1142    /// - [`SDL_PauseAudioDevice`]
1143    pub fn SDL_ResumeAudioDevice(devid: SDL_AudioDeviceID) -> ::core::primitive::bool;
1144}
1145
1146unsafe extern "C" {
1147    /// Use this function to query if an audio device is paused.
1148    ///
1149    /// Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
1150    /// has to bind a stream before any audio will flow.
1151    ///
1152    /// Physical devices can not be paused or unpaused, only logical devices
1153    /// created through [`SDL_OpenAudioDevice()`] can be. Physical and invalid device
1154    /// IDs will report themselves as unpaused here.
1155    ///
1156    /// ## Parameters
1157    /// - `devid`: a device opened by [`SDL_OpenAudioDevice()`].
1158    ///
1159    /// ## Return value
1160    /// Returns true if device is valid and paused, false otherwise.
1161    ///
1162    /// ## Thread safety
1163    /// It is safe to call this function from any thread.
1164    ///
1165    /// ## Availability
1166    /// This function is available since SDL 3.2.0.
1167    ///
1168    /// ## See also
1169    /// - [`SDL_PauseAudioDevice`]
1170    /// - [`SDL_ResumeAudioDevice`]
1171    pub fn SDL_AudioDevicePaused(devid: SDL_AudioDeviceID) -> ::core::primitive::bool;
1172}
1173
1174unsafe extern "C" {
1175    /// Get the gain of an audio device.
1176    ///
1177    /// The gain of a device is its volume; a larger gain means a louder output,
1178    /// with a gain of zero being silence.
1179    ///
1180    /// Audio devices default to a gain of 1.0f (no change in output).
1181    ///
1182    /// Physical devices may not have their gain changed, only logical devices, and
1183    /// this function will always return -1.0f when used on physical devices.
1184    ///
1185    /// ## Parameters
1186    /// - `devid`: the audio device to query.
1187    ///
1188    /// ## Return value
1189    /// Returns the gain of the device or -1.0f on failure; call [`SDL_GetError()`]
1190    ///   for more information.
1191    ///
1192    /// ## Thread safety
1193    /// It is safe to call this function from any thread.
1194    ///
1195    /// ## Availability
1196    /// This function is available since SDL 3.2.0.
1197    ///
1198    /// ## See also
1199    /// - [`SDL_SetAudioDeviceGain`]
1200    pub fn SDL_GetAudioDeviceGain(devid: SDL_AudioDeviceID) -> ::core::ffi::c_float;
1201}
1202
1203unsafe extern "C" {
1204    /// Change the gain of an audio device.
1205    ///
1206    /// The gain of a device is its volume; a larger gain means a louder output,
1207    /// with a gain of zero being silence.
1208    ///
1209    /// Audio devices default to a gain of 1.0f (no change in output).
1210    ///
1211    /// Physical devices may not have their gain changed, only logical devices, and
1212    /// this function will always return false when used on physical devices. While
1213    /// it might seem attractive to adjust several logical devices at once in this
1214    /// way, it would allow an app or library to interfere with another portion of
1215    /// the program's otherwise-isolated devices.
1216    ///
1217    /// This is applied, along with any per-audiostream gain, during playback to
1218    /// the hardware, and can be continuously changed to create various effects. On
1219    /// recording devices, this will adjust the gain before passing the data into
1220    /// an audiostream; that recording audiostream can then adjust its gain further
1221    /// when outputting the data elsewhere, if it likes, but that second gain is
1222    /// not applied until the data leaves the audiostream again.
1223    ///
1224    /// ## Parameters
1225    /// - `devid`: the audio device on which to change gain.
1226    /// - `gain`: the gain. 1.0f is no change, 0.0f is silence.
1227    ///
1228    /// ## Return value
1229    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1230    ///   information.
1231    ///
1232    /// ## Thread safety
1233    /// It is safe to call this function from any thread, as it holds
1234    ///   a stream-specific mutex while running.
1235    ///
1236    /// ## Availability
1237    /// This function is available since SDL 3.2.0.
1238    ///
1239    /// ## See also
1240    /// - [`SDL_GetAudioDeviceGain`]
1241    pub fn SDL_SetAudioDeviceGain(
1242        devid: SDL_AudioDeviceID,
1243        gain: ::core::ffi::c_float,
1244    ) -> ::core::primitive::bool;
1245}
1246
1247unsafe extern "C" {
1248    /// Close a previously-opened audio device.
1249    ///
1250    /// The application should close open audio devices once they are no longer
1251    /// needed.
1252    ///
1253    /// This function may block briefly while pending audio data is played by the
1254    /// hardware, so that applications don't drop the last buffer of data they
1255    /// supplied if terminating immediately afterwards.
1256    ///
1257    /// ## Parameters
1258    /// - `devid`: an audio device id previously returned by
1259    ///   [`SDL_OpenAudioDevice()`].
1260    ///
1261    /// ## Thread safety
1262    /// It is safe to call this function from any thread.
1263    ///
1264    /// ## Availability
1265    /// This function is available since SDL 3.2.0.
1266    ///
1267    /// ## See also
1268    /// - [`SDL_OpenAudioDevice`]
1269    pub fn SDL_CloseAudioDevice(devid: SDL_AudioDeviceID);
1270}
1271
1272unsafe extern "C" {
1273    /// Bind a list of audio streams to an audio device.
1274    ///
1275    /// Audio data will flow through any bound streams. For a playback device, data
1276    /// for all bound streams will be mixed together and fed to the device. For a
1277    /// recording device, a copy of recorded data will be provided to each bound
1278    /// stream.
1279    ///
1280    /// Audio streams can only be bound to an open device. This operation is
1281    /// atomic--all streams bound in the same call will start processing at the
1282    /// same time, so they can stay in sync. Also: either all streams will be bound
1283    /// or none of them will be.
1284    ///
1285    /// It is an error to bind an already-bound stream; it must be explicitly
1286    /// unbound first.
1287    ///
1288    /// Binding a stream to a device will set its output format for playback
1289    /// devices, and its input format for recording devices, so they match the
1290    /// device's settings. The caller is welcome to change the other end of the
1291    /// stream's format at any time with [`SDL_SetAudioStreamFormat()`]. If the other
1292    /// end of the stream's format has never been set (the audio stream was created
1293    /// with a NULL audio spec), this function will set it to match the device
1294    /// end's format.
1295    ///
1296    /// ## Parameters
1297    /// - `devid`: an audio device to bind a stream to.
1298    /// - `streams`: an array of audio streams to bind.
1299    /// - `num_streams`: number streams listed in the `streams` array.
1300    ///
1301    /// ## Return value
1302    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1303    ///   information.
1304    ///
1305    /// ## Thread safety
1306    /// It is safe to call this function from any thread.
1307    ///
1308    /// ## Availability
1309    /// This function is available since SDL 3.2.0.
1310    ///
1311    /// ## See also
1312    /// - [`SDL_BindAudioStreams`]
1313    /// - [`SDL_UnbindAudioStream`]
1314    /// - [`SDL_GetAudioStreamDevice`]
1315    pub fn SDL_BindAudioStreams(
1316        devid: SDL_AudioDeviceID,
1317        streams: *const *mut SDL_AudioStream,
1318        num_streams: ::core::ffi::c_int,
1319    ) -> ::core::primitive::bool;
1320}
1321
1322unsafe extern "C" {
1323    /// Bind a single audio stream to an audio device.
1324    ///
1325    /// This is a convenience function, equivalent to calling
1326    /// `SDL_BindAudioStreams(devid, &stream, 1)`.
1327    ///
1328    /// ## Parameters
1329    /// - `devid`: an audio device to bind a stream to.
1330    /// - `stream`: an audio stream to bind to a device.
1331    ///
1332    /// ## Return value
1333    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1334    ///   information.
1335    ///
1336    /// ## Thread safety
1337    /// It is safe to call this function from any thread.
1338    ///
1339    /// ## Availability
1340    /// This function is available since SDL 3.2.0.
1341    ///
1342    /// ## See also
1343    /// - [`SDL_BindAudioStreams`]
1344    /// - [`SDL_UnbindAudioStream`]
1345    /// - [`SDL_GetAudioStreamDevice`]
1346    pub fn SDL_BindAudioStream(
1347        devid: SDL_AudioDeviceID,
1348        stream: *mut SDL_AudioStream,
1349    ) -> ::core::primitive::bool;
1350}
1351
1352unsafe extern "C" {
1353    /// Unbind a list of audio streams from their audio devices.
1354    ///
1355    /// The streams being unbound do not all have to be on the same device. All
1356    /// streams on the same device will be unbound atomically (data will stop
1357    /// flowing through all unbound streams on the same device at the same time).
1358    ///
1359    /// Unbinding a stream that isn't bound to a device is a legal no-op.
1360    ///
1361    /// ## Parameters
1362    /// - `streams`: an array of audio streams to unbind. Can be NULL or contain
1363    ///   NULL.
1364    /// - `num_streams`: number streams listed in the `streams` array.
1365    ///
1366    /// ## Thread safety
1367    /// It is safe to call this function from any thread.
1368    ///
1369    /// ## Availability
1370    /// This function is available since SDL 3.2.0.
1371    ///
1372    /// ## See also
1373    /// - [`SDL_BindAudioStreams`]
1374    pub fn SDL_UnbindAudioStreams(
1375        streams: *const *mut SDL_AudioStream,
1376        num_streams: ::core::ffi::c_int,
1377    );
1378}
1379
1380unsafe extern "C" {
1381    /// Unbind a single audio stream from its audio device.
1382    ///
1383    /// This is a convenience function, equivalent to calling
1384    /// `SDL_UnbindAudioStreams(&stream, 1)`.
1385    ///
1386    /// ## Parameters
1387    /// - `stream`: an audio stream to unbind from a device. Can be NULL.
1388    ///
1389    /// ## Thread safety
1390    /// It is safe to call this function from any thread.
1391    ///
1392    /// ## Availability
1393    /// This function is available since SDL 3.2.0.
1394    ///
1395    /// ## See also
1396    /// - [`SDL_BindAudioStream`]
1397    pub fn SDL_UnbindAudioStream(stream: *mut SDL_AudioStream);
1398}
1399
1400unsafe extern "C" {
1401    /// Query an audio stream for its currently-bound device.
1402    ///
1403    /// This reports the logical audio device that an audio stream is currently
1404    /// bound to.
1405    ///
1406    /// If not bound, or invalid, this returns zero, which is not a valid device
1407    /// ID.
1408    ///
1409    /// ## Parameters
1410    /// - `stream`: the audio stream to query.
1411    ///
1412    /// ## Return value
1413    /// Returns the bound audio device, or 0 if not bound or invalid.
1414    ///
1415    /// ## Thread safety
1416    /// It is safe to call this function from any thread.
1417    ///
1418    /// ## Availability
1419    /// This function is available since SDL 3.2.0.
1420    ///
1421    /// ## See also
1422    /// - [`SDL_BindAudioStream`]
1423    /// - [`SDL_BindAudioStreams`]
1424    pub fn SDL_GetAudioStreamDevice(stream: *mut SDL_AudioStream) -> SDL_AudioDeviceID;
1425}
1426
1427unsafe extern "C" {
1428    /// Create a new audio stream.
1429    ///
1430    /// Note that `src_spec` or `dst_spec` may be NULL, but any attempts to
1431    /// put or get data from an audio stream will fail until it has valid
1432    /// specs assigned to both ends of the stream. Specs can be assigned later
1433    /// through [`SDL_SetAudioStreamFormat()`], or binding the stream to an audio
1434    /// device (which will set the format of only the input or output,
1435    /// depending on what kind of device the stream was bound to).
1436    ///
1437    /// ## Parameters
1438    /// - `src_spec`: the format details of the input audio. May be NULL.
1439    /// - `dst_spec`: the format details of the output audio. May be NULL.
1440    ///
1441    /// ## Return value
1442    /// Returns a new audio stream on success or NULL on failure; call
1443    ///   [`SDL_GetError()`] for more information.
1444    ///
1445    /// ## Thread safety
1446    /// It is safe to call this function from any thread.
1447    ///
1448    /// ## Availability
1449    /// This function is available since SDL 3.2.0.
1450    ///
1451    /// ## See also
1452    /// - [`SDL_PutAudioStreamData`]
1453    /// - [`SDL_GetAudioStreamData`]
1454    /// - [`SDL_GetAudioStreamAvailable`]
1455    /// - [`SDL_FlushAudioStream`]
1456    /// - [`SDL_ClearAudioStream`]
1457    /// - [`SDL_SetAudioStreamFormat`]
1458    /// - [`SDL_DestroyAudioStream`]
1459    pub fn SDL_CreateAudioStream(
1460        src_spec: *const SDL_AudioSpec,
1461        dst_spec: *const SDL_AudioSpec,
1462    ) -> *mut SDL_AudioStream;
1463}
1464
1465unsafe extern "C" {
1466    /// Get the properties associated with an audio stream.
1467    ///
1468    /// The application can hang any data it wants here, but the following
1469    /// properties are understood by SDL:
1470    ///
1471    /// - [`SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN`]\: if true (the default), the
1472    ///   stream be automatically cleaned up when the audio subsystem quits. If set
1473    ///   to false, the streams will persist beyond that. This property is ignored
1474    ///   for streams created through [`SDL_OpenAudioDeviceStream()`], and will always
1475    ///   be cleaned up. Streams that are not cleaned up will still be unbound from
1476    ///   devices when the audio subsystem quits. This property was added in SDL
1477    ///   3.4.0.
1478    ///
1479    /// ## Parameters
1480    /// - `stream`: the [`SDL_AudioStream`] to query.
1481    ///
1482    /// ## Return value
1483    /// Returns a valid property ID on success or 0 on failure; call
1484    ///   [`SDL_GetError()`] for more information.
1485    ///
1486    /// ## Thread safety
1487    /// It is safe to call this function from any thread.
1488    ///
1489    /// ## Availability
1490    /// This function is available since SDL 3.2.0.
1491    pub fn SDL_GetAudioStreamProperties(stream: *mut SDL_AudioStream) -> SDL_PropertiesID;
1492}
1493
1494pub const SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN: *const ::core::ffi::c_char =
1495    c"SDL.audiostream.auto_cleanup".as_ptr();
1496
1497unsafe extern "C" {
1498    /// Query the current format of an audio stream.
1499    ///
1500    /// ## Parameters
1501    /// - `stream`: the [`SDL_AudioStream`] to query.
1502    /// - `src_spec`: where to store the input audio format; ignored if NULL.
1503    /// - `dst_spec`: where to store the output audio format; ignored if NULL.
1504    ///
1505    /// ## Return value
1506    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1507    ///   information.
1508    ///
1509    /// ## Thread safety
1510    /// It is safe to call this function from any thread, as it holds
1511    ///   a stream-specific mutex while running.
1512    ///
1513    /// ## Availability
1514    /// This function is available since SDL 3.2.0.
1515    ///
1516    /// ## See also
1517    /// - [`SDL_SetAudioStreamFormat`]
1518    pub fn SDL_GetAudioStreamFormat(
1519        stream: *mut SDL_AudioStream,
1520        src_spec: *mut SDL_AudioSpec,
1521        dst_spec: *mut SDL_AudioSpec,
1522    ) -> ::core::primitive::bool;
1523}
1524
1525unsafe extern "C" {
1526    /// Change the input and output formats of an audio stream.
1527    ///
1528    /// Future calls to and [`SDL_GetAudioStreamAvailable`] and [`SDL_GetAudioStreamData`]
1529    /// will reflect the new format, and future calls to [`SDL_PutAudioStreamData`]
1530    /// must provide data in the new input formats.
1531    ///
1532    /// Data that was previously queued in the stream will still be operated on in
1533    /// the format that was current when it was added, which is to say you can put
1534    /// the end of a sound file in one format to a stream, change formats for the
1535    /// next sound file, and start putting that new data while the previous sound
1536    /// file is still queued, and everything will still play back correctly.
1537    ///
1538    /// If a stream is bound to a device, then the format of the side of the stream
1539    /// bound to a device cannot be changed (src_spec for recording devices,
1540    /// dst_spec for playback devices). Attempts to make a change to this side will
1541    /// be ignored, but this will not report an error. The other side's format can
1542    /// be changed.
1543    ///
1544    /// `src_spec` and `dst_spec` may each be NULL; a NULL spec signals not to
1545    /// change the current format for that side of the stream.
1546    ///
1547    /// ## Parameters
1548    /// - `stream`: the stream the format is being changed.
1549    /// - `src_spec`: the new format of the audio input; if NULL, it is not
1550    ///   changed.
1551    /// - `dst_spec`: the new format of the audio output; if NULL, it is not
1552    ///   changed.
1553    ///
1554    /// ## Return value
1555    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1556    ///   information.
1557    ///
1558    /// ## Thread safety
1559    /// It is safe to call this function from any thread, as it holds
1560    ///   a stream-specific mutex while running.
1561    ///
1562    /// ## Availability
1563    /// This function is available since SDL 3.2.0.
1564    ///
1565    /// ## See also
1566    /// - [`SDL_GetAudioStreamFormat`]
1567    /// - [`SDL_SetAudioStreamFrequencyRatio`]
1568    pub fn SDL_SetAudioStreamFormat(
1569        stream: *mut SDL_AudioStream,
1570        src_spec: *const SDL_AudioSpec,
1571        dst_spec: *const SDL_AudioSpec,
1572    ) -> ::core::primitive::bool;
1573}
1574
1575unsafe extern "C" {
1576    /// Get the frequency ratio of an audio stream.
1577    ///
1578    /// ## Parameters
1579    /// - `stream`: the [`SDL_AudioStream`] to query.
1580    ///
1581    /// ## Return value
1582    /// Returns the frequency ratio of the stream or 0.0 on failure; call
1583    ///   [`SDL_GetError()`] for more information.
1584    ///
1585    /// ## Thread safety
1586    /// It is safe to call this function from any thread, as it holds
1587    ///   a stream-specific mutex while running.
1588    ///
1589    /// ## Availability
1590    /// This function is available since SDL 3.2.0.
1591    ///
1592    /// ## See also
1593    /// - [`SDL_SetAudioStreamFrequencyRatio`]
1594    pub fn SDL_GetAudioStreamFrequencyRatio(stream: *mut SDL_AudioStream) -> ::core::ffi::c_float;
1595}
1596
1597unsafe extern "C" {
1598    /// Change the frequency ratio of an audio stream.
1599    ///
1600    /// The frequency ratio is used to adjust the rate at which input data is
1601    /// consumed. Changing this effectively modifies the speed and pitch of the
1602    /// audio. A value greater than 1.0f will play the audio faster, and at a
1603    /// higher pitch. A value less than 1.0f will play the audio slower, and at a
1604    /// lower pitch. 1.0f means play at normal speed.
1605    ///
1606    /// This is applied during [`SDL_GetAudioStreamData`], and can be continuously
1607    /// changed to create various effects.
1608    ///
1609    /// ## Parameters
1610    /// - `stream`: the stream on which the frequency ratio is being changed.
1611    /// - `ratio`: the frequency ratio. 1.0 is normal speed. Must be between 0.01
1612    ///   and 100.
1613    ///
1614    /// ## Return value
1615    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1616    ///   information.
1617    ///
1618    /// ## Thread safety
1619    /// It is safe to call this function from any thread, as it holds
1620    ///   a stream-specific mutex while running.
1621    ///
1622    /// ## Availability
1623    /// This function is available since SDL 3.2.0.
1624    ///
1625    /// ## See also
1626    /// - [`SDL_GetAudioStreamFrequencyRatio`]
1627    /// - [`SDL_SetAudioStreamFormat`]
1628    pub fn SDL_SetAudioStreamFrequencyRatio(
1629        stream: *mut SDL_AudioStream,
1630        ratio: ::core::ffi::c_float,
1631    ) -> ::core::primitive::bool;
1632}
1633
1634unsafe extern "C" {
1635    /// Get the gain of an audio stream.
1636    ///
1637    /// The gain of a stream is its volume; a larger gain means a louder output,
1638    /// with a gain of zero being silence.
1639    ///
1640    /// Audio streams default to a gain of 1.0f (no change in output).
1641    ///
1642    /// ## Parameters
1643    /// - `stream`: the [`SDL_AudioStream`] to query.
1644    ///
1645    /// ## Return value
1646    /// Returns the gain of the stream or -1.0f on failure; call [`SDL_GetError()`]
1647    ///   for more information.
1648    ///
1649    /// ## Thread safety
1650    /// It is safe to call this function from any thread, as it holds
1651    ///   a stream-specific mutex while running.
1652    ///
1653    /// ## Availability
1654    /// This function is available since SDL 3.2.0.
1655    ///
1656    /// ## See also
1657    /// - [`SDL_SetAudioStreamGain`]
1658    pub fn SDL_GetAudioStreamGain(stream: *mut SDL_AudioStream) -> ::core::ffi::c_float;
1659}
1660
1661unsafe extern "C" {
1662    /// Change the gain of an audio stream.
1663    ///
1664    /// The gain of a stream is its volume; a larger gain means a louder output,
1665    /// with a gain of zero being silence.
1666    ///
1667    /// Audio streams default to a gain of 1.0f (no change in output).
1668    ///
1669    /// This is applied during [`SDL_GetAudioStreamData`], and can be continuously
1670    /// changed to create various effects.
1671    ///
1672    /// ## Parameters
1673    /// - `stream`: the stream on which the gain is being changed.
1674    /// - `gain`: the gain. 1.0f is no change, 0.0f is silence.
1675    ///
1676    /// ## Return value
1677    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1678    ///   information.
1679    ///
1680    /// ## Thread safety
1681    /// It is safe to call this function from any thread, as it holds
1682    ///   a stream-specific mutex while running.
1683    ///
1684    /// ## Availability
1685    /// This function is available since SDL 3.2.0.
1686    ///
1687    /// ## See also
1688    /// - [`SDL_GetAudioStreamGain`]
1689    pub fn SDL_SetAudioStreamGain(
1690        stream: *mut SDL_AudioStream,
1691        gain: ::core::ffi::c_float,
1692    ) -> ::core::primitive::bool;
1693}
1694
1695unsafe extern "C" {
1696    /// Get the current input channel map of an audio stream.
1697    ///
1698    /// Channel maps are optional; most things do not need them, instead passing
1699    /// data in the [order that SDL expects](CategoryAudio#channel-layouts).
1700    ///
1701    /// Audio streams default to no remapping applied. This is represented by
1702    /// returning NULL, and does not signify an error.
1703    ///
1704    /// ## Parameters
1705    /// - `stream`: the [`SDL_AudioStream`] to query.
1706    /// - `count`: On output, set to number of channels in the map. Can be NULL.
1707    ///
1708    /// ## Return value
1709    /// Returns an array of the current channel mapping, with as many elements as
1710    ///   the current output spec's channels, or NULL if default. This
1711    ///   should be freed with [`SDL_free()`] when it is no longer needed.
1712    ///
1713    /// ## Thread safety
1714    /// It is safe to call this function from any thread, as it holds
1715    ///   a stream-specific mutex while running.
1716    ///
1717    /// ## Availability
1718    /// This function is available since SDL 3.2.0.
1719    ///
1720    /// ## See also
1721    /// - [`SDL_SetAudioStreamInputChannelMap`]
1722    pub fn SDL_GetAudioStreamInputChannelMap(
1723        stream: *mut SDL_AudioStream,
1724        count: *mut ::core::ffi::c_int,
1725    ) -> *mut ::core::ffi::c_int;
1726}
1727
1728unsafe extern "C" {
1729    /// Get the current output channel map of an audio stream.
1730    ///
1731    /// Channel maps are optional; most things do not need them, instead passing
1732    /// data in the [order that SDL expects](CategoryAudio#channel-layouts).
1733    ///
1734    /// Audio streams default to no remapping applied. This is represented by
1735    /// returning NULL, and does not signify an error.
1736    ///
1737    /// ## Parameters
1738    /// - `stream`: the [`SDL_AudioStream`] to query.
1739    /// - `count`: On output, set to number of channels in the map. Can be NULL.
1740    ///
1741    /// ## Return value
1742    /// Returns an array of the current channel mapping, with as many elements as
1743    ///   the current output spec's channels, or NULL if default. This
1744    ///   should be freed with [`SDL_free()`] when it is no longer needed.
1745    ///
1746    /// ## Thread safety
1747    /// It is safe to call this function from any thread, as it holds
1748    ///   a stream-specific mutex while running.
1749    ///
1750    /// ## Availability
1751    /// This function is available since SDL 3.2.0.
1752    ///
1753    /// ## See also
1754    /// - [`SDL_SetAudioStreamInputChannelMap`]
1755    pub fn SDL_GetAudioStreamOutputChannelMap(
1756        stream: *mut SDL_AudioStream,
1757        count: *mut ::core::ffi::c_int,
1758    ) -> *mut ::core::ffi::c_int;
1759}
1760
1761unsafe extern "C" {
1762    /// Set the current input channel map of an audio stream.
1763    ///
1764    /// Channel maps are optional; most things do not need them, instead passing
1765    /// data in the [order that SDL expects](CategoryAudio#channel-layouts).
1766    ///
1767    /// The input channel map reorders data that is added to a stream via
1768    /// [`SDL_PutAudioStreamData`]. Future calls to [`SDL_PutAudioStreamData`] must provide
1769    /// data in the new channel order.
1770    ///
1771    /// Each item in the array represents an input channel, and its value is the
1772    /// channel that it should be remapped to. To reverse a stereo signal's left
1773    /// and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap
1774    /// multiple channels to the same thing, so `{ 1, 1 }` would duplicate the
1775    /// right channel to both channels of a stereo signal. An element in the
1776    /// channel map set to -1 instead of a valid channel will mute that channel,
1777    /// setting it to a silence value.
1778    ///
1779    /// You cannot change the number of channels through a channel map, just
1780    /// reorder/mute them.
1781    ///
1782    /// Data that was previously queued in the stream will still be operated on in
1783    /// the order that was current when it was added, which is to say you can put
1784    /// the end of a sound file in one order to a stream, change orders for the
1785    /// next sound file, and start putting that new data while the previous sound
1786    /// file is still queued, and everything will still play back correctly.
1787    ///
1788    /// Audio streams default to no remapping applied. Passing a NULL channel map
1789    /// is legal, and turns off remapping.
1790    ///
1791    /// SDL will copy the channel map; the caller does not have to save this array
1792    /// after this call.
1793    ///
1794    /// If `count` is not equal to the current number of channels in the audio
1795    /// stream's format, this will fail. This is a safety measure to make sure a
1796    /// race condition hasn't changed the format while this call is setting the
1797    /// channel map.
1798    ///
1799    /// Unlike attempting to change the stream's format, the input channel map on a
1800    /// stream bound to a recording device is permitted to change at any time; any
1801    /// data added to the stream from the device after this call will have the new
1802    /// mapping, but previously-added data will still have the prior mapping.
1803    ///
1804    /// ## Parameters
1805    /// - `stream`: the [`SDL_AudioStream`] to change.
1806    /// - `chmap`: the new channel map, NULL to reset to default.
1807    /// - `count`: The number of channels in the map.
1808    ///
1809    /// ## Return value
1810    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1811    ///   information.
1812    ///
1813    /// ## Thread safety
1814    /// It is safe to call this function from any thread, as it holds
1815    ///   a stream-specific mutex while running. Don't change the
1816    ///   stream's format to have a different number of channels from a
1817    ///   different thread at the same time, though!
1818    ///
1819    /// ## Availability
1820    /// This function is available since SDL 3.2.0.
1821    ///
1822    /// ## See also
1823    /// - [`SDL_SetAudioStreamOutputChannelMap`]
1824    pub fn SDL_SetAudioStreamInputChannelMap(
1825        stream: *mut SDL_AudioStream,
1826        chmap: *const ::core::ffi::c_int,
1827        count: ::core::ffi::c_int,
1828    ) -> ::core::primitive::bool;
1829}
1830
1831unsafe extern "C" {
1832    /// Set the current output channel map of an audio stream.
1833    ///
1834    /// Channel maps are optional; most things do not need them, instead passing
1835    /// data in the [order that SDL expects](CategoryAudio#channel-layouts).
1836    ///
1837    /// The output channel map reorders data that is leaving a stream via
1838    /// [`SDL_GetAudioStreamData`].
1839    ///
1840    /// Each item in the array represents an input channel, and its value is the
1841    /// channel that it should be remapped to. To reverse a stereo signal's left
1842    /// and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap
1843    /// multiple channels to the same thing, so `{ 1, 1 }` would duplicate the
1844    /// right channel to both channels of a stereo signal. An element in the
1845    /// channel map set to -1 instead of a valid channel will mute that channel,
1846    /// setting it to a silence value.
1847    ///
1848    /// You cannot change the number of channels through a channel map, just
1849    /// reorder/mute them.
1850    ///
1851    /// The output channel map can be changed at any time, as output remapping is
1852    /// applied during [`SDL_GetAudioStreamData`].
1853    ///
1854    /// Audio streams default to no remapping applied. Passing a NULL channel map
1855    /// is legal, and turns off remapping.
1856    ///
1857    /// SDL will copy the channel map; the caller does not have to save this array
1858    /// after this call.
1859    ///
1860    /// If `count` is not equal to the current number of channels in the audio
1861    /// stream's format, this will fail. This is a safety measure to make sure a
1862    /// race condition hasn't changed the format while this call is setting the
1863    /// channel map.
1864    ///
1865    /// Unlike attempting to change the stream's format, the output channel map on
1866    /// a stream bound to a recording device is permitted to change at any time;
1867    /// any data added to the stream after this call will have the new mapping, but
1868    /// previously-added data will still have the prior mapping. When the channel
1869    /// map doesn't match the hardware's channel layout, SDL will convert the data
1870    /// before feeding it to the device for playback.
1871    ///
1872    /// ## Parameters
1873    /// - `stream`: the [`SDL_AudioStream`] to change.
1874    /// - `chmap`: the new channel map, NULL to reset to default.
1875    /// - `count`: The number of channels in the map.
1876    ///
1877    /// ## Return value
1878    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1879    ///   information.
1880    ///
1881    /// ## Thread safety
1882    /// It is safe to call this function from any thread, as it holds
1883    ///   a stream-specific mutex while running. Don't change the
1884    ///   stream's format to have a different number of channels from a
1885    ///   a different thread at the same time, though!
1886    ///
1887    /// ## Availability
1888    /// This function is available since SDL 3.2.0.
1889    ///
1890    /// ## See also
1891    /// - [`SDL_SetAudioStreamInputChannelMap`]
1892    pub fn SDL_SetAudioStreamOutputChannelMap(
1893        stream: *mut SDL_AudioStream,
1894        chmap: *const ::core::ffi::c_int,
1895        count: ::core::ffi::c_int,
1896    ) -> ::core::primitive::bool;
1897}
1898
1899unsafe extern "C" {
1900    /// Add data to the stream.
1901    ///
1902    /// This data must match the format/channels/samplerate specified in the latest
1903    /// call to [`SDL_SetAudioStreamFormat`], or the format specified when creating the
1904    /// stream if it hasn't been changed.
1905    ///
1906    /// Note that this call simply copies the unconverted data for later. This is
1907    /// different than SDL2, where data was converted during the Put call and the
1908    /// Get call would just dequeue the previously-converted data.
1909    ///
1910    /// ## Parameters
1911    /// - `stream`: the stream the audio data is being added to.
1912    /// - `buf`: a pointer to the audio data to add.
1913    /// - `len`: the number of bytes to write to the stream.
1914    ///
1915    /// ## Return value
1916    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1917    ///   information.
1918    ///
1919    /// ## Thread safety
1920    /// It is safe to call this function from any thread, but if the
1921    ///   stream has a callback set, the caller might need to manage
1922    ///   extra locking.
1923    ///
1924    /// ## Availability
1925    /// This function is available since SDL 3.2.0.
1926    ///
1927    /// ## See also
1928    /// - [`SDL_ClearAudioStream`]
1929    /// - [`SDL_FlushAudioStream`]
1930    /// - [`SDL_GetAudioStreamData`]
1931    /// - [`SDL_GetAudioStreamQueued`]
1932    pub fn SDL_PutAudioStreamData(
1933        stream: *mut SDL_AudioStream,
1934        buf: *const ::core::ffi::c_void,
1935        len: ::core::ffi::c_int,
1936    ) -> ::core::primitive::bool;
1937}
1938
1939/// A callback that fires for completed [`SDL_PutAudioStreamDataNoCopy()`] data.
1940///
1941/// When using [`SDL_PutAudioStreamDataNoCopy()`] to provide data to an
1942/// [`SDL_AudioStream`], it's not safe to dispose of the data until the stream has
1943/// completely consumed it. Often times it's difficult to know exactly when
1944/// this has happened.
1945///
1946/// This callback fires once when the stream no longer needs the buffer,
1947/// allowing the app to easily free or reuse it.
1948///
1949/// ## Parameters
1950/// - `userdata`: an opaque pointer provided by the app for their personal
1951///   use.
1952/// - `buf`: the pointer provided to [`SDL_PutAudioStreamDataNoCopy()`].
1953/// - `buflen`: the size of buffer, in bytes, provided to
1954///   [`SDL_PutAudioStreamDataNoCopy()`].
1955///
1956/// ## Thread safety
1957/// This callbacks may run from any thread, so if you need to
1958///   protect shared data, you should use [`SDL_LockAudioStream`] to
1959///   serialize access; this lock will be held before your callback
1960///   is called, so your callback does not need to manage the lock
1961///   explicitly.
1962///
1963/// ## Availability
1964/// This datatype is available since SDL 3.4.0.
1965///
1966/// ## See also
1967/// - [`SDL_SetAudioStreamGetCallback`]
1968/// - [`SDL_SetAudioStreamPutCallback`]
1969pub type SDL_AudioStreamDataCompleteCallback = ::core::option::Option<
1970    unsafe extern "C" fn(
1971        userdata: *mut ::core::ffi::c_void,
1972        buf: *const ::core::ffi::c_void,
1973        buflen: ::core::ffi::c_int,
1974    ),
1975>;
1976
1977unsafe extern "C" {
1978    /// Add external data to an audio stream without copying it.
1979    ///
1980    /// Unlike [`SDL_PutAudioStreamData()`], this function does not make a copy of the
1981    /// provided data, instead storing the provided pointer. This means that the
1982    /// put operation does not need to allocate and copy the data, but the original
1983    /// data must remain available until the stream is done with it, either by
1984    /// being read from the stream in its entirety, or a call to
1985    /// [`SDL_ClearAudioStream()`] or [`SDL_DestroyAudioStream()`].
1986    ///
1987    /// The data must match the format/channels/samplerate specified in the latest
1988    /// call to [`SDL_SetAudioStreamFormat`], or the format specified when creating the
1989    /// stream if it hasn't been changed.
1990    ///
1991    /// An optional callback may be provided, which is called when the stream no
1992    /// longer needs the data. Once this callback fires, the stream will not access
1993    /// the data again. This callback will fire for any reason the data is no
1994    /// longer needed, including clearing or destroying the stream.
1995    ///
1996    /// Note that there is still an allocation to store tracking information, so
1997    /// this function is more efficient for larger blocks of data. If you're
1998    /// planning to put a few samples at a time, it will be more efficient to use
1999    /// [`SDL_PutAudioStreamData()`], which allocates and buffers in blocks.
2000    ///
2001    /// ## Parameters
2002    /// - `stream`: the stream the audio data is being added to.
2003    /// - `buf`: a pointer to the audio data to add.
2004    /// - `len`: the number of bytes to add to the stream.
2005    /// - `callback`: the callback function to call when the data is no longer
2006    ///   needed by the stream. May be NULL.
2007    /// - `userdata`: an opaque pointer provided to the callback for its own
2008    ///   personal use.
2009    ///
2010    /// ## Return value
2011    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2012    ///   information.
2013    ///
2014    /// ## Thread safety
2015    /// It is safe to call this function from any thread, but if the
2016    ///   stream has a callback set, the caller might need to manage
2017    ///   extra locking.
2018    ///
2019    /// ## Availability
2020    /// This function is available since SDL 3.4.0.
2021    ///
2022    /// ## See also
2023    /// - [`SDL_ClearAudioStream`]
2024    /// - [`SDL_FlushAudioStream`]
2025    /// - [`SDL_GetAudioStreamData`]
2026    /// - [`SDL_GetAudioStreamQueued`]
2027    pub fn SDL_PutAudioStreamDataNoCopy(
2028        stream: *mut SDL_AudioStream,
2029        buf: *const ::core::ffi::c_void,
2030        len: ::core::ffi::c_int,
2031        callback: SDL_AudioStreamDataCompleteCallback,
2032        userdata: *mut ::core::ffi::c_void,
2033    ) -> ::core::primitive::bool;
2034}
2035
2036unsafe extern "C" {
2037    /// Add data to the stream with each channel in a separate array.
2038    ///
2039    /// This data must match the format/channels/samplerate specified in the latest
2040    /// call to [`SDL_SetAudioStreamFormat`], or the format specified when creating the
2041    /// stream if it hasn't been changed.
2042    ///
2043    /// The data will be interleaved and queued. Note that [`SDL_AudioStream`] only
2044    /// operates on interleaved data, so this is simply a convenience function for
2045    /// easily queueing data from sources that provide separate arrays. There is no
2046    /// equivalent function to retrieve planar data.
2047    ///
2048    /// The arrays in `channel_buffers` are ordered as they are to be interleaved;
2049    /// the first array will be the first sample in the interleaved data. Any
2050    /// individual array may be NULL; in this case, silence will be interleaved for
2051    /// that channel.
2052    ///
2053    /// `num_channels` specifies how many arrays are in `channel_buffers`. This can
2054    /// be used as a safety to prevent overflow, in case the stream format has
2055    /// changed elsewhere. If more channels are specified than the current input
2056    /// spec, they are ignored. If less channels are specified, the missing arrays
2057    /// are treated as if they are NULL (silence is written to those channels). If
2058    /// the count is -1, SDL will assume the array count matches the current input
2059    /// spec.
2060    ///
2061    /// Note that `num_samples` is the number of _samples per array_. This can also
2062    /// be thought of as the number of _sample frames_ to be queued. A value of 1
2063    /// with stereo arrays will queue two samples to the stream. This is different
2064    /// than [`SDL_PutAudioStreamData`], which wants the size of a single array in
2065    /// bytes.
2066    ///
2067    /// ## Parameters
2068    /// - `stream`: the stream the audio data is being added to.
2069    /// - `channel_buffers`: a pointer to an array of arrays, one array per
2070    ///   channel.
2071    /// - `num_channels`: the number of arrays in `channel_buffers` or -1.
2072    /// - `num_samples`: the number of _samples_ per array to write to the
2073    ///   stream.
2074    ///
2075    /// ## Return value
2076    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2077    ///   information.
2078    ///
2079    /// ## Thread safety
2080    /// It is safe to call this function from any thread, but if the
2081    ///   stream has a callback set, the caller might need to manage
2082    ///   extra locking.
2083    ///
2084    /// ## Availability
2085    /// This function is available since SDL 3.4.0.
2086    ///
2087    /// ## See also
2088    /// - [`SDL_ClearAudioStream`]
2089    /// - [`SDL_FlushAudioStream`]
2090    /// - [`SDL_GetAudioStreamData`]
2091    /// - [`SDL_GetAudioStreamQueued`]
2092    pub fn SDL_PutAudioStreamPlanarData(
2093        stream: *mut SDL_AudioStream,
2094        channel_buffers: *const *const ::core::ffi::c_void,
2095        num_channels: ::core::ffi::c_int,
2096        num_samples: ::core::ffi::c_int,
2097    ) -> ::core::primitive::bool;
2098}
2099
2100unsafe extern "C" {
2101    /// Get converted/resampled data from the stream.
2102    ///
2103    /// The input/output data format/channels/samplerate is specified when creating
2104    /// the stream, and can be changed after creation by calling
2105    /// [`SDL_SetAudioStreamFormat`].
2106    ///
2107    /// Note that any conversion and resampling necessary is done during this call,
2108    /// and [`SDL_PutAudioStreamData`] simply queues unconverted data for later. This
2109    /// is different than SDL2, where that work was done while inputting new data
2110    /// to the stream and requesting the output just copied the converted data.
2111    ///
2112    /// ## Parameters
2113    /// - `stream`: the stream the audio is being requested from.
2114    /// - `buf`: a buffer to fill with audio data.
2115    /// - `len`: the maximum number of bytes to fill.
2116    ///
2117    /// ## Return value
2118    /// Returns the number of bytes read from the stream or -1 on failure; call
2119    ///   [`SDL_GetError()`] for more information.
2120    ///
2121    /// ## Thread safety
2122    /// It is safe to call this function from any thread, but if the
2123    ///   stream has a callback set, the caller might need to manage
2124    ///   extra locking.
2125    ///
2126    /// ## Availability
2127    /// This function is available since SDL 3.2.0.
2128    ///
2129    /// ## See also
2130    /// - [`SDL_ClearAudioStream`]
2131    /// - [`SDL_GetAudioStreamAvailable`]
2132    /// - [`SDL_PutAudioStreamData`]
2133    pub fn SDL_GetAudioStreamData(
2134        stream: *mut SDL_AudioStream,
2135        buf: *mut ::core::ffi::c_void,
2136        len: ::core::ffi::c_int,
2137    ) -> ::core::ffi::c_int;
2138}
2139
2140unsafe extern "C" {
2141    /// Get the number of converted/resampled bytes available.
2142    ///
2143    /// The stream may be buffering data behind the scenes until it has enough to
2144    /// resample correctly, so this number might be lower than what you expect, or
2145    /// even be zero. Add more data or flush the stream if you need the data now.
2146    ///
2147    /// If the stream has so much data that it would overflow an int, the return
2148    /// value is clamped to a maximum value, but no queued data is lost; if there
2149    /// are gigabytes of data queued, the app might need to read some of it with
2150    /// [`SDL_GetAudioStreamData`] before this function's return value is no longer
2151    /// clamped.
2152    ///
2153    /// ## Parameters
2154    /// - `stream`: the audio stream to query.
2155    ///
2156    /// ## Return value
2157    /// Returns the number of converted/resampled bytes available or -1 on
2158    ///   failure; call [`SDL_GetError()`] for more information.
2159    ///
2160    /// ## Thread safety
2161    /// It is safe to call this function from any thread.
2162    ///
2163    /// ## Availability
2164    /// This function is available since SDL 3.2.0.
2165    ///
2166    /// ## See also
2167    /// - [`SDL_GetAudioStreamData`]
2168    /// - [`SDL_PutAudioStreamData`]
2169    pub fn SDL_GetAudioStreamAvailable(stream: *mut SDL_AudioStream) -> ::core::ffi::c_int;
2170}
2171
2172unsafe extern "C" {
2173    /// Get the number of bytes currently queued.
2174    ///
2175    /// This is the number of bytes put into a stream as input, not the number that
2176    /// can be retrieved as output. Because of several details, it's not possible
2177    /// to calculate one number directly from the other. If you need to know how
2178    /// much usable data can be retrieved right now, you should use
2179    /// [`SDL_GetAudioStreamAvailable()`] and not this function.
2180    ///
2181    /// Note that audio streams can change their input format at any time, even if
2182    /// there is still data queued in a different format, so the returned byte
2183    /// count will not necessarily match the number of _sample frames_ available.
2184    /// Users of this API should be aware of format changes they make when feeding
2185    /// a stream and plan accordingly.
2186    ///
2187    /// Queued data is not converted until it is consumed by
2188    /// [`SDL_GetAudioStreamData`], so this value should be representative of the exact
2189    /// data that was put into the stream.
2190    ///
2191    /// If the stream has so much data that it would overflow an int, the return
2192    /// value is clamped to a maximum value, but no queued data is lost; if there
2193    /// are gigabytes of data queued, the app might need to read some of it with
2194    /// [`SDL_GetAudioStreamData`] before this function's return value is no longer
2195    /// clamped.
2196    ///
2197    /// ## Parameters
2198    /// - `stream`: the audio stream to query.
2199    ///
2200    /// ## Return value
2201    /// Returns the number of bytes queued or -1 on failure; call [`SDL_GetError()`]
2202    ///   for more information.
2203    ///
2204    /// ## Thread safety
2205    /// It is safe to call this function from any thread.
2206    ///
2207    /// ## Availability
2208    /// This function is available since SDL 3.2.0.
2209    ///
2210    /// ## See also
2211    /// - [`SDL_PutAudioStreamData`]
2212    /// - [`SDL_ClearAudioStream`]
2213    pub fn SDL_GetAudioStreamQueued(stream: *mut SDL_AudioStream) -> ::core::ffi::c_int;
2214}
2215
2216unsafe extern "C" {
2217    /// Tell the stream that you're done sending data, and anything being buffered
2218    /// should be converted/resampled and made available immediately.
2219    ///
2220    /// It is legal to add more data to a stream after flushing, but there may be
2221    /// audio gaps in the output. Generally this is intended to signal the end of
2222    /// input, so the complete output becomes available.
2223    ///
2224    /// ## Parameters
2225    /// - `stream`: the audio stream to flush.
2226    ///
2227    /// ## Return value
2228    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2229    ///   information.
2230    ///
2231    /// ## Thread safety
2232    /// It is safe to call this function from any thread.
2233    ///
2234    /// ## Availability
2235    /// This function is available since SDL 3.2.0.
2236    ///
2237    /// ## See also
2238    /// - [`SDL_PutAudioStreamData`]
2239    pub fn SDL_FlushAudioStream(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2240}
2241
2242unsafe extern "C" {
2243    /// Clear any pending data in the stream.
2244    ///
2245    /// This drops any queued data, so there will be nothing to read from the
2246    /// stream until more is added.
2247    ///
2248    /// ## Parameters
2249    /// - `stream`: the audio stream to clear.
2250    ///
2251    /// ## Return value
2252    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2253    ///   information.
2254    ///
2255    /// ## Thread safety
2256    /// It is safe to call this function from any thread.
2257    ///
2258    /// ## Availability
2259    /// This function is available since SDL 3.2.0.
2260    ///
2261    /// ## See also
2262    /// - [`SDL_GetAudioStreamAvailable`]
2263    /// - [`SDL_GetAudioStreamData`]
2264    /// - [`SDL_GetAudioStreamQueued`]
2265    /// - [`SDL_PutAudioStreamData`]
2266    pub fn SDL_ClearAudioStream(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2267}
2268
2269unsafe extern "C" {
2270    /// Use this function to pause audio playback on the audio device associated
2271    /// with an audio stream.
2272    ///
2273    /// This function pauses audio processing for a given device. Any bound audio
2274    /// streams will not progress, and no audio will be generated. Pausing one
2275    /// device does not prevent other unpaused devices from running.
2276    ///
2277    /// Pausing a device can be useful to halt all audio without unbinding all the
2278    /// audio streams. This might be useful while a game is paused, or a level is
2279    /// loading, etc.
2280    ///
2281    /// ## Parameters
2282    /// - `stream`: the audio stream associated with the audio device to pause.
2283    ///
2284    /// ## Return value
2285    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2286    ///   information.
2287    ///
2288    /// ## Thread safety
2289    /// It is safe to call this function from any thread.
2290    ///
2291    /// ## Availability
2292    /// This function is available since SDL 3.2.0.
2293    ///
2294    /// ## See also
2295    /// - [`SDL_ResumeAudioStreamDevice`]
2296    pub fn SDL_PauseAudioStreamDevice(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2297}
2298
2299unsafe extern "C" {
2300    /// Use this function to unpause audio playback on the audio device associated
2301    /// with an audio stream.
2302    ///
2303    /// This function unpauses audio processing for a given device that has
2304    /// previously been paused. Once unpaused, any bound audio streams will begin
2305    /// to progress again, and audio can be generated.
2306    ///
2307    /// [`SDL_OpenAudioDeviceStream`] opens audio devices in a paused state, so this
2308    /// function call is required for audio playback to begin on such devices.
2309    ///
2310    /// ## Parameters
2311    /// - `stream`: the audio stream associated with the audio device to resume.
2312    ///
2313    /// ## Return value
2314    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2315    ///   information.
2316    ///
2317    /// ## Thread safety
2318    /// It is safe to call this function from any thread.
2319    ///
2320    /// ## Availability
2321    /// This function is available since SDL 3.2.0.
2322    ///
2323    /// ## See also
2324    /// - [`SDL_PauseAudioStreamDevice`]
2325    pub fn SDL_ResumeAudioStreamDevice(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2326}
2327
2328unsafe extern "C" {
2329    /// Use this function to query if an audio device associated with a stream is
2330    /// paused.
2331    ///
2332    /// Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
2333    /// has to bind a stream before any audio will flow.
2334    ///
2335    /// ## Parameters
2336    /// - `stream`: the audio stream associated with the audio device to query.
2337    ///
2338    /// ## Return value
2339    /// Returns true if device is valid and paused, false otherwise.
2340    ///
2341    /// ## Thread safety
2342    /// It is safe to call this function from any thread.
2343    ///
2344    /// ## Availability
2345    /// This function is available since SDL 3.2.0.
2346    ///
2347    /// ## See also
2348    /// - [`SDL_PauseAudioStreamDevice`]
2349    /// - [`SDL_ResumeAudioStreamDevice`]
2350    pub fn SDL_AudioStreamDevicePaused(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2351}
2352
2353unsafe extern "C" {
2354    /// Lock an audio stream for serialized access.
2355    ///
2356    /// Each [`SDL_AudioStream`] has an internal mutex it uses to protect its data
2357    /// structures from threading conflicts. This function allows an app to lock
2358    /// that mutex, which could be useful if registering callbacks on this stream.
2359    ///
2360    /// One does not need to lock a stream to use in it most cases, as the stream
2361    /// manages this lock internally. However, this lock is held during callbacks,
2362    /// which may run from arbitrary threads at any time, so if an app needs to
2363    /// protect shared data during those callbacks, locking the stream guarantees
2364    /// that the callback is not running while the lock is held.
2365    ///
2366    /// As this is just a wrapper over [`SDL_LockMutex`] for an internal lock; it has
2367    /// all the same attributes (recursive locks are allowed, etc).
2368    ///
2369    /// ## Parameters
2370    /// - `stream`: the audio stream to lock.
2371    ///
2372    /// ## Return value
2373    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2374    ///   information.
2375    ///
2376    /// ## Thread safety
2377    /// It is safe to call this function from any thread.
2378    ///
2379    /// ## Availability
2380    /// This function is available since SDL 3.2.0.
2381    ///
2382    /// ## See also
2383    /// - [`SDL_UnlockAudioStream`]
2384    pub fn SDL_LockAudioStream(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2385}
2386
2387unsafe extern "C" {
2388    /// Unlock an audio stream for serialized access.
2389    ///
2390    /// This unlocks an audio stream after a call to [`SDL_LockAudioStream`].
2391    ///
2392    /// ## Parameters
2393    /// - `stream`: the audio stream to unlock.
2394    ///
2395    /// ## Return value
2396    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2397    ///   information.
2398    ///
2399    /// ## Thread safety
2400    /// You should only call this from the same thread that
2401    ///   previously called [`SDL_LockAudioStream`].
2402    ///
2403    /// ## Availability
2404    /// This function is available since SDL 3.2.0.
2405    ///
2406    /// ## See also
2407    /// - [`SDL_LockAudioStream`]
2408    pub fn SDL_UnlockAudioStream(stream: *mut SDL_AudioStream) -> ::core::primitive::bool;
2409}
2410
2411/// A callback that fires when data passes through an [`SDL_AudioStream`].
2412///
2413/// Apps can (optionally) register a callback with an audio stream that is
2414/// called when data is added with [`SDL_PutAudioStreamData`], or requested with
2415/// [`SDL_GetAudioStreamData`].
2416///
2417/// Two values are offered here: one is the amount of additional data needed to
2418/// satisfy the immediate request (which might be zero if the stream already
2419/// has enough data queued) and the other is the total amount being requested.
2420/// In a Get call triggering a Put callback, these values can be different. In
2421/// a Put call triggering a Get callback, these values are always the same.
2422///
2423/// Byte counts might be slightly overestimated due to buffering or resampling,
2424/// and may change from call to call.
2425///
2426/// This callback is not required to do anything. Generally this is useful for
2427/// adding/reading data on demand, and the app will often put/get data as
2428/// appropriate, but the system goes on with the data currently available to it
2429/// if this callback does nothing.
2430///
2431/// Do not call [`SDL_DestroyAudioStream()`] on `stream` during this callback.
2432///
2433/// ## Parameters
2434/// - `stream`: the SDL audio stream associated with this callback.
2435/// - `additional_amount`: the amount of data, in bytes, that is needed right
2436///   now.
2437/// - `total_amount`: the total amount of data requested, in bytes, that is
2438///   requested or available.
2439/// - `userdata`: an opaque pointer provided by the app for their personal
2440///   use.
2441///
2442/// ## Thread safety
2443/// This callbacks may run from any thread, so if you need to
2444///   protect shared data, you should use [`SDL_LockAudioStream`] to
2445///   serialize access; this lock will be held before your callback
2446///   is called, so your callback does not need to manage the lock
2447///   explicitly.
2448///
2449/// ## Availability
2450/// This datatype is available since SDL 3.2.0.
2451///
2452/// ## See also
2453/// - [`SDL_SetAudioStreamGetCallback`]
2454/// - [`SDL_SetAudioStreamPutCallback`]
2455pub type SDL_AudioStreamCallback = ::core::option::Option<
2456    unsafe extern "C" fn(
2457        userdata: *mut ::core::ffi::c_void,
2458        stream: *mut SDL_AudioStream,
2459        additional_amount: ::core::ffi::c_int,
2460        total_amount: ::core::ffi::c_int,
2461    ),
2462>;
2463
2464unsafe extern "C" {
2465    /// Set a callback that runs when data is requested from an audio stream.
2466    ///
2467    /// This callback is called _before_ data is obtained from the stream, giving
2468    /// the callback the chance to add more on-demand.
2469    ///
2470    /// The callback can (optionally) call [`SDL_PutAudioStreamData()`] to add more
2471    /// audio to the stream during this call; if needed, the request that triggered
2472    /// this callback will obtain the new data immediately.
2473    ///
2474    /// The callback's `additional_amount` argument is roughly how many bytes of
2475    /// _unconverted_ data (in the stream's input format) is needed by the caller,
2476    /// although this may overestimate a little for safety. This takes into account
2477    /// how much is already in the stream and only asks for any extra necessary to
2478    /// resolve the request, which means the callback may be asked for zero bytes,
2479    /// and a different amount on each call.
2480    ///
2481    /// The callback is not required to supply exact amounts; it is allowed to
2482    /// supply too much or too little or none at all. The caller will get what's
2483    /// available, up to the amount they requested, regardless of this callback's
2484    /// outcome.
2485    ///
2486    /// Clearing or flushing an audio stream does not call this callback.
2487    ///
2488    /// This function obtains the stream's lock, which means any existing callback
2489    /// (get or put) in progress will finish running before setting the new
2490    /// callback.
2491    ///
2492    /// Setting a NULL function turns off the callback.
2493    ///
2494    /// ## Parameters
2495    /// - `stream`: the audio stream to set the new callback on.
2496    /// - `callback`: the new callback function to call when data is requested
2497    ///   from the stream.
2498    /// - `userdata`: an opaque pointer provided to the callback for its own
2499    ///   personal use.
2500    ///
2501    /// ## Return value
2502    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2503    ///   information. This only fails if `stream` is NULL.
2504    ///
2505    /// ## Thread safety
2506    /// It is safe to call this function from any thread.
2507    ///
2508    /// ## Availability
2509    /// This function is available since SDL 3.2.0.
2510    ///
2511    /// ## See also
2512    /// - [`SDL_SetAudioStreamPutCallback`]
2513    pub fn SDL_SetAudioStreamGetCallback(
2514        stream: *mut SDL_AudioStream,
2515        callback: SDL_AudioStreamCallback,
2516        userdata: *mut ::core::ffi::c_void,
2517    ) -> ::core::primitive::bool;
2518}
2519
2520unsafe extern "C" {
2521    /// Set a callback that runs when data is added to an audio stream.
2522    ///
2523    /// This callback is called _after_ the data is added to the stream, giving the
2524    /// callback the chance to obtain it immediately.
2525    ///
2526    /// The callback can (optionally) call [`SDL_GetAudioStreamData()`] to obtain audio
2527    /// from the stream during this call.
2528    ///
2529    /// The callback's `additional_amount` argument is how many bytes of
2530    /// _converted_ data (in the stream's output format) was provided by the
2531    /// caller, although this may underestimate a little for safety. This value
2532    /// might be less than what is currently available in the stream, if data was
2533    /// already there, and might be less than the caller provided if the stream
2534    /// needs to keep a buffer to aid in resampling. Which means the callback may
2535    /// be provided with zero bytes, and a different amount on each call.
2536    ///
2537    /// The callback may call [`SDL_GetAudioStreamAvailable`] to see the total amount
2538    /// currently available to read from the stream, instead of the total provided
2539    /// by the current call.
2540    ///
2541    /// The callback is not required to obtain all data. It is allowed to read less
2542    /// or none at all. Anything not read now simply remains in the stream for
2543    /// later access.
2544    ///
2545    /// Clearing or flushing an audio stream does not call this callback.
2546    ///
2547    /// This function obtains the stream's lock, which means any existing callback
2548    /// (get or put) in progress will finish running before setting the new
2549    /// callback.
2550    ///
2551    /// Setting a NULL function turns off the callback.
2552    ///
2553    /// ## Parameters
2554    /// - `stream`: the audio stream to set the new callback on.
2555    /// - `callback`: the new callback function to call when data is added to the
2556    ///   stream.
2557    /// - `userdata`: an opaque pointer provided to the callback for its own
2558    ///   personal use.
2559    ///
2560    /// ## Return value
2561    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2562    ///   information. This only fails if `stream` is NULL.
2563    ///
2564    /// ## Thread safety
2565    /// It is safe to call this function from any thread.
2566    ///
2567    /// ## Availability
2568    /// This function is available since SDL 3.2.0.
2569    ///
2570    /// ## See also
2571    /// - [`SDL_SetAudioStreamGetCallback`]
2572    pub fn SDL_SetAudioStreamPutCallback(
2573        stream: *mut SDL_AudioStream,
2574        callback: SDL_AudioStreamCallback,
2575        userdata: *mut ::core::ffi::c_void,
2576    ) -> ::core::primitive::bool;
2577}
2578
2579unsafe extern "C" {
2580    /// Free an audio stream.
2581    ///
2582    /// This will release all allocated data, including any audio that is still
2583    /// queued. You do not need to manually clear the stream first.
2584    ///
2585    /// If this stream was bound to an audio device, it is unbound during this
2586    /// call. If this stream was created with [`SDL_OpenAudioDeviceStream`], the audio
2587    /// device that was opened alongside this stream's creation will be closed,
2588    /// too.
2589    ///
2590    /// ## Parameters
2591    /// - `stream`: the audio stream to destroy.
2592    ///
2593    /// ## Thread safety
2594    /// It is safe to call this function from any thread.
2595    ///
2596    /// ## Availability
2597    /// This function is available since SDL 3.2.0.
2598    ///
2599    /// ## See also
2600    /// - [`SDL_CreateAudioStream`]
2601    pub fn SDL_DestroyAudioStream(stream: *mut SDL_AudioStream);
2602}
2603
2604unsafe extern "C" {
2605    /// Convenience function for straightforward audio init for the common case.
2606    ///
2607    /// If all your app intends to do is provide a single source of PCM audio, this
2608    /// function allows you to do all your audio setup in a single call.
2609    ///
2610    /// This is also intended to be a clean means to migrate apps from SDL2.
2611    ///
2612    /// This function will open an audio device, create a stream and bind it.
2613    /// Unlike other methods of setup, the audio device will be closed when this
2614    /// stream is destroyed, so the app can treat the returned [`SDL_AudioStream`] as
2615    /// the only object needed to manage audio playback.
2616    ///
2617    /// Also unlike other functions, the audio device begins paused. This is to map
2618    /// more closely to SDL2-style behavior, since there is no extra step here to
2619    /// bind a stream to begin audio flowing. The audio device should be resumed
2620    /// with [`SDL_ResumeAudioStreamDevice()`].
2621    ///
2622    /// This function works with both playback and recording devices.
2623    ///
2624    /// The `spec` parameter represents the app's side of the audio stream. That
2625    /// is, for recording audio, this will be the output format, and for playing
2626    /// audio, this will be the input format. If spec is NULL, the system will
2627    /// choose the format, and the app can use [`SDL_GetAudioStreamFormat()`] to obtain
2628    /// this information later.
2629    ///
2630    /// If you don't care about opening a specific audio device, you can (and
2631    /// probably _should_), use [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`] for playback and
2632    /// [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`] for recording.
2633    ///
2634    /// One can optionally provide a callback function; if NULL, the app is
2635    /// expected to queue audio data for playback (or unqueue audio data if
2636    /// capturing). Otherwise, the callback will begin to fire once the device is
2637    /// unpaused.
2638    ///
2639    /// Destroying the returned stream with [`SDL_DestroyAudioStream`] will also close
2640    /// the audio device associated with this stream.
2641    ///
2642    /// ## Parameters
2643    /// - `devid`: an audio device to open, or [`SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK`]
2644    ///   or [`SDL_AUDIO_DEVICE_DEFAULT_RECORDING`].
2645    /// - `spec`: the audio stream's data format. Can be NULL.
2646    /// - `callback`: a callback where the app will provide new data for
2647    ///   playback, or receive new data for recording. Can be NULL,
2648    ///   in which case the app will need to call
2649    ///   [`SDL_PutAudioStreamData`] or [`SDL_GetAudioStreamData`] as
2650    ///   necessary.
2651    /// - `userdata`: app-controlled pointer passed to callback. Can be NULL.
2652    ///   Ignored if callback is NULL.
2653    ///
2654    /// ## Return value
2655    /// Returns an audio stream on success, ready to use, or NULL on failure; call
2656    ///   [`SDL_GetError()`] for more information. When done with this stream,
2657    ///   call [`SDL_DestroyAudioStream`] to free resources and close the
2658    ///   device.
2659    ///
2660    /// ## Thread safety
2661    /// It is safe to call this function from any thread.
2662    ///
2663    /// ## Availability
2664    /// This function is available since SDL 3.2.0.
2665    ///
2666    /// ## See also
2667    /// - [`SDL_GetAudioStreamDevice`]
2668    /// - [`SDL_ResumeAudioStreamDevice`]
2669    pub fn SDL_OpenAudioDeviceStream(
2670        devid: SDL_AudioDeviceID,
2671        spec: *const SDL_AudioSpec,
2672        callback: SDL_AudioStreamCallback,
2673        userdata: *mut ::core::ffi::c_void,
2674    ) -> *mut SDL_AudioStream;
2675}
2676
2677/// A callback that fires when data is about to be fed to an audio device.
2678///
2679/// This is useful for accessing the final mix, perhaps for writing a
2680/// visualizer or applying a final effect to the audio data before playback.
2681///
2682/// This callback should run as quickly as possible and not block for any
2683/// significant time, as this callback delays submission of data to the audio
2684/// device, which can cause audio playback problems.
2685///
2686/// The postmix callback _must_ be able to handle any audio data format
2687/// specified in `spec`, which can change between callbacks if the audio device
2688/// changed. However, this only covers frequency and channel count; data is
2689/// always provided here in [`SDL_AUDIO_F32`] format.
2690///
2691/// The postmix callback runs _after_ logical device gain and audiostream gain
2692/// have been applied, which is to say you can make the output data louder at
2693/// this point than the gain settings would suggest.
2694///
2695/// ## Parameters
2696/// - `userdata`: a pointer provided by the app through
2697///   [`SDL_SetAudioPostmixCallback`], for its own use.
2698/// - `spec`: the current format of audio that is to be submitted to the
2699///   audio device.
2700/// - `buffer`: the buffer of audio samples to be submitted. The callback can
2701///   inspect and/or modify this data.
2702/// - `buflen`: the size of `buffer` in bytes.
2703///
2704/// ## Thread safety
2705/// This will run from a background thread owned by SDL. The
2706///   application is responsible for locking resources the callback
2707///   touches that need to be protected.
2708///
2709/// ## Availability
2710/// This datatype is available since SDL 3.2.0.
2711///
2712/// ## See also
2713/// - [`SDL_SetAudioPostmixCallback`]
2714pub type SDL_AudioPostmixCallback = ::core::option::Option<
2715    unsafe extern "C" fn(
2716        userdata: *mut ::core::ffi::c_void,
2717        spec: *const SDL_AudioSpec,
2718        buffer: *mut ::core::ffi::c_float,
2719        buflen: ::core::ffi::c_int,
2720    ),
2721>;
2722
2723unsafe extern "C" {
2724    /// Set a callback that fires when data is about to be fed to an audio device.
2725    ///
2726    /// This is useful for accessing the final mix, perhaps for writing a
2727    /// visualizer or applying a final effect to the audio data before playback.
2728    ///
2729    /// The buffer is the final mix of all bound audio streams on an opened device;
2730    /// this callback will fire regularly for any device that is both opened and
2731    /// unpaused. If there is no new data to mix, either because no streams are
2732    /// bound to the device or all the streams are empty, this callback will still
2733    /// fire with the entire buffer set to silence.
2734    ///
2735    /// This callback is allowed to make changes to the data; the contents of the
2736    /// buffer after this call is what is ultimately passed along to the hardware.
2737    ///
2738    /// The callback is always provided the data in float format (values from -1.0f
2739    /// to 1.0f), but the number of channels or sample rate may be different than
2740    /// the format the app requested when opening the device; SDL might have had to
2741    /// manage a conversion behind the scenes, or the playback might have jumped to
2742    /// new physical hardware when a system default changed, etc. These details may
2743    /// change between calls. Accordingly, the size of the buffer might change
2744    /// between calls as well.
2745    ///
2746    /// This callback can run at any time, and from any thread; if you need to
2747    /// serialize access to your app's data, you should provide and use a mutex or
2748    /// other synchronization device.
2749    ///
2750    /// All of this to say: there are specific needs this callback can fulfill, but
2751    /// it is not the simplest interface. Apps should generally provide audio in
2752    /// their preferred format through an [`SDL_AudioStream`] and let SDL handle the
2753    /// difference.
2754    ///
2755    /// This function is extremely time-sensitive; the callback should do the least
2756    /// amount of work possible and return as quickly as it can. The longer the
2757    /// callback runs, the higher the risk of audio dropouts or other problems.
2758    ///
2759    /// This function will block until the audio device is in between iterations,
2760    /// so any existing callback that might be running will finish before this
2761    /// function sets the new callback and returns.
2762    ///
2763    /// Setting a NULL callback function disables any previously-set callback.
2764    ///
2765    /// ## Parameters
2766    /// - `devid`: the ID of an opened audio device.
2767    /// - `callback`: a callback function to be called. Can be NULL.
2768    /// - `userdata`: app-controlled pointer passed to callback. Can be NULL.
2769    ///
2770    /// ## Return value
2771    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2772    ///   information.
2773    ///
2774    /// ## Thread safety
2775    /// It is safe to call this function from any thread.
2776    ///
2777    /// ## Availability
2778    /// This function is available since SDL 3.2.0.
2779    pub fn SDL_SetAudioPostmixCallback(
2780        devid: SDL_AudioDeviceID,
2781        callback: SDL_AudioPostmixCallback,
2782        userdata: *mut ::core::ffi::c_void,
2783    ) -> ::core::primitive::bool;
2784}
2785
2786unsafe extern "C" {
2787    /// Load the audio data of a WAVE file into memory.
2788    ///
2789    /// Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to
2790    /// be valid pointers. The entire data portion of the file is then loaded into
2791    /// memory and decoded if necessary.
2792    ///
2793    /// Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
2794    /// 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
2795    /// A-law and mu-law (8 bits). Other formats are currently unsupported and
2796    /// cause an error.
2797    ///
2798    /// If this function succeeds, the return value is zero and the pointer to the
2799    /// audio data allocated by the function is written to `audio_buf` and its
2800    /// length in bytes to `audio_len`. The [`SDL_AudioSpec`] members `freq`,
2801    /// `channels`, and `format` are set to the values of the audio data in the
2802    /// buffer.
2803    ///
2804    /// It's necessary to use [`SDL_free()`] to free the audio data returned in
2805    /// `audio_buf` when it is no longer used.
2806    ///
2807    /// Because of the underspecification of the .WAV format, there are many
2808    /// problematic files in the wild that cause issues with strict decoders. To
2809    /// provide compatibility with these files, this decoder is lenient in regards
2810    /// to the truncation of the file, the fact chunk, and the size of the RIFF
2811    /// chunk. The hints [`SDL_HINT_WAVE_RIFF_CHUNK_SIZE`],
2812    /// [`SDL_HINT_WAVE_TRUNCATION`], and [`SDL_HINT_WAVE_FACT_CHUNK`] can be used to
2813    /// tune the behavior of the loading process.
2814    ///
2815    /// Any file that is invalid (due to truncation, corruption, or wrong values in
2816    /// the headers), too big, or unsupported causes an error. Additionally, any
2817    /// critical I/O error from the data source will terminate the loading process
2818    /// with an error. The function returns NULL on error and in all cases (with
2819    /// the exception of `src` being NULL), an appropriate error message will be
2820    /// set.
2821    ///
2822    /// It is required that the data source supports seeking.
2823    ///
2824    /// Example:
2825    ///
2826    /// ```c
2827    /// SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), true, &spec, &buf, &len);
2828    /// ```
2829    ///
2830    /// Note that the [`SDL_LoadWAV`] function does this same thing for you, but in a
2831    /// less messy way:
2832    ///
2833    /// ```c
2834    /// SDL_LoadWAV("sample.wav", &spec, &buf, &len);
2835    /// ```
2836    ///
2837    /// ## Parameters
2838    /// - `src`: the data source for the WAVE data.
2839    /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `src` before returning, even
2840    ///   in the case of an error.
2841    /// - `spec`: a pointer to an [`SDL_AudioSpec`] that will be set to the WAVE
2842    ///   data's format details on successful return.
2843    /// - `audio_buf`: a pointer filled with the audio data, allocated by the
2844    ///   function.
2845    /// - `audio_len`: a pointer filled with the length of the audio data buffer
2846    ///   in bytes.
2847    ///
2848    /// ## Return value
2849    /// Returns true on success. `audio_buf` will be filled with a pointer to an
2850    ///   allocated buffer containing the audio data, and `audio_len` is
2851    ///   filled with the length of that audio buffer in bytes.
2852    ///
2853    /// ```text
2854    ///      This function returns false if the .WAV file cannot be opened,
2855    ///      uses an unknown data format, or is corrupt; call SDL_GetError()
2856    ///      for more information.
2857    ///
2858    ///      When the application is done with the data returned in
2859    ///      `audio_buf`, it should call SDL_free() to dispose of it.
2860    /// ```
2861    ///
2862    /// \threadsafety It is safe to call this function from any thread.
2863    ///
2864    /// ## Availability
2865    /// This function is available since SDL 3.2.0.
2866    ///
2867    /// ## See also
2868    /// - [`SDL_free`]
2869    /// - [`SDL_LoadWAV`]
2870    pub fn SDL_LoadWAV_IO(
2871        src: *mut SDL_IOStream,
2872        closeio: ::core::primitive::bool,
2873        spec: *mut SDL_AudioSpec,
2874        audio_buf: *mut *mut Uint8,
2875        audio_len: *mut Uint32,
2876    ) -> ::core::primitive::bool;
2877}
2878
2879unsafe extern "C" {
2880    /// Loads a WAV from a file path.
2881    ///
2882    /// This is a convenience function that is effectively the same as:
2883    ///
2884    /// ```c
2885    /// SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len);
2886    /// ```
2887    ///
2888    /// ## Parameters
2889    /// - `path`: the file path of the WAV file to open.
2890    /// - `spec`: a pointer to an [`SDL_AudioSpec`] that will be set to the WAVE
2891    ///   data's format details on successful return.
2892    /// - `audio_buf`: a pointer filled with the audio data, allocated by the
2893    ///   function.
2894    /// - `audio_len`: a pointer filled with the length of the audio data buffer
2895    ///   in bytes.
2896    ///
2897    /// ## Return value
2898    /// Returns true on success. `audio_buf` will be filled with a pointer to an
2899    ///   allocated buffer containing the audio data, and `audio_len` is
2900    ///   filled with the length of that audio buffer in bytes.
2901    ///
2902    /// ```text
2903    ///      This function returns false if the .WAV file cannot be opened,
2904    ///      uses an unknown data format, or is corrupt; call SDL_GetError()
2905    ///      for more information.
2906    ///
2907    ///      When the application is done with the data returned in
2908    ///      `audio_buf`, it should call SDL_free() to dispose of it.
2909    /// ```
2910    ///
2911    /// \threadsafety It is safe to call this function from any thread.
2912    ///
2913    /// ## Availability
2914    /// This function is available since SDL 3.2.0.
2915    ///
2916    /// ## See also
2917    /// - [`SDL_free`]
2918    /// - [`SDL_LoadWAV_IO`]
2919    pub fn SDL_LoadWAV(
2920        path: *const ::core::ffi::c_char,
2921        spec: *mut SDL_AudioSpec,
2922        audio_buf: *mut *mut Uint8,
2923        audio_len: *mut Uint32,
2924    ) -> ::core::primitive::bool;
2925}
2926
2927unsafe extern "C" {
2928    /// Mix audio data in a specified format.
2929    ///
2930    /// This takes an audio buffer `src` of `len` bytes of `format` data and mixes
2931    /// it into `dst`, performing addition, volume adjustment, and overflow
2932    /// clipping. The buffer pointed to by `dst` must also be `len` bytes of
2933    /// `format` data.
2934    ///
2935    /// This is provided for convenience -- you can mix your own audio data.
2936    ///
2937    /// Do not use this function for mixing together more than two streams of
2938    /// sample data. The output from repeated application of this function may be
2939    /// distorted by clipping, because there is no accumulator with greater range
2940    /// than the input (not to mention this being an inefficient way of doing it).
2941    ///
2942    /// It is a common misconception that this function is required to write audio
2943    /// data to an output stream in an audio callback. While you can do that,
2944    /// [`SDL_MixAudio()`] is really only needed when you're mixing a single audio
2945    /// stream with a volume adjustment.
2946    ///
2947    /// ## Parameters
2948    /// - `dst`: the destination for the mixed audio.
2949    /// - `src`: the source audio buffer to be mixed.
2950    /// - `format`: the [`SDL_AudioFormat`] structure representing the desired audio
2951    ///   format.
2952    /// - `len`: the length of the audio buffer in bytes.
2953    /// - `volume`: ranges from 0.0 - 1.0, and should be set to 1.0 for full
2954    ///   audio volume.
2955    ///
2956    /// ## Return value
2957    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2958    ///   information.
2959    ///
2960    /// ## Thread safety
2961    /// It is safe to call this function from any thread.
2962    ///
2963    /// ## Availability
2964    /// This function is available since SDL 3.2.0.
2965    pub fn SDL_MixAudio(
2966        dst: *mut Uint8,
2967        src: *const Uint8,
2968        format: SDL_AudioFormat,
2969        len: Uint32,
2970        volume: ::core::ffi::c_float,
2971    ) -> ::core::primitive::bool;
2972}
2973
2974unsafe extern "C" {
2975    /// Convert some audio data of one format to another format.
2976    ///
2977    /// Please note that this function is for convenience, but should not be used
2978    /// to resample audio in blocks, as it will introduce audio artifacts on the
2979    /// boundaries. You should only use this function if you are converting audio
2980    /// data in its entirety in one call. If you want to convert audio in smaller
2981    /// chunks, use an [`SDL_AudioStream`], which is designed for this situation.
2982    ///
2983    /// Internally, this function creates and destroys an [`SDL_AudioStream`] on each
2984    /// use, so it's also less efficient than using one directly, if you need to
2985    /// convert multiple times.
2986    ///
2987    /// ## Parameters
2988    /// - `src_spec`: the format details of the input audio.
2989    /// - `src_data`: the audio data to be converted.
2990    /// - `src_len`: the len of src_data.
2991    /// - `dst_spec`: the format details of the output audio.
2992    /// - `dst_data`: will be filled with a pointer to converted audio data,
2993    ///   which should be freed with [`SDL_free()`]. On error, it will be
2994    ///   NULL.
2995    /// - `dst_len`: will be filled with the len of dst_data.
2996    ///
2997    /// ## Return value
2998    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2999    ///   information.
3000    ///
3001    /// ## Thread safety
3002    /// It is safe to call this function from any thread.
3003    ///
3004    /// ## Availability
3005    /// This function is available since SDL 3.2.0.
3006    pub fn SDL_ConvertAudioSamples(
3007        src_spec: *const SDL_AudioSpec,
3008        src_data: *const Uint8,
3009        src_len: ::core::ffi::c_int,
3010        dst_spec: *const SDL_AudioSpec,
3011        dst_data: *mut *mut Uint8,
3012        dst_len: *mut ::core::ffi::c_int,
3013    ) -> ::core::primitive::bool;
3014}
3015
3016unsafe extern "C" {
3017    /// Get the human readable name of an audio format.
3018    ///
3019    /// ## Parameters
3020    /// - `format`: the audio format to query.
3021    ///
3022    /// ## Return value
3023    /// Returns the human readable name of the specified audio format or
3024    ///   "SDL_AUDIO_UNKNOWN" if the format isn't recognized.
3025    ///
3026    /// ## Thread safety
3027    /// It is safe to call this function from any thread.
3028    ///
3029    /// ## Availability
3030    /// This function is available since SDL 3.2.0.
3031    pub fn SDL_GetAudioFormatName(format: SDL_AudioFormat) -> *const ::core::ffi::c_char;
3032}
3033
3034unsafe extern "C" {
3035    /// Get the appropriate memset value for silencing an audio format.
3036    ///
3037    /// The value returned by this function can be used as the second argument to
3038    /// memset (or [`SDL_memset`]) to set an audio buffer in a specific format to
3039    /// silence.
3040    ///
3041    /// ## Parameters
3042    /// - `format`: the audio data format to query.
3043    ///
3044    /// ## Return value
3045    /// Returns a byte value that can be passed to memset.
3046    ///
3047    /// ## Thread safety
3048    /// It is safe to call this function from any thread.
3049    ///
3050    /// ## Availability
3051    /// This function is available since SDL 3.2.0.
3052    pub safe fn SDL_GetSilenceValueForFormat(format: SDL_AudioFormat) -> ::core::ffi::c_int;
3053}
3054
3055/// The opaque handle that represents an audio stream.
3056///
3057/// [`SDL_AudioStream`] is an audio conversion interface.
3058///
3059/// - It can handle resampling data in chunks without generating artifacts,
3060///   when it doesn't have the complete buffer available.
3061/// - It can handle incoming data in any variable size.
3062/// - It can handle input/output format changes on the fly.
3063/// - It can remap audio channels between inputs and outputs.
3064/// - You push data as you have it, and pull it when you need it; the
3065///   stream will buffer data as needed.
3066/// - It can also function as a basic audio data queue even if you just have
3067///   sound that needs to pass from one place to another.
3068/// - You can hook callbacks up to them when more data is added or requested,
3069///   to manage data on-the-fly.
3070///
3071/// Audio streams are the core of the SDL3 audio interface. You create one or
3072/// more of them, bind them to an opened audio device, and feed data to them
3073/// (or for recording, consume data from them).
3074///
3075/// ## Availability
3076/// This struct is available since SDL 3.2.0.
3077///
3078/// ## See also
3079/// - [`SDL_CreateAudioStream`]
3080#[repr(C)]
3081pub struct SDL_AudioStream {
3082    _opaque: [::core::primitive::u8; 0],
3083}
3084
3085#[cfg(doc)]
3086use crate::everything::*;