1<HTML 2><HEAD 3><TITLE 4>SDL_LoadWAV</TITLE 5><META 6NAME="GENERATOR" 7CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ 8"><LINK 9REL="HOME" 10TITLE="SDL Library Documentation" 11HREF="index.html"><LINK 12REL="UP" 13TITLE="Audio" 14HREF="audio.html"><LINK 15REL="PREVIOUS" 16TITLE="SDL_GetAudioStatus" 17HREF="sdlgetaudiostatus.html"><LINK 18REL="NEXT" 19TITLE="SDL_FreeWAV" 20HREF="sdlfreewav.html"></HEAD 21><BODY 22CLASS="REFENTRY" 23BGCOLOR="#FFF8DC" 24TEXT="#000000" 25LINK="#0000ee" 26VLINK="#551a8b" 27ALINK="#ff0000" 28><DIV 29CLASS="NAVHEADER" 30><TABLE 31SUMMARY="Header navigation table" 32WIDTH="100%" 33BORDER="0" 34CELLPADDING="0" 35CELLSPACING="0" 36><TR 37><TH 38COLSPAN="3" 39ALIGN="center" 40>SDL Library Documentation</TH 41></TR 42><TR 43><TD 44WIDTH="10%" 45ALIGN="left" 46VALIGN="bottom" 47><A 48HREF="sdlgetaudiostatus.html" 49ACCESSKEY="P" 50>Prev</A 51></TD 52><TD 53WIDTH="80%" 54ALIGN="center" 55VALIGN="bottom" 56></TD 57><TD 58WIDTH="10%" 59ALIGN="right" 60VALIGN="bottom" 61><A 62HREF="sdlfreewav.html" 63ACCESSKEY="N" 64>Next</A 65></TD 66></TR 67></TABLE 68><HR 69ALIGN="LEFT" 70WIDTH="100%"></DIV 71><H1 72><A 73NAME="SDLLOADWAV" 74></A 75>SDL_LoadWAV</H1 76><DIV 77CLASS="REFNAMEDIV" 78><A 79NAME="AEN6816" 80></A 81><H2 82>Name</H2 83>SDL_LoadWAV -- Load a WAVE file</DIV 84><DIV 85CLASS="REFSYNOPSISDIV" 86><A 87NAME="AEN6819" 88></A 89><H2 90>Synopsis</H2 91><DIV 92CLASS="FUNCSYNOPSIS" 93><A 94NAME="AEN6820" 95></A 96><P 97></P 98><PRE 99CLASS="FUNCSYNOPSISINFO" 100>#include "SDL.h"</PRE 101><P 102><CODE 103><CODE 104CLASS="FUNCDEF" 105>SDL_AudioSpec *<B 106CLASS="FSFUNC" 107>SDL_LoadWAV</B 108></CODE 109>(const char *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);</CODE 110></P 111><P 112></P 113></DIV 114></DIV 115><DIV 116CLASS="REFSECT1" 117><A 118NAME="AEN6826" 119></A 120><H2 121>Description</H2 122><P 123><TT 124CLASS="FUNCTION" 125>SDL_LoadWAV</TT 126> 127This function loads a WAVE <TT 128CLASS="PARAMETER" 129><I 130>file</I 131></TT 132> into memory.</P 133><P 134>If this function succeeds, it returns the given 135<A 136HREF="sdlaudiospec.html" 137><TT 138CLASS="FUNCTION" 139>SDL_AudioSpec</TT 140></A 141>, 142filled with the audio data format of the wave data, and sets 143<TT 144CLASS="PARAMETER" 145><I 146>audio_buf</I 147></TT 148> to a <TT 149CLASS="FUNCTION" 150>malloc</TT 151>'d 152buffer containing the audio data, and sets <TT 153CLASS="PARAMETER" 154><I 155>audio_len</I 156></TT 157> 158to the length of that audio buffer, in bytes. You need to free the audio 159buffer with <A 160HREF="sdlfreewav.html" 161><TT 162CLASS="FUNCTION" 163>SDL_FreeWAV</TT 164></A 165> when you are 166done with it.</P 167><P 168>This function returns <TT 169CLASS="LITERAL" 170>NULL</TT 171> and sets the SDL 172error message if the wave file cannot be opened, uses an unknown data format, 173or is corrupt. Currently raw, MS-ADPCM and IMA-ADPCM WAVE files are supported.</P 174></DIV 175><DIV 176CLASS="REFSECT1" 177><A 178NAME="AEN6841" 179></A 180><H2 181>Example</H2 182><PRE 183CLASS="PROGRAMLISTING" 184>SDL_AudioSpec wav_spec; 185Uint32 wav_length; 186Uint8 *wav_buffer; 187 188/* Load the WAV */ 189if( SDL_LoadWAV("test.wav", &wav_spec, &wav_buffer, &wav_length) == NULL ){ 190 fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError()); 191 exit(-1); 192} 193. 194. 195. 196/* Do stuff with the WAV */ 197. 198. 199/* Free It */ 200SDL_FreeWAV(wav_buffer);</PRE 201></DIV 202><DIV 203CLASS="REFSECT1" 204><A 205NAME="AEN6844" 206></A 207><H2 208>See Also</H2 209><P 210><A 211HREF="sdlaudiospec.html" 212><SPAN 213CLASS="STRUCTNAME" 214>SDL_AudioSpec</SPAN 215></A 216>, 217<A 218HREF="sdlopenaudio.html" 219><TT 220CLASS="FUNCTION" 221>SDL_OpenAudio</TT 222></A 223>, 224<A 225HREF="sdlfreewav.html" 226><TT 227CLASS="FUNCTION" 228>SDL_FreeWAV</TT 229></A 230></P 231></DIV 232><DIV 233CLASS="NAVFOOTER" 234><HR 235ALIGN="LEFT" 236WIDTH="100%"><TABLE 237SUMMARY="Footer navigation table" 238WIDTH="100%" 239BORDER="0" 240CELLPADDING="0" 241CELLSPACING="0" 242><TR 243><TD 244WIDTH="33%" 245ALIGN="left" 246VALIGN="top" 247><A 248HREF="sdlgetaudiostatus.html" 249ACCESSKEY="P" 250>Prev</A 251></TD 252><TD 253WIDTH="34%" 254ALIGN="center" 255VALIGN="top" 256><A 257HREF="index.html" 258ACCESSKEY="H" 259>Home</A 260></TD 261><TD 262WIDTH="33%" 263ALIGN="right" 264VALIGN="top" 265><A 266HREF="sdlfreewav.html" 267ACCESSKEY="N" 268>Next</A 269></TD 270></TR 271><TR 272><TD 273WIDTH="33%" 274ALIGN="left" 275VALIGN="top" 276>SDL_GetAudioStatus</TD 277><TD 278WIDTH="34%" 279ALIGN="center" 280VALIGN="top" 281><A 282HREF="audio.html" 283ACCESSKEY="U" 284>Up</A 285></TD 286><TD 287WIDTH="33%" 288ALIGN="right" 289VALIGN="top" 290>SDL_FreeWAV</TD 291></TR 292></TABLE 293></DIV 294></BODY 295></HTML 296>