Path: blob/master/thirdparty/sdl/include/SDL3/SDL_audio.h
21884 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryAudio23*24* Audio functionality for the SDL library.25*26* All audio in SDL3 revolves around SDL_AudioStream. Whether you want to play27* or record audio, convert it, stream it, buffer it, or mix it, you're going28* to be passing it through an audio stream.29*30* Audio streams are quite flexible; they can accept any amount of data at a31* time, in any supported format, and output it as needed in any other format,32* even if the data format changes on either side halfway through.33*34* An app opens an audio device and binds any number of audio streams to it,35* feeding more data to the streams as available. When the device needs more36* data, it will pull it from all bound streams and mix them together for37* playback.38*39* Audio streams can also use an app-provided callback to supply data40* on-demand, which maps pretty closely to the SDL2 audio model.41*42* SDL also provides a simple .WAV loader in SDL_LoadWAV (and SDL_LoadWAV_IO43* if you aren't reading from a file) as a basic means to load sound data into44* your program.45*46* ## Logical audio devices47*48* In SDL3, opening a physical device (like a SoundBlaster 16 Pro) gives you a49* logical device ID that you can bind audio streams to. In almost all cases,50* logical devices can be used anywhere in the API that a physical device is51* normally used. However, since each device opening generates a new logical52* device, different parts of the program (say, a VoIP library, or53* text-to-speech framework, or maybe some other sort of mixer on top of SDL)54* can have their own device opens that do not interfere with each other; each55* logical device will mix its separate audio down to a single buffer, fed to56* the physical device, behind the scenes. As many logical devices as you like57* can come and go; SDL will only have to open the physical device at the OS58* level once, and will manage all the logical devices on top of it59* internally.60*61* One other benefit of logical devices: if you don't open a specific physical62* device, instead opting for the default, SDL can automatically migrate those63* logical devices to different hardware as circumstances change: a user64* plugged in headphones? The system default changed? SDL can transparently65* migrate the logical devices to the correct physical device seamlessly and66* keep playing; the app doesn't even have to know it happened if it doesn't67* want to.68*69* ## Simplified audio70*71* As a simplified model for when a single source of audio is all that's72* needed, an app can use SDL_OpenAudioDeviceStream, which is a single73* function to open an audio device, create an audio stream, bind that stream74* to the newly-opened device, and (optionally) provide a callback for75* obtaining audio data. When using this function, the primary interface is76* the SDL_AudioStream and the device handle is mostly hidden away; destroying77* a stream created through this function will also close the device, stream78* bindings cannot be changed, etc. One other quirk of this is that the device79* is started in a _paused_ state and must be explicitly resumed; this is80* partially to offer a clean migration for SDL2 apps and partially because81* the app might have to do more setup before playback begins; in the82* non-simplified form, nothing will play until a stream is bound to a device,83* so they start _unpaused_.84*85* ## Channel layouts86*87* Audio data passing through SDL is uncompressed PCM data, interleaved. One88* can provide their own decompression through an MP3, etc, decoder, but SDL89* does not provide this directly. Each interleaved channel of data is meant90* to be in a specific order.91*92* Abbreviations:93*94* - FRONT = single mono speaker95* - FL = front left speaker96* - FR = front right speaker97* - FC = front center speaker98* - BL = back left speaker99* - BR = back right speaker100* - SR = surround right speaker101* - SL = surround left speaker102* - BC = back center speaker103* - LFE = low-frequency speaker104*105* These are listed in the order they are laid out in memory, so "FL, FR"106* means "the front left speaker is laid out in memory first, then the front107* right, then it repeats for the next audio frame".108*109* - 1 channel (mono) layout: FRONT110* - 2 channels (stereo) layout: FL, FR111* - 3 channels (2.1) layout: FL, FR, LFE112* - 4 channels (quad) layout: FL, FR, BL, BR113* - 5 channels (4.1) layout: FL, FR, LFE, BL, BR114* - 6 channels (5.1) layout: FL, FR, FC, LFE, BL, BR (last two can also be115* SL, SR)116* - 7 channels (6.1) layout: FL, FR, FC, LFE, BC, SL, SR117* - 8 channels (7.1) layout: FL, FR, FC, LFE, BL, BR, SL, SR118*119* This is the same order as DirectSound expects, but applied to all120* platforms; SDL will swizzle the channels as necessary if a platform expects121* something different.122*123* SDL_AudioStream can also be provided channel maps to change this ordering124* to whatever is necessary, in other audio processing scenarios.125*/126127#ifndef SDL_audio_h_128#define SDL_audio_h_129130#include <SDL3/SDL_stdinc.h>131#include <SDL3/SDL_endian.h>132#include <SDL3/SDL_error.h>133#include <SDL3/SDL_mutex.h>134#include <SDL3/SDL_properties.h>135#include <SDL3/SDL_iostream.h>136137#include <SDL3/SDL_begin_code.h>138/* Set up for C function definitions, even when using C++ */139#ifdef __cplusplus140extern "C" {141#endif142143/**144* Mask of bits in an SDL_AudioFormat that contains the format bit size.145*146* Generally one should use SDL_AUDIO_BITSIZE instead of this macro directly.147*148* \since This macro is available since SDL 3.2.0.149*/150#define SDL_AUDIO_MASK_BITSIZE (0xFFu)151152/**153* Mask of bits in an SDL_AudioFormat that contain the floating point flag.154*155* Generally one should use SDL_AUDIO_ISFLOAT instead of this macro directly.156*157* \since This macro is available since SDL 3.2.0.158*/159#define SDL_AUDIO_MASK_FLOAT (1u<<8)160161/**162* Mask of bits in an SDL_AudioFormat that contain the bigendian flag.163*164* Generally one should use SDL_AUDIO_ISBIGENDIAN or SDL_AUDIO_ISLITTLEENDIAN165* instead of this macro directly.166*167* \since This macro is available since SDL 3.2.0.168*/169#define SDL_AUDIO_MASK_BIG_ENDIAN (1u<<12)170171/**172* Mask of bits in an SDL_AudioFormat that contain the signed data flag.173*174* Generally one should use SDL_AUDIO_ISSIGNED instead of this macro directly.175*176* \since This macro is available since SDL 3.2.0.177*/178#define SDL_AUDIO_MASK_SIGNED (1u<<15)179180/**181* Define an SDL_AudioFormat value.182*183* SDL does not support custom audio formats, so this macro is not of much use184* externally, but it can be illustrative as to what the various bits of an185* SDL_AudioFormat mean.186*187* For example, SDL_AUDIO_S32LE looks like this:188*189* ```c190* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32)191* ```192*193* \param signed 1 for signed data, 0 for unsigned data.194* \param bigendian 1 for bigendian data, 0 for littleendian data.195* \param flt 1 for floating point data, 0 for integer data.196* \param size number of bits per sample.197* \returns a format value in the style of SDL_AudioFormat.198*199* \threadsafety It is safe to call this macro from any thread.200*201* \since This macro is available since SDL 3.2.0.202*/203#define SDL_DEFINE_AUDIO_FORMAT(signed, bigendian, flt, size) \204(((Uint16)(signed) << 15) | ((Uint16)(bigendian) << 12) | ((Uint16)(flt) << 8) | ((size) & SDL_AUDIO_MASK_BITSIZE))205206/**207* Audio format.208*209* \since This enum is available since SDL 3.2.0.210*211* \sa SDL_AUDIO_BITSIZE212* \sa SDL_AUDIO_BYTESIZE213* \sa SDL_AUDIO_ISINT214* \sa SDL_AUDIO_ISFLOAT215* \sa SDL_AUDIO_ISBIGENDIAN216* \sa SDL_AUDIO_ISLITTLEENDIAN217* \sa SDL_AUDIO_ISSIGNED218* \sa SDL_AUDIO_ISUNSIGNED219*/220typedef enum SDL_AudioFormat221{222SDL_AUDIO_UNKNOWN = 0x0000u, /**< Unspecified audio format */223SDL_AUDIO_U8 = 0x0008u, /**< Unsigned 8-bit samples */224/* SDL_DEFINE_AUDIO_FORMAT(0, 0, 0, 8), */225SDL_AUDIO_S8 = 0x8008u, /**< Signed 8-bit samples */226/* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 8), */227SDL_AUDIO_S16LE = 0x8010u, /**< Signed 16-bit samples */228/* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 16), */229SDL_AUDIO_S16BE = 0x9010u, /**< As above, but big-endian byte order */230/* SDL_DEFINE_AUDIO_FORMAT(1, 1, 0, 16), */231SDL_AUDIO_S32LE = 0x8020u, /**< 32-bit integer samples */232/* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32), */233SDL_AUDIO_S32BE = 0x9020u, /**< As above, but big-endian byte order */234/* SDL_DEFINE_AUDIO_FORMAT(1, 1, 0, 32), */235SDL_AUDIO_F32LE = 0x8120u, /**< 32-bit floating point samples */236/* SDL_DEFINE_AUDIO_FORMAT(1, 0, 1, 32), */237SDL_AUDIO_F32BE = 0x9120u, /**< As above, but big-endian byte order */238/* SDL_DEFINE_AUDIO_FORMAT(1, 1, 1, 32), */239240/* These represent the current system's byteorder. */241#if SDL_BYTEORDER == SDL_LIL_ENDIAN242SDL_AUDIO_S16 = SDL_AUDIO_S16LE,243SDL_AUDIO_S32 = SDL_AUDIO_S32LE,244SDL_AUDIO_F32 = SDL_AUDIO_F32LE245#else246SDL_AUDIO_S16 = SDL_AUDIO_S16BE,247SDL_AUDIO_S32 = SDL_AUDIO_S32BE,248SDL_AUDIO_F32 = SDL_AUDIO_F32BE249#endif250} SDL_AudioFormat;251252253/**254* Retrieve the size, in bits, from an SDL_AudioFormat.255*256* For example, `SDL_AUDIO_BITSIZE(SDL_AUDIO_S16)` returns 16.257*258* \param x an SDL_AudioFormat value.259* \returns data size in bits.260*261* \threadsafety It is safe to call this macro from any thread.262*263* \since This macro is available since SDL 3.2.0.264*/265#define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)266267/**268* Retrieve the size, in bytes, from an SDL_AudioFormat.269*270* For example, `SDL_AUDIO_BYTESIZE(SDL_AUDIO_S16)` returns 2.271*272* \param x an SDL_AudioFormat value.273* \returns data size in bytes.274*275* \threadsafety It is safe to call this macro from any thread.276*277* \since This macro is available since SDL 3.2.0.278*/279#define SDL_AUDIO_BYTESIZE(x) (SDL_AUDIO_BITSIZE(x) / 8)280281/**282* Determine if an SDL_AudioFormat represents floating point data.283*284* For example, `SDL_AUDIO_ISFLOAT(SDL_AUDIO_S16)` returns 0.285*286* \param x an SDL_AudioFormat value.287* \returns non-zero if format is floating point, zero otherwise.288*289* \threadsafety It is safe to call this macro from any thread.290*291* \since This macro is available since SDL 3.2.0.292*/293#define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)294295/**296* Determine if an SDL_AudioFormat represents bigendian data.297*298* For example, `SDL_AUDIO_ISBIGENDIAN(SDL_AUDIO_S16LE)` returns 0.299*300* \param x an SDL_AudioFormat value.301* \returns non-zero if format is bigendian, zero otherwise.302*303* \threadsafety It is safe to call this macro from any thread.304*305* \since This macro is available since SDL 3.2.0.306*/307#define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)308309/**310* Determine if an SDL_AudioFormat represents littleendian data.311*312* For example, `SDL_AUDIO_ISLITTLEENDIAN(SDL_AUDIO_S16BE)` returns 0.313*314* \param x an SDL_AudioFormat value.315* \returns non-zero if format is littleendian, zero otherwise.316*317* \threadsafety It is safe to call this macro from any thread.318*319* \since This macro is available since SDL 3.2.0.320*/321#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))322323/**324* Determine if an SDL_AudioFormat represents signed data.325*326* For example, `SDL_AUDIO_ISSIGNED(SDL_AUDIO_U8)` returns 0.327*328* \param x an SDL_AudioFormat value.329* \returns non-zero if format is signed, zero otherwise.330*331* \threadsafety It is safe to call this macro from any thread.332*333* \since This macro is available since SDL 3.2.0.334*/335#define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED)336337/**338* Determine if an SDL_AudioFormat represents integer data.339*340* For example, `SDL_AUDIO_ISINT(SDL_AUDIO_F32)` returns 0.341*342* \param x an SDL_AudioFormat value.343* \returns non-zero if format is integer, zero otherwise.344*345* \threadsafety It is safe to call this macro from any thread.346*347* \since This macro is available since SDL 3.2.0.348*/349#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))350351/**352* Determine if an SDL_AudioFormat represents unsigned data.353*354* For example, `SDL_AUDIO_ISUNSIGNED(SDL_AUDIO_S16)` returns 0.355*356* \param x an SDL_AudioFormat value.357* \returns non-zero if format is unsigned, zero otherwise.358*359* \threadsafety It is safe to call this macro from any thread.360*361* \since This macro is available since SDL 3.2.0.362*/363#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))364365366/**367* SDL Audio Device instance IDs.368*369* Zero is used to signify an invalid/null device.370*371* \since This datatype is available since SDL 3.2.0.372*/373typedef Uint32 SDL_AudioDeviceID;374375/**376* A value used to request a default playback audio device.377*378* Several functions that require an SDL_AudioDeviceID will accept this value379* to signify the app just wants the system to choose a default device instead380* of the app providing a specific one.381*382* \since This macro is available since SDL 3.2.0.383*/384#define SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK ((SDL_AudioDeviceID) 0xFFFFFFFFu)385386/**387* A value used to request a default recording audio device.388*389* Several functions that require an SDL_AudioDeviceID will accept this value390* to signify the app just wants the system to choose a default device instead391* of the app providing a specific one.392*393* \since This macro is available since SDL 3.2.0.394*/395#define SDL_AUDIO_DEVICE_DEFAULT_RECORDING ((SDL_AudioDeviceID) 0xFFFFFFFEu)396397/**398* Format specifier for audio data.399*400* \since This struct is available since SDL 3.2.0.401*402* \sa SDL_AudioFormat403*/404typedef struct SDL_AudioSpec405{406SDL_AudioFormat format; /**< Audio data format */407int channels; /**< Number of channels: 1 mono, 2 stereo, etc */408int freq; /**< sample rate: sample frames per second */409} SDL_AudioSpec;410411/**412* Calculate the size of each audio frame (in bytes) from an SDL_AudioSpec.413*414* This reports on the size of an audio sample frame: stereo Sint16 data (2415* channels of 2 bytes each) would be 4 bytes per frame, for example.416*417* \param x an SDL_AudioSpec to query.418* \returns the number of bytes used per sample frame.419*420* \threadsafety It is safe to call this macro from any thread.421*422* \since This macro is available since SDL 3.2.0.423*/424#define SDL_AUDIO_FRAMESIZE(x) (SDL_AUDIO_BYTESIZE((x).format) * (x).channels)425426/**427* The opaque handle that represents an audio stream.428*429* SDL_AudioStream is an audio conversion interface.430*431* - It can handle resampling data in chunks without generating artifacts,432* when it doesn't have the complete buffer available.433* - It can handle incoming data in any variable size.434* - It can handle input/output format changes on the fly.435* - It can remap audio channels between inputs and outputs.436* - You push data as you have it, and pull it when you need it437* - It can also function as a basic audio data queue even if you just have438* sound that needs to pass from one place to another.439* - You can hook callbacks up to them when more data is added or requested,440* to manage data on-the-fly.441*442* Audio streams are the core of the SDL3 audio interface. You create one or443* more of them, bind them to an opened audio device, and feed data to them444* (or for recording, consume data from them).445*446* \since This struct is available since SDL 3.2.0.447*448* \sa SDL_CreateAudioStream449*/450typedef struct SDL_AudioStream SDL_AudioStream;451452453/* Function prototypes */454455/**456* Use this function to get the number of built-in audio drivers.457*458* This function returns a hardcoded number. This never returns a negative459* value; if there are no drivers compiled into this build of SDL, this460* function returns zero. The presence of a driver in this list does not mean461* it will function, it just means SDL is capable of interacting with that462* interface. For example, a build of SDL might have esound support, but if463* there's no esound server available, SDL's esound driver would fail if used.464*465* By default, SDL tries all drivers, in its preferred order, until one is466* found to be usable.467*468* \returns the number of built-in audio drivers.469*470* \threadsafety It is safe to call this function from any thread.471*472* \since This function is available since SDL 3.2.0.473*474* \sa SDL_GetAudioDriver475*/476extern SDL_DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);477478/**479* Use this function to get the name of a built in audio driver.480*481* The list of audio drivers is given in the order that they are normally482* initialized by default; the drivers that seem more reasonable to choose483* first (as far as the SDL developers believe) are earlier in the list.484*485* The names of drivers are all simple, low-ASCII identifiers, like "alsa",486* "coreaudio" or "wasapi". These never have Unicode characters, and are not487* meant to be proper names.488*489* \param index the index of the audio driver; the value ranges from 0 to490* SDL_GetNumAudioDrivers() - 1.491* \returns the name of the audio driver at the requested index, or NULL if an492* invalid index was specified.493*494* \threadsafety It is safe to call this function from any thread.495*496* \since This function is available since SDL 3.2.0.497*498* \sa SDL_GetNumAudioDrivers499*/500extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);501502/**503* Get the name of the current audio driver.504*505* The names of drivers are all simple, low-ASCII identifiers, like "alsa",506* "coreaudio" or "wasapi". These never have Unicode characters, and are not507* meant to be proper names.508*509* \returns the name of the current audio driver or NULL if no driver has been510* initialized.511*512* \threadsafety It is safe to call this function from any thread.513*514* \since This function is available since SDL 3.2.0.515*/516extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);517518/**519* Get a list of currently-connected audio playback devices.520*521* This returns of list of available devices that play sound, perhaps to522* speakers or headphones ("playback" devices). If you want devices that523* record audio, like a microphone ("recording" devices), use524* SDL_GetAudioRecordingDevices() instead.525*526* This only returns a list of physical devices; it will not have any device527* IDs returned by SDL_OpenAudioDevice().528*529* If this function returns NULL, to signify an error, `*count` will be set to530* zero.531*532* \param count a pointer filled in with the number of devices returned, may533* be NULL.534* \returns a 0 terminated array of device instance IDs or NULL on error; call535* SDL_GetError() for more information. This should be freed with536* SDL_free() when it is no longer needed.537*538* \threadsafety It is safe to call this function from any thread.539*540* \since This function is available since SDL 3.2.0.541*542* \sa SDL_OpenAudioDevice543* \sa SDL_GetAudioRecordingDevices544*/545extern SDL_DECLSPEC SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count);546547/**548* Get a list of currently-connected audio recording devices.549*550* This returns of list of available devices that record audio, like a551* microphone ("recording" devices). If you want devices that play sound,552* perhaps to speakers or headphones ("playback" devices), use553* SDL_GetAudioPlaybackDevices() instead.554*555* This only returns a list of physical devices; it will not have any device556* IDs returned by SDL_OpenAudioDevice().557*558* If this function returns NULL, to signify an error, `*count` will be set to559* zero.560*561* \param count a pointer filled in with the number of devices returned, may562* be NULL.563* \returns a 0 terminated array of device instance IDs, or NULL on failure;564* call SDL_GetError() for more information. This should be freed565* with SDL_free() when it is no longer needed.566*567* \threadsafety It is safe to call this function from any thread.568*569* \since This function is available since SDL 3.2.0.570*571* \sa SDL_OpenAudioDevice572* \sa SDL_GetAudioPlaybackDevices573*/574extern SDL_DECLSPEC SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count);575576/**577* Get the human-readable name of a specific audio device.578*579* \param devid the instance ID of the device to query.580* \returns the name of the audio device, or NULL on failure; call581* SDL_GetError() for more information.582*583* \threadsafety It is safe to call this function from any thread.584*585* \since This function is available since SDL 3.2.0.586*587* \sa SDL_GetAudioPlaybackDevices588* \sa SDL_GetAudioRecordingDevices589*/590extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);591592/**593* Get the current audio format of a specific audio device.594*595* For an opened device, this will report the format the device is currently596* using. If the device isn't yet opened, this will report the device's597* preferred format (or a reasonable default if this can't be determined).598*599* You may also specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or600* SDL_AUDIO_DEVICE_DEFAULT_RECORDING here, which is useful for getting a601* reasonable recommendation before opening the system-recommended default602* device.603*604* You can also use this to request the current device buffer size. This is605* specified in sample frames and represents the amount of data SDL will feed606* to the physical hardware in each chunk. This can be converted to607* milliseconds of audio with the following equation:608*609* `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);`610*611* Buffer size is only important if you need low-level control over the audio612* playback timing. Most apps do not need this.613*614* \param devid the instance ID of the device to query.615* \param spec on return, will be filled with device details.616* \param sample_frames pointer to store device buffer size, in sample frames.617* Can be NULL.618* \returns true on success or false on failure; call SDL_GetError() for more619* information.620*621* \threadsafety It is safe to call this function from any thread.622*623* \since This function is available since SDL 3.2.0.624*/625extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames);626627/**628* Get the current channel map of an audio device.629*630* Channel maps are optional; most things do not need them, instead passing631* data in the [order that SDL expects](CategoryAudio#channel-layouts).632*633* Audio devices usually have no remapping applied. This is represented by634* returning NULL, and does not signify an error.635*636* \param devid the instance ID of the device to query.637* \param count On output, set to number of channels in the map. Can be NULL.638* \returns an array of the current channel mapping, with as many elements as639* the current output spec's channels, or NULL if default. This640* should be freed with SDL_free() when it is no longer needed.641*642* \threadsafety It is safe to call this function from any thread.643*644* \since This function is available since SDL 3.2.0.645*646* \sa SDL_SetAudioStreamInputChannelMap647*/648extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count);649650/**651* Open a specific audio device.652*653* You can open both playback and recording devices through this function.654* Playback devices will take data from bound audio streams, mix it, and send655* it to the hardware. Recording devices will feed any bound audio streams656* with a copy of any incoming data.657*658* An opened audio device starts out with no audio streams bound. To start659* audio playing, bind a stream and supply audio data to it. Unlike SDL2,660* there is no audio callback; you only bind audio streams and make sure they661* have data flowing into them (however, you can simulate SDL2's semantics662* fairly closely by using SDL_OpenAudioDeviceStream instead of this663* function).664*665* If you don't care about opening a specific device, pass a `devid` of either666* `SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK` or667* `SDL_AUDIO_DEVICE_DEFAULT_RECORDING`. In this case, SDL will try to pick668* the most reasonable default, and may also switch between physical devices669* seamlessly later, if the most reasonable default changes during the670* lifetime of this opened device (user changed the default in the OS's system671* preferences, the default got unplugged so the system jumped to a new672* default, the user plugged in headphones on a mobile device, etc). Unless673* you have a good reason to choose a specific device, this is probably what674* you want.675*676* You may request a specific format for the audio device, but there is no677* promise the device will honor that request for several reasons. As such,678* it's only meant to be a hint as to what data your app will provide. Audio679* streams will accept data in whatever format you specify and manage680* conversion for you as appropriate. SDL_GetAudioDeviceFormat can tell you681* the preferred format for the device before opening and the actual format682* the device is using after opening.683*684* It's legal to open the same device ID more than once; each successful open685* will generate a new logical SDL_AudioDeviceID that is managed separately686* from others on the same physical device. This allows libraries to open a687* device separately from the main app and bind its own streams without688* conflicting.689*690* It is also legal to open a device ID returned by a previous call to this691* function; doing so just creates another logical device on the same physical692* device. This may be useful for making logical groupings of audio streams.693*694* This function returns the opened device ID on success. This is a new,695* unique SDL_AudioDeviceID that represents a logical device.696*697* Some backends might offer arbitrary devices (for example, a networked audio698* protocol that can connect to an arbitrary server). For these, as a change699* from SDL2, you should open a default device ID and use an SDL hint to700* specify the target if you care, or otherwise let the backend figure out a701* reasonable default. Most backends don't offer anything like this, and often702* this would be an end user setting an environment variable for their custom703* need, and not something an application should specifically manage.704*705* When done with an audio device, possibly at the end of the app's life, one706* should call SDL_CloseAudioDevice() on the returned device id.707*708* \param devid the device instance id to open, or709* SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or710* SDL_AUDIO_DEVICE_DEFAULT_RECORDING for the most reasonable711* default device.712* \param spec the requested device configuration. Can be NULL to use713* reasonable defaults.714* \returns the device ID on success or 0 on failure; call SDL_GetError() for715* more information.716*717* \threadsafety It is safe to call this function from any thread.718*719* \since This function is available since SDL 3.2.0.720*721* \sa SDL_CloseAudioDevice722* \sa SDL_GetAudioDeviceFormat723*/724extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);725726/**727* Determine if an audio device is physical (instead of logical).728*729* An SDL_AudioDeviceID that represents physical hardware is a physical730* device; there is one for each piece of hardware that SDL can see. Logical731* devices are created by calling SDL_OpenAudioDevice or732* SDL_OpenAudioDeviceStream, and while each is associated with a physical733* device, there can be any number of logical devices on one physical device.734*735* For the most part, logical and physical IDs are interchangeable--if you try736* to open a logical device, SDL understands to assign that effort to the737* underlying physical device, etc. However, it might be useful to know if an738* arbitrary device ID is physical or logical. This function reports which.739*740* This function may return either true or false for invalid device IDs.741*742* \param devid the device ID to query.743* \returns true if devid is a physical device, false if it is logical.744*745* \threadsafety It is safe to call this function from any thread.746*747* \since This function is available since SDL 3.2.0.748*/749extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePhysical(SDL_AudioDeviceID devid);750751/**752* Determine if an audio device is a playback device (instead of recording).753*754* This function may return either true or false for invalid device IDs.755*756* \param devid the device ID to query.757* \returns true if devid is a playback device, false if it is recording.758*759* \threadsafety It is safe to call this function from any thread.760*761* \since This function is available since SDL 3.2.0.762*/763extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePlayback(SDL_AudioDeviceID devid);764765/**766* Use this function to pause audio playback on a specified device.767*768* This function pauses audio processing for a given device. Any bound audio769* streams will not progress, and no audio will be generated. Pausing one770* device does not prevent other unpaused devices from running.771*772* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app773* has to bind a stream before any audio will flow. Pausing a paused device is774* a legal no-op.775*776* Pausing a device can be useful to halt all audio without unbinding all the777* audio streams. This might be useful while a game is paused, or a level is778* loading, etc.779*780* Physical devices can not be paused or unpaused, only logical devices781* created through SDL_OpenAudioDevice() can be.782*783* \param devid a device opened by SDL_OpenAudioDevice().784* \returns true on success or false on failure; call SDL_GetError() for more785* information.786*787* \threadsafety It is safe to call this function from any thread.788*789* \since This function is available since SDL 3.2.0.790*791* \sa SDL_ResumeAudioDevice792* \sa SDL_AudioDevicePaused793*/794extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID devid);795796/**797* Use this function to unpause audio playback on a specified device.798*799* This function unpauses audio processing for a given device that has800* previously been paused with SDL_PauseAudioDevice(). Once unpaused, any801* bound audio streams will begin to progress again, and audio can be802* generated.803*804* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app805* has to bind a stream before any audio will flow. Unpausing an unpaused806* device is a legal no-op.807*808* Physical devices can not be paused or unpaused, only logical devices809* created through SDL_OpenAudioDevice() can be.810*811* \param devid a device opened by SDL_OpenAudioDevice().812* \returns true on success or false on failure; call SDL_GetError() for more813* information.814*815* \threadsafety It is safe to call this function from any thread.816*817* \since This function is available since SDL 3.2.0.818*819* \sa SDL_AudioDevicePaused820* \sa SDL_PauseAudioDevice821*/822extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID devid);823824/**825* Use this function to query if an audio device is paused.826*827* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app828* has to bind a stream before any audio will flow.829*830* Physical devices can not be paused or unpaused, only logical devices831* created through SDL_OpenAudioDevice() can be. Physical and invalid device832* IDs will report themselves as unpaused here.833*834* \param devid a device opened by SDL_OpenAudioDevice().835* \returns true if device is valid and paused, false otherwise.836*837* \threadsafety It is safe to call this function from any thread.838*839* \since This function is available since SDL 3.2.0.840*841* \sa SDL_PauseAudioDevice842* \sa SDL_ResumeAudioDevice843*/844extern SDL_DECLSPEC bool SDLCALL SDL_AudioDevicePaused(SDL_AudioDeviceID devid);845846/**847* Get the gain of an audio device.848*849* The gain of a device is its volume; a larger gain means a louder output,850* with a gain of zero being silence.851*852* Audio devices default to a gain of 1.0f (no change in output).853*854* Physical devices may not have their gain changed, only logical devices, and855* this function will always return -1.0f when used on physical devices.856*857* \param devid the audio device to query.858* \returns the gain of the device or -1.0f on failure; call SDL_GetError()859* for more information.860*861* \threadsafety It is safe to call this function from any thread.862*863* \since This function is available since SDL 3.2.0.864*865* \sa SDL_SetAudioDeviceGain866*/867extern SDL_DECLSPEC float SDLCALL SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid);868869/**870* Change the gain of an audio device.871*872* The gain of a device is its volume; a larger gain means a louder output,873* with a gain of zero being silence.874*875* Audio devices default to a gain of 1.0f (no change in output).876*877* Physical devices may not have their gain changed, only logical devices, and878* this function will always return false when used on physical devices. While879* it might seem attractive to adjust several logical devices at once in this880* way, it would allow an app or library to interfere with another portion of881* the program's otherwise-isolated devices.882*883* This is applied, along with any per-audiostream gain, during playback to884* the hardware, and can be continuously changed to create various effects. On885* recording devices, this will adjust the gain before passing the data into886* an audiostream; that recording audiostream can then adjust its gain further887* when outputting the data elsewhere, if it likes, but that second gain is888* not applied until the data leaves the audiostream again.889*890* \param devid the audio device on which to change gain.891* \param gain the gain. 1.0f is no change, 0.0f is silence.892* \returns true on success or false on failure; call SDL_GetError() for more893* information.894*895* \threadsafety It is safe to call this function from any thread, as it holds896* a stream-specific mutex while running.897*898* \since This function is available since SDL 3.2.0.899*900* \sa SDL_GetAudioDeviceGain901*/902extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain);903904/**905* Close a previously-opened audio device.906*907* The application should close open audio devices once they are no longer908* needed.909*910* This function may block briefly while pending audio data is played by the911* hardware, so that applications don't drop the last buffer of data they912* supplied if terminating immediately afterwards.913*914* \param devid an audio device id previously returned by915* SDL_OpenAudioDevice().916*917* \threadsafety It is safe to call this function from any thread.918*919* \since This function is available since SDL 3.2.0.920*921* \sa SDL_OpenAudioDevice922*/923extern SDL_DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);924925/**926* Bind a list of audio streams to an audio device.927*928* Audio data will flow through any bound streams. For a playback device, data929* for all bound streams will be mixed together and fed to the device. For a930* recording device, a copy of recorded data will be provided to each bound931* stream.932*933* Audio streams can only be bound to an open device. This operation is934* atomic--all streams bound in the same call will start processing at the935* same time, so they can stay in sync. Also: either all streams will be bound936* or none of them will be.937*938* It is an error to bind an already-bound stream; it must be explicitly939* unbound first.940*941* Binding a stream to a device will set its output format for playback942* devices, and its input format for recording devices, so they match the943* device's settings. The caller is welcome to change the other end of the944* stream's format at any time with SDL_SetAudioStreamFormat(). If the other945* end of the stream's format has never been set (the audio stream was created946* with a NULL audio spec), this function will set it to match the device947* end's format.948*949* \param devid an audio device to bind a stream to.950* \param streams an array of audio streams to bind.951* \param num_streams number streams listed in the `streams` array.952* \returns true on success or false on failure; call SDL_GetError() for more953* information.954*955* \threadsafety It is safe to call this function from any thread.956*957* \since This function is available since SDL 3.2.0.958*959* \sa SDL_BindAudioStreams960* \sa SDL_UnbindAudioStream961* \sa SDL_GetAudioStreamDevice962*/963extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *streams, int num_streams);964965/**966* Bind a single audio stream to an audio device.967*968* This is a convenience function, equivalent to calling969* `SDL_BindAudioStreams(devid, &stream, 1)`.970*971* \param devid an audio device to bind a stream to.972* \param stream an audio stream to bind to a device.973* \returns true on success or false on failure; call SDL_GetError() for more974* information.975*976* \threadsafety It is safe to call this function from any thread.977*978* \since This function is available since SDL 3.2.0.979*980* \sa SDL_BindAudioStreams981* \sa SDL_UnbindAudioStream982* \sa SDL_GetAudioStreamDevice983*/984extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);985986/**987* Unbind a list of audio streams from their audio devices.988*989* The streams being unbound do not all have to be on the same device. All990* streams on the same device will be unbound atomically (data will stop991* flowing through all unbound streams on the same device at the same time).992*993* Unbinding a stream that isn't bound to a device is a legal no-op.994*995* \param streams an array of audio streams to unbind. Can be NULL or contain996* NULL.997* \param num_streams number streams listed in the `streams` array.998*999* \threadsafety It is safe to call this function from any thread.1000*1001* \since This function is available since SDL 3.2.0.1002*1003* \sa SDL_BindAudioStreams1004*/1005extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream * const *streams, int num_streams);10061007/**1008* Unbind a single audio stream from its audio device.1009*1010* This is a convenience function, equivalent to calling1011* `SDL_UnbindAudioStreams(&stream, 1)`.1012*1013* \param stream an audio stream to unbind from a device. Can be NULL.1014*1015* \threadsafety It is safe to call this function from any thread.1016*1017* \since This function is available since SDL 3.2.0.1018*1019* \sa SDL_BindAudioStream1020*/1021extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);10221023/**1024* Query an audio stream for its currently-bound device.1025*1026* This reports the logical audio device that an audio stream is currently bound to.1027*1028* If not bound, or invalid, this returns zero, which is not a valid device1029* ID.1030*1031* \param stream the audio stream to query.1032* \returns the bound audio device, or 0 if not bound or invalid.1033*1034* \threadsafety It is safe to call this function from any thread.1035*1036* \since This function is available since SDL 3.2.0.1037*1038* \sa SDL_BindAudioStream1039* \sa SDL_BindAudioStreams1040*/1041extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_AudioStream *stream);10421043/**1044* Create a new audio stream.1045*1046* \param src_spec the format details of the input audio.1047* \param dst_spec the format details of the output audio.1048* \returns a new audio stream on success or NULL on failure; call1049* SDL_GetError() for more information.1050*1051* \threadsafety It is safe to call this function from any thread.1052*1053* \since This function is available since SDL 3.2.0.1054*1055* \sa SDL_PutAudioStreamData1056* \sa SDL_GetAudioStreamData1057* \sa SDL_GetAudioStreamAvailable1058* \sa SDL_FlushAudioStream1059* \sa SDL_ClearAudioStream1060* \sa SDL_SetAudioStreamFormat1061* \sa SDL_DestroyAudioStream1062*/1063extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);10641065/**1066* Get the properties associated with an audio stream.1067*1068* \param stream the SDL_AudioStream to query.1069* \returns a valid property ID on success or 0 on failure; call1070* SDL_GetError() for more information.1071*1072* \threadsafety It is safe to call this function from any thread.1073*1074* \since This function is available since SDL 3.2.0.1075*/1076extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);10771078/**1079* Query the current format of an audio stream.1080*1081* \param stream the SDL_AudioStream to query.1082* \param src_spec where to store the input audio format; ignored if NULL.1083* \param dst_spec where to store the output audio format; ignored if NULL.1084* \returns true on success or false on failure; call SDL_GetError() for more1085* information.1086*1087* \threadsafety It is safe to call this function from any thread, as it holds1088* a stream-specific mutex while running.1089*1090* \since This function is available since SDL 3.2.0.1091*1092* \sa SDL_SetAudioStreamFormat1093*/1094extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec);10951096/**1097* Change the input and output formats of an audio stream.1098*1099* Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData1100* will reflect the new format, and future calls to SDL_PutAudioStreamData1101* must provide data in the new input formats.1102*1103* Data that was previously queued in the stream will still be operated on in1104* the format that was current when it was added, which is to say you can put1105* the end of a sound file in one format to a stream, change formats for the1106* next sound file, and start putting that new data while the previous sound1107* file is still queued, and everything will still play back correctly.1108*1109* If a stream is bound to a device, then the format of the side of the stream1110* bound to a device cannot be changed (src_spec for recording devices,1111* dst_spec for playback devices). Attempts to make a change to this side will1112* be ignored, but this will not report an error. The other side's format can1113* be changed.1114*1115* \param stream the stream the format is being changed.1116* \param src_spec the new format of the audio input; if NULL, it is not1117* changed.1118* \param dst_spec the new format of the audio output; if NULL, it is not1119* changed.1120* \returns true on success or false on failure; call SDL_GetError() for more1121* information.1122*1123* \threadsafety It is safe to call this function from any thread, as it holds1124* a stream-specific mutex while running.1125*1126* \since This function is available since SDL 3.2.0.1127*1128* \sa SDL_GetAudioStreamFormat1129* \sa SDL_SetAudioStreamFrequencyRatio1130*/1131extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);11321133/**1134* Get the frequency ratio of an audio stream.1135*1136* \param stream the SDL_AudioStream to query.1137* \returns the frequency ratio of the stream or 0.0 on failure; call1138* SDL_GetError() for more information.1139*1140* \threadsafety It is safe to call this function from any thread, as it holds1141* a stream-specific mutex while running.1142*1143* \since This function is available since SDL 3.2.0.1144*1145* \sa SDL_SetAudioStreamFrequencyRatio1146*/1147extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream);11481149/**1150* Change the frequency ratio of an audio stream.1151*1152* The frequency ratio is used to adjust the rate at which input data is1153* consumed. Changing this effectively modifies the speed and pitch of the1154* audio. A value greater than 1.0 will play the audio faster, and at a higher1155* pitch. A value less than 1.0 will play the audio slower, and at a lower1156* pitch.1157*1158* This is applied during SDL_GetAudioStreamData, and can be continuously1159* changed to create various effects.1160*1161* \param stream the stream the frequency ratio is being changed.1162* \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.011163* and 100.1164* \returns true on success or false on failure; call SDL_GetError() for more1165* information.1166*1167* \threadsafety It is safe to call this function from any thread, as it holds1168* a stream-specific mutex while running.1169*1170* \since This function is available since SDL 3.2.0.1171*1172* \sa SDL_GetAudioStreamFrequencyRatio1173* \sa SDL_SetAudioStreamFormat1174*/1175extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);11761177/**1178* Get the gain of an audio stream.1179*1180* The gain of a stream is its volume; a larger gain means a louder output,1181* with a gain of zero being silence.1182*1183* Audio streams default to a gain of 1.0f (no change in output).1184*1185* \param stream the SDL_AudioStream to query.1186* \returns the gain of the stream or -1.0f on failure; call SDL_GetError()1187* for more information.1188*1189* \threadsafety It is safe to call this function from any thread, as it holds1190* a stream-specific mutex while running.1191*1192* \since This function is available since SDL 3.2.0.1193*1194* \sa SDL_SetAudioStreamGain1195*/1196extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamGain(SDL_AudioStream *stream);11971198/**1199* Change the gain of an audio stream.1200*1201* The gain of a stream is its volume; a larger gain means a louder output,1202* with a gain of zero being silence.1203*1204* Audio streams default to a gain of 1.0f (no change in output).1205*1206* This is applied during SDL_GetAudioStreamData, and can be continuously1207* changed to create various effects.1208*1209* \param stream the stream on which the gain is being changed.1210* \param gain the gain. 1.0f is no change, 0.0f is silence.1211* \returns true on success or false on failure; call SDL_GetError() for more1212* information.1213*1214* \threadsafety It is safe to call this function from any thread, as it holds1215* a stream-specific mutex while running.1216*1217* \since This function is available since SDL 3.2.0.1218*1219* \sa SDL_GetAudioStreamGain1220*/1221extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain);12221223/**1224* Get the current input channel map of an audio stream.1225*1226* Channel maps are optional; most things do not need them, instead passing1227* data in the [order that SDL expects](CategoryAudio#channel-layouts).1228*1229* Audio streams default to no remapping applied. This is represented by1230* returning NULL, and does not signify an error.1231*1232* \param stream the SDL_AudioStream to query.1233* \param count On output, set to number of channels in the map. Can be NULL.1234* \returns an array of the current channel mapping, with as many elements as1235* the current output spec's channels, or NULL if default. This1236* should be freed with SDL_free() when it is no longer needed.1237*1238* \threadsafety It is safe to call this function from any thread, as it holds1239* a stream-specific mutex while running.1240*1241* \since This function is available since SDL 3.2.0.1242*1243* \sa SDL_SetAudioStreamInputChannelMap1244*/1245extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count);12461247/**1248* Get the current output channel map of an audio stream.1249*1250* Channel maps are optional; most things do not need them, instead passing1251* data in the [order that SDL expects](CategoryAudio#channel-layouts).1252*1253* Audio streams default to no remapping applied. This is represented by1254* returning NULL, and does not signify an error.1255*1256* \param stream the SDL_AudioStream to query.1257* \param count On output, set to number of channels in the map. Can be NULL.1258* \returns an array of the current channel mapping, with as many elements as1259* the current output spec's channels, or NULL if default. This1260* should be freed with SDL_free() when it is no longer needed.1261*1262* \threadsafety It is safe to call this function from any thread, as it holds1263* a stream-specific mutex while running.1264*1265* \since This function is available since SDL 3.2.0.1266*1267* \sa SDL_SetAudioStreamInputChannelMap1268*/1269extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count);12701271/**1272* Set the current input channel map of an audio stream.1273*1274* Channel maps are optional; most things do not need them, instead passing1275* data in the [order that SDL expects](CategoryAudio#channel-layouts).1276*1277* The input channel map reorders data that is added to a stream via1278* SDL_PutAudioStreamData. Future calls to SDL_PutAudioStreamData must provide1279* data in the new channel order.1280*1281* Each item in the array represents an input channel, and its value is the1282* channel that it should be remapped to. To reverse a stereo signal's left1283* and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap1284* multiple channels to the same thing, so `{ 1, 1 }` would duplicate the1285* right channel to both channels of a stereo signal. An element in the1286* channel map set to -1 instead of a valid channel will mute that channel,1287* setting it to a silence value.1288*1289* You cannot change the number of channels through a channel map, just1290* reorder/mute them.1291*1292* Data that was previously queued in the stream will still be operated on in1293* the order that was current when it was added, which is to say you can put1294* the end of a sound file in one order to a stream, change orders for the1295* next sound file, and start putting that new data while the previous sound1296* file is still queued, and everything will still play back correctly.1297*1298* Audio streams default to no remapping applied. Passing a NULL channel map1299* is legal, and turns off remapping.1300*1301* SDL will copy the channel map; the caller does not have to save this array1302* after this call.1303*1304* If `count` is not equal to the current number of channels in the audio1305* stream's format, this will fail. This is a safety measure to make sure a1306* race condition hasn't changed the format while this call is setting the1307* channel map.1308*1309* Unlike attempting to change the stream's format, the input channel map on a1310* stream bound to a recording device is permitted to change at any time; any1311* data added to the stream from the device after this call will have the new1312* mapping, but previously-added data will still have the prior mapping.1313*1314* \param stream the SDL_AudioStream to change.1315* \param chmap the new channel map, NULL to reset to default.1316* \param count The number of channels in the map.1317* \returns true on success or false on failure; call SDL_GetError() for more1318* information.1319*1320* \threadsafety It is safe to call this function from any thread, as it holds1321* a stream-specific mutex while running. Don't change the1322* stream's format to have a different number of channels from a1323* a different thread at the same time, though!1324*1325* \since This function is available since SDL 3.2.0.1326*1327* \sa SDL_SetAudioStreamInputChannelMap1328*/1329extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);13301331/**1332* Set the current output channel map of an audio stream.1333*1334* Channel maps are optional; most things do not need them, instead passing1335* data in the [order that SDL expects](CategoryAudio#channel-layouts).1336*1337* The output channel map reorders data that leaving a stream via1338* SDL_GetAudioStreamData.1339*1340* Each item in the array represents an input channel, and its value is the1341* channel that it should be remapped to. To reverse a stereo signal's left1342* and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap1343* multiple channels to the same thing, so `{ 1, 1 }` would duplicate the1344* right channel to both channels of a stereo signal. An element in the1345* channel map set to -1 instead of a valid channel will mute that channel,1346* setting it to a silence value.1347*1348* You cannot change the number of channels through a channel map, just1349* reorder/mute them.1350*1351* The output channel map can be changed at any time, as output remapping is1352* applied during SDL_GetAudioStreamData.1353*1354* Audio streams default to no remapping applied. Passing a NULL channel map1355* is legal, and turns off remapping.1356*1357* SDL will copy the channel map; the caller does not have to save this array1358* after this call.1359*1360* If `count` is not equal to the current number of channels in the audio1361* stream's format, this will fail. This is a safety measure to make sure a1362* race condition hasn't changed the format while this call is setting the1363* channel map.1364*1365* Unlike attempting to change the stream's format, the output channel map on1366* a stream bound to a recording device is permitted to change at any time;1367* any data added to the stream after this call will have the new mapping, but1368* previously-added data will still have the prior mapping. When the channel1369* map doesn't match the hardware's channel layout, SDL will convert the data1370* before feeding it to the device for playback.1371*1372* \param stream the SDL_AudioStream to change.1373* \param chmap the new channel map, NULL to reset to default.1374* \param count The number of channels in the map.1375* \returns true on success or false on failure; call SDL_GetError() for more1376* information.1377*1378* \threadsafety It is safe to call this function from any thread, as it holds1379* a stream-specific mutex while running. Don't change the1380* stream's format to have a different number of channels from a1381* a different thread at the same time, though!1382*1383* \since This function is available since SDL 3.2.0.1384*1385* \sa SDL_SetAudioStreamInputChannelMap1386*/1387extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);13881389/**1390* Add data to the stream.1391*1392* This data must match the format/channels/samplerate specified in the latest1393* call to SDL_SetAudioStreamFormat, or the format specified when creating the1394* stream if it hasn't been changed.1395*1396* Note that this call simply copies the unconverted data for later. This is1397* different than SDL2, where data was converted during the Put call and the1398* Get call would just dequeue the previously-converted data.1399*1400* \param stream the stream the audio data is being added to.1401* \param buf a pointer to the audio data to add.1402* \param len the number of bytes to write to the stream.1403* \returns true on success or false on failure; call SDL_GetError() for more1404* information.1405*1406* \threadsafety It is safe to call this function from any thread, but if the1407* stream has a callback set, the caller might need to manage1408* extra locking.1409*1410* \since This function is available since SDL 3.2.0.1411*1412* \sa SDL_ClearAudioStream1413* \sa SDL_FlushAudioStream1414* \sa SDL_GetAudioStreamData1415* \sa SDL_GetAudioStreamQueued1416*/1417extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);14181419/**1420* Get converted/resampled data from the stream.1421*1422* The input/output data format/channels/samplerate is specified when creating1423* the stream, and can be changed after creation by calling1424* SDL_SetAudioStreamFormat.1425*1426* Note that any conversion and resampling necessary is done during this call,1427* and SDL_PutAudioStreamData simply queues unconverted data for later. This1428* is different than SDL2, where that work was done while inputting new data1429* to the stream and requesting the output just copied the converted data.1430*1431* \param stream the stream the audio is being requested from.1432* \param buf a buffer to fill with audio data.1433* \param len the maximum number of bytes to fill.1434* \returns the number of bytes read from the stream or -1 on failure; call1435* SDL_GetError() for more information.1436*1437* \threadsafety It is safe to call this function from any thread, but if the1438* stream has a callback set, the caller might need to manage1439* extra locking.1440*1441* \since This function is available since SDL 3.2.0.1442*1443* \sa SDL_ClearAudioStream1444* \sa SDL_GetAudioStreamAvailable1445* \sa SDL_PutAudioStreamData1446*/1447extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);14481449/**1450* Get the number of converted/resampled bytes available.1451*1452* The stream may be buffering data behind the scenes until it has enough to1453* resample correctly, so this number might be lower than what you expect, or1454* even be zero. Add more data or flush the stream if you need the data now.1455*1456* If the stream has so much data that it would overflow an int, the return1457* value is clamped to a maximum value, but no queued data is lost; if there1458* are gigabytes of data queued, the app might need to read some of it with1459* SDL_GetAudioStreamData before this function's return value is no longer1460* clamped.1461*1462* \param stream the audio stream to query.1463* \returns the number of converted/resampled bytes available or -1 on1464* failure; call SDL_GetError() for more information.1465*1466* \threadsafety It is safe to call this function from any thread.1467*1468* \since This function is available since SDL 3.2.0.1469*1470* \sa SDL_GetAudioStreamData1471* \sa SDL_PutAudioStreamData1472*/1473extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);147414751476/**1477* Get the number of bytes currently queued.1478*1479* This is the number of bytes put into a stream as input, not the number that1480* can be retrieved as output. Because of several details, it's not possible1481* to calculate one number directly from the other. If you need to know how1482* much usable data can be retrieved right now, you should use1483* SDL_GetAudioStreamAvailable() and not this function.1484*1485* Note that audio streams can change their input format at any time, even if1486* there is still data queued in a different format, so the returned byte1487* count will not necessarily match the number of _sample frames_ available.1488* Users of this API should be aware of format changes they make when feeding1489* a stream and plan accordingly.1490*1491* Queued data is not converted until it is consumed by1492* SDL_GetAudioStreamData, so this value should be representative of the exact1493* data that was put into the stream.1494*1495* If the stream has so much data that it would overflow an int, the return1496* value is clamped to a maximum value, but no queued data is lost; if there1497* are gigabytes of data queued, the app might need to read some of it with1498* SDL_GetAudioStreamData before this function's return value is no longer1499* clamped.1500*1501* \param stream the audio stream to query.1502* \returns the number of bytes queued or -1 on failure; call SDL_GetError()1503* for more information.1504*1505* \threadsafety It is safe to call this function from any thread.1506*1507* \since This function is available since SDL 3.2.0.1508*1509* \sa SDL_PutAudioStreamData1510* \sa SDL_ClearAudioStream1511*/1512extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream);151315141515/**1516* Tell the stream that you're done sending data, and anything being buffered1517* should be converted/resampled and made available immediately.1518*1519* It is legal to add more data to a stream after flushing, but there may be1520* audio gaps in the output. Generally this is intended to signal the end of1521* input, so the complete output becomes available.1522*1523* \param stream the audio stream to flush.1524* \returns true on success or false on failure; call SDL_GetError() for more1525* information.1526*1527* \threadsafety It is safe to call this function from any thread.1528*1529* \since This function is available since SDL 3.2.0.1530*1531* \sa SDL_PutAudioStreamData1532*/1533extern SDL_DECLSPEC bool SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);15341535/**1536* Clear any pending data in the stream.1537*1538* This drops any queued data, so there will be nothing to read from the1539* stream until more is added.1540*1541* \param stream the audio stream to clear.1542* \returns true on success or false on failure; call SDL_GetError() for more1543* information.1544*1545* \threadsafety It is safe to call this function from any thread.1546*1547* \since This function is available since SDL 3.2.0.1548*1549* \sa SDL_GetAudioStreamAvailable1550* \sa SDL_GetAudioStreamData1551* \sa SDL_GetAudioStreamQueued1552* \sa SDL_PutAudioStreamData1553*/1554extern SDL_DECLSPEC bool SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);15551556/**1557* Use this function to pause audio playback on the audio device associated1558* with an audio stream.1559*1560* This function pauses audio processing for a given device. Any bound audio1561* streams will not progress, and no audio will be generated. Pausing one1562* device does not prevent other unpaused devices from running.1563*1564* Pausing a device can be useful to halt all audio without unbinding all the1565* audio streams. This might be useful while a game is paused, or a level is1566* loading, etc.1567*1568* \param stream the audio stream associated with the audio device to pause.1569* \returns true on success or false on failure; call SDL_GetError() for more1570* information.1571*1572* \threadsafety It is safe to call this function from any thread.1573*1574* \since This function is available since SDL 3.2.0.1575*1576* \sa SDL_ResumeAudioStreamDevice1577*/1578extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stream);15791580/**1581* Use this function to unpause audio playback on the audio device associated1582* with an audio stream.1583*1584* This function unpauses audio processing for a given device that has1585* previously been paused. Once unpaused, any bound audio streams will begin1586* to progress again, and audio can be generated.1587*1588* Remember, SDL_OpenAudioDeviceStream opens device in a paused state, so this1589* function call is required for audio playback to begin on such device.1590*1591* \param stream the audio stream associated with the audio device to resume.1592* \returns true on success or false on failure; call SDL_GetError() for more1593* information.1594*1595* \threadsafety It is safe to call this function from any thread.1596*1597* \since This function is available since SDL 3.2.0.1598*1599* \sa SDL_PauseAudioStreamDevice1600*/1601extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream);16021603/**1604* Use this function to query if an audio device associated with a stream is1605* paused.1606*1607* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app1608* has to bind a stream before any audio will flow.1609*1610* \param stream the audio stream associated with the audio device to query.1611* \returns true if device is valid and paused, false otherwise.1612*1613* \threadsafety It is safe to call this function from any thread.1614*1615* \since This function is available since SDL 3.2.0.1616*1617* \sa SDL_PauseAudioStreamDevice1618* \sa SDL_ResumeAudioStreamDevice1619*/1620extern SDL_DECLSPEC bool SDLCALL SDL_AudioStreamDevicePaused(SDL_AudioStream *stream);162116221623/**1624* Lock an audio stream for serialized access.1625*1626* Each SDL_AudioStream has an internal mutex it uses to protect its data1627* structures from threading conflicts. This function allows an app to lock1628* that mutex, which could be useful if registering callbacks on this stream.1629*1630* One does not need to lock a stream to use in it most cases, as the stream1631* manages this lock internally. However, this lock is held during callbacks,1632* which may run from arbitrary threads at any time, so if an app needs to1633* protect shared data during those callbacks, locking the stream guarantees1634* that the callback is not running while the lock is held.1635*1636* As this is just a wrapper over SDL_LockMutex for an internal lock; it has1637* all the same attributes (recursive locks are allowed, etc).1638*1639* \param stream the audio stream to lock.1640* \returns true on success or false on failure; call SDL_GetError() for more1641* information.1642*1643* \threadsafety It is safe to call this function from any thread.1644*1645* \since This function is available since SDL 3.2.0.1646*1647* \sa SDL_UnlockAudioStream1648*/1649extern SDL_DECLSPEC bool SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream);165016511652/**1653* Unlock an audio stream for serialized access.1654*1655* This unlocks an audio stream after a call to SDL_LockAudioStream.1656*1657* \param stream the audio stream to unlock.1658* \returns true on success or false on failure; call SDL_GetError() for more1659* information.1660*1661* \threadsafety You should only call this from the same thread that1662* previously called SDL_LockAudioStream.1663*1664* \since This function is available since SDL 3.2.0.1665*1666* \sa SDL_LockAudioStream1667*/1668extern SDL_DECLSPEC bool SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);16691670/**1671* A callback that fires when data passes through an SDL_AudioStream.1672*1673* Apps can (optionally) register a callback with an audio stream that is1674* called when data is added with SDL_PutAudioStreamData, or requested with1675* SDL_GetAudioStreamData.1676*1677* Two values are offered here: one is the amount of additional data needed to1678* satisfy the immediate request (which might be zero if the stream already1679* has enough data queued) and the other is the total amount being requested.1680* In a Get call triggering a Put callback, these values can be different. In1681* a Put call triggering a Get callback, these values are always the same.1682*1683* Byte counts might be slightly overestimated due to buffering or resampling,1684* and may change from call to call.1685*1686* This callback is not required to do anything. Generally this is useful for1687* adding/reading data on demand, and the app will often put/get data as1688* appropriate, but the system goes on with the data currently available to it1689* if this callback does nothing.1690*1691* \param stream the SDL audio stream associated with this callback.1692* \param additional_amount the amount of data, in bytes, that is needed right1693* now.1694* \param total_amount the total amount of data requested, in bytes, that is1695* requested or available.1696* \param userdata an opaque pointer provided by the app for their personal1697* use.1698*1699* \threadsafety This callbacks may run from any thread, so if you need to1700* protect shared data, you should use SDL_LockAudioStream to1701* serialize access; this lock will be held before your callback1702* is called, so your callback does not need to manage the lock1703* explicitly.1704*1705* \since This datatype is available since SDL 3.2.0.1706*1707* \sa SDL_SetAudioStreamGetCallback1708* \sa SDL_SetAudioStreamPutCallback1709*/1710typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount);17111712/**1713* Set a callback that runs when data is requested from an audio stream.1714*1715* This callback is called _before_ data is obtained from the stream, giving1716* the callback the chance to add more on-demand.1717*1718* The callback can (optionally) call SDL_PutAudioStreamData() to add more1719* audio to the stream during this call; if needed, the request that triggered1720* this callback will obtain the new data immediately.1721*1722* The callback's `additional_amount` argument is roughly how many bytes of1723* _unconverted_ data (in the stream's input format) is needed by the caller,1724* although this may overestimate a little for safety. This takes into account1725* how much is already in the stream and only asks for any extra necessary to1726* resolve the request, which means the callback may be asked for zero bytes,1727* and a different amount on each call.1728*1729* The callback is not required to supply exact amounts; it is allowed to1730* supply too much or too little or none at all. The caller will get what's1731* available, up to the amount they requested, regardless of this callback's1732* outcome.1733*1734* Clearing or flushing an audio stream does not call this callback.1735*1736* This function obtains the stream's lock, which means any existing callback1737* (get or put) in progress will finish running before setting the new1738* callback.1739*1740* Setting a NULL function turns off the callback.1741*1742* \param stream the audio stream to set the new callback on.1743* \param callback the new callback function to call when data is requested1744* from the stream.1745* \param userdata an opaque pointer provided to the callback for its own1746* personal use.1747* \returns true on success or false on failure; call SDL_GetError() for more1748* information. This only fails if `stream` is NULL.1749*1750* \threadsafety It is safe to call this function from any thread.1751*1752* \since This function is available since SDL 3.2.0.1753*1754* \sa SDL_SetAudioStreamPutCallback1755*/1756extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);17571758/**1759* Set a callback that runs when data is added to an audio stream.1760*1761* This callback is called _after_ the data is added to the stream, giving the1762* callback the chance to obtain it immediately.1763*1764* The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio1765* from the stream during this call.1766*1767* The callback's `additional_amount` argument is how many bytes of1768* _converted_ data (in the stream's output format) was provided by the1769* caller, although this may underestimate a little for safety. This value1770* might be less than what is currently available in the stream, if data was1771* already there, and might be less than the caller provided if the stream1772* needs to keep a buffer to aid in resampling. Which means the callback may1773* be provided with zero bytes, and a different amount on each call.1774*1775* The callback may call SDL_GetAudioStreamAvailable to see the total amount1776* currently available to read from the stream, instead of the total provided1777* by the current call.1778*1779* The callback is not required to obtain all data. It is allowed to read less1780* or none at all. Anything not read now simply remains in the stream for1781* later access.1782*1783* Clearing or flushing an audio stream does not call this callback.1784*1785* This function obtains the stream's lock, which means any existing callback1786* (get or put) in progress will finish running before setting the new1787* callback.1788*1789* Setting a NULL function turns off the callback.1790*1791* \param stream the audio stream to set the new callback on.1792* \param callback the new callback function to call when data is added to the1793* stream.1794* \param userdata an opaque pointer provided to the callback for its own1795* personal use.1796* \returns true on success or false on failure; call SDL_GetError() for more1797* information. This only fails if `stream` is NULL.1798*1799* \threadsafety It is safe to call this function from any thread.1800*1801* \since This function is available since SDL 3.2.0.1802*1803* \sa SDL_SetAudioStreamGetCallback1804*/1805extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);180618071808/**1809* Free an audio stream.1810*1811* This will release all allocated data, including any audio that is still1812* queued. You do not need to manually clear the stream first.1813*1814* If this stream was bound to an audio device, it is unbound during this1815* call. If this stream was created with SDL_OpenAudioDeviceStream, the audio1816* device that was opened alongside this stream's creation will be closed,1817* too.1818*1819* \param stream the audio stream to destroy.1820*1821* \threadsafety It is safe to call this function from any thread.1822*1823* \since This function is available since SDL 3.2.0.1824*1825* \sa SDL_CreateAudioStream1826*/1827extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);182818291830/**1831* Convenience function for straightforward audio init for the common case.1832*1833* If all your app intends to do is provide a single source of PCM audio, this1834* function allows you to do all your audio setup in a single call.1835*1836* This is also intended to be a clean means to migrate apps from SDL2.1837*1838* This function will open an audio device, create a stream and bind it.1839* Unlike other methods of setup, the audio device will be closed when this1840* stream is destroyed, so the app can treat the returned SDL_AudioStream as1841* the only object needed to manage audio playback.1842*1843* Also unlike other functions, the audio device begins paused. This is to map1844* more closely to SDL2-style behavior, since there is no extra step here to1845* bind a stream to begin audio flowing. The audio device should be resumed1846* with `SDL_ResumeAudioStreamDevice(stream);`1847*1848* This function works with both playback and recording devices.1849*1850* The `spec` parameter represents the app's side of the audio stream. That1851* is, for recording audio, this will be the output format, and for playing1852* audio, this will be the input format. If spec is NULL, the system will1853* choose the format, and the app can use SDL_GetAudioStreamFormat() to obtain1854* this information later.1855*1856* If you don't care about opening a specific audio device, you can (and1857* probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and1858* SDL_AUDIO_DEVICE_DEFAULT_RECORDING for recording.1859*1860* One can optionally provide a callback function; if NULL, the app is1861* expected to queue audio data for playback (or unqueue audio data if1862* capturing). Otherwise, the callback will begin to fire once the device is1863* unpaused.1864*1865* Destroying the returned stream with SDL_DestroyAudioStream will also close1866* the audio device associated with this stream.1867*1868* \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK1869* or SDL_AUDIO_DEVICE_DEFAULT_RECORDING.1870* \param spec the audio stream's data format. Can be NULL.1871* \param callback a callback where the app will provide new data for1872* playback, or receive new data for recording. Can be NULL,1873* in which case the app will need to call1874* SDL_PutAudioStreamData or SDL_GetAudioStreamData as1875* necessary.1876* \param userdata app-controlled pointer passed to callback. Can be NULL.1877* Ignored if callback is NULL.1878* \returns an audio stream on success, ready to use, or NULL on failure; call1879* SDL_GetError() for more information. When done with this stream,1880* call SDL_DestroyAudioStream to free resources and close the1881* device.1882*1883* \threadsafety It is safe to call this function from any thread.1884*1885* \since This function is available since SDL 3.2.0.1886*1887* \sa SDL_GetAudioStreamDevice1888* \sa SDL_ResumeAudioStreamDevice1889*/1890extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);18911892/**1893* A callback that fires when data is about to be fed to an audio device.1894*1895* This is useful for accessing the final mix, perhaps for writing a1896* visualizer or applying a final effect to the audio data before playback.1897*1898* This callback should run as quickly as possible and not block for any1899* significant time, as this callback delays submission of data to the audio1900* device, which can cause audio playback problems.1901*1902* The postmix callback _must_ be able to handle any audio data format1903* specified in `spec`, which can change between callbacks if the audio device1904* changed. However, this only covers frequency and channel count; data is1905* always provided here in SDL_AUDIO_F32 format.1906*1907* The postmix callback runs _after_ logical device gain and audiostream gain1908* have been applied, which is to say you can make the output data louder at1909* this point than the gain settings would suggest.1910*1911* \param userdata a pointer provided by the app through1912* SDL_SetAudioPostmixCallback, for its own use.1913* \param spec the current format of audio that is to be submitted to the1914* audio device.1915* \param buffer the buffer of audio samples to be submitted. The callback can1916* inspect and/or modify this data.1917* \param buflen the size of `buffer` in bytes.1918*1919* \threadsafety This will run from a background thread owned by SDL. The1920* application is responsible for locking resources the callback1921* touches that need to be protected.1922*1923* \since This datatype is available since SDL 3.2.0.1924*1925* \sa SDL_SetAudioPostmixCallback1926*/1927typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_AudioSpec *spec, float *buffer, int buflen);19281929/**1930* Set a callback that fires when data is about to be fed to an audio device.1931*1932* This is useful for accessing the final mix, perhaps for writing a1933* visualizer or applying a final effect to the audio data before playback.1934*1935* The buffer is the final mix of all bound audio streams on an opened device;1936* this callback will fire regularly for any device that is both opened and1937* unpaused. If there is no new data to mix, either because no streams are1938* bound to the device or all the streams are empty, this callback will still1939* fire with the entire buffer set to silence.1940*1941* This callback is allowed to make changes to the data; the contents of the1942* buffer after this call is what is ultimately passed along to the hardware.1943*1944* The callback is always provided the data in float format (values from -1.0f1945* to 1.0f), but the number of channels or sample rate may be different than1946* the format the app requested when opening the device; SDL might have had to1947* manage a conversion behind the scenes, or the playback might have jumped to1948* new physical hardware when a system default changed, etc. These details may1949* change between calls. Accordingly, the size of the buffer might change1950* between calls as well.1951*1952* This callback can run at any time, and from any thread; if you need to1953* serialize access to your app's data, you should provide and use a mutex or1954* other synchronization device.1955*1956* All of this to say: there are specific needs this callback can fulfill, but1957* it is not the simplest interface. Apps should generally provide audio in1958* their preferred format through an SDL_AudioStream and let SDL handle the1959* difference.1960*1961* This function is extremely time-sensitive; the callback should do the least1962* amount of work possible and return as quickly as it can. The longer the1963* callback runs, the higher the risk of audio dropouts or other problems.1964*1965* This function will block until the audio device is in between iterations,1966* so any existing callback that might be running will finish before this1967* function sets the new callback and returns.1968*1969* Setting a NULL callback function disables any previously-set callback.1970*1971* \param devid the ID of an opened audio device.1972* \param callback a callback function to be called. Can be NULL.1973* \param userdata app-controlled pointer passed to callback. Can be NULL.1974* \returns true on success or false on failure; call SDL_GetError() for more1975* information.1976*1977* \threadsafety It is safe to call this function from any thread.1978*1979* \since This function is available since SDL 3.2.0.1980*/1981extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata);198219831984/**1985* Load the audio data of a WAVE file into memory.1986*1987* Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to1988* be valid pointers. The entire data portion of the file is then loaded into1989* memory and decoded if necessary.1990*1991* Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and1992* 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and1993* A-law and mu-law (8 bits). Other formats are currently unsupported and1994* cause an error.1995*1996* If this function succeeds, the return value is zero and the pointer to the1997* audio data allocated by the function is written to `audio_buf` and its1998* length in bytes to `audio_len`. The SDL_AudioSpec members `freq`,1999* `channels`, and `format` are set to the values of the audio data in the2000* buffer.2001*2002* It's necessary to use SDL_free() to free the audio data returned in2003* `audio_buf` when it is no longer used.2004*2005* Because of the underspecification of the .WAV format, there are many2006* problematic files in the wild that cause issues with strict decoders. To2007* provide compatibility with these files, this decoder is lenient in regards2008* to the truncation of the file, the fact chunk, and the size of the RIFF2009* chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,2010* `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to2011* tune the behavior of the loading process.2012*2013* Any file that is invalid (due to truncation, corruption, or wrong values in2014* the headers), too big, or unsupported causes an error. Additionally, any2015* critical I/O error from the data source will terminate the loading process2016* with an error. The function returns NULL on error and in all cases (with2017* the exception of `src` being NULL), an appropriate error message will be2018* set.2019*2020* It is required that the data source supports seeking.2021*2022* Example:2023*2024* ```c2025* SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), true, &spec, &buf, &len);2026* ```2027*2028* Note that the SDL_LoadWAV function does this same thing for you, but in a2029* less messy way:2030*2031* ```c2032* SDL_LoadWAV("sample.wav", &spec, &buf, &len);2033* ```2034*2035* \param src the data source for the WAVE data.2036* \param closeio if true, calls SDL_CloseIO() on `src` before returning, even2037* in the case of an error.2038* \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE2039* data's format details on successful return.2040* \param audio_buf a pointer filled with the audio data, allocated by the2041* function.2042* \param audio_len a pointer filled with the length of the audio data buffer2043* in bytes.2044* \returns true on success. `audio_buf` will be filled with a pointer to an2045* allocated buffer containing the audio data, and `audio_len` is2046* filled with the length of that audio buffer in bytes.2047*2048* This function returns false if the .WAV file cannot be opened,2049* uses an unknown data format, or is corrupt; call SDL_GetError()2050* for more information.2051*2052* When the application is done with the data returned in2053* `audio_buf`, it should call SDL_free() to dispose of it.2054*2055* \threadsafety It is safe to call this function from any thread.2056*2057* \since This function is available since SDL 3.2.0.2058*2059* \sa SDL_free2060* \sa SDL_LoadWAV2061*/2062extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV_IO(SDL_IOStream *src, bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);20632064/**2065* Loads a WAV from a file path.2066*2067* This is a convenience function that is effectively the same as:2068*2069* ```c2070* SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len);2071* ```2072*2073* \param path the file path of the WAV file to open.2074* \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE2075* data's format details on successful return.2076* \param audio_buf a pointer filled with the audio data, allocated by the2077* function.2078* \param audio_len a pointer filled with the length of the audio data buffer2079* in bytes.2080* \returns true on success. `audio_buf` will be filled with a pointer to an2081* allocated buffer containing the audio data, and `audio_len` is2082* filled with the length of that audio buffer in bytes.2083*2084* This function returns false if the .WAV file cannot be opened,2085* uses an unknown data format, or is corrupt; call SDL_GetError()2086* for more information.2087*2088* When the application is done with the data returned in2089* `audio_buf`, it should call SDL_free() to dispose of it.2090*2091* \threadsafety It is safe to call this function from any thread.2092*2093* \since This function is available since SDL 3.2.0.2094*2095* \sa SDL_free2096* \sa SDL_LoadWAV_IO2097*/2098extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);20992100/**2101* Mix audio data in a specified format.2102*2103* This takes an audio buffer `src` of `len` bytes of `format` data and mixes2104* it into `dst`, performing addition, volume adjustment, and overflow2105* clipping. The buffer pointed to by `dst` must also be `len` bytes of2106* `format` data.2107*2108* This is provided for convenience -- you can mix your own audio data.2109*2110* Do not use this function for mixing together more than two streams of2111* sample data. The output from repeated application of this function may be2112* distorted by clipping, because there is no accumulator with greater range2113* than the input (not to mention this being an inefficient way of doing it).2114*2115* It is a common misconception that this function is required to write audio2116* data to an output stream in an audio callback. While you can do that,2117* SDL_MixAudio() is really only needed when you're mixing a single audio2118* stream with a volume adjustment.2119*2120* \param dst the destination for the mixed audio.2121* \param src the source audio buffer to be mixed.2122* \param format the SDL_AudioFormat structure representing the desired audio2123* format.2124* \param len the length of the audio buffer in bytes.2125* \param volume ranges from 0.0 - 1.0, and should be set to 1.0 for full2126* audio volume.2127* \returns true on success or false on failure; call SDL_GetError() for more2128* information.2129*2130* \threadsafety It is safe to call this function from any thread.2131*2132* \since This function is available since SDL 3.2.0.2133*/2134extern SDL_DECLSPEC bool SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume);21352136/**2137* Convert some audio data of one format to another format.2138*2139* Please note that this function is for convenience, but should not be used2140* to resample audio in blocks, as it will introduce audio artifacts on the2141* boundaries. You should only use this function if you are converting audio2142* data in its entirety in one call. If you want to convert audio in smaller2143* chunks, use an SDL_AudioStream, which is designed for this situation.2144*2145* Internally, this function creates and destroys an SDL_AudioStream on each2146* use, so it's also less efficient than using one directly, if you need to2147* convert multiple times.2148*2149* \param src_spec the format details of the input audio.2150* \param src_data the audio data to be converted.2151* \param src_len the len of src_data.2152* \param dst_spec the format details of the output audio.2153* \param dst_data will be filled with a pointer to converted audio data,2154* which should be freed with SDL_free(). On error, it will be2155* NULL.2156* \param dst_len will be filled with the len of dst_data.2157* \returns true on success or false on failure; call SDL_GetError() for more2158* information.2159*2160* \threadsafety It is safe to call this function from any thread.2161*2162* \since This function is available since SDL 3.2.0.2163*/2164extern SDL_DECLSPEC bool SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len);21652166/**2167* Get the human readable name of an audio format.2168*2169* \param format the audio format to query.2170* \returns the human readable name of the specified audio format or2171* "SDL_AUDIO_UNKNOWN" if the format isn't recognized.2172*2173* \threadsafety It is safe to call this function from any thread.2174*2175* \since This function is available since SDL 3.2.0.2176*/2177extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioFormatName(SDL_AudioFormat format);21782179/**2180* Get the appropriate memset value for silencing an audio format.2181*2182* The value returned by this function can be used as the second argument to2183* memset (or SDL_memset) to set an audio buffer in a specific format to2184* silence.2185*2186* \param format the audio data format to query.2187* \returns a byte value that can be passed to memset.2188*2189* \threadsafety It is safe to call this function from any thread.2190*2191* \since This function is available since SDL 3.2.0.2192*/2193extern SDL_DECLSPEC int SDLCALL SDL_GetSilenceValueForFormat(SDL_AudioFormat format);219421952196/* Ends C function definitions when using C++ */2197#ifdef __cplusplus2198}2199#endif2200#include <SDL3/SDL_close_code.h>22012202#endif /* SDL_audio_h_ */220322042205