Chris@0: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> Chris@0: <HTML> Chris@0: Chris@0: <HEAD> Chris@0: <TITLE> Chris@0: Secret Rabbit Code (aka libsamplerate) Chris@0: </TITLE> Chris@0: <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)"> Chris@0: <META NAME="Version" CONTENT="libsamplerate-0.1.8"> Chris@0: <META NAME="Description" CONTENT="The Secret Rabbit Code Home Page"> Chris@0: <META NAME="Keywords" CONTENT="libsamplerate sound resample audio dsp Linux"> Chris@0: <LINK REL=StyleSheet HREF="SRC.css" TYPE="text/css" MEDIA="all"> Chris@0: </HEAD> Chris@0: Chris@0: <BODY TEXT="#FFFFFF" BGCOLOR="#000000" LINK="#FB1465" VLINK="#FB1465" ALINK="#FB1465"> Chris@0: <!-- pepper --> Chris@0: <CENTER> Chris@0: <IMG SRC="SRC.png" HEIGHT=100 WIDTH=760 ALT="SRC.png"> Chris@0: </CENTER> Chris@0: <!-- pepper --> Chris@0: <BR> Chris@0: <!-- pepper --> Chris@0: <TABLE ALIGN="center" WIDTH="98%"> Chris@0: <TR> Chris@0: <TD VALIGN="top"> Chris@0: <BR> Chris@0: <DIV CLASS="nav"> Chris@0: <BR> Chris@0: <A HREF="index.html">Home</A><BR> Chris@0: <BR> Chris@0: <A HREF="api_simple.html">Simple API</A><BR> Chris@0: <A HREF="api_full.html">Full API</A><BR> Chris@0: <A HREF="api_callback.html">Callback API</A><BR> Chris@0: <A HREF="api_misc.html">Miscellaneous</A><BR> Chris@0: <A HREF="api_misc.html#ErrorReporting">Error Handling</A><BR> Chris@0: <BR> Chris@0: <DIV CLASS="block"> Chris@0: Author :<BR>Erik de Castro Lopo Chris@0: <!-- pepper --> Chris@0: <BR><BR> Chris@0: <!-- pepper --> Chris@0: Chris@0: </DIV> Chris@0: <IMG SRC= Chris@0: "/cgi-bin/Count.cgi?ft=6|frgb=55;55;55|tr=0|md=6|dd=B|st=1|sh=1|df=src_api.dat" Chris@0: HEIGHT=30 WIDTH=100 ALT="counter.gif"> Chris@0: </DIV> Chris@0: Chris@0: </TD> Chris@0: <!-- pepper --> Chris@0: <!-- ######################################################################## --> Chris@0: <!-- pepper --> Chris@0: <TD VALIGN="top"> Chris@0: <DIV CLASS="block"> Chris@0: Chris@0: <H1><B>Callback API</B></H1> Chris@0: <P> Chris@0: The callback API consists of the following functions : Chris@0: </P> Chris@0: <PRE> Chris@0: typedef long (*src_callback_t) (void *cb_data, float **data) ; Chris@0: Chris@0: SRC_STATE* <A HREF="#Init">src_callback_new</A> (src_callback_t func, Chris@0: int converter_type, int channels, Chris@0: int *error, void* cb_data) ; Chris@0: Chris@0: SRC_STATE* <A HREF="api_full.html#CleanUp">src_delete</A> (SRC_STATE *state) ; Chris@0: Chris@0: long <A HREF="#Read">src_callback_read</A> (SRC_STATE *state, double src_ratio, Chris@0: long frames, float *data) ; Chris@0: Chris@0: int <A HREF="api_full.html#Reset">src_reset</A> (SRC_STATE *state) ; Chris@0: int <A HREF="api_full.html#SetRatio">src_set_ratio</A> (SRC_STATE *state, double new_ratio) ; Chris@0: </PRE> Chris@0: <BR> Chris@0: Chris@0: <P> Chris@0: Like the Chris@0: <A HREF="api_simple.html">simple API</a> Chris@0: and the Chris@0: <A HREF="api_full.html">full API</a>, Chris@0: the callback based API is able to operate on interleaved multi channel data. Chris@0: </P> Chris@0: Chris@0: <P> Chris@0: An example of the use of the callback based API can be found in the Chris@0: <B>varispeed-play</B> program in the <B>examples/</B> directory of the Chris@0: source code tarball. Chris@0: </P> Chris@0: Chris@0: <!-- pepper --> Chris@0: <A NAME="Init"></A> Chris@0: <H3><BR>Initialisation</H3> Chris@0: <PRE> Chris@0: SRC_STATE* src_callback_new (src_callback_t func, Chris@0: int converter_type, int channels, Chris@0: int *error, void* cb_data) ; Chris@0: </PRE> Chris@0: <P> Chris@0: The <B>src_callback_new</B> function returns an anonymous pointer to a Chris@0: sample rate converter callback object, src_state. Chris@0: This is the same type of object as that returned by <A HREF="api_full.html#init"> Chris@0: src_new</A>, but with different internal state. Chris@0: Although these are the same object type, they cannot be used interchangeably. Chris@0: If an error occurs the function returns a NULL pointer and fills in the Chris@0: error value pointed to by the <B>error</B> pointer supplied by the caller. Chris@0: </P> Chris@0: <P> Chris@0: The caller then passes the SRC_STATE object to the <B>src_callback_read</B> Chris@0: function to pull data out of the converter. Chris@0: When the caller is finished with the converter they should pass it to the Chris@0: clean up function <A HREF="api_full.html#CleanUp">src_delete</A>. Chris@0: </P> Chris@0: <P> Chris@0: The <B>func</B> parameter is a user supplied function which must match the Chris@0: <B>src_callback_t</B> type signature while <B>cb_data</B> is a pointer to Chris@0: data which be passed as the first parameter to the user supplied callback Chris@0: function. Chris@0: This function is called by the converter whenever it needs input data as a Chris@0: result of being calls to <B>src_callback_read</B>. Chris@0: </P> Chris@0: <P> Chris@0: If the converter was initialised to work with more than one channel, the Chris@0: callback function must work with mutiple channels of interleaved data. Chris@0: The callback function should return the number of frames it supplying to Chris@0: the converter. Chris@0: For multi channel files, this return value should be the number of floats Chris@0: divided by the number of channels. Chris@0: </P> Chris@0: <P> Chris@0: The converter must be one of the supplied converter types documented Chris@0: <A HREF="api_misc.html#Converters">here</A>. Chris@0: </P> Chris@0: <P> Chris@0: The caller then passes the SRC_STATE pointer to the <B>src_callback_read</B> Chris@0: function to pull data out of the converter. Chris@0: </P> Chris@0: Chris@0: <!-- pepper --> Chris@0: <A NAME="Read"></A> Chris@0: <H3><BR>Callback Read</H3> Chris@0: <PRE> Chris@0: long src_callback_read (SRC_STATE *state, double src_ratio, Chris@0: long frames, float *data) ; Chris@0: </PRE> Chris@0: <P> Chris@0: The <B>src_callback_read</B> function is passed the Chris@0: <A HREF="api_misc.html#SRC_DATA"><B>SRC_STATE</B></A> Chris@0: pointer returned by <B>src_callback_new</B>, the coversion ratio Chris@0: (output_sample_rate / input_sample_rate), the maximum number of output frames Chris@0: to generate and a pointer to a buffer in which to place the output data. Chris@0: For multi channel files, the data int the output buffer is stored in Chris@0: interleaved format. Chris@0: </P> Chris@0: <P> Chris@0: The <B>src_callback_read</B> function returns the number of frames generated Chris@0: or zero if an error occurs or it runs out of input (ie the user supplied Chris@0: callback function returns zero and there is no more data buffered internally). Chris@0: If an error has occurred, the function <A HREF="api_misc.html#ErrorReporting"> Chris@0: src_error</A> will return non-zero. Chris@0: </P> Chris@0: Chris@0: <P> Chris@0: See also : Chris@0: <A HREF="api_full.html#SetRatio"><B>src_set_ratio</B></A> Chris@0: </P> Chris@0: Chris@0: <!-- pepper --> Chris@0: Chris@0: </DIV> Chris@0: </TD></TR> Chris@0: </TABLE> Chris@0: Chris@0: </BODY> Chris@0: </HTML> Chris@0: