docs/html/sdlconvertaudio.html
changeset 3352 6dc250ebdd80
parent 3351 8e0182c236d8
child 3353 6b14223dd5c7
     1.1 --- a/docs/html/sdlconvertaudio.html	Wed Oct 07 06:11:53 2009 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,407 +0,0 @@
     1.4 -<HTML
     1.5 -><HEAD
     1.6 -><TITLE
     1.7 ->SDL_ConvertAudio</TITLE
     1.8 -><META
     1.9 -NAME="GENERATOR"
    1.10 -CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
    1.11 -"><LINK
    1.12 -REL="HOME"
    1.13 -TITLE="SDL Library Documentation"
    1.14 -HREF="index.html"><LINK
    1.15 -REL="UP"
    1.16 -TITLE="Audio"
    1.17 -HREF="audio.html"><LINK
    1.18 -REL="PREVIOUS"
    1.19 -TITLE="SDL_BuildAudioCVT"
    1.20 -HREF="sdlbuildaudiocvt.html"><LINK
    1.21 -REL="NEXT"
    1.22 -TITLE="SDL_MixAudio"
    1.23 -HREF="sdlmixaudio.html"></HEAD
    1.24 -><BODY
    1.25 -CLASS="REFENTRY"
    1.26 -BGCOLOR="#FFF8DC"
    1.27 -TEXT="#000000"
    1.28 -LINK="#0000ee"
    1.29 -VLINK="#551a8b"
    1.30 -ALINK="#ff0000"
    1.31 -><DIV
    1.32 -CLASS="NAVHEADER"
    1.33 -><TABLE
    1.34 -SUMMARY="Header navigation table"
    1.35 -WIDTH="100%"
    1.36 -BORDER="0"
    1.37 -CELLPADDING="0"
    1.38 -CELLSPACING="0"
    1.39 -><TR
    1.40 -><TH
    1.41 -COLSPAN="3"
    1.42 -ALIGN="center"
    1.43 ->SDL Library Documentation</TH
    1.44 -></TR
    1.45 -><TR
    1.46 -><TD
    1.47 -WIDTH="10%"
    1.48 -ALIGN="left"
    1.49 -VALIGN="bottom"
    1.50 -><A
    1.51 -HREF="sdlbuildaudiocvt.html"
    1.52 -ACCESSKEY="P"
    1.53 ->Prev</A
    1.54 -></TD
    1.55 -><TD
    1.56 -WIDTH="80%"
    1.57 -ALIGN="center"
    1.58 -VALIGN="bottom"
    1.59 -></TD
    1.60 -><TD
    1.61 -WIDTH="10%"
    1.62 -ALIGN="right"
    1.63 -VALIGN="bottom"
    1.64 -><A
    1.65 -HREF="sdlmixaudio.html"
    1.66 -ACCESSKEY="N"
    1.67 ->Next</A
    1.68 -></TD
    1.69 -></TR
    1.70 -></TABLE
    1.71 -><HR
    1.72 -ALIGN="LEFT"
    1.73 -WIDTH="100%"></DIV
    1.74 -><H1
    1.75 -><A
    1.76 -NAME="SDLCONVERTAUDIO"
    1.77 -></A
    1.78 ->SDL_ConvertAudio</H1
    1.79 -><DIV
    1.80 -CLASS="REFNAMEDIV"
    1.81 -><A
    1.82 -NAME="AEN7048"
    1.83 -></A
    1.84 -><H2
    1.85 ->Name</H2
    1.86 ->SDL_ConvertAudio&nbsp;--&nbsp;Convert audio data to a desired audio format.</DIV
    1.87 -><DIV
    1.88 -CLASS="REFSYNOPSISDIV"
    1.89 -><A
    1.90 -NAME="AEN7051"
    1.91 -></A
    1.92 -><H2
    1.93 ->Synopsis</H2
    1.94 -><DIV
    1.95 -CLASS="FUNCSYNOPSIS"
    1.96 -><A
    1.97 -NAME="AEN7052"
    1.98 -></A
    1.99 -><P
   1.100 -></P
   1.101 -><PRE
   1.102 -CLASS="FUNCSYNOPSISINFO"
   1.103 ->#include "SDL.h"</PRE
   1.104 -><P
   1.105 -><CODE
   1.106 -><CODE
   1.107 -CLASS="FUNCDEF"
   1.108 ->int <B
   1.109 -CLASS="FSFUNC"
   1.110 ->SDL_ConvertAudio</B
   1.111 -></CODE
   1.112 ->(SDL_AudioCVT *cvt);</CODE
   1.113 -></P
   1.114 -><P
   1.115 -></P
   1.116 -></DIV
   1.117 -></DIV
   1.118 -><DIV
   1.119 -CLASS="REFSECT1"
   1.120 -><A
   1.121 -NAME="AEN7058"
   1.122 -></A
   1.123 -><H2
   1.124 ->Description</H2
   1.125 -><P
   1.126 -><TT
   1.127 -CLASS="FUNCTION"
   1.128 ->SDL_ConvertAudio</TT
   1.129 -> takes one parameter, <TT
   1.130 -CLASS="PARAMETER"
   1.131 -><I
   1.132 ->cvt</I
   1.133 -></TT
   1.134 ->, which was previously initilized. Initilizing a <A
   1.135 -HREF="sdlaudiocvt.html"
   1.136 -><SPAN
   1.137 -CLASS="STRUCTNAME"
   1.138 ->SDL_AudioCVT</SPAN
   1.139 -></A
   1.140 -> is a two step process. First of all, the structure must be passed to <A
   1.141 -HREF="sdlbuildaudiocvt.html"
   1.142 -><TT
   1.143 -CLASS="FUNCTION"
   1.144 ->SDL_BuildAudioCVT</TT
   1.145 -></A
   1.146 -> along with source and destination format parameters. Secondly, the <SPAN
   1.147 -CLASS="STRUCTNAME"
   1.148 ->cvt</SPAN
   1.149 ->-&#62;<TT
   1.150 -CLASS="STRUCTFIELD"
   1.151 -><I
   1.152 ->buf</I
   1.153 -></TT
   1.154 -> and <SPAN
   1.155 -CLASS="STRUCTNAME"
   1.156 ->cvt</SPAN
   1.157 ->-&#62;<TT
   1.158 -CLASS="STRUCTFIELD"
   1.159 -><I
   1.160 ->len</I
   1.161 -></TT
   1.162 -> fields must be setup. <SPAN
   1.163 -CLASS="STRUCTNAME"
   1.164 ->cvt</SPAN
   1.165 ->-&#62;<TT
   1.166 -CLASS="STRUCTFIELD"
   1.167 -><I
   1.168 ->buf</I
   1.169 -></TT
   1.170 -> should point to the audio data and <SPAN
   1.171 -CLASS="STRUCTNAME"
   1.172 ->cvt</SPAN
   1.173 ->-&#62;<TT
   1.174 -CLASS="STRUCTFIELD"
   1.175 -><I
   1.176 ->len</I
   1.177 -></TT
   1.178 -> should be set to the length of the audio data in bytes. Remember, the length of the buffer pointed to by <TT
   1.179 -CLASS="STRUCTFIELD"
   1.180 -><I
   1.181 ->buf</I
   1.182 -></TT
   1.183 -> show be <TT
   1.184 -CLASS="STRUCTFIELD"
   1.185 -><I
   1.186 ->len</I
   1.187 -></TT
   1.188 ->*<TT
   1.189 -CLASS="STRUCTFIELD"
   1.190 -><I
   1.191 ->len_mult</I
   1.192 -></TT
   1.193 -> bytes in length.</P
   1.194 -><P
   1.195 ->Once the <SPAN
   1.196 -CLASS="STRUCTNAME"
   1.197 ->SDL_AudioCVT</SPAN
   1.198 ->structure is initilized then we can pass it to <TT
   1.199 -CLASS="FUNCTION"
   1.200 ->SDL_ConvertAudio</TT
   1.201 ->, which will convert the audio data pointer to by <SPAN
   1.202 -CLASS="STRUCTNAME"
   1.203 ->cvt</SPAN
   1.204 ->-&#62;<TT
   1.205 -CLASS="STRUCTFIELD"
   1.206 -><I
   1.207 ->buf</I
   1.208 -></TT
   1.209 ->. If <TT
   1.210 -CLASS="FUNCTION"
   1.211 ->SDL_ConvertAudio</TT
   1.212 -> returned <SPAN
   1.213 -CLASS="RETURNVALUE"
   1.214 ->0</SPAN
   1.215 -> then the conversion was completed successfully, otherwise <SPAN
   1.216 -CLASS="RETURNVALUE"
   1.217 ->-1</SPAN
   1.218 -> is returned.</P
   1.219 -><P
   1.220 ->If the conversion completed successfully then the converted audio data can be read from <SPAN
   1.221 -CLASS="STRUCTNAME"
   1.222 ->cvt</SPAN
   1.223 ->-&#62;<TT
   1.224 -CLASS="STRUCTFIELD"
   1.225 -><I
   1.226 ->buf</I
   1.227 -></TT
   1.228 ->. The amount of valid, converted, audio data in the buffer is equal to <SPAN
   1.229 -CLASS="STRUCTNAME"
   1.230 ->cvt</SPAN
   1.231 ->-&#62;<TT
   1.232 -CLASS="STRUCTFIELD"
   1.233 -><I
   1.234 ->len</I
   1.235 -></TT
   1.236 ->*<TT
   1.237 -CLASS="STRUCTFIELD"
   1.238 -><I
   1.239 ->cvt</I
   1.240 -></TT
   1.241 ->-&#62;<SPAN
   1.242 -CLASS="STRUCTNAME"
   1.243 ->len_ratio</SPAN
   1.244 ->.</P
   1.245 -></DIV
   1.246 -><DIV
   1.247 -CLASS="REFSECT1"
   1.248 -><A
   1.249 -NAME="AEN7093"
   1.250 -></A
   1.251 -><H2
   1.252 ->Examples</H2
   1.253 -><PRE
   1.254 -CLASS="PROGRAMLISTING"
   1.255 ->/* Converting some WAV data to hardware format */
   1.256 -void my_audio_callback(void *userdata, Uint8 *stream, int len);
   1.257 -
   1.258 -SDL_AudioSpec *desired, *obtained;
   1.259 -SDL_AudioSpec wav_spec;
   1.260 -SDL_AudioCVT  wav_cvt;
   1.261 -Uint32 wav_len;
   1.262 -Uint8 *wav_buf;
   1.263 -int ret;
   1.264 -
   1.265 -/* Allocated audio specs */
   1.266 -desired = malloc(sizeof(SDL_AudioSpec));
   1.267 -obtained = malloc(sizeof(SDL_AudioSpec));
   1.268 -
   1.269 -/* Set desired format */
   1.270 -desired-&#62;freq=22050;
   1.271 -desired-&#62;format=AUDIO_S16LSB;
   1.272 -desired-&#62;samples=8192;
   1.273 -desired-&#62;callback=my_audio_callback;
   1.274 -desired-&#62;userdata=NULL;
   1.275 -
   1.276 -/* Open the audio device */
   1.277 -if ( SDL_OpenAudio(desired, obtained) &#60; 0 ){
   1.278 -  fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   1.279 -  exit(-1);
   1.280 -}
   1.281 -        
   1.282 -free(desired);
   1.283 -
   1.284 -/* Load the test.wav */
   1.285 -if( SDL_LoadWAV("test.wav", &#38;wav_spec, &#38;wav_buf, &#38;wav_len) == NULL ){
   1.286 -  fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError());
   1.287 -  SDL_CloseAudio();
   1.288 -  free(obtained);
   1.289 -  exit(-1);
   1.290 -}
   1.291 -                                            
   1.292 -/* Build AudioCVT */
   1.293 -ret = SDL_BuildAudioCVT(&#38;wav_cvt,
   1.294 -                        wav_spec.format, wav_spec.channels, wav_spec.freq,
   1.295 -                        obtained-&#62;format, obtained-&#62;channels, obtained-&#62;freq);
   1.296 -
   1.297 -/* Check that the convert was built */
   1.298 -if(ret==-1){
   1.299 -  fprintf(stderr, "Couldn't build converter!\n");
   1.300 -  SDL_CloseAudio();
   1.301 -  free(obtained);
   1.302 -  SDL_FreeWAV(wav_buf);
   1.303 -}
   1.304 -
   1.305 -/* Setup for conversion */
   1.306 -wav_cvt.buf = malloc(wav_len * wav_cvt.len_mult);
   1.307 -wav_cvt.len = wav_len;
   1.308 -memcpy(wav_cvt.buf, wav_buf, wav_len);
   1.309 -
   1.310 -/* We can delete to original WAV data now */
   1.311 -SDL_FreeWAV(wav_buf);
   1.312 -
   1.313 -/* And now we're ready to convert */
   1.314 -SDL_ConvertAudio(&#38;wav_cvt);
   1.315 -
   1.316 -/* do whatever */
   1.317 -.
   1.318 -.
   1.319 -.
   1.320 -.
   1.321 -&#13;</PRE
   1.322 -></DIV
   1.323 -><DIV
   1.324 -CLASS="REFSECT1"
   1.325 -><A
   1.326 -NAME="AEN7096"
   1.327 -></A
   1.328 -><H2
   1.329 ->See Also</H2
   1.330 -><P
   1.331 -><A
   1.332 -HREF="sdlbuildaudiocvt.html"
   1.333 -><TT
   1.334 -CLASS="FUNCTION"
   1.335 ->SDL_BuildAudioCVT</TT
   1.336 -></A
   1.337 ->,
   1.338 -<A
   1.339 -HREF="sdlaudiocvt.html"
   1.340 -><TT
   1.341 -CLASS="FUNCTION"
   1.342 ->SDL_AudioCVT</TT
   1.343 -></A
   1.344 -></P
   1.345 -></DIV
   1.346 -><DIV
   1.347 -CLASS="NAVFOOTER"
   1.348 -><HR
   1.349 -ALIGN="LEFT"
   1.350 -WIDTH="100%"><TABLE
   1.351 -SUMMARY="Footer navigation table"
   1.352 -WIDTH="100%"
   1.353 -BORDER="0"
   1.354 -CELLPADDING="0"
   1.355 -CELLSPACING="0"
   1.356 -><TR
   1.357 -><TD
   1.358 -WIDTH="33%"
   1.359 -ALIGN="left"
   1.360 -VALIGN="top"
   1.361 -><A
   1.362 -HREF="sdlbuildaudiocvt.html"
   1.363 -ACCESSKEY="P"
   1.364 ->Prev</A
   1.365 -></TD
   1.366 -><TD
   1.367 -WIDTH="34%"
   1.368 -ALIGN="center"
   1.369 -VALIGN="top"
   1.370 -><A
   1.371 -HREF="index.html"
   1.372 -ACCESSKEY="H"
   1.373 ->Home</A
   1.374 -></TD
   1.375 -><TD
   1.376 -WIDTH="33%"
   1.377 -ALIGN="right"
   1.378 -VALIGN="top"
   1.379 -><A
   1.380 -HREF="sdlmixaudio.html"
   1.381 -ACCESSKEY="N"
   1.382 ->Next</A
   1.383 -></TD
   1.384 -></TR
   1.385 -><TR
   1.386 -><TD
   1.387 -WIDTH="33%"
   1.388 -ALIGN="left"
   1.389 -VALIGN="top"
   1.390 ->SDL_BuildAudioCVT</TD
   1.391 -><TD
   1.392 -WIDTH="34%"
   1.393 -ALIGN="center"
   1.394 -VALIGN="top"
   1.395 -><A
   1.396 -HREF="audio.html"
   1.397 -ACCESSKEY="U"
   1.398 ->Up</A
   1.399 -></TD
   1.400 -><TD
   1.401 -WIDTH="33%"
   1.402 -ALIGN="right"
   1.403 -VALIGN="top"
   1.404 ->SDL_MixAudio</TD
   1.405 -></TR
   1.406 -></TABLE
   1.407 -></DIV
   1.408 -></BODY
   1.409 -></HTML
   1.410 ->
   1.411 \ No newline at end of file