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_misc.html#ErrorReporting">Error Handling</A><BR>
Chris@0: 	<A HREF="api_misc.html">Miscellaneous</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>Miscellaneous API Documentation</B></H1>
Chris@0: <A NAME="ErrorReporting"></A>
Chris@0: <H3><BR>Error Reporting</H3>
Chris@0: <P>
Chris@0: Most of the API functions either return an integer error (ie <B>src_simple</B> 
Chris@0: and  <B>src_process</B>) or return an integer error value via an int pointer 
Chris@0: parameter (<B>src_new</B>).
Chris@0: These integer error values can be converted into a human readable text strings by 
Chris@0: calling the function:
Chris@0: </P>
Chris@0: <PRE>
Chris@0:       const char* src_strerror (int error) ;
Chris@0: </PRE>
Chris@0: <P>
Chris@0: which  will return an error string for valid error numbers, the string "No Error" 
Chris@0: for an error value of zero or a NULL pointer if no error message has been defined 
Chris@0: for that error value.
Chris@0: </P>
Chris@0: 
Chris@0: <A NAME="Converters"></A>
Chris@0: <H3><BR>Converters</H3>
Chris@0: <P>
Chris@0: Secret Rabbit Code has a number of different converters which can be selected
Chris@0: using the <B>converter_type</B> parameter when calling <B>src_simple</B> or
Chris@0: <b>src_new</B>.
Chris@0: Currently, the five converters available are:
Chris@0: </P>
Chris@0: <PRE>
Chris@0:       enum
Chris@0:       {    
Chris@0:           SRC_SINC_BEST_QUALITY       = 0,
Chris@0:           SRC_SINC_MEDIUM_QUALITY     = 1,
Chris@0:           SRC_SINC_FASTEST            = 2,
Chris@0:           SRC_ZERO_ORDER_HOLD         = 3,
Chris@0:           SRC_LINEAR                  = 4
Chris@0:       } ;
Chris@0: </PRE>
Chris@0: <P>
Chris@0: As new converters are added, they will given a number corresponding to the 
Chris@0: next inetger.
Chris@0: </P>
Chris@0: 
Chris@0: <P>
Chris@0: The details of these converters are as follows:
Chris@0: </P>
Chris@0: <UL>
Chris@0: 	<LI> <B>SRC_SINC_BEST_QUALITY</B> - This is a bandlimited interpolator derived 
Chris@0: 		from the mathematical <B>sinc</B> function and this is the highest
Chris@0: 		quality sinc based converter, providing a worst case Signal-to-Noise
Chris@0: 		Ratio (SNR) of 97 decibels (dB) at a bandwidth of 97&#37;.
Chris@0: 		All three SRC_SINC_* converters are based on the techniques of 
Chris@0: 		<A HREF="http://ccrma-www.stanford.edu/~jos/resample/">Julius O. Smith</A>
Chris@0: 		although this code was developed independantly.
Chris@0: 	<LI> <B>SRC_SINC_MEDIUM_QUALITY</B> - This is another bandlimited interpolator 
Chris@0: 		much like the previous one. It has an SNR of 97dB and a bandwidth of 90&#37;.
Chris@0: 		The speed of the conversion is much faster than the previous one.
Chris@0: 	<LI> <B>SRC_SINC_FASTEST</B> - This is the fastest bandlimited interpolator and
Chris@0: 		has an SNR of 97dB and a bandwidth of 80&#37;.
Chris@0: 	<LI><B>SRC_ZERO_ORDER_HOLD</B> - A Zero Order Hold converter (interpolated value
Chris@0: 		is equal to the last value). The quality is poor but the conversion speed is
Chris@0: 		blindlingly fast.
Chris@0: 	<li><b>SRC_LINEAR</b> - A linear converter. Again the quality is poor, but the 
Chris@0: 		conversion speed is blindingly fast.
Chris@0: </UL>
Chris@0: <P>
Chris@0: There are two functions that give either a (text string) name or description
Chris@0: for each converter:
Chris@0: </P>
Chris@0: <PRE>
Chris@0:       const char *src_get_name (int converter_type) ;
Chris@0:       const char *src_get_description (int converter_type) ;
Chris@0: </PRE>
Chris@0: <P>
Chris@0: The name will typically be a short string for use in a dialog box, while the 
Chris@0: description string is longer.
Chris@0: </P>
Chris@0: <P>
Chris@0: Both of these functions return a NULL pointer if there is no converter for the 
Chris@0: given <B>converter_type</B> value.
Chris@0: Since the converters have consecutive <B>converter_type</B> values, the caller
Chris@0: is easily able to figure out the number of converters at run time. 
Chris@0: This enables a binary dynamically linked against an old version of the library 
Chris@0: to know about converters from later versions of the library as they become 
Chris@0: available.
Chris@0: </P>
Chris@0: 
Chris@0: <A NAME="SRC_DATA"></A>
Chris@0: <H3><BR>SRC_DATA</H3>
Chris@0: <P>
Chris@0: Both the simple and the full featured versions of the API use the <B>SRC_DATA</B>
Chris@0: struct to pass audio and control data into the sample rate converter.
Chris@0: This struct is defined as:
Chris@0: </P>
Chris@0: <PRE>
Chris@0:       typedef struct
Chris@0:       {   float  *data_in, *data_out ;
Chris@0: 
Chris@0:           long   input_frames, output_frames ;
Chris@0:           long   input_frames_used, output_frames_gen ;
Chris@0: 
Chris@0:           int    end_of_input ;
Chris@0: 
Chris@0:           double src_ratio ;
Chris@0:       } SRC_DATA ;
Chris@0: </PRE>
Chris@0: <P>
Chris@0: The <B>data_in</B> pointer is used to pass audio data into the converter while the
Chris@0: <B>data_out</B> pointer supplies the converter with an array to hold the converter's
Chris@0: output.
Chris@0: For a converter which has been configured for mulitchannel operation, these pointers
Chris@0: need to point to a single array of interleaved data.
Chris@0: </P>
Chris@0: <P>
Chris@0: The <B>input_frames</B> and <B>output_frames</B> fields supply the converter with 
Chris@0: the lengths of the arrays (in frames) pointed to by the <B>data_in</B> and 
Chris@0: <b>data_out</B> pointers respectively.
Chris@0: For monophinc data, these values would indicate the length of the arrays while
Chris@0: for multi channel data these values would be equal to the the length of the array
Chris@0: divided by the number of channels.
Chris@0: </P>
Chris@0: 
Chris@0: <P>
Chris@0: The <B>end_of_input</B> field is only used when the sample rate converter is used
Chris@0: by calling the <B>src_process</B> function.
Chris@0: In this case it should be set to zero if more buffers are to be passed to the 
Chris@0: converter and 1 if the current buffer is the last.
Chris@0: </P>
Chris@0: <P>
Chris@0: Finally, the <B>src_ratio</B> field specifies the conversion ratio defined as
Chris@0: the input sample rate divided by the output sample rate.
Chris@0: For a connected set of buffers, this value can be varies on each call to 
Chris@0: <B>src_process</B> resulting in a time varying sample rate conversion 
Chris@0: process.
Chris@0: For time varying sample rate conversions, the ratio will be linearly
Chris@0: interpolated between the <B>src_ratio</B> value of the previous call
Chris@0: to <B>src_process</B> and the value for the current call.
Chris@0: </P>
Chris@0: <P>
Chris@0: The <B>input_frames_used</B> and <B>output_frames_gen</B> fields are set by the
Chris@0: converter to inform the caller of the number of frames consumed from the
Chris@0: <B>data_in</B> array and the number of frames generated in the <B>data_out</B>
Chris@0: array respectively.
Chris@0: These values are for the current call to <B>src_process</B> only.
Chris@0: </P>
Chris@0: 
Chris@0: <A NAME="Aux"></A>
Chris@0: <H3><BR>Auxillary Functions</H3>
Chris@0: <P>
Chris@0: There are four auxillary functions for converting arrays of float data
Chris@0: to and from short or int data.
Chris@0: These functions are defined as:
Chris@0: </P>
Chris@0: <PRE>
Chris@0:     void src_short_to_float_array (const short *in, float *out, int len) ;
Chris@0:     void src_float_to_short_array (const float *in, short *out, int len) ;
Chris@0:     void src_int_to_float_array (const int *in, float *out, int len) ;
Chris@0:     void src_float_to_int_array (const float *in, int *out, int len) ;
Chris@0: </PRE>
Chris@0: <P>
Chris@0: The float data is assumed to be in the range [-1.0, 1.0] and it is
Chris@0: automatically scaled on the conversion to and from float.
Chris@0: On the float to short/int conversion path, any data values which would overflow
Chris@0: the range of short/int data are clipped.
Chris@0: </P>
Chris@0: 
Chris@0: </DIV>
Chris@0: </TD></TR>
Chris@0: </TABLE>
Chris@0: 
Chris@0: </BODY>
Chris@0: </HTML>
Chris@0: