shithub: libsamplerate

Download patch

ref: c78fbbce2789af3e327657557e4d953b12ee8f19
parent: 09d00868afafbbeb7632e764ed658ca3a6d60d4a
author: evpobr <[email protected]>
date: Sun Oct 25 09:53:29 EDT 2020

Remove useless duplicate `channels` fields

--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -27,7 +27,6 @@
 
 typedef struct
 {	int		linear_magic_marker ;
-	int		channels ;
 	int		dirty ;
 	long	in_count, in_used ;
 	long	out_count, out_gen ;
@@ -53,13 +52,13 @@
 
 	if (!priv->dirty)
 	{	/* If we have just been reset, set the last_value data. */
-		for (ch = 0 ; ch < priv->channels ; ch++)
+		for (ch = 0 ; ch < state->channels ; ch++)
 			priv->last_value [ch] = data->data_in [ch] ;
 		priv->dirty = true ;
 		} ;
 
-	priv->in_count = data->input_frames * priv->channels ;
-	priv->out_count = data->output_frames * priv->channels ;
+	priv->in_count = data->input_frames * state->channels ;
+	priv->out_count = data->output_frames * state->channels ;
 	priv->in_used = priv->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -72,13 +71,13 @@
 	/* Calculate samples before first sample in input array. */
 	while (input_index < 1.0 && priv->out_gen < priv->out_count)
 	{
-		if (priv->in_used + priv->channels * (1.0 + input_index) >= priv->in_count)
+		if (priv->in_used + state->channels * (1.0 + input_index) >= priv->in_count)
 			break ;
 
 		if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
 			src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
 
-		for (ch = 0 ; ch < priv->channels ; ch++)
+		for (ch = 0 ; ch < state->channels ; ch++)
 		{	data->data_out [priv->out_gen] = (float) (priv->last_value [ch] + input_index *
 										(data->data_in [ch] - priv->last_value [ch])) ;
 			priv->out_gen ++ ;
@@ -89,23 +88,23 @@
 		} ;
 
 	rem = fmod_one (input_index) ;
-	priv->in_used += priv->channels * lrint (input_index - rem) ;
+	priv->in_used += state->channels * lrint (input_index - rem) ;
 	input_index = rem ;
 
 	/* Main processing loop. */
-	while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index < priv->in_count)
+	while (priv->out_gen < priv->out_count && priv->in_used + state->channels * input_index < priv->in_count)
 	{
 		if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
 			src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
 
-		if (SRC_DEBUG && priv->in_used < priv->channels && input_index < 1.0)
-		{	printf ("Whoops!!!!   in_used : %ld     channels : %d     input_index : %f\n", priv->in_used, priv->channels, input_index) ;
+		if (SRC_DEBUG && priv->in_used < state->channels && input_index < 1.0)
+		{	printf ("Whoops!!!!   in_used : %ld     channels : %d     input_index : %f\n", priv->in_used, state->channels, input_index) ;
 			exit (1) ;
 			} ;
 
-		for (ch = 0 ; ch < priv->channels ; ch++)
-		{	data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - priv->channels + ch] + input_index *
-						(data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - priv->channels + ch])) ;
+		for (ch = 0 ; ch < state->channels ; ch++)
+		{	data->data_out [priv->out_gen] = (float) (data->data_in [priv->in_used - state->channels + ch] + input_index *
+						(data->data_in [priv->in_used + ch] - data->data_in [priv->in_used - state->channels + ch])) ;
 			priv->out_gen ++ ;
 			} ;
 
@@ -113,12 +112,12 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		priv->in_used += priv->channels * lrint (input_index - rem) ;
+		priv->in_used += state->channels * lrint (input_index - rem) ;
 		input_index = rem ;
 		} ;
 
 	if (priv->in_used > priv->in_count)
