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