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