Path: blob/main/contrib/libsamplerate/samplerate.h
39478 views
/*1** Copyright (c) 2002-2016, Erik de Castro Lopo <[email protected]>2** All rights reserved.3**4** This code is released under 2-clause BSD license. Please see the5** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING6*/78/*9** API documentation is available here:10** http://libsndfile.github.io/libsamplerate/api.html11*/1213#ifndef SAMPLERATE_H14#define SAMPLERATE_H1516#ifdef __cplusplus17extern "C" {18#endif /* __cplusplus */192021/* Opaque data type SRC_STATE. */22typedef struct SRC_STATE_tag SRC_STATE ;2324/* SRC_DATA is used to pass data to src_simple() and src_process(). */25typedef struct26{ const float *data_in ;27float *data_out ;2829long input_frames, output_frames ;30long input_frames_used, output_frames_gen ;3132int end_of_input ;3334double src_ratio ;35} SRC_DATA ;3637/*38** User supplied callback function type for use with src_callback_new()39** and src_callback_read(). First parameter is the same pointer that was40** passed into src_callback_new(). Second parameter is pointer to a41** pointer. The user supplied callback function must modify *data to42** point to the start of the user supplied float array. The user supplied43** function must return the number of frames that **data points to.44*/4546typedef long (*src_callback_t) (void *cb_data, float **data) ;4748/*49** Standard initialisation function : return an anonymous pointer to the50** internal state of the converter. Choose a converter from the enums below.51** Error returned in *error.52*/5354SRC_STATE* src_new (int converter_type, int channels, int *error) ;5556/*57** Clone a handle : return an anonymous pointer to a new converter58** containing the same internal state as orig. Error returned in *error.59*/60SRC_STATE* src_clone (SRC_STATE* orig, int *error) ;6162/*63** Initilisation for callback based API : return an anonymous pointer to the64** internal state of the converter. Choose a converter from the enums below.65** The cb_data pointer can point to any data or be set to NULL. Whatever the66** value, when processing, user supplied function "func" gets called with67** cb_data as first parameter.68*/6970SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,71int *error, void* cb_data) ;7273/*74** Cleanup all internal allocations.75** Always returns NULL.76*/7778SRC_STATE* src_delete (SRC_STATE *state) ;7980/*81** Standard processing function.82** Returns non zero on error.83*/8485int src_process (SRC_STATE *state, SRC_DATA *data) ;8687/*88** Callback based processing function. Read up to frames worth of data from89** the converter int *data and return frames read or -1 on error.90*/91long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;9293/*94** Simple interface for performing a single conversion from input buffer to95** output buffer at a fixed conversion ratio.96** Simple interface does not require initialisation as it can only operate on97** a single buffer worth of audio.98*/99100int src_simple (SRC_DATA *data, int converter_type, int channels) ;101102/*103** This library contains a number of different sample rate converters,104** numbered 0 through N.105**106** Return a string giving either a name or a more full description of each107** sample rate converter or NULL if no sample rate converter exists for108** the given value. The converters are sequentially numbered from 0 to N.109*/110111const char *src_get_name (int converter_type) ;112const char *src_get_description (int converter_type) ;113const char *src_get_version (void) ;114115/*116** Set a new SRC ratio. This allows step responses117** in the conversion ratio.118** Returns non zero on error.119*/120121int src_set_ratio (SRC_STATE *state, double new_ratio) ;122123/*124** Get the current channel count.125** Returns negative on error, positive channel count otherwise126*/127128int src_get_channels (SRC_STATE *state) ;129130/*131** Reset the internal SRC state.132** Does not modify the quality settings.133** Does not free any memory allocations.134** Returns non zero on error.135*/136137int src_reset (SRC_STATE *state) ;138139/*140** Return TRUE if ratio is a valid conversion ratio, FALSE141** otherwise.142*/143144int src_is_valid_ratio (double ratio) ;145146/*147** Return an error number.148*/149150int src_error (SRC_STATE *state) ;151152/*153** Convert the error number into a string.154*/155const char* src_strerror (int error) ;156157/*158** The following enums can be used to set the interpolator type159** using the function src_set_converter().160*/161162enum163{164SRC_SINC_BEST_QUALITY = 0,165SRC_SINC_MEDIUM_QUALITY = 1,166SRC_SINC_FASTEST = 2,167SRC_ZERO_ORDER_HOLD = 3,168SRC_LINEAR = 4,169} ;170171/*172** Extra helper functions for converting from short to float and173** back again.174*/175176void src_short_to_float_array (const short *in, float *out, int len) ;177void src_float_to_short_array (const float *in, short *out, int len) ;178179void src_int_to_float_array (const int *in, float *out, int len) ;180void src_float_to_int_array (const float *in, int *out, int len) ;181182183#ifdef __cplusplus184} /* extern "C" */185#endif /* __cplusplus */186187#endif /* SAMPLERATE_H */188189190191