Chris@41:
Chris@41:
Callback API
Chris@41:
Chris@41: The callback API consists of the following functions :
Chris@41:
Chris@41:
Chris@41: typedef long (*src_callback_t) (void *cb_data, float **data) ;
Chris@41:
Chris@41: SRC_STATE* src_callback_new (src_callback_t func,
Chris@41: int converter_type, int channels,
Chris@41: int *error, void* cb_data) ;
Chris@41:
Chris@41: SRC_STATE* src_delete (SRC_STATE *state) ;
Chris@41:
Chris@41: long src_callback_read (SRC_STATE *state, double src_ratio,
Chris@41: long frames, float *data) ;
Chris@41:
Chris@41: int src_reset (SRC_STATE *state) ;
Chris@41: int src_set_ratio (SRC_STATE *state, double new_ratio) ;
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Chris@41: Like the
Chris@41: simple API
Chris@41: and the
Chris@41: full API,
Chris@41: the callback based API is able to operate on interleaved multi channel data.
Chris@41:
Chris@41:
Chris@41:
Chris@41: An example of the use of the callback based API can be found in the
Chris@41: varispeed-play program in the examples/ directory of the
Chris@41: source code tarball.
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Initialisation
Chris@41:
Chris@41: SRC_STATE* src_callback_new (src_callback_t func,
Chris@41: int converter_type, int channels,
Chris@41: int *error, void* cb_data) ;
Chris@41:
Chris@41:
Chris@41: The src_callback_new function returns an anonymous pointer to a
Chris@41: sample rate converter callback object, src_state.
Chris@41: This is the same type of object as that returned by
Chris@41: src_new, but with different internal state.
Chris@41: Although these are the same object type, they cannot be used interchangeably.
Chris@41: If an error occurs the function returns a NULL pointer and fills in the
Chris@41: error value pointed to by the error pointer supplied by the caller.
Chris@41:
Chris@41:
Chris@41: The caller then passes the SRC_STATE object to the src_callback_read
Chris@41: function to pull data out of the converter.
Chris@41: When the caller is finished with the converter they should pass it to the
Chris@41: clean up function src_delete.
Chris@41:
Chris@41:
Chris@41: The func parameter is a user supplied function which must match the
Chris@41: src_callback_t type signature while cb_data is a pointer to
Chris@41: data which be passed as the first parameter to the user supplied callback
Chris@41: function.
Chris@41: This function is called by the converter whenever it needs input data as a
Chris@41: result of being calls to src_callback_read.
Chris@41:
Chris@41:
Chris@41: If the converter was initialised to work with more than one channel, the
Chris@41: callback function must work with mutiple channels of interleaved data.
Chris@41: The callback function should return the number of frames it supplying to
Chris@41: the converter.
Chris@41: For multi channel files, this return value should be the number of floats
Chris@41: divided by the number of channels.
Chris@41:
Chris@41:
Chris@41: The converter must be one of the supplied converter types documented
Chris@41: here.
Chris@41:
Chris@41:
Chris@41: The caller then passes the SRC_STATE pointer to the src_callback_read
Chris@41: function to pull data out of the converter.
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Callback Read
Chris@41:
Chris@41: long src_callback_read (SRC_STATE *state, double src_ratio,
Chris@41: long frames, float *data) ;
Chris@41:
Chris@41:
Chris@41: The src_callback_read function is passed the
Chris@41: SRC_STATE
Chris@41: pointer returned by src_callback_new, the coversion ratio
Chris@41: (output_sample_rate / input_sample_rate), the maximum number of output frames
Chris@41: to generate and a pointer to a buffer in which to place the output data.
Chris@41: For multi channel files, the data int the output buffer is stored in
Chris@41: interleaved format.
Chris@41:
Chris@41:
Chris@41: The src_callback_read function returns the number of frames generated
Chris@41: or zero if an error occurs or it runs out of input (ie the user supplied
Chris@41: callback function returns zero and there is no more data buffered internally).
Chris@41: If an error has occurred, the function
Chris@41: src_error will return non-zero.
Chris@41:
Chris@41:
Chris@41:
Chris@41: See also :
Chris@41: src_set_ratio
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Chris@41:
Chris@41: