1<HTML 2><HEAD 3><TITLE 4>SDL_AudioCVT</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_FreeWAV" 17HREF="sdlfreewav.html"><LINK 18REL="NEXT" 19TITLE="SDL_BuildAudioCVT" 20HREF="sdlbuildaudiocvt.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="sdlfreewav.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="sdlbuildaudiocvt.html" 63ACCESSKEY="N" 64>Next</A 65></TD 66></TR 67></TABLE 68><HR 69ALIGN="LEFT" 70WIDTH="100%"></DIV 71><H1 72><A 73NAME="SDLAUDIOCVT" 74></A 75>SDL_AudioCVT</H1 76><DIV 77CLASS="REFNAMEDIV" 78><A 79NAME="AEN6884" 80></A 81><H2 82>Name</H2 83>SDL_AudioCVT -- Audio Conversion Structure</DIV 84><DIV 85CLASS="REFSECT1" 86><A 87NAME="AEN6887" 88></A 89><H2 90>Structure Definition</H2 91><PRE 92CLASS="PROGRAMLISTING" 93>typedef struct{ 94 int needed; 95 Uint16 src_format; 96 Uint16 dest_format; 97 double rate_incr; 98 Uint8 *buf; 99 int len; 100 int len_cvt; 101 int len_mult; 102 double len_ratio; 103 void (*filters[10])(struct SDL_AudioCVT *cvt, Uint16 format); 104 int filter_index; 105} SDL_AudioCVT;</PRE 106></DIV 107><DIV 108CLASS="REFSECT1" 109><A 110NAME="AEN6890" 111></A 112><H2 113>Structure Data</H2 114><DIV 115CLASS="INFORMALTABLE" 116><A 117NAME="AEN6892" 118></A 119><P 120></P 121><TABLE 122BORDER="0" 123CLASS="CALSTABLE" 124><TBODY 125><TR 126><TD 127ALIGN="LEFT" 128VALIGN="TOP" 129><TT 130CLASS="STRUCTFIELD" 131><I 132>needed</I 133></TT 134></TD 135><TD 136ALIGN="LEFT" 137VALIGN="TOP" 138>Set to one if the conversion is possible</TD 139></TR 140><TR 141><TD 142ALIGN="LEFT" 143VALIGN="TOP" 144><TT 145CLASS="STRUCTFIELD" 146><I 147>src_format</I 148></TT 149></TD 150><TD 151ALIGN="LEFT" 152VALIGN="TOP" 153>Audio format of the source</TD 154></TR 155><TR 156><TD 157ALIGN="LEFT" 158VALIGN="TOP" 159><TT 160CLASS="STRUCTFIELD" 161><I 162>dest_format</I 163></TT 164></TD 165><TD 166ALIGN="LEFT" 167VALIGN="TOP" 168>Audio format of the destination</TD 169></TR 170><TR 171><TD 172ALIGN="LEFT" 173VALIGN="TOP" 174><TT 175CLASS="STRUCTFIELD" 176><I 177>rate_incr</I 178></TT 179></TD 180><TD 181ALIGN="LEFT" 182VALIGN="TOP" 183>Rate conversion increment</TD 184></TR 185><TR 186><TD 187ALIGN="LEFT" 188VALIGN="TOP" 189><TT 190CLASS="STRUCTFIELD" 191><I 192>buf</I 193></TT 194></TD 195><TD 196ALIGN="LEFT" 197VALIGN="TOP" 198>Audio buffer</TD 199></TR 200><TR 201><TD 202ALIGN="LEFT" 203VALIGN="TOP" 204><TT 205CLASS="STRUCTFIELD" 206><I 207>len</I 208></TT 209></TD 210><TD 211ALIGN="LEFT" 212VALIGN="TOP" 213>Length of the original audio buffer in bytes</TD 214></TR 215><TR 216><TD 217ALIGN="LEFT" 218VALIGN="TOP" 219><TT 220CLASS="STRUCTFIELD" 221><I 222>len_cvt</I 223></TT 224></TD 225><TD 226ALIGN="LEFT" 227VALIGN="TOP" 228>Length of converted audio buffer in bytes (calculated)</TD 229></TR 230><TR 231><TD 232ALIGN="LEFT" 233VALIGN="TOP" 234><TT 235CLASS="STRUCTFIELD" 236><I 237>len_mult</I 238></TT 239></TD 240><TD 241ALIGN="LEFT" 242VALIGN="TOP" 243><TT 244CLASS="STRUCTFIELD" 245><I 246>buf</I 247></TT 248> must be <TT 249CLASS="STRUCTFIELD" 250><I 251>len</I 252></TT 253>*<TT 254CLASS="STRUCTFIELD" 255><I 256>len_mult</I 257></TT 258> bytes in size(calculated)</TD 259></TR 260><TR 261><TD 262ALIGN="LEFT" 263VALIGN="TOP" 264><TT 265CLASS="STRUCTFIELD" 266><I 267>len_ratio</I 268></TT 269></TD 270><TD 271ALIGN="LEFT" 272VALIGN="TOP" 273>Final audio size is <TT 274CLASS="STRUCTFIELD" 275><I 276>len</I 277></TT 278>*<TT 279CLASS="STRUCTFIELD" 280><I 281>len_ratio</I 282></TT 283></TD 284></TR 285><TR 286><TD 287ALIGN="LEFT" 288VALIGN="TOP" 289><TT 290CLASS="STRUCTFIELD" 291><I 292>filters[10](..)</I 293></TT 294></TD 295><TD 296ALIGN="LEFT" 297VALIGN="TOP" 298>Pointers to functions needed for this conversion</TD 299></TR 300><TR 301><TD 302ALIGN="LEFT" 303VALIGN="TOP" 304><TT 305CLASS="STRUCTFIELD" 306><I 307>filter_index</I 308></TT 309></TD 310><TD 311ALIGN="LEFT" 312VALIGN="TOP" 313>Current conversion function</TD 314></TR 315></TBODY 316></TABLE 317><P 318></P 319></DIV 320></DIV 321><DIV 322CLASS="REFSECT1" 323><A 324NAME="AEN6944" 325></A 326><H2 327>Description</H2 328><P 329>The <SPAN 330CLASS="STRUCTNAME" 331>SDL_AudioCVT</SPAN 332> is used to convert audio data between different formats. A <SPAN 333CLASS="STRUCTNAME" 334>SDL_AudioCVT</SPAN 335> structure is created with the <A 336HREF="sdlbuildaudiocvt.html" 337><TT 338CLASS="FUNCTION" 339>SDL_BuildAudioCVT</TT 340></A 341> function, while the actual conversion is done by the <A 342HREF="sdlconvertaudio.html" 343><TT 344CLASS="FUNCTION" 345>SDL_ConvertAudio</TT 346></A 347> function.</P 348><P 349>Many of the fields in the <SPAN 350CLASS="STRUCTNAME" 351>SDL_AudioCVT</SPAN 352> structure should be considered private and their function will not be discussed here.</P 353><P 354></P 355><DIV 356CLASS="VARIABLELIST" 357><DL 358><DT 359><SPAN 360CLASS="TYPE" 361>Uint8 *</SPAN 362><TT 363CLASS="STRUCTFIELD" 364><I 365>buf</I 366></TT 367></DT 368><DD 369><P 370>This points to the audio data that will be used in the conversion. It is both the source and the destination, which means the converted audio data overwrites the original data. It also means that the converted data may be larger than the original data (if you were converting from 8-bit to 16-bit, for instance), so you must ensure <TT 371CLASS="STRUCTFIELD" 372><I 373>buf</I 374></TT 375> is large enough. See below.</P 376></DD 377><DT 378><SPAN 379CLASS="TYPE" 380>int</SPAN 381> <TT 382CLASS="STRUCTFIELD" 383><I 384>len</I 385></TT 386></DT 387><DD 388><P 389>This is the length of the original audio data in bytes.</P 390></DD 391><DT 392><SPAN 393CLASS="TYPE" 394>int</SPAN 395> <TT 396CLASS="STRUCTFIELD" 397><I 398>len_mult</I 399></TT 400></DT 401><DD 402><P 403>As explained above, the audio buffer needs to be big enough to store the converted data, which may be bigger than the original audio data. The length of <TT 404CLASS="STRUCTFIELD" 405><I 406>buf</I 407></TT 408> should be <TT 409CLASS="STRUCTFIELD" 410><I 411>len</I 412></TT 413>*<TT 414CLASS="STRUCTFIELD" 415><I 416>len_mult</I 417></TT 418>.</P 419></DD 420><DT 421><SPAN 422CLASS="TYPE" 423>double</SPAN 424> <TT 425CLASS="STRUCTFIELD" 426><I 427>len_ratio</I 428></TT 429></DT 430><DD 431><P 432>When you have finished converting your audio data, you need to know how much of your audio buffer is valid. <TT 433CLASS="STRUCTFIELD" 434><I 435>len</I 436></TT 437>*<TT 438CLASS="STRUCTFIELD" 439><I 440>len_ratio</I 441></TT 442> is the size of the converted audio data in bytes. This is very similar to <TT 443CLASS="STRUCTFIELD" 444><I 445>len_mult</I 446></TT 447>, however when the convert audio data is shorter than the original <TT 448CLASS="STRUCTFIELD" 449><I 450>len_mult</I 451></TT 452> would be 1. <TT 453CLASS="STRUCTFIELD" 454><I 455>len_ratio</I 456></TT 457>, on the other hand, would be a fractional number between 0 and 1.</P 458></DD 459></DL 460></DIV 461></DIV 462><DIV 463CLASS="REFSECT1" 464><A 465NAME="AEN6989" 466></A 467><H2 468>See Also</H2 469><P 470><A 471HREF="sdlbuildaudiocvt.html" 472><TT 473CLASS="FUNCTION" 474>SDL_BuildAudioCVT</TT 475></A 476>, 477<A 478HREF="sdlconvertaudio.html" 479><TT 480CLASS="FUNCTION" 481>SDL_ConvertAudio</TT 482></A 483>, 484<A 485HREF="sdlaudiospec.html" 486><SPAN 487CLASS="STRUCTNAME" 488>SDL_AudioSpec</SPAN 489></A 490></P 491></DIV 492><DIV 493CLASS="NAVFOOTER" 494><HR 495ALIGN="LEFT" 496WIDTH="100%"><TABLE 497SUMMARY="Footer navigation table" 498WIDTH="100%" 499BORDER="0" 500CELLPADDING="0" 501CELLSPACING="0" 502><TR 503><TD 504WIDTH="33%" 505ALIGN="left" 506VALIGN="top" 507><A 508HREF="sdlfreewav.html" 509ACCESSKEY="P" 510>Prev</A 511></TD 512><TD 513WIDTH="34%" 514ALIGN="center" 515VALIGN="top" 516><A 517HREF="index.html" 518ACCESSKEY="H" 519>Home</A 520></TD 521><TD 522WIDTH="33%" 523ALIGN="right" 524VALIGN="top" 525><A 526HREF="sdlbuildaudiocvt.html" 527ACCESSKEY="N" 528>Next</A 529></TD 530></TR 531><TR 532><TD 533WIDTH="33%" 534ALIGN="left" 535VALIGN="top" 536>SDL_FreeWAV</TD 537><TD 538WIDTH="34%" 539ALIGN="center" 540VALIGN="top" 541><A 542HREF="audio.html" 543ACCESSKEY="U" 544>Up</A 545></TD 546><TD 547WIDTH="33%" 548ALIGN="right" 549VALIGN="top" 550>SDL_BuildAudioCVT</TD 551></TR 552></TABLE 553></DIV 554></BODY 555></HTML 556>