-	{	input_index += (priv->in_used - priv->in_count) / priv->channels ;
+	{	input_index += (priv->in_used - priv->in_count) / state->channels ;
 		priv->in_used = priv->in_count ;
 		} ;
 
@@ -125,14 +124,14 @@
 	state->last_position = input_index ;
 
 	if (priv->in_used > 0)
-		for (ch = 0 ; ch < priv->channels ; ch++)
-			priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
+		for (ch = 0 ; ch < state->channels ; ch++)
+			priv->last_value [ch] = data->data_in [priv->in_used - state->channels + ch] ;
 
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = priv->in_used / priv->channels ;
-	data->output_frames_gen = priv->out_gen / priv->channels ;
+	data->input_frames_used = priv->in_used / state->channels ;
+	data->output_frames_gen = priv->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* linear_vari_process */
@@ -179,7 +178,6 @@
 		return SRC_ERR_MALLOC_FAILED ;
 
 	priv->linear_magic_marker = LINEAR_MAGIC_MARKER ;
-	priv->channels = state->channels ;
 
 	state->const_process = linear_vari_process ;
 	state->vari_process = linear_vari_process ;
@@ -202,9 +200,8 @@
 	if (priv == NULL)
 		return ;
 
-	priv->channels = state->channels ;
 	priv->dirty = false ;
-	memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
+	memset (priv->last_value, 0, sizeof (priv->last_value [0]) * state->channels) ;
 
 	return ;
 } /* linear_reset */
@@ -217,7 +214,7 @@
 
 	LINEAR_DATA *to_priv = NULL ;
 	LINEAR_DATA* from_priv = (LINEAR_DATA*) from->private_data ;
-	size_t private_size = sizeof (*to_priv) + from_priv->channels * sizeof (float) ;
+	size_t private_size = sizeof (*to_priv) + from->channels * sizeof (float) ;
 
 	if ((to_priv = ZERO_ALLOC (LINEAR_DATA, private_size)) == NULL)
 		return SRC_ERR_MALLOC_FAILED ;
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -39,7 +39,6 @@
 typedef struct
 {	int		sinc_magic_marker ;
 
-	int		channels ;
 	long	in_count, in_used ;
 	long	out_count, out_gen ;
 
@@ -64,7 +63,7 @@
 static enum SRC_ERR sinc_stereo_vari_process (SRC_STATE *state, SRC_DATA *data) ;
 static enum SRC_ERR sinc_mono_vari_process (SRC_STATE *state, SRC_DATA *data) ;
 
-static int prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
+static int prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len) WARN_UNUSED ;
 
 static void sinc_reset (SRC_STATE *state) ;
 static enum SRC_ERR sinc_copy (SRC_STATE *from, SRC_STATE *to) ;
@@ -160,7 +159,6 @@
 	memset (&temp_filter, 0, sizeof (temp_filter)) ;
 
 	temp_filter.sinc_magic_marker = SINC_MAGIC_MARKER ;
-	temp_filter.channels = state->channels ;
 
 	if (state->channels > ARRAY_LEN (temp_filter.left_calc))
 		return SRC_ERR_BAD_CHANNEL_COUNT ;
@@ -220,10 +218,10 @@
 
 	temp_filter.b_len = 3 * (int) lrint ((temp_filter.coeff_half_len + 2.0) / temp_filter.index_inc * SRC_MAX_RATIO + 1) ;
 	temp_filter.b_len = MAX (temp_filter.b_len, 4096) ;
-	temp_filter.b_len *= temp_filter.channels ;
+	temp_filter.b_len *= state->channels ;
 	temp_filter.b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
 
-	if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
+	if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + state->channels))) == NULL)
 		return SRC_ERR_MALLOC_FAILED ;
 
 	*filter = temp_filter ;
@@ -259,7 +257,7 @@
 	memset (filter->buffer, 0, filter->b_len * sizeof (filter->buffer [0])) ;
 
 	/* Set this for a sanity check */
