Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Secret Rabbit Code (aka libsamplerate) Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41:
Chris@41: SRC.png Chris@41:
Chris@41: Chris@41:
Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41: Chris@41:
Chris@41:
Chris@41: Chris@41: Chris@41:
Chris@41:
Chris@41: Chris@41:

Miscellaneous API Documentation

Chris@41: Chris@41:


Error Reporting

Chris@41:

Chris@41: Most of the API functions either return an integer error (ie src_simple Chris@41: and src_process) or return an integer error value via an int pointer Chris@41: parameter (src_new). Chris@41: These integer error values can be converted into a human readable text strings by Chris@41: calling the function: Chris@41:

Chris@41:
Chris@41:       const char* src_strerror (int error) ;
Chris@41: 
Chris@41:

Chris@41: which will return an error string for valid error numbers, the string "No Error" Chris@41: for an error value of zero or a NULL pointer if no error message has been defined Chris@41: for that error value. Chris@41:

Chris@41: Chris@41: Chris@41:


Converters

Chris@41:

Chris@41: Secret Rabbit Code has a number of different converters which can be selected Chris@41: using the converter_type parameter when calling src_simple or Chris@41: src_new. Chris@41: Currently, the five converters available are: Chris@41:

Chris@41:
Chris@41:       enum
Chris@41:       {    
Chris@41:           SRC_SINC_BEST_QUALITY       = 0,
Chris@41:           SRC_SINC_MEDIUM_QUALITY     = 1,
Chris@41:           SRC_SINC_FASTEST            = 2,
Chris@41:           SRC_ZERO_ORDER_HOLD         = 3,
Chris@41:           SRC_LINEAR                  = 4
Chris@41:       } ;
Chris@41: 
Chris@41:

Chris@41: As new converters are added, they will given a number corresponding to the Chris@41: next inetger. Chris@41:

Chris@41: Chris@41:

Chris@41: The details of these converters are as follows: Chris@41:

Chris@41:
    Chris@41:
  • SRC_SINC_BEST_QUALITY - This is a bandlimited interpolator derived Chris@41: from the mathematical sinc function and this is the highest Chris@41: quality sinc based converter, providing a worst case Signal-to-Noise Chris@41: Ratio (SNR) of 97 decibels (dB) at a bandwidth of 97%. Chris@41: All three SRC_SINC_* converters are based on the techniques of Chris@41: Julius O. Smith Chris@41: although this code was developed independantly. Chris@41:
  • SRC_SINC_MEDIUM_QUALITY - This is another bandlimited interpolator Chris@41: much like the previous one. It has an SNR of 97dB and a bandwidth of 90%. Chris@41: The speed of the conversion is much faster than the previous one. Chris@41:
  • SRC_SINC_FASTEST - This is the fastest bandlimited interpolator and Chris@41: has an SNR of 97dB and a bandwidth of 80%. Chris@41:
  • SRC_ZERO_ORDER_HOLD - A Zero Order Hold converter (interpolated value Chris@41: is equal to the last value). The quality is poor but the conversion speed is Chris@41: blindlingly fast. Chris@41:
  • SRC_LINEAR - A linear converter. Again the quality is poor, but the Chris@41: conversion speed is blindingly fast. Chris@41:
Chris@41:

Chris@41: There are two functions that give either a (text string) name or description Chris@41: for each converter: Chris@41:

Chris@41:
Chris@41:       const char *src_get_name (int converter_type) ;
Chris@41:       const char *src_get_description (int converter_type) ;
Chris@41: 
Chris@41:

Chris@41: The name will typically be a short string for use in a dialog box, while the Chris@41: description string is longer. Chris@41:

Chris@41:

Chris@41: Both of these functions return a NULL pointer if there is no converter for the Chris@41: given converter_type value. Chris@41: Since the converters have consecutive converter_type values, the caller Chris@41: is easily able to figure out the number of converters at run time. Chris@41: This enables a binary dynamically linked against an old version of the library Chris@41: to know about converters from later versions of the library as they become Chris@41: available. Chris@41:

Chris@41: Chris@41: Chris@41:


SRC_DATA

Chris@41:

Chris@41: Both the simple and the full featured versions of the API use the SRC_DATA Chris@41: struct to pass audio and control data into the sample rate converter. Chris@41: This struct is defined as: Chris@41:

Chris@41:
Chris@41:       typedef struct
Chris@41:       {   float  *data_in, *data_out ;
Chris@41: 
Chris@41:           long   input_frames, output_frames ;
Chris@41:           long   input_frames_used, output_frames_gen ;
Chris@41: 
Chris@41:           int    end_of_input ;
Chris@41: 
Chris@41:           double src_ratio ;
Chris@41:       } SRC_DATA ;
Chris@41: 
Chris@41:

Chris@41: The data_in pointer is used to pass audio data into the converter while the Chris@41: data_out pointer supplies the converter with an array to hold the converter's Chris@41: output. Chris@41: For a converter which has been configured for mulitchannel operation, these pointers Chris@41: need to point to a single array of interleaved data. Chris@41:

Chris@41:

Chris@41: The input_frames and output_frames fields supply the converter with Chris@41: the lengths of the arrays (in frames) pointed to by the data_in and Chris@41: data_out pointers respectively. Chris@41: For monophinc data, these values would indicate the length of the arrays while Chris@41: for multi channel data these values would be equal to the the length of the array Chris@41: divided by the number of channels. Chris@41:

Chris@41: Chris@41:

Chris@41: The end_of_input field is only used when the sample rate converter is used Chris@41: by calling the src_process function. Chris@41: In this case it should be set to zero if more buffers are to be passed to the Chris@41: converter and 1 if the current buffer is the last. Chris@41:

Chris@41:

Chris@41: Finally, the src_ratio field specifies the conversion ratio defined as Chris@41: the input sample rate divided by the output sample rate. Chris@41: For a connected set of buffers, this value can be varies on each call to Chris@41: src_process resulting in a time varying sample rate conversion Chris@41: process. Chris@41: For time varying sample rate conversions, the ratio will be linearly Chris@41: interpolated between the src_ratio value of the previous call Chris@41: to src_process and the value for the current call. Chris@41:

Chris@41:

Chris@41: The input_frames_used and output_frames_gen fields are set by the Chris@41: converter to inform the caller of the number of frames consumed from the Chris@41: data_in array and the number of frames generated in the data_out Chris@41: array respectively. Chris@41: These values are for the current call to src_process only. Chris@41:

Chris@41: Chris@41: Chris@41:


Auxillary Functions

Chris@41:

Chris@41: There are four auxillary functions for converting arrays of float data Chris@41: to and from short or int data. Chris@41: These functions are defined as: Chris@41:

Chris@41:
Chris@41:     void src_short_to_float_array (const short *in, float *out, int len) ;
Chris@41:     void src_float_to_short_array (const float *in, short *out, int len) ;
Chris@41:     void src_int_to_float_array (const int *in, float *out, int len) ;
Chris@41:     void src_float_to_int_array (const float *in, int *out, int len) ;
Chris@41: 
Chris@41:

Chris@41: The float data is assumed to be in the range [-1.0, 1.0] and it is Chris@41: automatically scaled on the conversion to and from float. Chris@41: On the float to short/int conversion path, any data values which would overflow Chris@41: the range of short/int data are clipped. Chris@41:

Chris@41: Chris@41:
Chris@41:
Chris@41: Chris@41: Chris@41: Chris@41: