API reference / Audio
SDL_LoadWAV
Function, SDL3
Loads a WAV file into memory.
Declaration
#include <SDL3/SDL.h>
bool SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);Parameters
path | The path of the file. |
spec | Filled with the format of the sound. |
audio_buf | The address of a pointer. SDL writes the address of the samples there. |
audio_len | The address of a value for the size of the samples in bytes. |
Return value
True on success. On failure it returns false, and SDL_GetError gives the reason.
Example
if (!SDL_LoadWAV(path, &spec, &sound->data, &sound->length)) {
SDL_Log("SDL_LoadWAV failed: %s", SDL_GetError());
return false;
}See this code run in Play a sound. Download the full program (.zip)
Notes
- Free the samples with
SDL_free.
In SDL2
The name is the same, but it returns a pointer, or NULL on failure. Free the samples with SDL_FreeWAV.