cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: Secret Rabbit Code (aka libsamplerate) cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85:
cannam@85: SRC.png cannam@85:
cannam@85: cannam@85:
cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85: cannam@85:
cannam@85:
cannam@85: cannam@85: cannam@85:
cannam@85:
cannam@85: cannam@85:

Simple API

cannam@85: cannam@85:

cannam@85: Important Note: cannam@85: The simple API is not designed to work on small chunks of a larger piece of cannam@85: audio. cannam@85: If you attempt to use it this way you are doing it wrong and will not get the cannam@85: results you want. cannam@85: For processing audio data in chunks you must use the cannam@85: full api cannam@85: or the cannam@85: callback based api. cannam@85:

cannam@85: cannam@85:

cannam@85: cannam@85:

cannam@85: The simple API consists of a single function : cannam@85:

cannam@85:
cannam@85:       int src_simple (SRC_DATA *data, int converter_type, int channels) ;
cannam@85: 
cannam@85:

cannam@85: The use of this function rather than the more fully featured API requires the caller cannam@85: to know the total length of the input data before hand and that all input and output cannam@85: data can be held in the system's memory at once. cannam@85: It also assumes that there is a single constant ratio between input and output sample cannam@85: rates. cannam@85: cannam@85:

cannam@85: cannam@85:

cannam@85: Dealing with the easy stuff first, the converter_type parameter should be cannam@85: one of the values defined in samplerate.h and documented cannam@85: here while the channels parameter cannam@85: specifies the number of interleaved channels that the sample rate converter cannam@85: is being asked to process (number of input channels and output channels is always cannam@85: equal). cannam@85: There is no hard upper limit on the number of channels; it is limited purely cannam@85: by the amount of memory available. cannam@85:

cannam@85: cannam@85: cannam@85:

cannam@85: The first parameter to src_simple is a pointer to an SRC_DATA struct cannam@85: (more info here) defined as follows: cannam@85:

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

cannam@85: The fields of this struct which must be filled in by the caller are: cannam@85:

cannam@85:
cannam@85:       data_in       : A pointer to the input data samples.
cannam@85:       input_frames  : The number of frames of data pointed to by data_in.
cannam@85:       data_out      : A pointer to the output data samples.
cannam@85:       output_frames : Maximum number of frames pointer to by data_out.
cannam@85:       src_ratio     : Equal to output_sample_rate / input_sample_rate.
cannam@85: 
cannam@85:

cannam@85: When the src_simple function returns output_frames_gen will be cannam@85: set to the number of output frames generated and input_frames_used will cannam@85: be set to the number of input frames used to generate the provided number of cannam@85: output frames. cannam@85:

cannam@85:

cannam@85: The src_simple function returns a non-zero value when an error occurs. cannam@85: See here for how to convert the error value into cannam@85: a text string. cannam@85:

cannam@85: cannam@85:
cannam@85:
cannam@85: cannam@85: cannam@85: cannam@85: