Wiki Page Content


Use this function to load a WAVE from a file.


SDL_AudioSpec* SDL_LoadWAV(const char*    file,
                           SDL_AudioSpec* spec,
                           Uint8**        audio_buf,
                           Uint32*        audio_len)

Function Parameters


the name of the file to load


an SDL_AudioSpec structure that will be filled in with the wave file's format details


the audio buffer


the length of the audio buffer in bytes

Return Value

This function, if successfully called, returns a pointer to an SDL_AudioSpec structure filled with the audio data format of the wave source data. audio_buf is 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 NULL if the wave 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_FreeWAV() to dispose of it.

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... */


SDL_LoadWAV is a convenience macro that calls SDL_LoadWAV_RW().

This macro exists so you can pass a filename to SDL_LoadWAV_RW() without having to deal with the RWops API.

CategoryAPI, CategoryAudio

None: SDL_LoadWAV (last edited 2018-10-30 02:31:49 by RyanGordon)

Please include your contact information if you'd like to receive a reply.