shithub: libsamplerate

Download patch

ref: f714fb9316d49806397393728a0ba71336913ff5
parent: 7d077a4bfa2ad0c667b2c0e2625cce8acf9b4217
author: Erik de Castro Lopo <erikd@miles>
date: Sun Jun 27 09:13:15 EDT 2004

Use fmod() to calculate input_index. This is more resitant to rounding errors than -= floor(input_index).

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 2004-06-27  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
 
     * src/src_sinc.c
+    Use fmod() to calculate input_index. This is more resitant to rounding
+    errors than input_index -= floor (input_index).
+
+2004-06-25  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
+
+    * src/src_sinc.c
     Removed redundant field in SINC_FILTER struct.
 
 2004-06-15  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -251,7 +251,7 @@
 static int
 sinc_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	SINC_FILTER *filter ;
-	double		input_index, src_ratio, count, float_increment, terminate ;
+	double		input_index, src_ratio, count, float_increment, terminate, rem ;
 	increment_t	increment, start_filter_index ;
 	int			half_filter_chan_len, samples_in_hand, ch ;
 
@@ -331,9 +331,11 @@
 
 		/* Figure out the next index. */
 		input_index += 1.0 / src_ratio ;
+		rem = fmod (input_index, 1.0) ;
+		input_index -= rem ;
 
-		filter->b_current = (filter->b_current + filter->channels * lrint (floor (input_index))) % filter->b_len ;
-		input_index -= floor (input_index) ;
+		filter->b_current = (filter->b_current + filter->channels * lrint (round (input_index))) % filter->b_len ;
+		input_index = rem ;
 		} ;
 
 	psrc->last_position = input_index ;