ref: adebe2f6b9d2d94fd5f630106729ef3fbca44057
parent: 5f4abc505329bcdd75bc2ec9ddf77c93e96b8820
author: Erik de Castro Lopo <erikd@miles>
date: Fri Sep 10 05:43:56 EDT 2004
Add function callback_reset_test().
--- a/tests/reset_test.c
+++ b/tests/reset_test.c
@@ -24,10 +24,15 @@
#include "util.h"
-#define BUFFER_LEN 1024
+#define BUFFER_LEN 2048
+#define CB_READ_LEN 256
-static void reset_test (int converter) ;
+static void process_reset_test (int converter) ;
+static void callback_reset_test (int converter) ;
+static float data_one [BUFFER_LEN] ;
+static float data_zero [BUFFER_LEN] ;
+
int
main (void)
{ /* Force output of the Electric Fence banner message. */
@@ -35,10 +40,14 @@
puts ("") ;
- reset_test (SRC_ZERO_ORDER_HOLD) ;
- reset_test (SRC_LINEAR) ;
- reset_test (SRC_SINC_FASTEST) ;
+ process_reset_test (SRC_ZERO_ORDER_HOLD) ;
+ process_reset_test (SRC_LINEAR) ;
+ process_reset_test (SRC_SINC_FASTEST) ;
+ callback_reset_test (SRC_ZERO_ORDER_HOLD) ;
+ callback_reset_test (SRC_LINEAR) ;
+ callback_reset_test (SRC_SINC_FASTEST) ;
+
puts ("") ;
return 0 ;
@@ -45,16 +54,14 @@
} /* main */
static void
-reset_test (int converter)
-{ static float data_one [BUFFER_LEN] ;
- static float data_zero [BUFFER_LEN] ;
- static float output [BUFFER_LEN] ;
+process_reset_test (int converter)
+{ static float output [BUFFER_LEN] ;
SRC_STATE *src_state ;
SRC_DATA src_data ;
int k, error ;
- printf ("\treset_test (%-28s) ....... ", src_get_name (converter)) ;
+ printf ("\tprocess_reset_test (%-28s) ....... ", src_get_name (converter)) ;
fflush (stdout) ;
for (k = 0 ; k < BUFFER_LEN ; k++)
@@ -111,7 +118,127 @@
src_state = src_delete (src_state) ;
puts ("ok") ;
-} /* reset_test */
+} /* process_reset_test */
+
+/*==============================================================================
+*/
+
+typedef struct
+{ int channels ;
+ long count, total ;
+ float *data ;
+} TEST_CB_DATA ;
+
+static long
+test_callback_func (void *cb_data, float **data)
+{ TEST_CB_DATA *pcb_data ;
+
+ long frames ;
+
+ if ((pcb_data = cb_data) == NULL)
+ return 0 ;
+
+ if (data == NULL)
+ return 0 ;
+
+ if (pcb_data->total - pcb_data->count > 0)
+ frames = pcb_data->total - pcb_data->count ;
+ else
+ frames = 0 ;
+
+ *data = pcb_data->data + pcb_data->count ;
+ pcb_data->count += frames ;
+
+ return frames ;
+} /* test_callback_func */
+
+static void
+callback_reset_test (int converter)
+{ static TEST_CB_DATA test_callback_data ;
+
+ static float output [BUFFER_LEN] ;
+
+ SRC_STATE *src_state ;
+
+ double src_ratio = 1.1 ;
+ long read_count, read_total ;
+ int k, error ;
+
+ printf ("\tcallback_reset_test (%-28s) ....... ", src_get_name (converter)) ;
+ fflush (stdout) ;
+
+ for (k = 0 ; k < ARRAY_LEN (data_one) ; k++)
+ { data_one [k] = 1.0 ;
+ data_zero [k] = 0.0 ;
+ } ;
+
+ if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL)
+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
+ exit (1) ;
+ } ;
+
+ /* Process a bunch of 1.0 valued samples. */
+ test_callback_data.channels = 1 ;
+ test_callback_data.count = 0 ;
+ test_callback_data.total = ARRAY_LEN (data_one) ;
+ test_callback_data.data = data_one ;
+
+ read_total = 0 ;
+ do
+ { read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
+ read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
+ read_total += read_count ;
+ }
+ while (read_count > 0) ;
+
+ /* Check for errors. */
+ if ((error = src_error (src_state)) != 0)
+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
+ exit (1) ;
+ } ;
+
+ /* Reset the state of the converter.*/
+ src_reset (src_state) ;
+
+ /* Process a bunch of 0.0 valued samples. */
+ test_callback_data.channels = 1 ;
+ test_callback_data.count = 0 ;
+ test_callback_data.total = ARRAY_LEN (data_zero) ;
+ test_callback_data.data = data_zero ;
+
+ /* Now process some zero data. */
+ read_total = 0 ;
+ do
+ { read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
+ read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
+ read_total += read_count ;
+ }
+ while (read_count > 0) ;
+
+ /* Check for errors. */
+ if ((error = src_error (src_state)) != 0)
+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
+ exit (1) ;
+ } ;
+
+ /* Finally make sure that the output data is zero ie reset was sucessful. */
+ for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
+ if (output [k] != 0.0)
+ { printf ("\n\nLine %d : output [%d] should be 0.0, is %f.\n\n", __LINE__, k, output [k]) ;
+ save_oct_float ("output.dat", data_one, ARRAY_LEN (data_one), output, ARRAY_LEN (output)) ;
+ exit (1) ;
+ } ;
+
+ /* Make sure that this function has been exported. */
+ src_set_ratio (src_state, 1.0) ;
+
+ /* Delete converter. */
+ src_state = src_delete (src_state) ;
+
+ puts ("ok") ;
+} /* callback_reset_test */
+
+
/*
** Do not edit or modify anything in this comment block.
** The arch-tag line is a file identity tag for the GNU Arch