annotate src/libsamplerate-0.1.9/doc/api_misc.html @ 41:481f5f8c5634

Current libsamplerate source
author Chris Cannam
date Tue, 18 Oct 2016 13:24:45 +0100
parents
children
rev   line source
Chris@41 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Chris@41 2 <HTML>
Chris@41 3
Chris@41 4 <HEAD>
Chris@41 5 <TITLE>
Chris@41 6 Secret Rabbit Code (aka libsamplerate)
Chris@41 7 </TITLE>
Chris@41 8 <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
Chris@41 9 <META NAME="Version" CONTENT="libsamplerate-0.1.8">
Chris@41 10 <META NAME="Description" CONTENT="The Secret Rabbit Code Home Page">
Chris@41 11 <META NAME="Keywords" CONTENT="libsamplerate sound resample audio dsp Linux">
Chris@41 12 <LINK REL=StyleSheet HREF="SRC.css" TYPE="text/css" MEDIA="all">
Chris@41 13 </HEAD>
Chris@41 14
Chris@41 15 <BODY TEXT="#FFFFFF" BGCOLOR="#000000" LINK="#FB1465" VLINK="#FB1465" ALINK="#FB1465">
Chris@41 16 <!-- pepper -->
Chris@41 17 <CENTER>
Chris@41 18 <IMG SRC="SRC.png" HEIGHT=100 WIDTH=760 ALT="SRC.png">
Chris@41 19 </CENTER>
Chris@41 20 <!-- pepper -->
Chris@41 21 <BR>
Chris@41 22 <!-- pepper -->
Chris@41 23 <TABLE ALIGN="center" WIDTH="98%">
Chris@41 24 <TR>
Chris@41 25 <TD VALIGN="top">
Chris@41 26 <BR>
Chris@41 27 <DIV CLASS="nav">
Chris@41 28 <BR>
Chris@41 29 <A HREF="index.html">Home</A><BR>
Chris@41 30 <BR>
Chris@41 31 <A HREF="api_simple.html">Simple API</A><BR>
Chris@41 32 <A HREF="api_full.html">Full API</A><BR>
Chris@41 33 <A HREF="api_misc.html#ErrorReporting">Error Handling</A><BR>
Chris@41 34 <A HREF="api_misc.html">Miscellaneous</A><BR>
Chris@41 35 <BR>
Chris@41 36 <DIV CLASS="block">
Chris@41 37 Author :<BR>Erik de Castro Lopo
Chris@41 38 <!-- pepper -->
Chris@41 39 <BR><BR>
Chris@41 40 <!-- pepper -->
Chris@41 41
Chris@41 42 </DIV>
Chris@41 43 <IMG SRC=
Chris@41 44 "/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@41 45 HEIGHT=30 WIDTH=100 ALT="counter.gif">
Chris@41 46 </DIV>
Chris@41 47
Chris@41 48 </TD>
Chris@41 49 <!-- pepper -->
Chris@41 50 <!-- ######################################################################## -->
Chris@41 51 <!-- pepper -->
Chris@41 52 <TD VALIGN="top">
Chris@41 53 <DIV CLASS="block">
Chris@41 54
Chris@41 55 <H1><B>Miscellaneous API Documentation</B></H1>
Chris@41 56 <A NAME="ErrorReporting"></A>
Chris@41 57 <H3><BR>Error Reporting</H3>
Chris@41 58 <P>
Chris@41 59 Most of the API functions either return an integer error (ie <B>src_simple</B>
Chris@41 60 and <B>src_process</B>) or return an integer error value via an int pointer
Chris@41 61 parameter (<B>src_new</B>).
Chris@41 62 These integer error values can be converted into a human readable text strings by
Chris@41 63 calling the function:
Chris@41 64 </P>
Chris@41 65 <PRE>
Chris@41 66 const char* src_strerror (int error) ;
Chris@41 67 </PRE>
Chris@41 68 <P>
Chris@41 69 which will return an error string for valid error numbers, the string "No Error"
Chris@41 70 for an error value of zero or a NULL pointer if no error message has been defined
Chris@41 71 for that error value.
Chris@41 72 </P>
Chris@41 73
Chris@41 74 <A NAME="Converters"></A>
Chris@41 75 <H3><BR>Converters</H3>
Chris@41 76 <P>
Chris@41 77 Secret Rabbit Code has a number of different converters which can be selected
Chris@41 78 using the <B>converter_type</B> parameter when calling <B>src_simple</B> or
Chris@41 79 <b>src_new</B>.
Chris@41 80 Currently, the five converters available are:
Chris@41 81 </P>
Chris@41 82 <PRE>
Chris@41 83 enum
Chris@41 84 {
Chris@41 85 SRC_SINC_BEST_QUALITY = 0,
Chris@41 86 SRC_SINC_MEDIUM_QUALITY = 1,
Chris@41 87 SRC_SINC_FASTEST = 2,
Chris@41 88 SRC_ZERO_ORDER_HOLD = 3,
Chris@41 89 SRC_LINEAR = 4
Chris@41 90 } ;
Chris@41 91 </PRE>
Chris@41 92 <P>
Chris@41 93 As new converters are added, they will given a number corresponding to the
Chris@41 94 next inetger.
Chris@41 95 </P>
Chris@41 96
Chris@41 97 <P>
Chris@41 98 The details of these converters are as follows:
Chris@41 99 </P>
Chris@41 100 <UL>
Chris@41 101 <LI> <B>SRC_SINC_BEST_QUALITY</B> - This is a bandlimited interpolator derived
Chris@41 102 from the mathematical <B>sinc</B> function and this is the highest
Chris@41 103 quality sinc based converter, providing a worst case Signal-to-Noise
Chris@41 104 Ratio (SNR) of 97 decibels (dB) at a bandwidth of 97&#37;.
Chris@41 105 All three SRC_SINC_* converters are based on the techniques of
Chris@41 106 <A HREF="http://ccrma-www.stanford.edu/~jos/resample/">Julius O. Smith</A>
Chris@41 107 although this code was developed independantly.
Chris@41 108 <LI> <B>SRC_SINC_MEDIUM_QUALITY</B> - This is another bandlimited interpolator
Chris@41 109 much like the previous one. It has an SNR of 97dB and a bandwidth of 90&#37;.
Chris@41 110 The speed of the conversion is much faster than the previous one.
Chris@41 111 <LI> <B>SRC_SINC_FASTEST</B> - This is the fastest bandlimited interpolator and
Chris@41 112 has an SNR of 97dB and a bandwidth of 80&#37;.
Chris@41 113 <LI><B>SRC_ZERO_ORDER_HOLD</B> - A Zero Order Hold converter (interpolated value
Chris@41 114 is equal to the last value). The quality is poor but the conversion speed is
Chris@41 115 blindlingly fast.
Chris@41 116 <li><b>SRC_LINEAR</b> - A linear converter. Again the quality is poor, but the
Chris@41 117 conversion speed is blindingly fast.
Chris@41 118 </UL>
Chris@41 119 <P>
Chris@41 120 There are two functions that give either a (text string) name or description
Chris@41 121 for each converter:
Chris@41 122 </P>
Chris@41 123 <PRE>
Chris@41 124 const char *src_get_name (int converter_type) ;
Chris@41 125 const char *src_get_description (int converter_type) ;
Chris@41 126 </PRE>
Chris@41 127 <P>
Chris@41 128 The name will typically be a short string for use in a dialog box, while the
Chris@41 129 description string is longer.
Chris@41 130 </P>
Chris@41 131 <P>
Chris@41 132 Both of these functions return a NULL pointer if there is no converter for the
Chris@41 133 given <B>converter_type</B> value.
Chris@41 134 Since the converters have consecutive <B>converter_type</B> values, the caller
Chris@41 135 is easily able to figure out the number of converters at run time.
Chris@41 136 This enables a binary dynamically linked against an old version of the library
Chris@41 137 to know about converters from later versions of the library as they become
Chris@41 138 available.
Chris@41 139 </P>
Chris@41 140
Chris@41 141 <A NAME="SRC_DATA"></A>
Chris@41 142 <H3><BR>SRC_DATA</H3>
Chris@41 143 <P>
Chris@41 144 Both the simple and the full featured versions of the API use the <B>SRC_DATA</B>
Chris@41 145 struct to pass audio and control data into the sample rate converter.
Chris@41 146 This struct is defined as:
Chris@41 147 </P>
Chris@41 148 <PRE>
Chris@41 149 typedef struct
Chris@41 150 { float *data_in, *data_out ;
Chris@41 151
Chris@41 152 long input_frames, output_frames ;
Chris@41 153 long input_frames_used, output_frames_gen ;
Chris@41 154
Chris@41 155 int end_of_input ;
Chris@41 156
Chris@41 157 double src_ratio ;
Chris@41 158 } SRC_DATA ;
Chris@41 159 </PRE>
Chris@41 160 <P>
Chris@41 161 The <B>data_in</B> pointer is used to pass audio data into the converter while the
Chris@41 162 <B>data_out</B> pointer supplies the converter with an array to hold the converter's
Chris@41 163 output.
Chris@41 164 For a converter which has been configured for mulitchannel operation, these pointers
Chris@41 165 need to point to a single array of interleaved data.
Chris@41 166 </P>
Chris@41 167 <P>
Chris@41 168 The <B>input_frames</B> and <B>output_frames</B> fields supply the converter with
Chris@41 169 the lengths of the arrays (in frames) pointed to by the <B>data_in</B> and
Chris@41 170 <b>data_out</B> pointers respectively.
Chris@41 171 For monophinc data, these values would indicate the length of the arrays while
Chris@41 172 for multi channel data these values would be equal to the the length of the array
Chris@41 173 divided by the number of channels.
Chris@41 174 </P>
Chris@41 175
Chris@41 176 <P>
Chris@41 177 The <B>end_of_input</B> field is only used when the sample rate converter is used
Chris@41 178 by calling the <B>src_process</B> function.
Chris@41 179 In this case it should be set to zero if more buffers are to be passed to the
Chris@41 180 converter and 1 if the current buffer is the last.
Chris@41 181 </P>
Chris@41 182 <P>
Chris@41 183 Finally, the <B>src_ratio</B> field specifies the conversion ratio defined as
Chris@41 184 the input sample rate divided by the output sample rate.
Chris@41 185 For a connected set of buffers, this value can be varies on each call to
Chris@41 186 <B>src_process</B> resulting in a time varying sample rate conversion
Chris@41 187 process.
Chris@41 188 For time varying sample rate conversions, the ratio will be linearly
Chris@41 189 interpolated between the <B>src_ratio</B> value of the previous call
Chris@41 190 to <B>src_process</B> and the value for the current call.
Chris@41 191 </P>
Chris@41 192 <P>
Chris@41 193 The <B>input_frames_used</B> and <B>output_frames_gen</B> fields are set by the
Chris@41 194 converter to inform the caller of the number of frames consumed from the
Chris@41 195 <B>data_in</B> array and the number of frames generated in the <B>data_out</B>
Chris@41 196 array respectively.
Chris@41 197 These values are for the current call to <B>src_process</B> only.
Chris@41 198 </P>
Chris@41 199
Chris@41 200 <A NAME="Aux"></A>
Chris@41 201 <H3><BR>Auxillary Functions</H3>
Chris@41 202 <P>
Chris@41 203 There are four auxillary functions for converting arrays of float data
Chris@41 204 to and from short or int data.
Chris@41 205 These functions are defined as:
Chris@41 206 </P>
Chris@41 207 <PRE>
Chris@41 208 void src_short_to_float_array (const short *in, float *out, int len) ;
Chris@41 209 void src_float_to_short_array (const float *in, short *out, int len) ;
Chris@41 210 void src_int_to_float_array (const int *in, float *out, int len) ;
Chris@41 211 void src_float_to_int_array (const float *in, int *out, int len) ;
Chris@41 212 </PRE>
Chris@41 213 <P>
Chris@41 214 The float data is assumed to be in the range [-1.0, 1.0] and it is
Chris@41 215 automatically scaled on the conversion to and from float.
Chris@41 216 On the float to short/int conversion path, any data values which would overflow
Chris@41 217 the range of short/int data are clipped.
Chris@41 218 </P>
Chris@41 219
Chris@41 220 </DIV>
Chris@41 221 </TD></TR>
Chris@41 222 </TABLE>
Chris@41 223
Chris@41 224 </BODY>
Chris@41 225 </HTML>
Chris@41 226