History

Refactor SRC_STATE

Rename SRC_PRIVATE_tag to SRC_STATE_tag, now SRC_STATE is typedef of exsiting struct.

evpobr committed 6 years ago

Commit 7f461a31 parent 183610f5 files · +252 −265Browse files

Showing the changes to src (5 of 5 files). Show all

Unified · Split

5 files
  1. src/common.h +9 −9
  2. src/samplerate.c +81 −94
  3. src/src_linear.c +31 −31
  4. src/src_sinc.c +100 −100
  5. src/src_zoh.c +31 −31
src/common.h+9−9
@@ -98,7 +98,7 @@ enum · 97 unmodified lines
9898 SRC_ERR_MAX_ERROR
9999 } ;
100100
101−typedef struct SRC_PRIVATE_tag
101+struct SRC_STATE_tag
102102 { double last_ratio, last_position ;
103103
104104 int error ;
@@ -111,41 +111,41 @@ typedef struct SRC_PRIVATE_tag · 6 unmodified lines
111111 void *private_data ;
112112
113113 /* Varispeed process function. */
114− int (*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
114+ int (*vari_process) (SRC_STATE *state, SRC_DATA *data) ;
115115
116116 /* Constant speed process function. */
117− int (*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
117+ int (*const_process) (SRC_STATE *state, SRC_DATA *data) ;
118118
119119 /* State reset. */
120− void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
120+ void (*reset) (SRC_STATE *state) ;
121121
122122 /* State clone. */
123− int (*copy) (struct SRC_PRIVATE_tag *from, struct SRC_PRIVATE_tag *to) ;
123+ int (*copy) (SRC_STATE *from, SRC_STATE *to) ;
124124
125125 /* Data specific to SRC_MODE_CALLBACK. */
126126 src_callback_t callback_func ;
127127 void *user_callback_data ;
128128 long saved_frames ;
129129 const float *saved_data ;
130−} SRC_PRIVATE ;
130+} ;
131131
132132 /* In src_sinc.c */
133133 const char* sinc_get_name (int src_enum) ;
134134 const char* sinc_get_description (int src_enum) ;
135135
136−int sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
136+int sinc_set_converter (SRC_STATE *state, int src_enum) ;
137137
138138 /* In src_linear.c */
139139 const char* linear_get_name (int src_enum) ;
140140 const char* linear_get_description (int src_enum) ;
141141
142−int linear_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
142+int linear_set_converter (SRC_STATE *state, int src_enum) ;
143143
144144 /* In src_zoh.c */
145145 const char* zoh_get_name (int src_enum) ;
146146 const char* zoh_get_description (int src_enum) ;
147147
148−int zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) ;
148+int zoh_set_converter (SRC_STATE *state, int src_enum) ;
149149
150150 /*----------------------------------------------------------
151151 ** Common static inline functions.
src/samplerate.c+81−94
@@ -16,13 +16,12 @@ · 15 unmodified lines
1616 #include "samplerate.h"
1717 #include "common.h"
1818
19−static int psrc_set_converter (SRC_PRIVATE *psrc, int converter_type) ;
19+static int psrc_set_converter (SRC_STATE *state, int converter_type) ;
2020
2121
2222 SRC_STATE *
2323 src_new (int converter_type, int channels, int *error)
24−{ SRC_PRIVATE *psrc ;
25−
24+{
2625 if (error)
2726 *error = SRC_ERR_NO_ERROR ;
2827
@@ -32,58 +31,59 @@ src_new (int converter_type, int channels, int *error) · 3 unmodified lines
3231 return NULL ;
3332 } ;
3433
35− if ((psrc = ZERO_ALLOC (SRC_PRIVATE, sizeof (*psrc))) == NULL)
34+ SRC_STATE *state = ZERO_ALLOC (SRC_STATE, sizeof (SRC_STATE)) ;
35+ if (state == NULL)
3636 { if (error)
3737 *error = SRC_ERR_MALLOC_FAILED ;
3838 return NULL ;
3939 } ;
4040
41− psrc->channels = channels ;
42− psrc->mode = SRC_MODE_PROCESS ;
41+ state->channels = channels ;
42+ state->mode = SRC_MODE_PROCESS ;
4343
44− if (psrc_set_converter (psrc, converter_type) != SRC_ERR_NO_ERROR)
44+ if (psrc_set_converter (state, converter_type) != SRC_ERR_NO_ERROR)
4545 { if (error)
4646 *error = SRC_ERR_BAD_CONVERTER ;
47− free (psrc) ;
48− psrc = NULL ;
47+ free (state) ;
48+ state = NULL ;
4949 } ;
5050
51− src_reset ((SRC_STATE*) psrc) ;
51+ src_reset (state) ;
5252
53− return (SRC_STATE*) psrc ;
53+ return state ;
5454 } /* src_new */
5555
5656 SRC_STATE*
5757 src_clone (SRC_STATE* orig, int *error)
5858 {
59− SRC_PRIVATE *psrc ;
59+ SRC_STATE *state ;
6060 int copy_error ;
6161
6262 if (error)
6363 *error = SRC_ERR_NO_ERROR ;
6464
65− if ((psrc = ZERO_ALLOC (SRC_PRIVATE, sizeof (*psrc))) == NULL)
65+ if ((state = ZERO_ALLOC (SRC_STATE, sizeof (SRC_STATE))) == NULL)
6666 { if (error)
6767 *error = SRC_ERR_MALLOC_FAILED ;
6868 return NULL ;
6969 } ;
7070
71− SRC_PRIVATE *orig_priv = (SRC_PRIVATE*) orig ;
72− memcpy (psrc, orig_priv, sizeof (SRC_PRIVATE)) ;
71+ SRC_STATE *orig_state = orig ;
72+ memcpy (state, orig_state, sizeof (SRC_STATE)) ;
7373
74− if ((copy_error = orig_priv->copy (orig_priv, psrc)) != SRC_ERR_NO_ERROR)
74+ if ((copy_error = orig_state->copy (orig_state, state)) != SRC_ERR_NO_ERROR)
7575 { if (error)
7676 *error = copy_error ;
77− free (psrc) ;
78− psrc = NULL ;
77+ free (state) ;
78+ state = NULL ;
7979 } ;
8080
81− return (SRC_STATE*) psrc ;
81+ return state ;
8282 }
8383
8484 SRC_STATE*
8585 src_callback_new (src_callback_t func, int converter_type, int channels, int *error, void* cb_data)
86−{ SRC_STATE *src_state ;
86+{ SRC_STATE *state ;
8787
8888 if (func == NULL)
8989 { if (error)
@@ -94,28 +94,26 @@ src_callback_new (src_callback_t func, int converter_type, int channels, int *er · 4 unmodified lines
9494 if (error != NULL)
9595 *error = 0 ;
9696
97− if ((src_state = src_new (converter_type, channels, error)) == NULL)
97+ if ((state = src_new (converter_type, channels, error)) == NULL)
9898 return NULL ;
9999
100− src_reset (src_state) ;
100+ src_reset (state) ;
101101
102− ((SRC_PRIVATE*) src_state)->mode = SRC_MODE_CALLBACK ;
103− ((SRC_PRIVATE*) src_state)->callback_func = func ;
104− ((SRC_PRIVATE*) src_state)->user_callback_data = cb_data ;
102+ state->mode = SRC_MODE_CALLBACK ;
103+ state->callback_func = func ;
104+ state->user_callback_data = cb_data ;
105105
106− return src_state ;
106+ return state ;
107107 } /* src_callback_new */
108108
109109 SRC_STATE *
110110 src_delete (SRC_STATE *state)
111−{ SRC_PRIVATE *psrc ;
112−
113− psrc = (SRC_PRIVATE*) state ;
114− if (psrc)
115− { if (psrc->private_data)
116− free (psrc->private_data) ;
117− memset (psrc, 0, sizeof (SRC_PRIVATE)) ;
118− free (psrc) ;
111+{
112+ if (state)
113+ { if (state->private_data)
114+ free (state->private_data) ;
115+ memset (state, 0, sizeof (SRC_STATE)) ;
116+ free (state) ;
119117 } ;
120118
121119 return NULL ;
@@ -123,17 +121,15 @@ src_delete (SRC_STATE *state) · 1 unmodified line
123121
124122 int
125123 src_process (SRC_STATE *state, SRC_DATA *data)
126−{ SRC_PRIVATE *psrc ;
124+{
127125 int error ;
128126
129− psrc = (SRC_PRIVATE*) state ;
130−
131− if (psrc == NULL)
127+ if (state == NULL)
132128 return SRC_ERR_BAD_STATE ;
133− if (psrc->vari_process == NULL || psrc->const_process == NULL)
129+ if (state->vari_process == NULL || state->const_process == NULL)
134130 return SRC_ERR_BAD_PROC_PTR ;
135131
136− if (psrc->mode != SRC_MODE_PROCESS)
132+ if (state->mode != SRC_MODE_PROCESS)
137133 return SRC_ERR_BAD_MODE ;
138134
139135 /* Check for valid SRC_DATA first. */
@@ -155,13 +151,13 @@ src_process (SRC_STATE *state, SRC_DATA *data) · 15 unmodified lines
155151 data->output_frames = 0 ;
156152
157153 if (data->data_in < data->data_out)
158− { if (data->data_in + data->input_frames * psrc->channels > data->data_out)
154+ { if (data->data_in + data->input_frames * state->channels > data->data_out)
159155 { /*-printf ("\n\ndata_in: %p data_out: %p\n",
160156 (void*) (data->data_in + data->input_frames * psrc->channels), (void*) data->data_out) ;-*/
161157 return SRC_ERR_DATA_OVERLAP ;
162158 } ;
163159 }
164− else if (data->data_out + data->output_frames * psrc->channels > data->data_in)
160+ else if (data->data_out + data->output_frames * state->channels > data->data_in)
165161 { /*-printf ("\n\ndata_in : %p ouput frames: %ld data_out: %p\n", (void*) data->data_in, data->output_frames, (void*) data->data_out) ;
166162
167163 printf ("data_out: %p (%p) data_in: %p\n", (void*) data->data_out,
@@ -174,21 +170,21 @@ src_process (SRC_STATE *state, SRC_DATA *data) · 6 unmodified lines
174170 data->output_frames_gen = 0 ;
175171
176172 /* Special case for when last_ratio has not been set. */
177− if (psrc->last_ratio < (1.0 / SRC_MAX_RATIO))
178− psrc->last_ratio = data->src_ratio ;
173+ if (state->last_ratio < (1.0 / SRC_MAX_RATIO))
174+ state->last_ratio = data->src_ratio ;
179175
180176 /* Now process. */
181− if (fabs (psrc->last_ratio - data->src_ratio) < 1e-15)
182− error = psrc->const_process (psrc, data) ;
177+ if (fabs (state->last_ratio - data->src_ratio) < 1e-15)
178+ error = state->const_process (state, data) ;
183179 else
184− error = psrc->vari_process (psrc, data) ;
180+ error = state->vari_process (state, data) ;
185181
186182 return error ;
187183 } /* src_process */
188184
189185 long
190186 src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data)
191−{ SRC_PRIVATE *psrc ;
187+{
192188 SRC_DATA src_data ;
193189
194190 long output_frames_gen ;
@@ -200,15 +196,13 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 5 unmodified lines
200196 if (frames <= 0)
201197 return 0 ;
202198
203− psrc = (SRC_PRIVATE*) state ;
204−
205− if (psrc->mode != SRC_MODE_CALLBACK)
206− { psrc->error = SRC_ERR_BAD_MODE ;
199+ if (state->mode != SRC_MODE_CALLBACK)
200+ { state->error = SRC_ERR_BAD_MODE ;
207201 return 0 ;
208202 } ;
209203
210− if (psrc->callback_func == NULL)
211− { psrc->error = SRC_ERR_NULL_CALLBACK ;
204+ if (state->callback_func == NULL)
205+ { state->error = SRC_ERR_NULL_CALLBACK ;
212206 return 0 ;
213207 } ;
214208
@@ -216,7 +210,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 1 unmodified line
216210
217211 /* Check src_ratio is in range. */
218212 if (is_bad_src_ratio (src_ratio))
219− { psrc->error = SRC_ERR_BAD_SRC_RATIO ;
213+ { state->error = SRC_ERR_BAD_SRC_RATIO ;
220214 return 0 ;
221215 } ;
222216
@@ -225,8 +219,8 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 2 unmodified lines
225219 src_data.data_out = data ;
226220 src_data.output_frames = frames ;
227221
228− src_data.data_in = psrc->saved_data ;
229− src_data.input_frames = psrc->saved_frames ;
222+ src_data.data_in = state->saved_data ;
223+ src_data.input_frames = state->saved_frames ;
230224
231225 output_frames_gen = 0 ;
232226 while (output_frames_gen < frames)
@@ -238,7 +232,7 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 5 unmodified lines
238232 if (src_data.input_frames == 0)
239233 { float *ptr = dummy ;
240234
241− src_data.input_frames = psrc->callback_func (psrc->user_callback_data, &ptr) ;
235+ src_data.input_frames = state->callback_func (state->user_callback_data, &ptr) ;
242236 src_data.data_in = ptr ;
243237
244238 if (src_data.input_frames == 0)
@@ -250,17 +244,17 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 5 unmodified lines
250244 ** to SRC_MODE_PROCESS first and when we return set it back to
251245 ** SRC_MODE_CALLBACK.
252246 */
253− psrc->mode = SRC_MODE_PROCESS ;
247+ state->mode = SRC_MODE_PROCESS ;
254248 error = src_process (state, &src_data) ;
255− psrc->mode = SRC_MODE_CALLBACK ;
249+ state->mode = SRC_MODE_CALLBACK ;
256250
257251 if (error != 0)
258252 break ;
259253
260− src_data.data_in += src_data.input_frames_used * psrc->channels ;
254+ src_data.data_in += src_data.input_frames_used * state->channels ;
261255 src_data.input_frames -= src_data.input_frames_used ;
262256
263− src_data.data_out += src_data.output_frames_gen * psrc->channels ;
257+ src_data.data_out += src_data.output_frames_gen * state->channels ;
264258 src_data.output_frames -= src_data.output_frames_gen ;
265259
266260 output_frames_gen += src_data.output_frames_gen ;
@@ -269,11 +263,11 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 2 unmodified lines
269263 break ;
270264 } ;
271265
272− psrc->saved_data = src_data.data_in ;
273− psrc->saved_frames = src_data.input_frames ;
266+ state->saved_data = src_data.data_in ;
267+ state->saved_frames = src_data.input_frames ;
274268
275269 if (error != 0)
276− { psrc->error = error ;
270+ { state->error = error ;
277271 return 0 ;
278272 } ;
279273
@@ -285,54 +279,47 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 5 unmodified lines
285279
286280 int
287281 src_set_ratio (SRC_STATE *state, double new_ratio)
288−{ SRC_PRIVATE *psrc ;
289−
290− psrc = (SRC_PRIVATE*) state ;
291−
292− if (psrc == NULL)
282+{
283+ if (state == NULL)
293284 return SRC_ERR_BAD_STATE ;
294− if (psrc->vari_process == NULL || psrc->const_process == NULL)
285+ if (state->vari_process == NULL || state->const_process == NULL)
295286 return SRC_ERR_BAD_PROC_PTR ;
296287
297288 if (is_bad_src_ratio (new_ratio))
298289 return SRC_ERR_BAD_SRC_RATIO ;
299290
300− psrc->last_ratio = new_ratio ;
291+ state->last_ratio = new_ratio ;
301292
302293 return SRC_ERR_NO_ERROR ;
303294 } /* src_set_ratio */
304295
305296 int
306297 src_get_channels (SRC_STATE *state)
307−{ SRC_PRIVATE *psrc ;
308−
309− psrc = (SRC_PRIVATE*) state ;
310−
311− if (psrc == NULL)
298+{
299+ if (state == NULL)
312300 return -SRC_ERR_BAD_STATE ;
313− if (psrc->vari_process == NULL || psrc->const_process == NULL)
301+ if (state->vari_process == NULL || state->const_process == NULL)
314302 return -SRC_ERR_BAD_PROC_PTR ;
315303
316− return psrc->channels ;
304+ return state->channels ;
317305 } /* src_get_channels */
318306
319307 int
320308 src_reset (SRC_STATE *state)
321−{ SRC_PRIVATE *psrc ;
322−
323− if ((psrc = (SRC_PRIVATE*) state) == NULL)
309+{
310+ if (state == NULL)
324311 return SRC_ERR_BAD_STATE ;
325312
326− if (psrc->reset != NULL)
327− psrc->reset (psrc) ;
313+ if (state->reset != NULL)
314+ state->reset (state) ;
328315
329− psrc->last_position = 0.0 ;
330− psrc->last_ratio = 0.0 ;
316+ state->last_position = 0.0 ;
317+ state->last_ratio = 0.0 ;
331318
332− psrc->saved_data = NULL ;
333− psrc->saved_frames = 0 ;
319+ state->saved_data = NULL ;
320+ state->saved_frames = 0 ;
334321
335− psrc->error = SRC_ERR_NO_ERROR ;
322+ state->error = SRC_ERR_NO_ERROR ;
336323
337324 return SRC_ERR_NO_ERROR ;
338325 } /* src_reset */
@@ -394,7 +381,7 @@ src_is_valid_ratio (double ratio) · 55 unmodified lines
394381 int
395382 src_error (SRC_STATE *state)
396383 { if (state)
397− return ((SRC_PRIVATE*) state)->error ;
384+ return state->error ;
398385 return SRC_ERR_NO_ERROR ;
399386 } /* src_error */
400387
@@ -547,15 +534,15 @@ src_float_to_int_array (const float *in, int *out, int len) · 146 unmodified lines
547534 */
548535
549536 static int
550−psrc_set_converter (SRC_PRIVATE *psrc, int converter_type)
537+psrc_set_converter (SRC_STATE *state, int converter_type)
551538 {
552− if (sinc_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
539+ if (sinc_set_converter (state, converter_type) == SRC_ERR_NO_ERROR)
553540 return SRC_ERR_NO_ERROR ;
554541
555− if (zoh_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
542+ if (zoh_set_converter (state, converter_type) == SRC_ERR_NO_ERROR)
556543 return SRC_ERR_NO_ERROR ;
557544
558− if (linear_set_converter (psrc, converter_type) == SRC_ERR_NO_ERROR)
545+ if (linear_set_converter (state, converter_type) == SRC_ERR_NO_ERROR)
559546 return SRC_ERR_NO_ERROR ;
560547
561548 return SRC_ERR_BAD_CONVERTER ;
src/src_linear.c+31−31
@@ -14,9 +14,9 @@ · 13 unmodified lines
1414 #include "src_config.h"
1515 #include "common.h"
1616
17−static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
18−static void linear_reset (SRC_PRIVATE *psrc) ;
19−static int linear_copy (SRC_PRIVATE *from, SRC_PRIVATE *to) ;
17+static int linear_vari_process (SRC_STATE *state, SRC_DATA *data) ;
18+static void linear_reset (SRC_STATE *state) ;
19+static int linear_copy (SRC_STATE *from, SRC_STATE *to) ;
2020
2121 /*========================================================================================
2222 */
@@ -38,7 +38,7 @@ typedef struct · 15 unmodified lines
3838 */
3939
4040 static int
41−linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
41+linear_vari_process (SRC_STATE *state, SRC_DATA *data)
4242 { LINEAR_DATA *priv ;
4343 double src_ratio, input_index, rem ;
4444 int ch ;
@@ -46,10 +46,10 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
4646 if (data->input_frames <= 0)
4747 return SRC_ERR_NO_ERROR ;
4848
49− if (psrc->private_data == NULL)
49+ if (state->private_data == NULL)
5050 return SRC_ERR_NO_PRIVATE ;
5151
52− priv = (LINEAR_DATA*) psrc->private_data ;
52+ priv = (LINEAR_DATA*) state->private_data ;
5353
5454 if (priv->reset)
5555 { /* If we have just been reset, set the last_value data. */
@@ -62,12 +62,12 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
6262 priv->out_count = data->output_frames * priv->channels ;
6363 priv->in_used = priv->out_gen = 0 ;
6464
65− src_ratio = psrc->last_ratio ;
65+ src_ratio = state->last_ratio ;
6666
6767 if (is_bad_src_ratio (src_ratio))
6868 return SRC_ERR_BAD_INTERNAL_STATE ;
6969
70− input_index = psrc->last_position ;
70+ input_index = state->last_position ;
7171
7272 /* Calculate samples before first sample in input array. */
7373 while (input_index < 1.0 && priv->out_gen < priv->out_count)
@@ -75,8 +75,8 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
7575 if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
7676 break ;
7777
78− if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
79− src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
78+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
79+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
8080
8181 for (ch = 0 ; ch < priv->channels ; ch++)
8282 { data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
@@ -95,8 +95,8 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 12 unmodified lines
9595 /* Main processing loop. */
9696 while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
9797 {
98− if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
99− src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
98+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
99+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
100100
101101 if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
102102 { printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, priv->channels, input_index) ;
@@ -122,14 +122,14 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 19 unmodified lines
122122 priv->in_used = priv->in_count ;
123123 } ;
124124
125− psrc->last_position = input_index ;
125+ state->last_position = input_index ;
126126
127127 if (priv->in_used > 0)
128128 for (ch = 0 ; ch < priv->channels ; ch++)
129129 priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
130130
131131 /* Save current ratio rather then target ratio. */
132− psrc->last_ratio = src_ratio ;
132+ state->last_ratio = src_ratio ;
133133
134134 data->input_frames_used = priv->in_used / priv->channels ;
135135 data->output_frames_gen = priv->out_gen / priv->channels ;
@@ -159,34 +159,34 @@ linear_get_description (int src_enum) · 23 unmodified lines
159159 } /* linear_get_descrition */
160160
161161 int
162−linear_set_converter (SRC_PRIVATE *psrc, int src_enum)
162+linear_set_converter (SRC_STATE *state, int src_enum)
163163 { LINEAR_DATA *priv = NULL ;
164164
165165 if (src_enum != SRC_LINEAR)
166166 return SRC_ERR_BAD_CONVERTER ;
167167
168− if (psrc->private_data != NULL)
169− { free (psrc->private_data) ;
170− psrc->private_data = NULL ;
168+ if (state->private_data != NULL)
169+ { free (state->private_data) ;
170+ state->private_data = NULL ;
171171 } ;
172172
173− if (psrc->private_data == NULL)
174− { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + psrc->channels * sizeof (float)) ;
175− psrc->private_data = priv ;
173+ if (state->private_data == NULL)
174+ { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
175+ state->private_data = priv ;
176176 } ;
177177
178178 if (priv == NULL)
179179 return SRC_ERR_MALLOC_FAILED ;
180180
181181 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
182− priv->channels = psrc->channels ;
182+ priv->channels = state->channels ;
183183
184− psrc->const_process = linear_vari_process ;
185− psrc->vari_process = linear_vari_process ;
186− psrc->reset = linear_reset ;
187− psrc->copy = linear_copy ;
184+ state->const_process = linear_vari_process ;
185+ state->vari_process = linear_vari_process ;
186+ state->reset = linear_reset ;
187+ state->copy = linear_copy ;
188188
189− linear_reset (psrc) ;
189+ linear_reset (state) ;
190190
191191 return SRC_ERR_NO_ERROR ;
192192 } /* linear_set_converter */
@@ -195,14 +195,14 @@ linear_set_converter (SRC_PRIVATE *psrc, int src_enum) · 2 unmodified lines
195195 */
196196
197197 static void
198−linear_reset (SRC_PRIVATE *psrc)
198+linear_reset (SRC_STATE *state)
199199 { LINEAR_DATA *priv = NULL ;
200200
201− priv = (LINEAR_DATA*) psrc->private_data ;
201+ priv = (LINEAR_DATA*) state->private_data ;
202202 if (priv == NULL)
203203 return ;
204204
205− priv->channels = psrc->channels ;
205+ priv->channels = state->channels ;
206206 priv->reset = 1 ;
207207 memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
208208
@@ -210,7 +210,7 @@ linear_reset (SRC_PRIVATE *psrc) · 1 unmodified line
210210 } /* linear_reset */
211211
212212 static int
213−linear_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
213+linear_copy (SRC_STATE *from, SRC_STATE *to)
214214 {
215215 if (from->private_data == NULL)
216216 return SRC_ERR_NO_PRIVATE ;
src/src_sinc.c+100−100
@@ -58,16 +58,16 @@ typedef struct · 57 unmodified lines
5858 float buffer [] ;
5959 } SINC_FILTER ;
6060
61−static int sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
62−static int sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
63−static int sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
64−static int sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
65−static int sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
61+static int sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data) ;
62+static int sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data) ;
63+static int sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data) ;
64+static int sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data) ;
65+static int sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data) ;
6666
6767 static int prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
6868
69−static void sinc_reset (SRC_PRIVATE *psrc) ;
70−static int sinc_copy (SRC_PRIVATE *from, SRC_PRIVATE *to) ;
69+static void sinc_reset (SRC_STATE *state) ;
70+static int sinc_copy (SRC_STATE *from, SRC_STATE *to) ;
7171
7272 static inline increment_t
7373 double_to_fp (double x)
@@ -143,7 +143,7 @@ sinc_get_description (int src_enum) · 69 unmodified lines
143143 } /* sinc_get_descrition */
144144
145145 int
146−sinc_set_converter (SRC_PRIVATE *psrc, int src_enum)
146+sinc_set_converter (SRC_STATE *state, int src_enum)
147147 { SINC_FILTER *filter, temp_filter ;
148148 increment_t count ;
149149 uint32_t bits ;
@@ -152,43 +152,43 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 2 unmodified lines
152152 if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
153153 return SRC_ERR_SHIFT_BITS ;
154154
155− if (psrc->private_data != NULL)
156− { free (psrc->private_data) ;
157− psrc->private_data = NULL ;
155+ if (state->private_data != NULL)
156+ { free (state->private_data) ;
157+ state->private_data = NULL ;
158158 } ;
159159
160160 memset (&temp_filter, 0, sizeof (temp_filter)) ;
161161
162162 temp_filter.sinc_magic_marker = SINC_MAGIC_MARKER ;
163− temp_filter.channels = psrc->channels ;
163+ temp_filter.channels = state->channels ;
164164
165− if (psrc->channels > ARRAY_LEN (temp_filter.left_calc))
165+ if (state->channels > ARRAY_LEN (temp_filter.left_calc))
166166 return SRC_ERR_BAD_CHANNEL_COUNT ;
167− else if (psrc->channels == 1)
168− { psrc->const_process = sinc_mono_vari_process ;
169− psrc->vari_process = sinc_mono_vari_process ;
167+ else if (state->channels == 1)
168+ { state->const_process = sinc_mono_vari_process ;
169+ state->vari_process = sinc_mono_vari_process ;
170170 }
171171 else
172− if (psrc->channels == 2)
173− { psrc->const_process = sinc_stereo_vari_process ;
174− psrc->vari_process = sinc_stereo_vari_process ;
172+ if (state->channels == 2)
173+ { state->const_process = sinc_stereo_vari_process ;
174+ state->vari_process = sinc_stereo_vari_process ;
175175 }
176176 else
177− if (psrc->channels == 4)
178− { psrc->const_process = sinc_quad_vari_process ;
179− psrc->vari_process = sinc_quad_vari_process ;
177+ if (state->channels == 4)
178+ { state->const_process = sinc_quad_vari_process ;
179+ state->vari_process = sinc_quad_vari_process ;
180180 }
181181 else
182− if (psrc->channels == 6)
183− { psrc->const_process = sinc_hex_vari_process ;
184− psrc->vari_process = sinc_hex_vari_process ;
182+ if (state->channels == 6)
183+ { state->const_process = sinc_hex_vari_process ;
184+ state->vari_process = sinc_hex_vari_process ;
185185 }
186186 else
187− { psrc->const_process = sinc_multichan_vari_process ;
188− psrc->vari_process = sinc_multichan_vari_process ;
187+ { state->const_process = sinc_multichan_vari_process ;
188+ state->vari_process = sinc_multichan_vari_process ;
189189 } ;
190− psrc->reset = sinc_reset ;
191− psrc->copy = sinc_copy ;
190+ state->reset = sinc_reset ;
191+ state->copy = sinc_copy ;
192192
193193 switch (src_enum)
194194 { case SRC_SINC_FASTEST :
@@ -229,9 +229,9 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 34 unmodified lines
229229 *filter = temp_filter ;
230230 memset (&temp_filter, 0xEE, sizeof (temp_filter)) ;
231231
232− psrc->private_data = filter ;
232+ state->private_data = filter ;
233233
234− sinc_reset (psrc) ;
234+ sinc_reset (state) ;
235235
236236 count = filter->coeff_half_len ;
237237 for (bits = 0 ; (MAKE_INCREMENT_T (1) << bits) < count ; bits++)
@@ -244,10 +244,10 @@ sinc_set_converter (SRC_PRIVATE *psrc, int src_enum) · 6 unmodified lines
244244 } /* sinc_set_converter */
245245
246246 static void
247−sinc_reset (SRC_PRIVATE *psrc)
247+sinc_reset (SRC_STATE *state)
248248 { SINC_FILTER *filter ;
249249
250− filter = (SINC_FILTER*) psrc->private_data ;
250+ filter = (SINC_FILTER*) state->private_data ;
251251 if (filter == NULL)
252252 return ;
253253
@@ -263,7 +263,7 @@ sinc_reset (SRC_PRIVATE *psrc) · 9 unmodified lines
263263 } /* sinc_reset */
264264
265265 static int
266−sinc_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
266+sinc_copy (SRC_STATE *from, SRC_STATE *to)
267267 {
268268 if (from->private_data == NULL)
269269 return SRC_ERR_NO_PRIVATE ;
@@ -346,16 +346,16 @@ calc_output_single (SINC_FILTER *filter, increment_t increment, increment_t star · 76 unmodified lines
346346 } /* calc_output_single */
347347
348348 static int
349−sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
349+sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data)
350350 { SINC_FILTER *filter ;
351351 double input_index, src_ratio, count, float_increment, terminate, rem ;
352352 increment_t increment, start_filter_index ;
353353 int half_filter_chan_len, samples_in_hand ;
354354
355− if (psrc->private_data == NULL)
355+ if (state->private_data == NULL)
356356 return SRC_ERR_NO_PRIVATE ;
357357
358− filter = (SINC_FILTER*) psrc->private_data ;
358+ filter = (SINC_FILTER*) state->private_data ;
359359
360360 /* If there is not a problem, this will be optimised out. */
361361 if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
@@ -365,20 +365,20 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
365365 filter->out_count = data->output_frames * filter->channels ;
366366 filter->in_used = filter->out_gen = 0 ;
367367
368− src_ratio = psrc->last_ratio ;
368+ src_ratio = state->last_ratio ;
369369
370370 if (is_bad_src_ratio (src_ratio))
371371 return SRC_ERR_BAD_INTERNAL_STATE ;
372372
373373 /* Check the sample rate ratio wrt the buffer len. */
374374 count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
375− if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
376− count /= MIN (psrc->last_ratio, data->src_ratio) ;
375+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
376+ count /= MIN (state->last_ratio, data->src_ratio) ;
377377
378378 /* Maximum coefficientson either side of center point. */
379379 half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
380380
381− input_index = psrc->last_position ;
381+ input_index = state->last_position ;
382382
383383 rem = fmod_one (input_index) ;
384384 filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
@@ -393,8 +393,8 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 8 unmodified lines
393393 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
394394
395395 if (samples_in_hand <= half_filter_chan_len)
396− { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
397− return psrc->error ;
396+ { if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
397+ return state->error ;
398398
399399 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
400400 if (samples_in_hand <= half_filter_chan_len)
@@ -407,8 +407,8 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
407407 break ;
408408 } ;
409409
410− if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
411− src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
410+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
411+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
412412
413413 float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
414414 increment = double_to_fp (float_increment) ;
@@ -427,10 +427,10 @@ sinc_mono_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 12 unmodified lines
427427 input_index = rem ;
428428 } ;
429429
430− psrc->last_position = input_index ;
430+ state->last_position = input_index ;
431431
432432 /* Save current ratio rather then target ratio. */
433− psrc->last_ratio = src_ratio ;
433+ state->last_ratio = src_ratio ;
434434
435435 data->input_frames_used = filter->in_used / filter->channels ;
436436 data->output_frames_gen = filter->out_gen / filter->channels ;
@@ -502,16 +502,16 @@ calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t star · 65 unmodified lines
502502 } /* calc_output_stereo */
503503
504504 static int
505−sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
505+sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data)
506506 { SINC_FILTER *filter ;
507507 double input_index, src_ratio, count, float_increment, terminate, rem ;
508508 increment_t increment, start_filter_index ;
509509 int half_filter_chan_len, samples_in_hand ;
510510
511− if (psrc->private_data == NULL)
511+ if (state->private_data == NULL)
512512 return SRC_ERR_NO_PRIVATE ;
513513
514− filter = (SINC_FILTER*) psrc->private_data ;
514+ filter = (SINC_FILTER*) state->private_data ;
515515
516516 /* If there is not a problem, this will be optimised out. */
517517 if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
@@ -521,20 +521,20 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
521521 filter->out_count = data->output_frames * filter->channels ;
522522 filter->in_used = filter->out_gen = 0 ;
523523
524− src_ratio = psrc->last_ratio ;
524+ src_ratio = state->last_ratio ;
525525
526526 if (is_bad_src_ratio (src_ratio))
527527 return SRC_ERR_BAD_INTERNAL_STATE ;
528528
529529 /* Check the sample rate ratio wrt the buffer len. */
530530 count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
531− if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
532− count /= MIN (psrc->last_ratio, data->src_ratio) ;
531+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
532+ count /= MIN (state->last_ratio, data->src_ratio) ;
533533
534534 /* Maximum coefficientson either side of center point. */
535535 half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
536536
537− input_index = psrc->last_position ;
537+ input_index = state->last_position ;
538538
539539 rem = fmod_one (input_index) ;
540540 filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
@@ -549,8 +549,8 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 8 unmodified lines
549549 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
550550
551551 if (samples_in_hand <= half_filter_chan_len)
552− { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
553− return psrc->error ;
552+ { if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
553+ return state->error ;
554554
555555 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
556556 if (samples_in_hand <= half_filter_chan_len)
@@ -563,8 +563,8 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
563563 break ;
564564 } ;
565565
566− if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
567− src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
566+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
567+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
568568
569569 float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
570570 increment = double_to_fp (float_increment) ;
@@ -582,10 +582,10 @@ sinc_stereo_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 11 unmodified lines
582582 input_index = rem ;
583583 } ;
584584
585− psrc->last_position = input_index ;
585+ state->last_position = input_index ;
586586
587587 /* Save current ratio rather then target ratio. */
588− psrc->last_ratio = src_ratio ;
588+ state->last_ratio = src_ratio ;
589589
590590 data->input_frames_used = filter->in_used / filter->channels ;
591591 data->output_frames_gen = filter->out_gen / filter->channels ;
@@ -658,16 +658,16 @@ calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_ · 66 unmodified lines
658658 } /* calc_output_quad */
659659
660660 static int
661−sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
661+sinc_quad_vari_process (SRC_STATE *state, SRC_DATA *data)
662662 { SINC_FILTER *filter ;
663663 double input_index, src_ratio, count, float_increment, terminate, rem ;
664664 increment_t increment, start_filter_index ;
665665 int half_filter_chan_len, samples_in_hand ;
666666
667− if (psrc->private_data == NULL)
667+ if (state->private_data == NULL)
668668 return SRC_ERR_NO_PRIVATE ;
669669
670− filter = (SINC_FILTER*) psrc->private_data ;
670+ filter = (SINC_FILTER*) state->private_data ;
671671
672672 /* If there is not a problem, this will be optimised out. */
673673 if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
@@ -677,20 +677,20 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
677677 filter->out_count = data->output_frames * filter->channels ;
678678 filter->in_used = filter->out_gen = 0 ;
679679
680− src_ratio = psrc->last_ratio ;
680+ src_ratio = state->last_ratio ;
681681
682682 if (is_bad_src_ratio (src_ratio))
683683 return SRC_ERR_BAD_INTERNAL_STATE ;
684684
685685 /* Check the sample rate ratio wrt the buffer len. */
686686 count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
687− if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
688− count /= MIN (psrc->last_ratio, data->src_ratio) ;
687+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
688+ count /= MIN (state->last_ratio, data->src_ratio) ;
689689
690690 /* Maximum coefficientson either side of center point. */
691691 half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
692692
693− input_index = psrc->last_position ;
693+ input_index = state->last_position ;
694694
695695 rem = fmod_one (input_index) ;
696696 filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
@@ -705,8 +705,8 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 8 unmodified lines
705705 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
706706
707707 if (samples_in_hand <= half_filter_chan_len)
708− { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
709− return psrc->error ;
708+ { if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
709+ return state->error ;
710710
711711 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
712712 if (samples_in_hand <= half_filter_chan_len)
@@ -719,8 +719,8 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
719719 break ;
720720 } ;
721721
722− if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
723− src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
722+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
723+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
724724
725725 float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
726726 increment = double_to_fp (float_increment) ;
@@ -738,10 +738,10 @@ sinc_quad_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 11 unmodified lines
738738 input_index = rem ;
739739 } ;
740740
741− psrc->last_position = input_index ;
741+ state->last_position = input_index ;
742742
743743 /* Save current ratio rather then target ratio. */
744− psrc->last_ratio = src_ratio ;
744+ state->last_ratio = src_ratio ;
745745
746746 data->input_frames_used = filter->in_used / filter->channels ;
747747 data->output_frames_gen = filter->out_gen / filter->channels ;
@@ -813,16 +813,16 @@ calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_f · 65 unmodified lines
813813 } /* calc_output_hex */
814814
815815 static int
816−sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
816+sinc_hex_vari_process (SRC_STATE *state, SRC_DATA *data)
817817 { SINC_FILTER *filter ;
818818 double input_index, src_ratio, count, float_increment, terminate, rem ;
819819 increment_t increment, start_filter_index ;
820820 int half_filter_chan_len, samples_in_hand ;
821821
822− if (psrc->private_data == NULL)
822+ if (state->private_data == NULL)
823823 return SRC_ERR_NO_PRIVATE ;
824824
825− filter = (SINC_FILTER*) psrc->private_data ;
825+ filter = (SINC_FILTER*) state->private_data ;
826826
827827 /* If there is not a problem, this will be optimised out. */
828828 if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
@@ -832,20 +832,20 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
832832 filter->out_count = data->output_frames * filter->channels ;
833833 filter->in_used = filter->out_gen = 0 ;
834834
835− src_ratio = psrc->last_ratio ;
835+ src_ratio = state->last_ratio ;
836836
837837 if (is_bad_src_ratio (src_ratio))
838838 return SRC_ERR_BAD_INTERNAL_STATE ;
839839
840840 /* Check the sample rate ratio wrt the buffer len. */
841841 count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
842− if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
843− count /= MIN (psrc->last_ratio, data->src_ratio) ;
842+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
843+ count /= MIN (state->last_ratio, data->src_ratio) ;
844844
845845 /* Maximum coefficientson either side of center point. */
846846 half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
847847
848− input_index = psrc->last_position ;
848+ input_index = state->last_position ;
849849
850850 rem = fmod_one (input_index) ;
851851 filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
@@ -860,8 +860,8 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 8 unmodified lines
860860 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
861861
862862 if (samples_in_hand <= half_filter_chan_len)
863− { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
864− return psrc->error ;
863+ { if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
864+ return state->error ;
865865
866866 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
867867 if (samples_in_hand <= half_filter_chan_len)
@@ -874,8 +874,8 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
874874 break ;
875875 } ;
876876
877− if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
878− src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
877+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
878+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
879879
880880 float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
881881 increment = double_to_fp (float_increment) ;
@@ -893,10 +893,10 @@ sinc_hex_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 11 unmodified lines
893893 input_index = rem ;
894894 } ;
895895
896− psrc->last_position = input_index ;
896+ state->last_position = input_index ;
897897
898898 /* Save current ratio rather then target ratio. */
899− psrc->last_ratio = src_ratio ;
899+ state->last_ratio = src_ratio ;
900900
901901 data->input_frames_used = filter->in_used / filter->channels ;
902902 data->output_frames_gen = filter->out_gen / filter->channels ;
@@ -978,16 +978,16 @@ calc_output_multi (SINC_FILTER *filter, increment_t increment, increment_t start · 75 unmodified lines
978978 } /* calc_output_multi */
979979
980980 static int
981−sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
981+sinc_multichan_vari_process (SRC_STATE *state, SRC_DATA *data)
982982 { SINC_FILTER *filter ;
983983 double input_index, src_ratio, count, float_increment, terminate, rem ;
984984 increment_t increment, start_filter_index ;
985985 int half_filter_chan_len, samples_in_hand ;
986986
987− if (psrc->private_data == NULL)
987+ if (state->private_data == NULL)
988988 return SRC_ERR_NO_PRIVATE ;
989989
990− filter = (SINC_FILTER*) psrc->private_data ;
990+ filter = (SINC_FILTER*) state->private_data ;
991991
992992 /* If there is not a problem, this will be optimised out. */
993993 if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
@@ -997,20 +997,20 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
997997 filter->out_count = data->output_frames * filter->channels ;
998998 filter->in_used = filter->out_gen = 0 ;
999999
1000− src_ratio = psrc->last_ratio ;
1000+ src_ratio = state->last_ratio ;
10011001
10021002 if (is_bad_src_ratio (src_ratio))
10031003 return SRC_ERR_BAD_INTERNAL_STATE ;
10041004
10051005 /* Check the sample rate ratio wrt the buffer len. */
10061006 count = (filter->coeff_half_len + 2.0) / filter->index_inc ;
1007− if (MIN (psrc->last_ratio, data->src_ratio) < 1.0)
1008− count /= MIN (psrc->last_ratio, data->src_ratio) ;
1007+ if (MIN (state->last_ratio, data->src_ratio) < 1.0)
1008+ count /= MIN (state->last_ratio, data->src_ratio) ;
10091009
10101010 /* Maximum coefficientson either side of center point. */
10111011 half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
10121012
1013− input_index = psrc->last_position ;
1013+ input_index = state->last_position ;
10141014
10151015 rem = fmod_one (input_index) ;
10161016 filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
@@ -1025,8 +1025,8 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 8 unmodified lines
10251025 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
10261026
10271027 if (samples_in_hand <= half_filter_chan_len)
1028− { if ((psrc->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
1029− return psrc->error ;
1028+ { if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
1029+ return state->error ;
10301030
10311031 samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
10321032 if (samples_in_hand <= half_filter_chan_len)
@@ -1039,8 +1039,8 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
10391039 break ;
10401040 } ;
10411041
1042− if (filter->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > 1e-10)
1043− src_ratio = psrc->last_ratio + filter->out_gen * (data->src_ratio - psrc->last_ratio) / filter->out_count ;
1042+ if (filter->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > 1e-10)
1043+ src_ratio = state->last_ratio + filter->out_gen * (data->src_ratio - state->last_ratio) / filter->out_count ;
10441044
10451045 float_increment = filter->index_inc * (src_ratio < 1.0 ? src_ratio : 1.0) ;
10461046 increment = double_to_fp (float_increment) ;
@@ -1048,7 +1048,7 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
10481048 start_filter_index = double_to_fp (input_index * float_increment) ;
10491049
10501050 calc_output_multi (filter, increment, start_filter_index, filter->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
1051− filter->out_gen += psrc->channels ;
1051+ filter->out_gen += state->channels ;
10521052
10531053 /* Figure out the next index. */
10541054 input_index += 1.0 / src_ratio ;
@@ -1058,10 +1058,10 @@ sinc_multichan_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 3 unmodified lines
10581058 input_index = rem ;
10591059 } ;
10601060
1061− psrc->last_position = input_index ;
1061+ state->last_position = input_index ;
10621062
10631063 /* Save current ratio rather then target ratio. */
1064− psrc->last_ratio = src_ratio ;
1064+ state->last_ratio = src_ratio ;
10651065
10661066 data->input_frames_used = filter->in_used / filter->channels ;
10671067 data->output_frames_gen = filter->out_gen / filter->channels ;
src/src_zoh.c+31−31
@@ -14,9 +14,9 @@ · 13 unmodified lines
1414 #include "src_config.h"
1515 #include "common.h"
1616
17−static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
18−static void zoh_reset (SRC_PRIVATE *psrc) ;
19−static int zoh_copy (SRC_PRIVATE *from, SRC_PRIVATE *to) ;
17+static int zoh_vari_process (SRC_STATE *state, SRC_DATA *data) ;
18+static void zoh_reset (SRC_STATE *state) ;
19+static int zoh_copy (SRC_STATE *from, SRC_STATE *to) ;
2020
2121 /*========================================================================================
2222 */
@@ -36,7 +36,7 @@ typedef struct · 13 unmodified lines
3636 */
3737
3838 static int
39−zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
39+zoh_vari_process (SRC_STATE *state, SRC_DATA *data)
4040 { ZOH_DATA *priv ;
4141 double src_ratio, input_index, rem ;
4242 int ch ;
@@ -44,10 +44,10 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
4444 if (data->input_frames <= 0)
4545 return SRC_ERR_NO_ERROR ;
4646
47− if (psrc->private_data == NULL)
47+ if (state->private_data == NULL)
4848 return SRC_ERR_NO_PRIVATE ;
4949
50− priv = (ZOH_DATA*) psrc->private_data ;
50+ priv = (ZOH_DATA*) state->private_data ;
5151
5252 if (priv->reset)
5353 { /* If we have just been reset, set the last_value data. */
@@ -60,12 +60,12 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 6 unmodified lines
6060 priv->out_count = data->output_frames * priv->channels ;
6161 priv->in_used = priv->out_gen = 0 ;
6262
63− src_ratio = psrc->last_ratio ;
63+ src_ratio = state->last_ratio ;
6464
6565 if (is_bad_src_ratio (src_ratio))
6666 return SRC_ERR_BAD_INTERNAL_STATE ;
6767
68− input_index = psrc->last_position ;
68+ input_index = state->last_position ;
6969
7070 /* Calculate samples before first sample in input array. */
7171 while (input_index < 1.0 && priv->out_gen < priv->out_count)
@@ -73,8 +73,8 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
7373 if (priv->in_used + priv->channels * input_index >= priv->in_count)
7474 break ;
7575
76− if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
77− src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
76+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
77+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
7878
7979 for (ch = 0 ; ch < priv->channels ; ch++)
8080 { data->data_out [priv->out_gen] = priv->last_value [ch] ;
@@ -92,8 +92,8 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 11 unmodified lines
9292 /* Main processing loop. */
9393 while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index <= priv->in_count)
9494 {
95− if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
96− src_ratio = psrc->last_ratio + priv->out_gen * (data->src_ratio - psrc->last_ratio) / priv->out_count ;
95+ if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
96+ src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
9797
9898 for (ch = 0 ; ch < priv->channels ; ch++)
9999 { data->data_out [priv->out_gen] = data->data_in [priv->in_used - priv->channels + ch] ;
@@ -113,14 +113,14 @@ zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 13 unmodified lines
113113 priv->in_used = priv->in_count ;
114114 } ;
115115
116− psrc->last_position = input_index ;
116+ state->last_position = input_index ;
117117
118118 if (priv->in_used > 0)
119119 for (ch = 0 ; ch < priv->channels ; ch++)
120120 priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
121121
122122 /* Save current ratio rather then target ratio. */
123− psrc->last_ratio = src_ratio ;
123+ state->last_ratio = src_ratio ;
124124
125125 data->input_frames_used = priv->in_used / priv->channels ;
126126 data->output_frames_gen = priv->out_gen / priv->channels ;
@@ -150,34 +150,34 @@ zoh_get_description (int src_enum) · 23 unmodified lines
150150 } /* zoh_get_descrition */
151151
152152 int
153−zoh_set_converter (SRC_PRIVATE *psrc, int src_enum)
153+zoh_set_converter (SRC_STATE *state, int src_enum)
154154 { ZOH_DATA *priv = NULL ;
155155
156156 if (src_enum != SRC_ZERO_ORDER_HOLD)
157157 return SRC_ERR_BAD_CONVERTER ;
158158
159− if (psrc->private_data != NULL)
160− { free (psrc->private_data) ;
161− psrc->private_data = NULL ;
159+ if (state->private_data != NULL)
160+ { free (state->private_data) ;
161+ state->private_data = NULL ;
162162 } ;
163163
164− if (psrc->private_data == NULL)
165− { priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv) + psrc->channels * sizeof (float)) ;
166− psrc->private_data = priv ;
164+ if (state->private_data == NULL)
165+ { priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
166+ state->private_data = priv ;
167167 } ;
168168
169169 if (priv == NULL)
170170 return SRC_ERR_MALLOC_FAILED ;
171171
172172 priv->zoh_magic_marker = ZOH_MAGIC_MARKER ;
173− priv->channels = psrc->channels ;
173+ priv->channels = state->channels ;
174174
175− psrc->const_process = zoh_vari_process ;
176− psrc->vari_process = zoh_vari_process ;
177− psrc->reset = zoh_reset ;
178− psrc->copy = zoh_copy ;
175+ state->const_process = zoh_vari_process ;
176+ state->vari_process = zoh_vari_process ;
177+ state->reset = zoh_reset ;
178+ state->copy = zoh_copy ;
179179
180− zoh_reset (psrc) ;
180+ zoh_reset (state) ;
181181
182182 return SRC_ERR_NO_ERROR ;
183183 } /* zoh_set_converter */
@@ -186,14 +186,14 @@ zoh_set_converter (SRC_PRIVATE *psrc, int src_enum) · 2 unmodified lines
186186 */
187187
188188 static void
189−zoh_reset (SRC_PRIVATE *psrc)
189+zoh_reset (SRC_STATE *state)
190190 { ZOH_DATA *priv ;
191191
192− priv = (ZOH_DATA*) psrc->private_data ;
192+ priv = (ZOH_DATA*) state->private_data ;
193193 if (priv == NULL)
194194 return ;
195195
196− priv->channels = psrc->channels ;
196+ priv->channels = state->channels ;
197197 priv->reset = 1 ;
198198 memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
199199
@@ -201,7 +201,7 @@ zoh_reset (SRC_PRIVATE *psrc) · 1 unmodified line
201201 } /* zoh_reset */
202202
203203 static int
204−zoh_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)
204+zoh_copy (SRC_STATE *from, SRC_STATE *to)
205205 {
206206 if (from->private_data == NULL)
207207 return SRC_ERR_NO_PRIVATE ;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t