ref: ed072224bf5ca317f6e23d6d9e8376a07d70b228
dir: /doc/api_full.html/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Secret Rabbit Code (aka libsamplerate) </TITLE> <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)"> <META NAME="Version" CONTENT="libsamplerate-0.1.8"> <META NAME="Description" CONTENT="The Secret Rabbit Code Home Page"> <META NAME="Keywords" CONTENT="libsamplerate sound resample audio dsp Linux"> <LINK REL=StyleSheet HREF="SRC.css" TYPE="text/css" MEDIA="all"> </HEAD> <BODY TEXT="#FFFFFF" BGCOLOR="#000000" LINK="#FB1465" VLINK="#FB1465" ALINK="#FB1465"> <!-- pepper --> <CENTER> <IMG SRC="SRC.png" HEIGHT=100 WIDTH=760 ALT="SRC.png"> </CENTER> <!-- pepper --> <BR> <!-- pepper --> <TABLE ALIGN="center" WIDTH="98%"> <TR> <TD VALIGN="top"> <BR> <DIV CLASS="nav"> <BR> <A HREF="index.html">Home</A><BR> <BR> <A HREF="api_simple.html">Simple API</A><BR> <A HREF="api_full.html">Full API</A><BR> <A HREF="api_callback.html">Callback API</A><BR> <A HREF="api_misc.html">Miscellaneous</A><BR> <A HREF="api_misc.html#ErrorReporting">Error Handling</A><BR> <BR> <DIV CLASS="block"> Author :<BR>Erik de Castro Lopo <!-- pepper --> <BR><BR> <!-- pepper --> </DIV> <IMG SRC= "/cgi-bin/Count.cgi?ft=6|frgb=55;55;55|tr=0|md=6|dd=B|st=1|sh=1|df=src_api.dat" HEIGHT=30 WIDTH=100 ALT="counter.gif"> </DIV> </TD> <!-- pepper --> <!-- ######################################################################## --> <!-- pepper --> <TD VALIGN="top"> <DIV CLASS="block"> <H1><B>Full API</B></H1> <P> The full API consists of the following functions : </P> <PRE> SRC_STATE* <A HREF="#Init">src_new</A> (int converter_type, int channels, int *error) ; SRC_STATE* <A HREF="#CleanUp">src_delete</A> (SRC_STATE *state) ; int <A HREF="#Process">src_process</A> (SRC_STATE *state, SRC_DATA *data) ; int <A HREF="#Reset">src_reset</A> (SRC_STATE *state) ; int <A HREF="#SetRatio">src_set_ratio</A> (SRC_STATE *state, double new_ratio) ; </PRE> <A NAME="Init"></A> <H3><BR>Initialisation</H3> <PRE> SRC_STATE* src_new (int converter_type, int channels, int *error) ; </PRE> <P> The <B>src_new</B> function returns an anonymous pointer to a sample rate converter object, src_state. If an error occurs the function returns a NULL pointer and fills in the error value pointed to by the <B>error</B> pointer supplied by the caller. The converter must be one of the supplied converter types documented <A HREF="api_misc.html#Converters">here</A>. </P> <A NAME="CleanUp"></A> <H3><BR>Cleanup</H3> <PRE> SRC_STATE* src_delete (SRC_STATE *state) ; </PRE> <P> The <B>src_delete</B> function frees up all memory allocated for the given sample rate converter object and returns a NULL pointer. The caller is responsible for freeing any memory passed to the sample rate converter via the pointer to the <B>SRC_DATA</B> struct. </P> <A NAME="Process"></A> <H3><BR>Process</H3> <PRE> int src_process (SRC_STATE *state, SRC_DATA *data) ; </PRE> <P> The <B>src_process</B> function processes the data provided by the caller in an <B>SRC_DATA</B> struct using the sample rate converter object specified by the <B>SRC_STATE</B> pointer. When operating on streaming data, this function can be called over and over again, with each new call providing new input data and returning new output data. </P> <P> The <B>SRC_DATA</B> struct passed as the second parameter to the <B>src_process</B> function has the following fields: </P> <PRE> typedef struct { const float *data_in; float *data_out; long input_frames, output_frames ; long input_frames_used, output_frames_gen ; int end_of_input ; double src_ratio ; } SRC_DATA ; </PRE> <P> The fields of this struct which must be filled in by the caller are: </P> <PRE> data_in : A pointer to the input data samples. input_frames : The number of frames of data pointed to by data_in. data_out : A pointer to the output data samples. output_frames : Maximum number of frames pointer to by data_out. src_ratio : Equal to output_sample_rate / input_sample_rate. end_of_input : Equal to 0 if more input data is available and 1 otherwise. </PRE> <P> Note that the data_in and data_out arrays may not overlap. If they do, the library will return an error code. </P> <P> When the <B>src_process</B> function returns <B>output_frames_gen</B> will be set to the number of output frames generated and <B>input_frames_used</B> will be set to the number of input frames consumed to generate the provided number of output frames. </P> <P> The <B>src_process</B> function returns non-zero if an error occurs. The non-zero error return value can be decoded into a text string using the function documented <A HREF="api_misc.html#ErrorReporting">here</A>. </P> <A NAME="Reset"></A> <H3><BR>Reset</H3> <PRE> int src_reset (SRC_STATE *state) ; </PRE> <P> The <B>src_reset</B> function resets the internal state of the sample rate converter object to the same state it had immediately after its creation using <B>src_new</B>. This should be called whenever a sample rate converter is to be used on two separate, unrelated pieces of audio. </P> <A NAME="Clone"></A> <H3><BR>Clone</H3> <PRE> SRC_STATE* src_clone (SRC_STATE *state, int *error) ; </PRE> <P> The <B>src_clone</B> function creates a copy of the internal state of the sample rate converter object. The output of the next call to <B>src_process</B> will be identical for both the original and cloned state (given the same <B>SRC_DATA</B> input). This could be used to later resume sample rate conversion at a specific location in a stream with the same state, which may be useful in real-time applications. </P> <P> If an error occurs the function returns a NULL pointer and fills in the error value pointed to by the <B>error</B> pointer supplied by the caller. </P> <A NAME="SetRatio"></A> <H3><BR>Set Ratio</H3> <PRE> int src_set_ratio (SRC_STATE *state, double new_ratio) ; </PRE> <p> When using the <B>src_process</B> or <B>src_callback_process</B> APIs and updating the <B>src_ratio</B> field of the <B>SRC_STATE</B> struct, the library will try to smoothly transition between the conversion ratio of the last call and the conversion ratio of the current call. <p/> <P> If the user want to bypass this smooth transition and achieve a step response in the conversion ratio, the <B>src_set_ratio</B> function can be used to set the starting conversion ratio of the next call to <B>src_process</B> or <B>src_callback_process</B>. <p/> <P> This function returns non-zero on error and the error return value can be decoded into a text string using the function documented <A HREF="api_misc.html#ErrorReporting">here</A>.</P> <!-- <A HREF="mailto:[email protected]">For the spam bots</A> --> </DIV> </TD></TR> </TABLE> </BODY> </HTML>