shithub: libsamplerate

Download patch

ref: 3a6cc4f961981fece7cf4844b389205b4d0522ce
parent: b2cc20febf5d8bc50eaa4d6ad03c67d6f303d77f
author: Erik de Castro Lopo <erikd@miles>
date: Wed Aug 10 23:59:52 EDT 2005

Fix a bug in ZOH and LINEAR converters found after new test was added.

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-08-11  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
+
+    * tests/termination_test.c
+    Rename term_test() to init_term_test() and add extra test functionality
+    to sanity test the first sample output after reset.
+
+    * src/src_zoh.c src/src_linear.c
+    Fix bug found by new test. Thanks Stas Sergeev for bringint this to my
+    attention.
+
 2005-08-02  Erik de Castro Lopo  <erikd AT mega-nerd DOT com>
 
     * doc/Makefile.am
@@ -53,7 +63,7 @@
     * configure.ac Win32/Makefile.mingw.in
     Add preliminary support for compiling on Win32 using MinGW.
 
-    * configure.ac 
+    * configure.ac
     Bump version to 0.1.2.
     Add --enable-gcc-werror configure option.
 
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -43,6 +43,7 @@
 typedef struct
 {	int		linear_magic_marker ;
 	int		channels ;
+	int		reset ;
 	long	in_count, in_used ;
 	long	out_count, out_gen ;
 	float	last_value [1] ;
@@ -62,6 +63,13 @@
 
 	linear = (LINEAR_DATA*) psrc->private_data ;
 
+	if (linear->reset)
+	{	/* If we have just been reset, set the last_value data. */
+		for (ch = 0 ; ch < linear->channels ; ch++)
+			linear->last_value [ch] = data->data_in [ch] ;
+		linear->reset = 0 ;
+		} ;
+
 	linear->in_count = data->input_frames * linear->channels ;
 	linear->out_count = data->output_frames * linear->channels ;
 	linear->in_used = linear->out_gen = 0 ;
@@ -200,6 +208,9 @@
 	linear = (LINEAR_DATA*) psrc->private_data ;
 	if (linear == NULL)
 		return ;
+
+	linear->channels = psrc->channels ;
+	linear->reset = 1 ;
 
 	memset (linear->last_value, 0, sizeof (linear->last_value [0]) * linear->channels) ;
 } /* linear_reset */
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -41,6 +41,7 @@
 typedef struct
 {	int		zoh_magic_marker ;
 	int		channels ;
+	int		reset ;
 	long	in_count, in_used ;
 	long	out_count, out_gen ;
 	float	last_value [1] ;
@@ -60,6 +61,13 @@
 
 	zoh = (ZOH_DATA*) psrc->private_data ;
 
+	if (zoh->reset)
+	{	/* If we have just been reset, set the last_value data. */
+		for (ch = 0 ; ch < zoh->channels ; ch++)
+			zoh->last_value [ch] = data->data_in [ch] ;
+		zoh->reset = 0 ;
+		} ;
+
 	zoh->in_count = data->input_frames * zoh->channels ;
 	zoh->out_count = data->output_frames * zoh->channels ;
 	zoh->in_used = zoh->out_gen = 0 ;
@@ -194,6 +202,7 @@
 		return ;
 
 	zoh->channels = psrc->channels ;
+	zoh->reset = 1 ;
 	memset (zoh->last_value, 0, sizeof (zoh->last_value [0]) * zoh->channels) ;
 
 	return ;