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/src_linear.c (1 of 5 files). Show all

Unified · Split

src/src_linear.c+31−31
@@ -14,9 +14,9 @@ · 13 unmodified lines
14#include "src_config.h"14#include "src_config.h"
15#include "common.h"15#include "common.h"
16 16
17static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;17static int linear_vari_process (SRC_STATE *state, SRC_DATA *data) ;
18static void linear_reset (SRC_PRIVATE *psrc) ;18static void linear_reset (SRC_STATE *state) ;
19static int linear_copy (SRC_PRIVATE *from, SRC_PRIVATE *to) ;19static int linear_copy (SRC_STATE *from, SRC_STATE *to) ;
20 20
21/*========================================================================================21/*========================================================================================
22*/22*/
@@ -38,7 +38,7 @@ typedef struct · 15 unmodified lines
38*/38*/
39 39
40static int40static int
41linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)41linear_vari_process (SRC_STATE *state, SRC_DATA *data)
42{ LINEAR_DATA *priv ;42{ LINEAR_DATA *priv ;
43 double src_ratio, input_index, rem ;43 double src_ratio, input_index, rem ;
44 int ch ;44 int ch ;
@@ -46,10 +46,10 @@ linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) · 1 unmodified line
46 if (data->input_frames <= 0)46 if (data->input_frames <= 0)
47 return SRC_ERR_NO_ERROR ;47 return SRC_ERR_NO_ERROR ;
48 48
49 if (psrc->private_data == NULL)49 if (state->private_data == NULL)
50 return SRC_ERR_NO_PRIVATE ;50 return SRC_ERR_NO_PRIVATE ;
51 51
52 priv = (LINEAR_DATA*) psrc->private_data ;52 priv = (LINEAR_DATA*) state->private_data ;
53 53
54 if (priv->reset)54 if (priv->reset)
55 { /* If we have just been reset, set the last_value data. */55 { /* 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
62 priv->out_count = data->output_frames * priv->channels ;62 priv->out_count = data->output_frames * priv->channels ;
63 priv->in_used = priv->out_gen = 0 ;63 priv->in_used = priv->out_gen = 0 ;
64 64
65 src_ratio = psrc->last_ratio ;65 src_ratio = state->last_ratio ;
66 66
67 if (is_bad_src_ratio (src_ratio))67 if (is_bad_src_ratio (src_ratio))
68 return SRC_ERR_BAD_INTERNAL_STATE ;68 return SRC_ERR_BAD_INTERNAL_STATE ;
69 69
70 input_index = psrc->last_position ;70 input_index = state->last_position ;
71 71
72 /* Calculate samples before first sample in input array. */72 /* Calculate samples before first sample in input array. */
73 while (input_index < 1.0 && priv->out_gen < priv->out_count)73 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
75 if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)75 if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
76 break ;76 break ;
77 77
78 if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)78 if (priv->out_count > 0 && fabs (state->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 ;79 src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
80 80
81 for (ch = 0 ; ch < priv->channels ; ch++)81 for (ch = 0 ; ch < priv->channels ; ch++)
82 { data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *82 { 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
95 /* Main processing loop. */95 /* Main processing loop. */
96 while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)96 while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
97 {97 {
98 if (priv->out_count > 0 && fabs (psrc->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)98 if (priv->out_count > 0 && fabs (state->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 ;99 src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
100 100
101 if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)101 if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
102 { printf ("Whoops!!!! in_used : %ld channels : %d input_index : %f\n", priv->in_used, priv->channels, input_index) ;102 { 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
122 priv->in_used = priv->in_count ;122 priv->in_used = priv->in_count ;
123 } ;123 } ;
124 124
125 psrc->last_position = input_index ;125 state->last_position = input_index ;
126 126
127 if (priv->in_used > 0)127 if (priv->in_used > 0)
128 for (ch = 0 ; ch < priv->channels ; ch++)128 for (ch = 0 ; ch < priv->channels ; ch++)
129 priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;129 priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
130 130
131 /* Save current ratio rather then target ratio. */131 /* Save current ratio rather then target ratio. */
132 psrc->last_ratio = src_ratio ;132 state->last_ratio = src_ratio ;
133 133
134 data->input_frames_used = priv->in_used / priv->channels ;134 data->input_frames_used = priv->in_used / priv->channels ;
135 data->output_frames_gen = priv->out_gen / priv->channels ;135 data->output_frames_gen = priv->out_gen / priv->channels ;
@@ -159,34 +159,34 @@ linear_get_description (int src_enum) · 23 unmodified lines
159} /* linear_get_descrition */159} /* linear_get_descrition */
160 160
161int161int
162linear_set_converter (SRC_PRIVATE *psrc, int src_enum)162linear_set_converter (SRC_STATE *state, int src_enum)
163{ LINEAR_DATA *priv = NULL ;163{ LINEAR_DATA *priv = NULL ;
164 164
165 if (src_enum != SRC_LINEAR)165 if (src_enum != SRC_LINEAR)
166 return SRC_ERR_BAD_CONVERTER ;166 return SRC_ERR_BAD_CONVERTER ;
167 167
168 if (psrc->private_data != NULL)168 if (state->private_data != NULL)
169 { free (psrc->private_data) ;169 { free (state->private_data) ;
170 psrc->private_data = NULL ;170 state->private_data = NULL ;
171 } ;171 } ;
172 172
173 if (psrc->private_data == NULL)173 if (state->private_data == NULL)
174 { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + psrc->channels * sizeof (float)) ;174 { priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
175 psrc->private_data = priv ;175 state->private_data = priv ;
176 } ;176 } ;
177 177
178 if (priv == NULL)178 if (priv == NULL)
179 return SRC_ERR_MALLOC_FAILED ;179 return SRC_ERR_MALLOC_FAILED ;
180 180
181 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;181 priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
182 priv->channels = psrc->channels ;182 priv->channels = state->channels ;
183 183
184 psrc->const_process = linear_vari_process ;184 state->const_process = linear_vari_process ;
185 psrc->vari_process = linear_vari_process ;185 state->vari_process = linear_vari_process ;
186 psrc->reset = linear_reset ;186 state->reset = linear_reset ;
187 psrc->copy = linear_copy ;187 state->copy = linear_copy ;
188 188
189 linear_reset (psrc) ;189 linear_reset (state) ;
190 190
191 return SRC_ERR_NO_ERROR ;191 return SRC_ERR_NO_ERROR ;
192} /* linear_set_converter */192} /* linear_set_converter */
@@ -195,14 +195,14 @@ linear_set_converter (SRC_PRIVATE *psrc, int src_enum) · 2 unmodified lines
195*/195*/
196 196
197static void197static void
198linear_reset (SRC_PRIVATE *psrc)198linear_reset (SRC_STATE *state)
199{ LINEAR_DATA *priv = NULL ;199{ LINEAR_DATA *priv = NULL ;
200 200
201 priv = (LINEAR_DATA*) psrc->private_data ;201 priv = (LINEAR_DATA*) state->private_data ;
202 if (priv == NULL)202 if (priv == NULL)
203 return ;203 return ;
204 204
205 priv->channels = psrc->channels ;205 priv->channels = state->channels ;
206 priv->reset = 1 ;206 priv->reset = 1 ;
207 memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;207 memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
208 208
@@ -210,7 +210,7 @@ linear_reset (SRC_PRIVATE *psrc) · 1 unmodified line
210} /* linear_reset */210} /* linear_reset */
211 211
212static int212static int
213linear_copy (SRC_PRIVATE *from, SRC_PRIVATE *to)213linear_copy (SRC_STATE *from, SRC_STATE *to)
214{214{
215 if (from->private_data == NULL)215 if (from->private_data == NULL)
216 return SRC_ERR_NO_PRIVATE ;216 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