SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)


Loads a WAV from a file path.


int SDL_LoadWAV(const char *path, SDL_AudioSpec * spec,
                Uint8 ** audio_buf, Uint32 * audio_len);

Function Parameters


The file path of the WAV file to open.


A pointer to an SDL_AudioSpec that will be set to the WAVE data's format details on successful return.


A pointer filled with the audio data, allocated by the function.


A pointer filled with the length of the audio data buffer in bytes

Return Value

Returns This function, if successfully called, returns 0. audio_buf will be filled with a pointer to an allocated buffer containing the audio data, and audio_len is filled with the length of that audio buffer in bytes.

This function returns -1 if the .WAV file cannot be opened, uses an unknown data format, or is corrupt; call SDL_GetError() for more information.

When the application is done with the data returned in audio_buf, it should call SDL_free() to dispose of it.


This is a convenience function that is effectively the same as:

SDL_LoadWAV_RW(SDL_RWFromFile(path, "rb"), 1, spec, audio_buf, audio_len);

Note that in SDL2, this was a preprocessor macro and not a real function.

Thread Safety

It is safe to call this function from any thread.


This function is available since SDL 3.0.0.

Code Examples

SDL_AudioSpec wav_spec;
Uint32 wav_length;
Uint8 *wav_buffer;

/* Load the WAV */
if (SDL_LoadWAV("test.wav", &wav_spec, &wav_buffer, &wav_length) == NULL) {
    fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError());
} else {
    /* Do stuff with the WAV data, and then... */

CategoryAPI, CategoryAudio

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.