-	memset (filter->buffer + filter->b_len, 0xAA, filter->channels * sizeof (filter->buffer [0])) ;
+	memset (filter->buffer + filter->b_len, 0xAA, state->channels * sizeof (filter->buffer [0])) ;
 } /* sinc_reset */
 
 static enum SRC_ERR
@@ -270,7 +268,7 @@
 
 	SINC_FILTER *to_filter = NULL ;
 	SINC_FILTER* from_filter = (SINC_FILTER*) from->private_data ;
-	size_t private_length = sizeof (SINC_FILTER) + sizeof (from_filter->buffer [0]) * (from_filter->b_len + from_filter->channels) ;
+	size_t private_length = sizeof (SINC_FILTER) + sizeof (from_filter->buffer [0]) * (from_filter->b_len + from->channels) ;
 
 	if ((to_filter = ZERO_ALLOC (SINC_FILTER, private_length)) == NULL)
 		return SRC_ERR_MALLOC_FAILED ;
@@ -361,8 +359,8 @@
 	if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
 		return SRC_ERR_SIZE_INCOMPATIBILITY ;
 
-	filter->in_count = data->input_frames * filter->channels ;
-	filter->out_count = data->output_frames * filter->channels ;
+	filter->in_count = data->input_frames * state->channels ;
+	filter->out_count = data->output_frames * state->channels ;
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -376,12 +374,12 @@
 		count /= MIN (state->last_ratio, data->src_ratio) ;
 
 	/* Maximum coefficientson either side of center point. */
-	half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
+	half_filter_chan_len = state->channels * (int) (lrint (count) + 1) ;
 
 	input_index = state->last_position ;
 
 	rem = fmod_one (input_index) ;
-	filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+	filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 	input_index = rem ;
 
 	terminate = 1.0 / src_ratio + 1e-20 ;
@@ -393,7 +391,7 @@
 		samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
 
 		if (samples_in_hand <= half_filter_chan_len)
