Sophie

Sophie

distrib > Mandriva > 8.0 > i586 > media > main > by-pkgid > 6a3ae4e037535c68bd8a5fcce387b3cb > files > 686

kdemultimedia-2.1.1-5mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>C API</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.61
"><LINK
REL="HOME"
TITLE="The aRts Handbook"
HREF="index.html"><LINK
REL="UP"
TITLE="aRts Application Programming Interfaces"
HREF="arts-apis.html"><LINK
REL="PREVIOUS"
TITLE="artsflow"
HREF="artsflow.html"><LINK
REL="NEXT"
TITLE="aRts modules"
HREF="arts-modules.html"><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"><LINK
REL="stylesheet"
HREF="common/kde-common.css"
TYPE="text/css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"><META
HTTP-EQUIV="Content-Language"
CONTENT="en"><LINK
REL="stylesheet"
HREF="common/kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"><LINK
REL="stylesheet"
HREF="common/kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#AA0000"
VLINK="#AA0055"
ALINK="#AA0000"
STYLE="font-family: sans-serif;"
><DIV
CLASS="logoheader"
><A
HREF="http://www.kde.org/"
><IMG
SRC="common/logotp3.png"
BORDER="0"
ALT="The K Desktop Environment"
HEIGHT="62"
WIDTH="229"></A
></DIV
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> Handbook</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="artsflow.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 7. <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> Application Programming Interfaces</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="arts-modules.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="CAPI"
>7.8. C <SPAN
CLASS="ACRONYM"
>API</SPAN
></A
></H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="CAPIINTRO"
>7.8.1. Introduction</A
></H2
><P
> The <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> C <SPAN
CLASS="ACRONYM"
>API</SPAN
> was designed to make it easy to
writing and port plain C applications to the <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> sound server. It provides
streaming functionality (sending sample streams to
<SPAN
CLASS="APPLICATION"
>artsd</SPAN
>), either blocking or non-blocking. For most
applications you simply remove the few system calls that deal with your audio
device and replace them with the appropriate <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> calls.</P
><P
>I did two ports as a proof of concept: <SPAN
CLASS="APPLICATION"
>mpg123</SPAN
>
and <SPAN
CLASS="APPLICATION"
>quake</SPAN
>. You can get the patches from <A
HREF="http://space.twc.de/~stefan/kde/download/artsc-patches.tar.gz"
TARGET="_top"
>here</A
>.
Feel free to submit your own patches to the maintainer of <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> or of
multimedia software packages so that they can integrate <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> support into
their code.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="CAPIWALKTHRU"
>7.8.2. Quick Walkthrough</A
></H2
><P
>Sending audio to the sound server with the <SPAN
CLASS="ACRONYM"
>API</SPAN
> is very
simple:</P
><DIV
CLASS="PROCEDURE"
><OL
TYPE="1"
><LI
><P
>include the header file using <TT
CLASS="USERINPUT"
><B
>#include
&#60;artsc.h&#62;</B
></TT
></P
></LI
><LI
><P
>initialize the <SPAN
CLASS="ACRONYM"
>API</SPAN
> with
<TT
CLASS="FUNCTION"
>arts_init()</TT
></P
></LI
><LI
><P
>create a stream with
<TT
CLASS="FUNCTION"
>arts_play_stream()</TT
></P
></LI
><LI
><P
>configure specific parameters with
<TT
CLASS="FUNCTION"
>arts_stream_set()</TT
></P
></LI
><LI
><P
>write sampling data to the stream with
<TT
CLASS="FUNCTION"
>arts_write()</TT
></P
></LI
><LI
><P
>close the stream with
<TT
CLASS="FUNCTION"
>arts_close_stream()</TT
></P
></LI
><LI
><P
>free the <SPAN
CLASS="ACRONYM"
>API</SPAN
> with
<TT
CLASS="FUNCTION"
>arts_free()</TT
></P
></LI
></OL
></DIV
><P
>Here is a small example program that illustrates this:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>   1&nbsp;#include &#60;stdio.h&#62;
   2&nbsp;#include &#60;artsc.h&#62;
   3&nbsp;
   4&nbsp;int main()
   5&nbsp;{
   6&nbsp;    arts_stream_t stream;
   7&nbsp;    char buffer[8192];
   8&nbsp;    int bytes;
   9&nbsp;    int errorcode;
  10&nbsp;
  11&nbsp;    errorcode = arts_init();
  12&nbsp;    if (errorcode &#60; 0)
  13&nbsp;    {
  14&nbsp;        fprintf(stderr, "arts_init error: %s\n", arts_error_text(errorcode));
  15&nbsp;        return 1;
  16&nbsp;    }
  17&nbsp;
  18&nbsp;    stream = arts_play_stream(44100, 16, 2, "artsctest");
  19&nbsp;
  20&nbsp;    while((bytes = fread(buffer, 1, 8192, stdin)) &#62; 0)
  21&nbsp;    {
  22&nbsp;        errorcode = arts_write(stream, buffer, bytes);
  23&nbsp;        if(errorcode &#60; 0)
  24&nbsp;        {
  25&nbsp;            fprintf(stderr, "arts_write error: %s\n", arts_error_text(errorcode));
  26&nbsp;            return 1;
  27&nbsp;        }
  28&nbsp;    }
  29&nbsp;
  30&nbsp;    arts_close_stream(stream);
  31&nbsp;    arts_free();
  32&nbsp;
  33&nbsp;    return 0;
  34&nbsp;}</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="CAPIARTSCCONFIG"
>7.8.3. Compiling and Linking: <SPAN
CLASS="APPLICATION"
>artsc-config</SPAN
></A
></H2
><P
>To easily compile and link programs using the <SPAN
CLASS="APPLICATION"
>aRts</SPAN
> C
<SPAN
CLASS="ACRONYM"
>API</SPAN
>, the <SPAN
CLASS="APPLICATION"
>artsc-config</SPAN
> utility is
provided which knows which libraries you need to link and where the includes
are. It is called using</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
> <TT
CLASS="USERINPUT"
><B
><B
CLASS="COMMAND"
>artsc-config</B
> <TT
CLASS="OPTION"
>--libs</TT
></B
></TT
></PRE
></TD
></TR
></TABLE
><P
>to find out the libraries and </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
> <TT
CLASS="USERINPUT"
><B
><B
CLASS="COMMAND"
>artsc-config</B
> <TT
CLASS="OPTION"
>--cflags</TT
></B
></TT
></PRE
></TD
></TR
></TABLE
><P
>to find out additional C compiler flags. The example above could have been
compiled using the command line:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SCREEN"
> <TT
CLASS="USERINPUT"
><B
><B
CLASS="COMMAND"
>cc</B
> <TT
CLASS="OPTION"
>-o artsctest artsctest.c `artsc-config --cflags` `artsc-config --libs`</TT
></B
></TT
>
 
 <TT
CLASS="USERINPUT"
><B
><B
CLASS="COMMAND"
>cc</B
> <TT
CLASS="OPTION"
>-o artsctest</TT
> <TT
CLASS="OPTION"
>artsctest.c</TT
> <TT
CLASS="OPTION"
>`artsc-config --cflags`</TT
> <TT
CLASS="OPTION"
>`artsc-config --libs`</TT
></B
></TT
></PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="C-API-REFERENCE"
>7.8.4. Library Reference</A
></H2
><P
>[TODO: generate the documentation for artsc.h using kdoc]</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="artsflow.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="arts-modules.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>artsflow</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="arts-apis.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><SPAN
CLASS="APPLICATION"
>aRts</SPAN
> modules</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>