1+ #ifndef SAMPLERATE_H
2+ #define SAMPLERATE_H
3+
4+ /* Opaque data type SRC_STATE. */
5+ typedef struct SRC_STATE_tag SRC_STATE ;
6+
7+ /* SRC_DATA is used to pass data to src_simple() and src_process(). */
8+ typedef struct
9+ { const float * data_in ;
10+ float * data_out ;
11+
12+ long input_frames , output_frames ;
13+ long input_frames_used , output_frames_gen ;
14+
15+ int end_of_input ;
16+
17+ double src_ratio ;
18+ } SRC_DATA ;
19+
20+ /*
21+ ** User supplied callback function type for use with src_callback_new()
22+ ** and src_callback_read(). First parameter is the same pointer that was
23+ ** passed into src_callback_new(). Second parameter is pointer to a
24+ ** pointer. The user supplied callback function must modify *data to
25+ ** point to the start of the user supplied float array. The user supplied
26+ ** function must return the number of frames that **data points to.
27+ */
28+
29+ typedef long (* src_callback_t ) (void * cb_data , float * * data ) ;
30+
31+ /*
32+ ** Standard initialisation function : return an anonymous pointer to the
33+ ** internal state of the converter. Choose a converter from the enums below.
34+ ** Error returned in *error.
35+ */
36+
37+ SRC_STATE * src_new (int converter_type , int channels , int * error ) ;
38+
39+ /*
40+ ** Clone a handle : return an anonymous pointer to a new converter
41+ ** containing the same internal state as orig. Error returned in *error.
42+ */
43+ SRC_STATE * src_clone (SRC_STATE * orig , int * error ) ;
44+
45+ /*
46+ ** Initilisation for callback based API : return an anonymous pointer to the
47+ ** internal state of the converter. Choose a converter from the enums below.
48+ ** The cb_data pointer can point to any data or be set to NULL. Whatever the
49+ ** value, when processing, user supplied function "func" gets called with
50+ ** cb_data as first parameter.
51+ */
52+
53+ SRC_STATE * src_callback_new (src_callback_t func , int converter_type , int channels ,
54+ int * error , void * cb_data ) ;
55+
56+ /*
57+ ** Cleanup all internal allocations.
58+ ** Always returns NULL.
59+ */
60+
61+ SRC_STATE * src_delete (SRC_STATE * state ) ;
62+
63+ /*
64+ ** Standard processing function.
65+ ** Returns non zero on error.
66+ */
67+
68+ int src_process (SRC_STATE * state , SRC_DATA * data ) ;
69+
70+ /*
71+ ** Callback based processing function. Read up to frames worth of data from
72+ ** the converter int *data and return frames read or -1 on error.
73+ */
74+ long src_callback_read (SRC_STATE * state , double src_ratio , long frames , float * data ) ;
75+
76+ /*
77+ ** Simple interface for performing a single conversion from input buffer to
78+ ** output buffer at a fixed conversion ratio.
79+ ** Simple interface does not require initialisation as it can only operate on
80+ ** a single buffer worth of audio.
81+ */
82+
83+ int src_simple (SRC_DATA * data , int converter_type , int channels ) ;
84+
85+ /*
86+ ** This library contains a number of different sample rate converters,
87+ ** numbered 0 through N.
88+ **
89+ ** Return a string giving either a name or a more full description of each
90+ ** sample rate converter or NULL if no sample rate converter exists for
91+ ** the given value. The converters are sequentially numbered from 0 to N.
92+ */
93+
94+ const char * src_get_name (int converter_type ) ;
95+ const char * src_get_description (int converter_type ) ;
96+ const char * src_get_version (void ) ;
97+
98+ /*
99+ ** Set a new SRC ratio. This allows step responses
100+ ** in the conversion ratio.
101+ ** Returns non zero on error.
102+ */
103+
104+ int src_set_ratio (SRC_STATE * state , double new_ratio ) ;
105+
106+ /*
107+ ** Get the current channel count.
108+ ** Returns negative on error, positive channel count otherwise
109+ */
110+
111+ int src_get_channels (SRC_STATE * state ) ;
112+
113+ /*
114+ ** Reset the internal SRC state.
115+ ** Does not modify the quality settings.
116+ ** Does not free any memory allocations.
117+ ** Returns non zero on error.
118+ */
119+
120+ int src_reset (SRC_STATE * state ) ;
121+
122+ /*
123+ ** Return TRUE if ratio is a valid conversion ratio, FALSE
124+ ** otherwise.
125+ */
126+
127+ int src_is_valid_ratio (double ratio ) ;
128+
129+ /*
130+ ** Return an error number.
131+ */
132+
133+ int src_error (SRC_STATE * state ) ;
134+
135+ /*
136+ ** Convert the error number into a string.
137+ */
138+ const char * src_strerror (int error ) ;
139+
140+ /*
141+ ** The following enums can be used to set the interpolator type
142+ ** using the function src_set_converter().
143+ */
144+
145+ enum
146+ {
147+ SRC_SINC_BEST_QUALITY = 0 ,
148+ SRC_SINC_MEDIUM_QUALITY = 1 ,
149+ SRC_SINC_FASTEST = 2 ,
150+ SRC_ZERO_ORDER_HOLD = 3 ,
151+ SRC_LINEAR = 4 ,
152+ } ;
153+
154+ /*
155+ ** Extra helper functions for converting from short to float and
156+ ** back again.
157+ */
158+
159+ void src_short_to_float_array (const short * in , float * out , int len ) ;
160+ void src_float_to_short_array (const float * in , short * out , int len ) ;
161+
162+ void src_int_to_float_array (const int * in , float * out , int len ) ;
163+ void src_float_to_int_array (const float * in , int * out , int len ) ;
0 commit comments