sdlLoadWav function
Loads a WAV from a file path.
This is a convenience function that is effectively the same as:
SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len);
\param path the file path of the WAV file to open.
\param spec a pointer to an SDL_AudioSpec that will be set to the WAVE
data's format details on successful return.
\param audio_buf a pointer filled with the audio data, allocated by the
function.
\param audio_len a pointer filled with the length of the audio data buffer
in bytes.
\returns true on success. 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 false 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.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
\sa SDL_free \sa SDL_LoadWAV_IO
extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
Implementation
bool sdlLoadWav(String? path, Pointer<SdlAudioSpec> spec,
Pointer<Pointer<Uint8>> audioBuf, Pointer<Uint32> audioLen) {
final sdlLoadWavLookupFunction = libSdl3.lookupFunction<
Uint8 Function(Pointer<Utf8> path, Pointer<SdlAudioSpec> spec,
Pointer<Pointer<Uint8>> audioBuf, Pointer<Uint32> audioLen),
int Function(
Pointer<Utf8> path,
Pointer<SdlAudioSpec> spec,
Pointer<Pointer<Uint8>> audioBuf,
Pointer<Uint32> audioLen)>('SDL_LoadWAV');
final pathPointer = path != null ? path.toNativeUtf8() : nullptr;
final result =
sdlLoadWavLookupFunction(pathPointer, spec, audioBuf, audioLen) == 1;
calloc.free(pathPointer);
return result;
}