-		{	if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
+		{	if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
 				return state->error ;
 
 			samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
@@ -423,7 +421,7 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+		filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 		input_index = rem ;
 		} ;
 
@@ -432,14 +430,14 @@
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = filter->in_used / filter->channels ;
-	data->output_frames_gen = filter->out_gen / filter->channels ;
+	data->input_frames_used = filter->in_used / state->channels ;
+	data->output_frames_gen = filter->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* sinc_mono_vari_process */
 
 static inline void
-calc_output_stereo (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_stereo (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
 {	double		fraction, left [2], right [2], icoeff ;
 	increment_t	filter_index, max_filter_index ;
 	int			data_index, coeff_count, indx ;
@@ -451,7 +449,7 @@
 	filter_index = start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current - filter->channels * coeff_count ;
+	data_index = filter->b_current - channels * coeff_count ;
 
 	if (data_index < 0) /* Avoid underflow access to filter->buffer. */
 	{	int steps = int_div_ceil (-data_index, 2) ;
@@ -479,7 +477,7 @@
 	filter_index = increment - start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+	data_index = filter->b_current + channels * (1 + coeff_count) ;
 
 	right [0] = right [1] = 0.0 ;
 	do
@@ -517,8 +515,8 @@
 	if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
 		return SRC_ERR_SIZE_INCOMPATIBILITY ;
 
-	filter->in_count = data->input_frames * filter->channels ;
-	filter->out_count = data->output_frames * filter->channels ;
+	filter->in_count = data->input_frames * state->channels ;
+	filter->out_count = data->output_frames * state->channels ;
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -532,12 +530,12 @@
 		count /= MIN (state->last_ratio, data->src_ratio) ;
 
 	/* Maximum coefficientson either side of center point. */
-	half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
+	half_filter_chan_len = state->channels * (int) (lrint (count) + 1) ;
 
 	input_index = state->last_position ;
 
 	rem = fmod_one (input_index) ;
-	filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+	filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 	input_index = rem ;
 
 	terminate = 1.0 / src_ratio + 1e-20 ;
@@ -549,7 +547,7 @@
 		samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
 
 		if (samples_in_hand <= half_filter_chan_len)
-		{	if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
+		{	if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
 				return state->error ;
 
 			samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
@@ -571,7 +569,7 @@
 
 		start_filter_index = double_to_fp (input_index * float_increment) ;
 
-		calc_output_stereo (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+		calc_output_stereo (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
 		filter->out_gen += 2 ;
 
 		/* Figure out the next index. */
@@ -578,7 +576,7 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+		filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 		input_index = rem ;
 		} ;
 
@@ -587,14 +585,14 @@
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = filter->in_used / filter->channels ;
-	data->output_frames_gen = filter->out_gen / filter->channels ;
+	data->input_frames_used = filter->in_used / state->channels ;
+	data->output_frames_gen = filter->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* sinc_stereo_vari_process */
 
 static inline void
-calc_output_quad (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_quad (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
 {	double		fraction, left [4], right [4], icoeff ;
 	increment_t	filter_index, max_filter_index ;
 	int			data_index, coeff_count, indx ;
@@ -606,7 +604,7 @@
 	filter_index = start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current - filter->channels * coeff_count ;
+	data_index = filter->b_current - channels * coeff_count ;
 
 	if (data_index < 0) /* Avoid underflow access to filter->buffer. */
 	{	int steps = int_div_ceil (-data_index, 4) ;
@@ -634,7 +632,7 @@
 	filter_index = increment - start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+	data_index = filter->b_current + channels * (1 + coeff_count) ;
 
 	right [0] = right [1] = right [2] = right [3] = 0.0 ;
 	do
@@ -673,8 +671,8 @@
 	if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
 		return SRC_ERR_SIZE_INCOMPATIBILITY ;
 
-	filter->in_count = data->input_frames * filter->channels ;
-	filter->out_count = data->output_frames * filter->channels ;
+	filter->in_count = data->input_frames * state->channels ;
+	filter->out_count = data->output_frames * state->channels ;
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -688,12 +686,12 @@
 		count /= MIN (state->last_ratio, data->src_ratio) ;
 
 	/* Maximum coefficientson either side of center point. */
-	half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
+	half_filter_chan_len = state->channels * (int) (lrint (count) + 1) ;
 
 	input_index = state->last_position ;
 
 	rem = fmod_one (input_index) ;
-	filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+	filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 	input_index = rem ;
 
 	terminate = 1.0 / src_ratio + 1e-20 ;
@@ -705,7 +703,7 @@
 		samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
 
 		if (samples_in_hand <= half_filter_chan_len)
-		{	if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
+		{	if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
 				return state->error ;
 
 			samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
@@ -727,7 +725,7 @@
 
 		start_filter_index = double_to_fp (input_index * float_increment) ;
 
-		calc_output_quad (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+		calc_output_quad (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
 		filter->out_gen += 4 ;
 
 		/* Figure out the next index. */
@@ -734,7 +732,7 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+		filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 		input_index = rem ;
 		} ;
 
@@ -743,14 +741,14 @@
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = filter->in_used / filter->channels ;
-	data->output_frames_gen = filter->out_gen / filter->channels ;
+	data->input_frames_used = filter->in_used / state->channels ;
+	data->output_frames_gen = filter->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* sinc_quad_vari_process */
 
 static inline void
-calc_output_hex (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, double scale, float * output)
+calc_output_hex (SINC_FILTER *filter, int channels, increment_t increment, increment_t start_filter_index, double scale, float * output)
 {	double		fraction, left [6], right [6], icoeff ;
 	increment_t	filter_index, max_filter_index ;
 	int			data_index, coeff_count, indx ;
@@ -762,7 +760,7 @@
 	filter_index = start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current - filter->channels * coeff_count ;
+	data_index = filter->b_current - channels * coeff_count ;
 
 	if (data_index < 0) /* Avoid underflow access to filter->buffer. */
 	{	int steps = int_div_ceil (-data_index, 6) ;
@@ -790,7 +788,7 @@
 	filter_index = increment - start_filter_index ;
 	coeff_count = (max_filter_index - filter_index) / increment ;
 	filter_index = filter_index + coeff_count * increment ;
-	data_index = filter->b_current + filter->channels * (1 + coeff_count) ;
+	data_index = filter->b_current + channels * (1 + coeff_count) ;
 
 	right [0] = right [1] = right [2] = right [3] = right [4] = right [5] = 0.0 ;
 	do
@@ -828,8 +826,8 @@
 	if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
 		return SRC_ERR_SIZE_INCOMPATIBILITY ;
 
-	filter->in_count = data->input_frames * filter->channels ;
-	filter->out_count = data->output_frames * filter->channels ;
+	filter->in_count = data->input_frames * state->channels ;
+	filter->out_count = data->output_frames * state->channels ;
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -843,12 +841,12 @@
 		count /= MIN (state->last_ratio, data->src_ratio) ;
 
 	/* Maximum coefficientson either side of center point. */
-	half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
+	half_filter_chan_len = state->channels * (int) (lrint (count) + 1) ;
 
 	input_index = state->last_position ;
 
 	rem = fmod_one (input_index) ;
-	filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+	filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 	input_index = rem ;
 
 	terminate = 1.0 / src_ratio + 1e-20 ;
@@ -860,7 +858,7 @@
 		samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
 
 		if (samples_in_hand <= half_filter_chan_len)
-		{	if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
+		{	if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
 				return state->error ;
 
 			samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
@@ -882,7 +880,7 @@
 
 		start_filter_index = double_to_fp (input_index * float_increment) ;
 
-		calc_output_hex (filter, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+		calc_output_hex (filter, state->channels, increment, start_filter_index, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
 		filter->out_gen += 6 ;
 
 		/* Figure out the next index. */
@@ -889,7 +887,7 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+		filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 		input_index = rem ;
 		} ;
 
@@ -898,8 +896,8 @@
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = filter->in_used / filter->channels ;
-	data->output_frames_gen = filter->out_gen / filter->channels ;
+	data->input_frames_used = filter->in_used / state->channels ;
+	data->output_frames_gen = filter->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* sinc_hex_vari_process */
@@ -993,8 +991,8 @@
 	if (sizeof (filter->buffer [0]) != sizeof (data->data_in [0]))
 		return SRC_ERR_SIZE_INCOMPATIBILITY ;
 
-	filter->in_count = data->input_frames * filter->channels ;
-	filter->out_count = data->output_frames * filter->channels ;
+	filter->in_count = data->input_frames * state->channels ;
+	filter->out_count = data->output_frames * state->channels ;
 	filter->in_used = filter->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -1008,12 +1006,12 @@
 		count /= MIN (state->last_ratio, data->src_ratio) ;
 
 	/* Maximum coefficientson either side of center point. */
-	half_filter_chan_len = filter->channels * (int) (lrint (count) + 1) ;
+	half_filter_chan_len = state->channels * (int) (lrint (count) + 1) ;
 
 	input_index = state->last_position ;
 
 	rem = fmod_one (input_index) ;
-	filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+	filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 	input_index = rem ;
 
 	terminate = 1.0 / src_ratio + 1e-20 ;
@@ -1025,7 +1023,7 @@
 		samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
 
 		if (samples_in_hand <= half_filter_chan_len)
-		{	if ((state->error = prepare_data (filter, data, half_filter_chan_len)) != 0)
+		{	if ((state->error = prepare_data (filter, state->channels, data, half_filter_chan_len)) != 0)
 				return state->error ;
 
 			samples_in_hand = (filter->b_end - filter->b_current + filter->b_len) % filter->b_len ;
@@ -1047,7 +1045,7 @@
 
 		start_filter_index = double_to_fp (input_index * float_increment) ;
 
-		calc_output_multi (filter, increment, start_filter_index, filter->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
+		calc_output_multi (filter, increment, start_filter_index, state->channels, float_increment / filter->index_inc, data->data_out + filter->out_gen) ;
 		filter->out_gen += state->channels ;
 
 		/* Figure out the next index. */
@@ -1054,7 +1052,7 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (input_index - rem)) % filter->b_len ;
+		filter->b_current = (filter->b_current + state->channels * lrint (input_index - rem)) % filter->b_len ;
 		input_index = rem ;
 		} ;
 
@@ -1063,8 +1061,8 @@
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = filter->in_used / filter->channels ;
-	data->output_frames_gen = filter->out_gen / filter->channels ;
+	data->input_frames_used = filter->in_used / state->channels ;
+	data->output_frames_gen = filter->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* sinc_multichan_vari_process */
@@ -1073,7 +1071,7 @@
 */
 
 static int
-prepare_data (SINC_FILTER *filter, SRC_DATA *data, int half_filter_chan_len)
+prepare_data (SINC_FILTER *filter, int channels, SRC_DATA *data, int half_filter_chan_len)
 {	int len = 0 ;
 
 	if (filter->b_real_end >= 0)
@@ -1090,7 +1088,7 @@
 
 		filter->b_current = filter->b_end = half_filter_chan_len ;
 		}
-	else if (filter->b_end + half_filter_chan_len + filter->channels < filter->b_len)
+	else if (filter->b_end + half_filter_chan_len + channels < filter->b_len)
 	{	/*  Load data at current end position. */
 		len = MAX (filter->b_len - filter->b_current - half_filter_chan_len, 0) ;
 		}
@@ -1108,7 +1106,7 @@
 		} ;
 
 	len = MIN ((int) (filter->in_count - filter->in_used), len) ;
-	len -= (len % filter->channels) ;
+	len -= (len % channels) ;
 
 	if (len < 0 || filter->b_end + len > filter->b_len)
 		return SRC_ERR_SINC_PREPARE_DATA_BAD_LEN ;
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -25,7 +25,6 @@
 
 typedef struct
 {	int		zoh_magic_marker ;
-	int		channels ;
 	bool	dirty ;
 	long	in_count, in_used ;
 	long	out_count, out_gen ;
@@ -51,13 +50,13 @@
 
 	if (!priv->dirty)
 	{	/* If we have just been reset, set the last_value data. */
-		for (ch = 0 ; ch < priv->channels ; ch++)
+		for (ch = 0 ; ch < state->channels ; ch++)
 			priv->last_value [ch] = data->data_in [ch] ;
 		priv->dirty = true ;
 		} ;
 
-	priv->in_count = data->input_frames * priv->channels ;
-	priv->out_count = data->output_frames * priv->channels ;
+	priv->in_count = data->input_frames * state->channels ;
+	priv->out_count = data->output_frames * state->channels ;
 	priv->in_used = priv->out_gen = 0 ;
 
 	src_ratio = state->last_ratio ;
@@ -70,13 +69,13 @@
 	/* Calculate samples before first sample in input array. */
 	while (input_index < 1.0 && priv->out_gen < priv->out_count)
 	{
-		if (priv->in_used + priv->channels * input_index >= priv->in_count)
+		if (priv->in_used + state->channels * input_index >= priv->in_count)
 			break ;
 
 		if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
 			src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
 
-		for (ch = 0 ; ch < priv->channels ; ch++)
+		for (ch = 0 ; ch < state->channels ; ch++)
 		{	data->data_out [priv->out_gen] = priv->last_value [ch] ;
 			priv->out_gen ++ ;
 			} ;
@@ -86,17 +85,17 @@
 		} ;
 
 	rem = fmod_one (input_index) ;
-	priv->in_used += priv->channels * lrint (input_index - rem) ;
+	priv->in_used += state->channels * lrint (input_index - rem) ;
 	input_index = rem ;
 
 	/* Main processing loop. */
-	while (priv->out_gen < priv->out_count && priv->in_used + priv->channels * input_index <= priv->in_count)
+	while (priv->out_gen < priv->out_count && priv->in_used + state->channels * input_index <= priv->in_count)
 	{
 		if (priv->out_count > 0 && fabs (state->last_ratio - data->src_ratio) > SRC_MIN_RATIO_DIFF)
 			src_ratio = state->last_ratio + priv->out_gen * (data->src_ratio - state->last_ratio) / priv->out_count ;
 
-		for (ch = 0 ; ch < priv->channels ; ch++)
-		{	data->data_out [priv->out_gen] = data->data_in [priv->in_used - priv->channels + ch] ;
+		for (ch = 0 ; ch < state->channels ; ch++)
+		{	data->data_out [priv->out_gen] = data->data_in [priv->in_used - state->channels + ch] ;
 			priv->out_gen ++ ;
 			} ;
 
@@ -104,12 +103,12 @@
 		input_index += 1.0 / src_ratio ;
 		rem = fmod_one (input_index) ;
 
-		priv->in_used += priv->channels * lrint (input_index - rem) ;
+		priv->in_used += state->channels * lrint (input_index - rem) ;
 		input_index = rem ;
 		} ;
 
 	if (priv->in_used > priv->in_count)
-	{	input_index += (priv->in_used - priv->in_count) / priv->channels ;
+	{	input_index += (priv->in_used - priv->in_count) / state->channels ;
 		priv->in_used = priv->in_count ;
 		} ;
 
@@ -116,14 +115,14 @@
 	state->last_position = input_index ;
 
 	if (priv->in_used > 0)
-		for (ch = 0 ; ch < priv->channels ; ch++)
-			priv->last_value [ch] = data->data_in [priv->in_used - priv->channels + ch] ;
+		for (ch = 0 ; ch < state->channels ; ch++)
+			priv->last_value [ch] = data->data_in [priv->in_used - state->channels + ch] ;
 
 	/* Save current ratio rather then target ratio. */
 	state->last_ratio = src_ratio ;
 
-	data->input_frames_used = priv->in_used / priv->channels ;
-	data->output_frames_gen = priv->out_gen / priv->channels ;
+	data->input_frames_used = priv->in_used / state->channels ;
+	data->output_frames_gen = priv->out_gen / state->channels ;
 
 	return SRC_ERR_NO_ERROR ;
 } /* zoh_vari_process */
@@ -170,7 +169,6 @@
 		return SRC_ERR_MALLOC_FAILED ;
 
 	priv->zoh_magic_marker = ZOH_MAGIC_MARKER ;
-	priv->channels = state->channels ;
 
 	state->const_process = zoh_vari_process ;
 	state->vari_process = zoh_vari_process ;
@@ -193,9 +191,8 @@
 	if (priv == NULL)
 		return ;
 
-	priv->channels = state->channels ;
 	priv->dirty = false ;
-	memset (priv->last_value, 0, sizeof (priv->last_value [0]) * priv->channels) ;
+	memset (priv->last_value, 0, sizeof (priv->last_value [0]) * state->channels) ;
 
 	return ;
 } /* zoh_reset */
@@ -208,7 +205,7 @@
 
 	ZOH_DATA *to_priv = NULL ;
 	ZOH_DATA* from_priv = (ZOH_DATA*) from->private_data ;
-	size_t private_size = sizeof (*to_priv) + from_priv->channels * sizeof (float) ;
+	size_t private_size = sizeof (*to_priv) + from->channels * sizeof (float) ;
 
 	if ((to_priv = ZERO_ALLOC (ZOH_DATA, private_size)) == NULL)
 		return SRC_ERR_MALLOC_FAILED ;