Path: blob/master/thirdparty/sdl/include/SDL3/SDL_audio.h
9912 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().945*946* \param devid an audio device to bind a stream to.947* \param streams an array of audio streams to bind.948* \param num_streams number streams listed in the `streams` array.949* \returns true on success or false on failure; call SDL_GetError() for more950* information.951*952* \threadsafety It is safe to call this function from any thread.953*954* \since This function is available since SDL 3.2.0.955*956* \sa SDL_BindAudioStreams957* \sa SDL_UnbindAudioStream958* \sa SDL_GetAudioStreamDevice959*/960extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *streams, int num_streams);961962/**963* Bind a single audio stream to an audio device.964*965* This is a convenience function, equivalent to calling966* `SDL_BindAudioStreams(devid, &stream, 1)`.967*968* \param devid an audio device to bind a stream to.969* \param stream an audio stream to bind to a device.970* \returns true on success or false on failure; call SDL_GetError() for more971* information.972*973* \threadsafety It is safe to call this function from any thread.974*975* \since This function is available since SDL 3.2.0.976*977* \sa SDL_BindAudioStreams978* \sa SDL_UnbindAudioStream979* \sa SDL_GetAudioStreamDevice980*/981extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);982983/**984* Unbind a list of audio streams from their audio devices.985*986* The streams being unbound do not all have to be on the same device. All987* streams on the same device will be unbound atomically (data will stop988* flowing through all unbound streams on the same device at the same time).989*990* Unbinding a stream that isn't bound to a device is a legal no-op.991*992* \param streams an array of audio streams to unbind. Can be NULL or contain993* NULL.994* \param num_streams number streams listed in the `streams` array.995*996* \threadsafety It is safe to call this function from any thread.997*998* \since This function is available since SDL 3.2.0.999*1000* \sa SDL_BindAudioStreams1001*/1002extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream * const *streams, int num_streams);10031004/**1005* Unbind a single audio stream from its audio device.1006*1007* This is a convenience function, equivalent to calling1008* `SDL_UnbindAudioStreams(&stream, 1)`.1009*1010* \param stream an audio stream to unbind from a device. Can be NULL.1011*1012* \threadsafety It is safe to call this function from any thread.1013*1014* \since This function is available since SDL 3.2.0.1015*1016* \sa SDL_BindAudioStream1017*/1018extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);10191020/**1021* Query an audio stream for its currently-bound device.1022*1023* This reports the audio device that an audio stream is currently bound to.1024*1025* If not bound, or invalid, this returns zero, which is not a valid device1026* ID.1027*1028* \param stream the audio stream to query.1029* \returns the bound audio device, or 0 if not bound or invalid.1030*1031* \threadsafety It is safe to call this function from any thread.1032*1033* \since This function is available since SDL 3.2.0.1034*1035* \sa SDL_BindAudioStream1036* \sa SDL_BindAudioStreams1037*/1038extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_AudioStream *stream);10391040/**1041* Create a new audio stream.1042*1043* \param src_spec the format details of the input audio.1044* \param dst_spec the format details of the output audio.1045* \returns a new audio stream on success or NULL on failure; call1046* SDL_GetError() for more information.1047*1048* \threadsafety It is safe to call this function from any thread.1049*1050* \since This function is available since SDL 3.2.0.1051*1052* \sa SDL_PutAudioStreamData1053* \sa SDL_GetAudioStreamData1054* \sa SDL_GetAudioStreamAvailable1055* \sa SDL_FlushAudioStream1056* \sa SDL_ClearAudioStream1057* \sa SDL_SetAudioStreamFormat1058* \sa SDL_DestroyAudioStream1059*/1060extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);10611062/**1063* Get the properties associated with an audio stream.1064*1065* \param stream the SDL_AudioStream to query.1066* \returns a valid property ID on success or 0 on failure; call1067* SDL_GetError() for more information.1068*1069* \threadsafety It is safe to call this function from any thread.1070*1071* \since This function is available since SDL 3.2.0.1072*/1073extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);10741075/**1076* Query the current format of an audio stream.1077*1078* \param stream the SDL_AudioStream to query.1079* \param src_spec where to store the input audio format; ignored if NULL.1080* \param dst_spec where to store the output audio format; ignored if NULL.1081* \returns true on success or false on failure; call SDL_GetError() for more1082* information.1083*1084* \threadsafety It is safe to call this function from any thread, as it holds1085* a stream-specific mutex while running.1086*1087* \since This function is available since SDL 3.2.0.1088*1089* \sa SDL_SetAudioStreamFormat1090*/1091extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec);10921093/**1094* Change the input and output formats of an audio stream.1095*1096* Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData1097* will reflect the new format, and future calls to SDL_PutAudioStreamData1098* must provide data in the new input formats.1099*1100* Data that was previously queued in the stream will still be operated on in1101* the format that was current when it was added, which is to say you can put1102* the end of a sound file in one format to a stream, change formats for the1103* next sound file, and start putting that new data while the previous sound1104* file is still queued, and everything will still play back correctly.1105*1106* If a stream is bound to a device, then the format of the side of the stream1107* bound to a device cannot be changed (src_spec for recording devices,1108* dst_spec for playback devices). Attempts to make a change to this side will1109* be ignored, but this will not report an error. The other side's format can1110* be changed.1111*1112* \param stream the stream the format is being changed.1113* \param src_spec the new format of the audio input; if NULL, it is not1114* changed.1115* \param dst_spec the new format of the audio output; if NULL, it is not1116* changed.1117* \returns true on success or false on failure; call SDL_GetError() for more1118* information.1119*1120* \threadsafety It is safe to call this function from any thread, as it holds1121* a stream-specific mutex while running.1122*1123* \since This function is available since SDL 3.2.0.1124*1125* \sa SDL_GetAudioStreamFormat1126* \sa SDL_SetAudioStreamFrequencyRatio1127*/1128extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);11291130/**1131* Get the frequency ratio of an audio stream.1132*1133* \param stream the SDL_AudioStream to query.1134* \returns the frequency ratio of the stream or 0.0 on failure; call1135* SDL_GetError() for more information.1136*1137* \threadsafety It is safe to call this function from any thread, as it holds1138* a stream-specific mutex while running.1139*1140* \since This function is available since SDL 3.2.0.1141*1142* \sa SDL_SetAudioStreamFrequencyRatio1143*/1144extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream);11451146/**1147* Change the frequency ratio of an audio stream.1148*1149* The frequency ratio is used to adjust the rate at which input data is1150* consumed. Changing this effectively modifies the speed and pitch of the1151* audio. A value greater than 1.0 will play the audio faster, and at a higher1152* pitch. A value less than 1.0 will play the audio slower, and at a lower1153* pitch.1154*1155* This is applied during SDL_GetAudioStreamData, and can be continuously1156* changed to create various effects.1157*1158* \param stream the stream the frequency ratio is being changed.1159* \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.011160* and 100.1161* \returns true on success or false on failure; call SDL_GetError() for more1162* information.1163*1164* \threadsafety It is safe to call this function from any thread, as it holds1165* a stream-specific mutex while running.1166*1167* \since This function is available since SDL 3.2.0.1168*1169* \sa SDL_GetAudioStreamFrequencyRatio1170* \sa SDL_SetAudioStreamFormat1171*/1172extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);11731174/**1175* Get the gain of an audio stream.1176*1177* The gain of a stream is its volume; a larger gain means a louder output,1178* with a gain of zero being silence.1179*1180* Audio streams default to a gain of 1.0f (no change in output).1181*1182* \param stream the SDL_AudioStream to query.1183* \returns the gain of the stream or -1.0f on failure; call SDL_GetError()1184* for more information.1185*1186* \threadsafety It is safe to call this function from any thread, as it holds1187* a stream-specific mutex while running.1188*1189* \since This function is available since SDL 3.2.0.1190*1191* \sa SDL_SetAudioStreamGain1192*/1193extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamGain(SDL_AudioStream *stream);11941195/**1196* Change the gain of an audio stream.1197*1198* The gain of a stream is its volume; a larger gain means a louder output,1199* with a gain of zero being silence.1200*1201* Audio streams default to a gain of 1.0f (no change in output).1202*1203* This is applied during SDL_GetAudioStreamData, and can be continuously1204* changed to create various effects.1205*1206* \param stream the stream on which the gain is being changed.1207* \param gain the gain. 1.0f is no change, 0.0f is silence.1208* \returns true on success or false on failure; call SDL_GetError() for more1209* information.1210*1211* \threadsafety It is safe to call this function from any thread, as it holds1212* a stream-specific mutex while running.1213*1214* \since This function is available since SDL 3.2.0.1215*1216* \sa SDL_GetAudioStreamGain1217*/1218extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain);12191220/**1221* Get the current input channel map of an audio stream.1222*1223* Channel maps are optional; most things do not need them, instead passing1224* data in the [order that SDL expects](CategoryAudio#channel-layouts).1225*1226* Audio streams default to no remapping applied. This is represented by1227* returning NULL, and does not signify an error.1228*1229* \param stream the SDL_AudioStream to query.1230* \param count On output, set to number of channels in the map. Can be NULL.1231* \returns an array of the current channel mapping, with as many elements as1232* the current output spec's channels, or NULL if default. This1233* should be freed with SDL_free() when it is no longer needed.1234*1235* \threadsafety It is safe to call this function from any thread, as it holds1236* a stream-specific mutex while running.1237*1238* \since This function is available since SDL 3.2.0.1239*1240* \sa SDL_SetAudioStreamInputChannelMap1241*/1242extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count);12431244/**1245* Get the current output channel map of an audio stream.1246*1247* Channel maps are optional; most things do not need them, instead passing1248* data in the [order that SDL expects](CategoryAudio#channel-layouts).1249*1250* Audio streams default to no remapping applied. This is represented by1251* returning NULL, and does not signify an error.1252*1253* \param stream the SDL_AudioStream to query.1254* \param count On output, set to number of channels in the map. Can be NULL.1255* \returns an array of the current channel mapping, with as many elements as1256* the current output spec's channels, or NULL if default. This1257* should be freed with SDL_free() when it is no longer needed.1258*1259* \threadsafety It is safe to call this function from any thread, as it holds1260* a stream-specific mutex while running.1261*1262* \since This function is available since SDL 3.2.0.1263*1264* \sa SDL_SetAudioStreamInputChannelMap1265*/1266extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count);12671268/**1269* Set the current input channel map of an audio stream.1270*1271* Channel maps are optional; most things do not need them, instead passing1272* data in the [order that SDL expects](CategoryAudio#channel-layouts).1273*1274* The input channel map reorders data that is added to a stream via1275* SDL_PutAudioStreamData. Future calls to SDL_PutAudioStreamData must provide1276* data in the new channel order.1277*1278* Each item in the array represents an input channel, and its value is the1279* channel that it should be remapped to. To reverse a stereo signal's left1280* and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap1281* multiple channels to the same thing, so `{ 1, 1 }` would duplicate the1282* right channel to both channels of a stereo signal. An element in the1283* channel map set to -1 instead of a valid channel will mute that channel,1284* setting it to a silence value.1285*1286* You cannot change the number of channels through a channel map, just1287* reorder/mute them.1288*1289* Data that was previously queued in the stream will still be operated on in1290* the order that was current when it was added, which is to say you can put1291* the end of a sound file in one order to a stream, change orders for the1292* next sound file, and start putting that new data while the previous sound1293* file is still queued, and everything will still play back correctly.1294*1295* Audio streams default to no remapping applied. Passing a NULL channel map1296* is legal, and turns off remapping.1297*1298* SDL will copy the channel map; the caller does not have to save this array1299* after this call.1300*1301* If `count` is not equal to the current number of channels in the audio1302* stream's format, this will fail. This is a safety measure to make sure a1303* race condition hasn't changed the format while this call is setting the1304* channel map.1305*1306* Unlike attempting to change the stream's format, the input channel map on a1307* stream bound to a recording device is permitted to change at any time; any1308* data added to the stream from the device after this call will have the new1309* mapping, but previously-added data will still have the prior mapping.1310*1311* \param stream the SDL_AudioStream to change.1312* \param chmap the new channel map, NULL to reset to default.1313* \param count The number of channels in the map.1314* \returns true on success or false on failure; call SDL_GetError() for more1315* information.1316*1317* \threadsafety It is safe to call this function from any thread, as it holds1318* a stream-specific mutex while running. Don't change the1319* stream's format to have a different number of channels from a1320* a different thread at the same time, though!1321*1322* \since This function is available since SDL 3.2.0.1323*1324* \sa SDL_SetAudioStreamInputChannelMap1325*/1326extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);13271328/**1329* Set the current output channel map of an audio stream.1330*1331* Channel maps are optional; most things do not need them, instead passing1332* data in the [order that SDL expects](CategoryAudio#channel-layouts).1333*1334* The output channel map reorders data that leaving a stream via1335* SDL_GetAudioStreamData.1336*1337* Each item in the array represents an input channel, and its value is the1338* channel that it should be remapped to. To reverse a stereo signal's left1339* and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap1340* multiple channels to the same thing, so `{ 1, 1 }` would duplicate the1341* right channel to both channels of a stereo signal. An element in the1342* channel map set to -1 instead of a valid channel will mute that channel,1343* setting it to a silence value.1344*1345* You cannot change the number of channels through a channel map, just1346* reorder/mute them.1347*1348* The output channel map can be changed at any time, as output remapping is1349* applied during SDL_GetAudioStreamData.1350*1351* Audio streams default to no remapping applied. Passing a NULL channel map1352* is legal, and turns off remapping.1353*1354* SDL will copy the channel map; the caller does not have to save this array1355* after this call.1356*1357* If `count` is not equal to the current number of channels in the audio1358* stream's format, this will fail. This is a safety measure to make sure a1359* race condition hasn't changed the format while this call is setting the1360* channel map.1361*1362* Unlike attempting to change the stream's format, the output channel map on1363* a stream bound to a recording device is permitted to change at any time;1364* any data added to the stream after this call will have the new mapping, but1365* previously-added data will still have the prior mapping. When the channel1366* map doesn't match the hardware's channel layout, SDL will convert the data1367* before feeding it to the device for playback.1368*1369* \param stream the SDL_AudioStream to change.1370* \param chmap the new channel map, NULL to reset to default.1371* \param count The number of channels in the map.1372* \returns true on success or false on failure; call SDL_GetError() for more1373* information.1374*1375* \threadsafety It is safe to call this function from any thread, as it holds1376* a stream-specific mutex while running. Don't change the1377* stream's format to have a different number of channels from a1378* a different thread at the same time, though!1379*1380* \since This function is available since SDL 3.2.0.1381*1382* \sa SDL_SetAudioStreamInputChannelMap1383*/1384extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);13851386/**1387* Add data to the stream.1388*1389* This data must match the format/channels/samplerate specified in the latest1390* call to SDL_SetAudioStreamFormat, or the format specified when creating the1391* stream if it hasn't been changed.1392*1393* Note that this call simply copies the unconverted data for later. This is1394* different than SDL2, where data was converted during the Put call and the1395* Get call would just dequeue the previously-converted data.1396*1397* \param stream the stream the audio data is being added to.1398* \param buf a pointer to the audio data to add.1399* \param len the number of bytes to write to the stream.1400* \returns true on success or false on failure; call SDL_GetError() for more1401* information.1402*1403* \threadsafety It is safe to call this function from any thread, but if the1404* stream has a callback set, the caller might need to manage1405* extra locking.1406*1407* \since This function is available since SDL 3.2.0.1408*1409* \sa SDL_ClearAudioStream1410* \sa SDL_FlushAudioStream1411* \sa SDL_GetAudioStreamData1412* \sa SDL_GetAudioStreamQueued1413*/1414extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);14151416/**1417* Get converted/resampled data from the stream.1418*1419* The input/output data format/channels/samplerate is specified when creating1420* the stream, and can be changed after creation by calling1421* SDL_SetAudioStreamFormat.1422*1423* Note that any conversion and resampling necessary is done during this call,1424* and SDL_PutAudioStreamData simply queues unconverted data for later. This1425* is different than SDL2, where that work was done while inputting new data1426* to the stream and requesting the output just copied the converted data.1427*1428* \param stream the stream the audio is being requested from.1429* \param buf a buffer to fill with audio data.1430* \param len the maximum number of bytes to fill.1431* \returns the number of bytes read from the stream or -1 on failure; call1432* SDL_GetError() for more information.1433*1434* \threadsafety It is safe to call this function from any thread, but if the1435* stream has a callback set, the caller might need to manage1436* extra locking.1437*1438* \since This function is available since SDL 3.2.0.1439*1440* \sa SDL_ClearAudioStream1441* \sa SDL_GetAudioStreamAvailable1442* \sa SDL_PutAudioStreamData1443*/1444extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);14451446/**1447* Get the number of converted/resampled bytes available.1448*1449* The stream may be buffering data behind the scenes until it has enough to1450* resample correctly, so this number might be lower than what you expect, or1451* even be zero. Add more data or flush the stream if you need the data now.1452*1453* If the stream has so much data that it would overflow an int, the return1454* value is clamped to a maximum value, but no queued data is lost; if there1455* are gigabytes of data queued, the app might need to read some of it with1456* SDL_GetAudioStreamData before this function's return value is no longer1457* clamped.1458*1459* \param stream the audio stream to query.1460* \returns the number of converted/resampled bytes available or -1 on1461* failure; call SDL_GetError() for more information.1462*1463* \threadsafety It is safe to call this function from any thread.1464*1465* \since This function is available since SDL 3.2.0.1466*1467* \sa SDL_GetAudioStreamData1468* \sa SDL_PutAudioStreamData1469*/1470extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);147114721473/**1474* Get the number of bytes currently queued.1475*1476* This is the number of bytes put into a stream as input, not the number that1477* can be retrieved as output. Because of several details, it's not possible1478* to calculate one number directly from the other. If you need to know how1479* much usable data can be retrieved right now, you should use1480* SDL_GetAudioStreamAvailable() and not this function.1481*1482* Note that audio streams can change their input format at any time, even if1483* there is still data queued in a different format, so the returned byte1484* count will not necessarily match the number of _sample frames_ available.1485* Users of this API should be aware of format changes they make when feeding1486* a stream and plan accordingly.1487*1488* Queued data is not converted until it is consumed by1489* SDL_GetAudioStreamData, so this value should be representative of the exact1490* data that was put into the stream.1491*1492* If the stream has so much data that it would overflow an int, the return1493* value is clamped to a maximum value, but no queued data is lost; if there1494* are gigabytes of data queued, the app might need to read some of it with1495* SDL_GetAudioStreamData before this function's return value is no longer1496* clamped.1497*1498* \param stream the audio stream to query.1499* \returns the number of bytes queued or -1 on failure; call SDL_GetError()1500* for more information.1501*1502* \threadsafety It is safe to call this function from any thread.1503*1504* \since This function is available since SDL 3.2.0.1505*1506* \sa SDL_PutAudioStreamData1507* \sa SDL_ClearAudioStream1508*/1509extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream);151015111512/**1513* Tell the stream that you're done sending data, and anything being buffered1514* should be converted/resampled and made available immediately.1515*1516* It is legal to add more data to a stream after flushing, but there may be1517* audio gaps in the output. Generally this is intended to signal the end of1518* input, so the complete output becomes available.1519*1520* \param stream the audio stream to flush.1521* \returns true on success or false on failure; call SDL_GetError() for more1522* information.1523*1524* \threadsafety It is safe to call this function from any thread.1525*1526* \since This function is available since SDL 3.2.0.1527*1528* \sa SDL_PutAudioStreamData1529*/1530extern SDL_DECLSPEC bool SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);15311532/**1533* Clear any pending data in the stream.1534*1535* This drops any queued data, so there will be nothing to read from the1536* stream until more is added.1537*1538* \param stream the audio stream to clear.1539* \returns true on success or false on failure; call SDL_GetError() for more1540* information.1541*1542* \threadsafety It is safe to call this function from any thread.1543*1544* \since This function is available since SDL 3.2.0.1545*1546* \sa SDL_GetAudioStreamAvailable1547* \sa SDL_GetAudioStreamData1548* \sa SDL_GetAudioStreamQueued1549* \sa SDL_PutAudioStreamData1550*/1551extern SDL_DECLSPEC bool SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);15521553/**1554* Use this function to pause audio playback on the audio device associated1555* with an audio stream.1556*1557* This function pauses audio processing for a given device. Any bound audio1558* streams will not progress, and no audio will be generated. Pausing one1559* device does not prevent other unpaused devices from running.1560*1561* Pausing a device can be useful to halt all audio without unbinding all the1562* audio streams. This might be useful while a game is paused, or a level is1563* loading, etc.1564*1565* \param stream the audio stream associated with the audio device to pause.1566* \returns true on success or false on failure; call SDL_GetError() for more1567* information.1568*1569* \threadsafety It is safe to call this function from any thread.1570*1571* \since This function is available since SDL 3.2.0.1572*1573* \sa SDL_ResumeAudioStreamDevice1574*/1575extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stream);15761577/**1578* Use this function to unpause audio playback on the audio device associated1579* with an audio stream.1580*1581* This function unpauses audio processing for a given device that has1582* previously been paused. Once unpaused, any bound audio streams will begin1583* to progress again, and audio can be generated.1584*1585* Remember, SDL_OpenAudioDeviceStream opens device in a paused state, so this1586* function call is required for audio playback to begin on such device.1587*1588* \param stream the audio stream associated with the audio device to resume.1589* \returns true on success or false on failure; call SDL_GetError() for more1590* information.1591*1592* \threadsafety It is safe to call this function from any thread.1593*1594* \since This function is available since SDL 3.2.0.1595*1596* \sa SDL_PauseAudioStreamDevice1597*/1598extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream);15991600/**1601* Use this function to query if an audio device associated with a stream is1602* paused.1603*1604* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app1605* has to bind a stream before any audio will flow.1606*1607* \param stream the audio stream associated with the audio device to query.1608* \returns true if device is valid and paused, false otherwise.1609*1610* \threadsafety It is safe to call this function from any thread.1611*1612* \since This function is available since SDL 3.2.0.1613*1614* \sa SDL_PauseAudioStreamDevice1615* \sa SDL_ResumeAudioStreamDevice1616*/1617extern SDL_DECLSPEC bool SDLCALL SDL_AudioStreamDevicePaused(SDL_AudioStream *stream);161816191620/**1621* Lock an audio stream for serialized access.1622*1623* Each SDL_AudioStream has an internal mutex it uses to protect its data1624* structures from threading conflicts. This function allows an app to lock1625* that mutex, which could be useful if registering callbacks on this stream.1626*1627* One does not need to lock a stream to use in it most cases, as the stream1628* manages this lock internally. However, this lock is held during callbacks,1629* which may run from arbitrary threads at any time, so if an app needs to1630* protect shared data during those callbacks, locking the stream guarantees1631* that the callback is not running while the lock is held.1632*1633* As this is just a wrapper over SDL_LockMutex for an internal lock; it has1634* all the same attributes (recursive locks are allowed, etc).1635*1636* \param stream the audio stream to lock.1637* \returns true on success or false on failure; call SDL_GetError() for more1638* information.1639*1640* \threadsafety It is safe to call this function from any thread.1641*1642* \since This function is available since SDL 3.2.0.1643*1644* \sa SDL_UnlockAudioStream1645*/1646extern SDL_DECLSPEC bool SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream);164716481649/**1650* Unlock an audio stream for serialized access.1651*1652* This unlocks an audio stream after a call to SDL_LockAudioStream.1653*1654* \param stream the audio stream to unlock.1655* \returns true on success or false on failure; call SDL_GetError() for more1656* information.1657*1658* \threadsafety You should only call this from the same thread that1659* previously called SDL_LockAudioStream.1660*1661* \since This function is available since SDL 3.2.0.1662*1663* \sa SDL_LockAudioStream1664*/1665extern SDL_DECLSPEC bool SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);16661667/**1668* A callback that fires when data passes through an SDL_AudioStream.1669*1670* Apps can (optionally) register a callback with an audio stream that is1671* called when data is added with SDL_PutAudioStreamData, or requested with1672* SDL_GetAudioStreamData.1673*1674* Two values are offered here: one is the amount of additional data needed to1675* satisfy the immediate request (which might be zero if the stream already1676* has enough data queued) and the other is the total amount being requested.1677* In a Get call triggering a Put callback, these values can be different. In1678* a Put call triggering a Get callback, these values are always the same.1679*1680* Byte counts might be slightly overestimated due to buffering or resampling,1681* and may change from call to call.1682*1683* This callback is not required to do anything. Generally this is useful for1684* adding/reading data on demand, and the app will often put/get data as1685* appropriate, but the system goes on with the data currently available to it1686* if this callback does nothing.1687*1688* \param stream the SDL audio stream associated with this callback.1689* \param additional_amount the amount of data, in bytes, that is needed right1690* now.1691* \param total_amount the total amount of data requested, in bytes, that is1692* requested or available.1693* \param userdata an opaque pointer provided by the app for their personal1694* use.1695*1696* \threadsafety This callbacks may run from any thread, so if you need to1697* protect shared data, you should use SDL_LockAudioStream to1698* serialize access; this lock will be held before your callback1699* is called, so your callback does not need to manage the lock1700* explicitly.1701*1702* \since This datatype is available since SDL 3.2.0.1703*1704* \sa SDL_SetAudioStreamGetCallback1705* \sa SDL_SetAudioStreamPutCallback1706*/1707typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount);17081709/**1710* Set a callback that runs when data is requested from an audio stream.1711*1712* This callback is called _before_ data is obtained from the stream, giving1713* the callback the chance to add more on-demand.1714*1715* The callback can (optionally) call SDL_PutAudioStreamData() to add more1716* audio to the stream during this call; if needed, the request that triggered1717* this callback will obtain the new data immediately.1718*1719* The callback's `additional_amount` argument is roughly how many bytes of1720* _unconverted_ data (in the stream's input format) is needed by the caller,1721* although this may overestimate a little for safety. This takes into account1722* how much is already in the stream and only asks for any extra necessary to1723* resolve the request, which means the callback may be asked for zero bytes,1724* and a different amount on each call.1725*1726* The callback is not required to supply exact amounts; it is allowed to1727* supply too much or too little or none at all. The caller will get what's1728* available, up to the amount they requested, regardless of this callback's1729* outcome.1730*1731* Clearing or flushing an audio stream does not call this callback.1732*1733* This function obtains the stream's lock, which means any existing callback1734* (get or put) in progress will finish running before setting the new1735* callback.1736*1737* Setting a NULL function turns off the callback.1738*1739* \param stream the audio stream to set the new callback on.1740* \param callback the new callback function to call when data is requested1741* from the stream.1742* \param userdata an opaque pointer provided to the callback for its own1743* personal use.1744* \returns true on success or false on failure; call SDL_GetError() for more1745* information. This only fails if `stream` is NULL.1746*1747* \threadsafety It is safe to call this function from any thread.1748*1749* \since This function is available since SDL 3.2.0.1750*1751* \sa SDL_SetAudioStreamPutCallback1752*/1753extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);17541755/**1756* Set a callback that runs when data is added to an audio stream.1757*1758* This callback is called _after_ the data is added to the stream, giving the1759* callback the chance to obtain it immediately.1760*1761* The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio1762* from the stream during this call.1763*1764* The callback's `additional_amount` argument is how many bytes of1765* _converted_ data (in the stream's output format) was provided by the1766* caller, although this may underestimate a little for safety. This value1767* might be less than what is currently available in the stream, if data was1768* already there, and might be less than the caller provided if the stream1769* needs to keep a buffer to aid in resampling. Which means the callback may1770* be provided with zero bytes, and a different amount on each call.1771*1772* The callback may call SDL_GetAudioStreamAvailable to see the total amount1773* currently available to read from the stream, instead of the total provided1774* by the current call.1775*1776* The callback is not required to obtain all data. It is allowed to read less1777* or none at all. Anything not read now simply remains in the stream for1778* later access.1779*1780* Clearing or flushing an audio stream does not call this callback.1781*1782* This function obtains the stream's lock, which means any existing callback1783* (get or put) in progress will finish running before setting the new1784* callback.1785*1786* Setting a NULL function turns off the callback.1787*1788* \param stream the audio stream to set the new callback on.1789* \param callback the new callback function to call when data is added to the1790* stream.1791* \param userdata an opaque pointer provided to the callback for its own1792* personal use.1793* \returns true on success or false on failure; call SDL_GetError() for more1794* information. This only fails if `stream` is NULL.1795*1796* \threadsafety It is safe to call this function from any thread.1797*1798* \since This function is available since SDL 3.2.0.1799*1800* \sa SDL_SetAudioStreamGetCallback1801*/1802extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);180318041805/**1806* Free an audio stream.1807*1808* This will release all allocated data, including any audio that is still1809* queued. You do not need to manually clear the stream first.1810*1811* If this stream was bound to an audio device, it is unbound during this1812* call. If this stream was created with SDL_OpenAudioDeviceStream, the audio1813* device that was opened alongside this stream's creation will be closed,1814* too.1815*1816* \param stream the audio stream to destroy.1817*1818* \threadsafety It is safe to call this function from any thread.1819*1820* \since This function is available since SDL 3.2.0.1821*1822* \sa SDL_CreateAudioStream1823*/1824extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);182518261827/**1828* Convenience function for straightforward audio init for the common case.1829*1830* If all your app intends to do is provide a single source of PCM audio, this1831* function allows you to do all your audio setup in a single call.1832*1833* This is also intended to be a clean means to migrate apps from SDL2.1834*1835* This function will open an audio device, create a stream and bind it.1836* Unlike other methods of setup, the audio device will be closed when this1837* stream is destroyed, so the app can treat the returned SDL_AudioStream as1838* the only object needed to manage audio playback.1839*1840* Also unlike other functions, the audio device begins paused. This is to map1841* more closely to SDL2-style behavior, since there is no extra step here to1842* bind a stream to begin audio flowing. The audio device should be resumed1843* with `SDL_ResumeAudioStreamDevice(stream);`1844*1845* This function works with both playback and recording devices.1846*1847* The `spec` parameter represents the app's side of the audio stream. That1848* is, for recording audio, this will be the output format, and for playing1849* audio, this will be the input format. If spec is NULL, the system will1850* choose the format, and the app can use SDL_GetAudioStreamFormat() to obtain1851* this information later.1852*1853* If you don't care about opening a specific audio device, you can (and1854* probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and1855* SDL_AUDIO_DEVICE_DEFAULT_RECORDING for recording.1856*1857* One can optionally provide a callback function; if NULL, the app is1858* expected to queue audio data for playback (or unqueue audio data if1859* capturing). Otherwise, the callback will begin to fire once the device is1860* unpaused.1861*1862* Destroying the returned stream with SDL_DestroyAudioStream will also close1863* the audio device associated with this stream.1864*1865* \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK1866* or SDL_AUDIO_DEVICE_DEFAULT_RECORDING.1867* \param spec the audio stream's data format. Can be NULL.1868* \param callback a callback where the app will provide new data for1869* playback, or receive new data for recording. Can be NULL,1870* in which case the app will need to call1871* SDL_PutAudioStreamData or SDL_GetAudioStreamData as1872* necessary.1873* \param userdata app-controlled pointer passed to callback. Can be NULL.1874* Ignored if callback is NULL.1875* \returns an audio stream on success, ready to use, or NULL on failure; call1876* SDL_GetError() for more information. When done with this stream,1877* call SDL_DestroyAudioStream to free resources and close the1878* device.1879*1880* \threadsafety It is safe to call this function from any thread.1881*1882* \since This function is available since SDL 3.2.0.1883*1884* \sa SDL_GetAudioStreamDevice1885* \sa SDL_ResumeAudioStreamDevice1886*/1887extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);18881889/**1890* A callback that fires when data is about to be fed to an audio device.1891*1892* This is useful for accessing the final mix, perhaps for writing a1893* visualizer or applying a final effect to the audio data before playback.1894*1895* This callback should run as quickly as possible and not block for any1896* significant time, as this callback delays submission of data to the audio1897* device, which can cause audio playback problems.1898*1899* The postmix callback _must_ be able to handle any audio data format1900* specified in `spec`, which can change between callbacks if the audio device1901* changed. However, this only covers frequency and channel count; data is1902* always provided here in SDL_AUDIO_F32 format.1903*1904* The postmix callback runs _after_ logical device gain and audiostream gain1905* have been applied, which is to say you can make the output data louder at1906* this point than the gain settings would suggest.1907*1908* \param userdata a pointer provided by the app through1909* SDL_SetAudioPostmixCallback, for its own use.1910* \param spec the current format of audio that is to be submitted to the1911* audio device.1912* \param buffer the buffer of audio samples to be submitted. The callback can1913* inspect and/or modify this data.1914* \param buflen the size of `buffer` in bytes.1915*1916* \threadsafety This will run from a background thread owned by SDL. The1917* application is responsible for locking resources the callback1918* touches that need to be protected.1919*1920* \since This datatype is available since SDL 3.2.0.1921*1922* \sa SDL_SetAudioPostmixCallback1923*/1924typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_AudioSpec *spec, float *buffer, int buflen);19251926/**1927* Set a callback that fires when data is about to be fed to an audio device.1928*1929* This is useful for accessing the final mix, perhaps for writing a1930* visualizer or applying a final effect to the audio data before playback.1931*1932* The buffer is the final mix of all bound audio streams on an opened device;1933* this callback will fire regularly for any device that is both opened and1934* unpaused. If there is no new data to mix, either because no streams are1935* bound to the device or all the streams are empty, this callback will still1936* fire with the entire buffer set to silence.1937*1938* This callback is allowed to make changes to the data; the contents of the1939* buffer after this call is what is ultimately passed along to the hardware.1940*1941* The callback is always provided the data in float format (values from -1.0f1942* to 1.0f), but the number of channels or sample rate may be different than1943* the format the app requested when opening the device; SDL might have had to1944* manage a conversion behind the scenes, or the playback might have jumped to1945* new physical hardware when a system default changed, etc. These details may1946* change between calls. Accordingly, the size of the buffer might change1947* between calls as well.1948*1949* This callback can run at any time, and from any thread; if you need to1950* serialize access to your app's data, you should provide and use a mutex or1951* other synchronization device.1952*1953* All of this to say: there are specific needs this callback can fulfill, but1954* it is not the simplest interface. Apps should generally provide audio in1955* their preferred format through an SDL_AudioStream and let SDL handle the1956* difference.1957*1958* This function is extremely time-sensitive; the callback should do the least1959* amount of work possible and return as quickly as it can. The longer the1960* callback runs, the higher the risk of audio dropouts or other problems.1961*1962* This function will block until the audio device is in between iterations,1963* so any existing callback that might be running will finish before this1964* function sets the new callback and returns.1965*1966* Setting a NULL callback function disables any previously-set callback.1967*1968* \param devid the ID of an opened audio device.1969* \param callback a callback function to be called. Can be NULL.1970* \param userdata app-controlled pointer passed to callback. Can be NULL.1971* \returns true on success or false on failure; call SDL_GetError() for more1972* information.1973*1974* \threadsafety It is safe to call this function from any thread.1975*1976* \since This function is available since SDL 3.2.0.1977*/1978extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata);197919801981/**1982* Load the audio data of a WAVE file into memory.1983*1984* Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to1985* be valid pointers. The entire data portion of the file is then loaded into1986* memory and decoded if necessary.1987*1988* Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and1989* 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and1990* A-law and mu-law (8 bits). Other formats are currently unsupported and1991* cause an error.1992*1993* If this function succeeds, the return value is zero and the pointer to the1994* audio data allocated by the function is written to `audio_buf` and its1995* length in bytes to `audio_len`. The SDL_AudioSpec members `freq`,1996* `channels`, and `format` are set to the values of the audio data in the1997* buffer.1998*1999* It's necessary to use SDL_free() to free the audio data returned in2000* `audio_buf` when it is no longer used.2001*2002* Because of the underspecification of the .WAV format, there are many2003* problematic files in the wild that cause issues with strict decoders. To2004* provide compatibility with these files, this decoder is lenient in regards2005* to the truncation of the file, the fact chunk, and the size of the RIFF2006* chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,2007* `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to2008* tune the behavior of the loading process.2009*2010* Any file that is invalid (due to truncation, corruption, or wrong values in2011* the headers), too big, or unsupported causes an error. Additionally, any2012* critical I/O error from the data source will terminate the loading process2013* with an error. The function returns NULL on error and in all cases (with2014* the exception of `src` being NULL), an appropriate error message will be2015* set.2016*2017* It is required that the data source supports seeking.2018*2019* Example:2020*2021* ```c2022* SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), true, &spec, &buf, &len);2023* ```2024*2025* Note that the SDL_LoadWAV function does this same thing for you, but in a2026* less messy way:2027*2028* ```c2029* SDL_LoadWAV("sample.wav", &spec, &buf, &len);2030* ```2031*2032* \param src the data source for the WAVE data.2033* \param closeio if true, calls SDL_CloseIO() on `src` before returning, even2034* in the case of an error.2035* \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE2036* data's format details on successful return.2037* \param audio_buf a pointer filled with the audio data, allocated by the2038* function.2039* \param audio_len a pointer filled with the length of the audio data buffer2040* in bytes.2041* \returns true on success. `audio_buf` will be filled with a pointer to an2042* allocated buffer containing the audio data, and `audio_len` is2043* filled with the length of that audio buffer in bytes.2044*2045* This function returns false if the .WAV file cannot be opened,2046* uses an unknown data format, or is corrupt; call SDL_GetError()2047* for more information.2048*2049* When the application is done with the data returned in2050* `audio_buf`, it should call SDL_free() to dispose of it.2051*2052* \threadsafety It is safe to call this function from any thread.2053*2054* \since This function is available since SDL 3.2.0.2055*2056* \sa SDL_free2057* \sa SDL_LoadWAV2058*/2059extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV_IO(SDL_IOStream *src, bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);20602061/**2062* Loads a WAV from a file path.2063*2064* This is a convenience function that is effectively the same as:2065*2066* ```c2067* SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len);2068* ```2069*2070* \param path the file path of the WAV file to open.2071* \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE2072* data's format details on successful return.2073* \param audio_buf a pointer filled with the audio data, allocated by the2074* function.2075* \param audio_len a pointer filled with the length of the audio data buffer2076* in bytes.2077* \returns true on success. `audio_buf` will be filled with a pointer to an2078* allocated buffer containing the audio data, and `audio_len` is2079* filled with the length of that audio buffer in bytes.2080*2081* This function returns false if the .WAV file cannot be opened,2082* uses an unknown data format, or is corrupt; call SDL_GetError()2083* for more information.2084*2085* When the application is done with the data returned in2086* `audio_buf`, it should call SDL_free() to dispose of it.2087*2088* \threadsafety It is safe to call this function from any thread.2089*2090* \since This function is available since SDL 3.2.0.2091*2092* \sa SDL_free2093* \sa SDL_LoadWAV_IO2094*/2095extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);20962097/**2098* Mix audio data in a specified format.2099*2100* This takes an audio buffer `src` of `len` bytes of `format` data and mixes2101* it into `dst`, performing addition, volume adjustment, and overflow2102* clipping. The buffer pointed to by `dst` must also be `len` bytes of2103* `format` data.2104*2105* This is provided for convenience -- you can mix your own audio data.2106*2107* Do not use this function for mixing together more than two streams of2108* sample data. The output from repeated application of this function may be2109* distorted by clipping, because there is no accumulator with greater range2110* than the input (not to mention this being an inefficient way of doing it).2111*2112* It is a common misconception that this function is required to write audio2113* data to an output stream in an audio callback. While you can do that,2114* SDL_MixAudio() is really only needed when you're mixing a single audio2115* stream with a volume adjustment.2116*2117* \param dst the destination for the mixed audio.2118* \param src the source audio buffer to be mixed.2119* \param format the SDL_AudioFormat structure representing the desired audio2120* format.2121* \param len the length of the audio buffer in bytes.2122* \param volume ranges from 0.0 - 1.0, and should be set to 1.0 for full2123* audio volume.2124* \returns true on success or false on failure; call SDL_GetError() for more2125* information.2126*2127* \threadsafety It is safe to call this function from any thread.2128*2129* \since This function is available since SDL 3.2.0.2130*/2131extern SDL_DECLSPEC bool SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume);21322133/**2134* Convert some audio data of one format to another format.2135*2136* Please note that this function is for convenience, but should not be used2137* to resample audio in blocks, as it will introduce audio artifacts on the2138* boundaries. You should only use this function if you are converting audio2139* data in its entirety in one call. If you want to convert audio in smaller2140* chunks, use an SDL_AudioStream, which is designed for this situation.2141*2142* Internally, this function creates and destroys an SDL_AudioStream on each2143* use, so it's also less efficient than using one directly, if you need to2144* convert multiple times.2145*2146* \param src_spec the format details of the input audio.2147* \param src_data the audio data to be converted.2148* \param src_len the len of src_data.2149* \param dst_spec the format details of the output audio.2150* \param dst_data will be filled with a pointer to converted audio data,2151* which should be freed with SDL_free(). On error, it will be2152* NULL.2153* \param dst_len will be filled with the len of dst_data.2154* \returns true on success or false on failure; call SDL_GetError() for more2155* information.2156*2157* \threadsafety It is safe to call this function from any thread.2158*2159* \since This function is available since SDL 3.2.0.2160*/2161extern 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);21622163/**2164* Get the human readable name of an audio format.2165*2166* \param format the audio format to query.2167* \returns the human readable name of the specified audio format or2168* "SDL_AUDIO_UNKNOWN" if the format isn't recognized.2169*2170* \threadsafety It is safe to call this function from any thread.2171*2172* \since This function is available since SDL 3.2.0.2173*/2174extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioFormatName(SDL_AudioFormat format);21752176/**2177* Get the appropriate memset value for silencing an audio format.2178*2179* The value returned by this function can be used as the second argument to2180* memset (or SDL_memset) to set an audio buffer in a specific format to2181* silence.2182*2183* \param format the audio data format to query.2184* \returns a byte value that can be passed to memset.2185*2186* \threadsafety It is safe to call this function from any thread.2187*2188* \since This function is available since SDL 3.2.0.2189*/2190extern SDL_DECLSPEC int SDLCALL SDL_GetSilenceValueForFormat(SDL_AudioFormat format);219121922193/* Ends C function definitions when using C++ */2194#ifdef __cplusplus2195}2196#endif2197#include <SDL3/SDL_close_code.h>21982199#endif /* SDL_audio_h_ */220022012202