shithub: libsamplerate

Download patch

ref: 32a06fea3c26fb907291f14bd86b845a46b912e9
parent: 186d15fc4e3ea3c88243fcfbab6b4d1ac4fcba9e
author: Erik de Castro Lopo <erikd@miles>
date: Tue Aug 2 07:11:35 EDT 2005

src_(zoh|linear).c : Improve calculation of input_index.

--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -54,7 +54,7 @@
 static int
 linear_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	LINEAR_DATA *linear ;
-	double		src_ratio, input_index ;
+	double		src_ratio, input_index, rem ;
 	int			ch ;
 
 	if (psrc->private_data == NULL)
@@ -110,9 +110,10 @@
 
 		/* Figure out the next index. */
 		input_index += 1.0 / src_ratio ;
+		rem = fmod (input_index, 1.0) ;
 
-		linear->in_used += linear->channels * lrint (floor (input_index)) ;
-		input_index -= floor (input_index) ;
+		linear->in_used += linear->channels * lrint (input_index - rem) ;
+		input_index = rem ;
 		} ;
 
 	if (linear->in_used > linear->in_count)
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -52,7 +52,7 @@
 static int
 zoh_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	ZOH_DATA 	*zoh ;
-	double		src_ratio, input_index ;
+	double		src_ratio, input_index, rem ;
 	int			ch ;
 
 	if (psrc->private_data == NULL)
@@ -85,8 +85,9 @@
 		input_index += 1.0 / src_ratio ;
 		} ;
 
-	zoh->in_used += zoh->channels * lrint (floor (input_index)) ;
-	input_index -= floor (input_index) ;
+	rem = fmod (input_index, 1.0) ;
+	zoh->in_used += zoh->channels * lrint (input_index - rem) ;
+	input_index = rem ;
 
 	/* Main processing loop. */
 	while (zoh->out_gen < zoh->out_count && zoh->in_used + zoh->channels * input_index <= zoh->in_count)
@@ -101,9 +102,10 @@
 
 		/* Figure out the next index. */
 		input_index += 1.0 / src_ratio ;
+		rem = fmod (input_index, 1.0) ;
 
-		zoh->in_used += zoh->channels * lrint (floor (input_index)) ;
-		input_index -= floor (input_index) ;
+		zoh->in_used += zoh->channels * lrint (input_index - rem) ;
+		input_index = rem ;
 		} ;
 
 	if (zoh->in_used > zoh->in_count)