.\" This manpage content is licensed under Creative Commons
.\"  Attribution 4.0 International (CC BY 4.0)
.\"   https://creativecommons.org/licenses/by/4.0/
.\" This manpage was generated from SDL_mixer's wiki page for MIX_LoadAudioNoCopy:
.\"   https://wiki.libsdl.org/SDL3_mixer/MIX_LoadAudioNoCopy
.\" Generated with SDL/build-scripts/wikiheaders.pl
.\"  revision 3.2.6+ds-1
.\" Please report issues in this manpage's content at:
.\"   https://github.com/libsdl-org/sdlwiki/issues/new
.\" Please report issues in the generation of this manpage from the wiki at:
.\"   https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20MIX_LoadAudioNoCopy
.\" SDL_mixer can be found at https://libsdl.org/projects/SDL_mixer/
.de URL
\$2 \(laURL: \$1 \(ra\$3
..
.if \n[.g] .mso www.tmac
.TH MIX_LoadAudioNoCopy 3 "SDL_mixer 3.2.6" "SDL_mixer" "SDL_mixer3 FUNCTIONS"
.SH NAME
MIX_LoadAudioNoCopy \- Load audio for playback from a memory buffer without making a copy.
.SH SYNOPSIS
.nf
.B #include <SDL3_mixer/SDL_mixer.h>
.PP
.BI "MIX_Audio * MIX_LoadAudioNoCopy(MIX_Mixer *mixer, const void *data, size_t datalen, bool free_when_done);
.fi
.SH DESCRIPTION
When loading audio through most other LoadAudio functions, the data will be cached fully in RAM in its original data format, for decoding on-demand\[char46] This function does most of the same work as those functions, but instead uses a buffer of memory provided by the app that it does not make a copy of\[char46]
.PP
This buffer must live for the entire time the returned
.BR MIX_Audio
lives, as the mixer will access the buffer whenever it needs to mix more data\[char46]
.PP
This function is meant to maximize efficiency: if the data is already in memory and can remain there, don\(aqt copy it\[char46] This data can be in any supported audio file format (WAV, MP3, etc); it will be decoded on the fly while mixing\[char46] Unlike
.BR MIX_LoadAudio (),
there is no
.BR predecode
option offered here, as this is meant to optimize for data that\(aqs already in memory and intends to exist there for significant time; since predecoding would only need the file format data once, upfront, one could simply wrap it in SDL_CreateIOFromConstMem() and pass that to
.BR MIX_LoadAudio_IO ()\[char46]
.PP

.BR MIX_Audio
objects can be shared between multiple mixers\[char46] The
.BR mixer
parameter just suggests the most likely mixer to use this audio, in case some optimization might be applied, but this is not required, and a NULL mixer may be specified\[char46]
.PP
If
.BR free_when_done
is true, SDL_mixer will call
.BR SDL_free(data)
when the returned
.BR MIX_Audio
is eventually destroyed\[char46] This can be useful when the data is not static, but rather loaded elsewhere for this specific
.BR MIX_Audio
and simply wants to avoid the extra copy\[char46]
.PP
As audio format information is obtained from the file format metadata, this isn\(aqt useful for raw PCM data; in that case, use
.BR MIX_LoadRawAudioNoCopy ()
instead, which offers an SDL_AudioSpec\[char46]
.PP
Once a
.BR MIX_Audio
is created, it can be assigned to a
.BR MIX_Track
with
.BR MIX_SetTrackAudio (),
or played without any management with
.BR MIX_PlayAudio ()\[char46]
.PP
When done with a
.BR MIX_Audio ,
it can be freed with
.BR MIX_DestroyAudio ()\[char46]

.SH FUNCTION PARAMETERS
.TP
.I mixer
a mixer this audio is intended to be used with\[char46] May be NULL\[char46]
.TP
.I data
the buffer where the audio data lives\[char46]
.TP
.I datalen
the size, in bytes, of the buffer\[char46]
.TP
.I free_when_done
if true,
.BR data
will be given to SDL_free() when the
.BR MIX_Audio
is destroyed\[char46]
.SH RETURN VALUE
Returns an audio object that can be used to make sound on a mixer, or NULL on failure; call SDL_GetError() for more information\[char46]

.SH THREAD SAFETY
It is safe to call this function from any thread\[char46]

.SH AVAILABILITY
This function is available since SDL_mixer 3\[char46]0\[char46]0\[char46]

.SH SEE ALSO
.BR MIX_DestroyAudio (3),
.BR MIX_SetTrackAudio (3),
.BR MIX_LoadRawAudioNoCopy (3),
.BR MIX_LoadAudio_IO (3)
