History

Add function callback_reset_test().

Erik de Castro Lopo committed 22 years ago

Commit adebe2f1 parent 5f4abc51 file · +138 −11Browse files

Unified · Split

tests/reset_test.c+138−11
@@ -24,9 +24,14 @@ · 23 unmodified lines
2424
2525 #include "util.h"
2626
27−#define BUFFER_LEN 1024
27+#define BUFFER_LEN 2048
28+#define CB_READ_LEN 256
2829
29−static void reset_test (int converter) ;
30+static void process_reset_test (int converter) ;
31+static void callback_reset_test (int converter) ;
32+
33+static float data_one [BUFFER_LEN] ;
34+static float data_zero [BUFFER_LEN] ;
3035
3136 int
3237 main (void)
@@ -35,9 +40,13 @@ main (void) · 2 unmodified lines
3540
3641 puts ("") ;
3742
38− reset_test (SRC_ZERO_ORDER_HOLD) ;
39− reset_test (SRC_LINEAR) ;
40− reset_test (SRC_SINC_FASTEST) ;
43+ process_reset_test (SRC_ZERO_ORDER_HOLD) ;
44+ process_reset_test (SRC_LINEAR) ;
45+ process_reset_test (SRC_SINC_FASTEST) ;
46+
47+ callback_reset_test (SRC_ZERO_ORDER_HOLD) ;
48+ callback_reset_test (SRC_LINEAR) ;
49+ callback_reset_test (SRC_SINC_FASTEST) ;
4150
4251 puts ("") ;
4352
@@ -45,16 +54,14 @@ main (void) · 1 unmodified line
4554 } /* main */
4655
4756 static void
48−reset_test (int converter)
49−{ static float data_one [BUFFER_LEN] ;
50− static float data_zero [BUFFER_LEN] ;
51− static float output [BUFFER_LEN] ;
57+process_reset_test (int converter)
58+{ static float output [BUFFER_LEN] ;
5259
5360 SRC_STATE *src_state ;
5461 SRC_DATA src_data ;
5562 int k, error ;
5663
57− printf ("\treset_test (%-28s) ....... ", src_get_name (converter)) ;
64+ printf ("\tprocess_reset_test (%-28s) ....... ", src_get_name (converter)) ;
5865 fflush (stdout) ;
5966
6067 for (k = 0 ; k < BUFFER_LEN ; k++)
@@ -111,7 +118,127 @@ reset_test (int converter) · 50 unmodified lines
111118 src_state = src_delete (src_state) ;
112119
113120 puts ("ok") ;
114−} /* reset_test */
121+} /* process_reset_test */
122+
123+/*==============================================================================
124+*/
125+
126+typedef struct
127+{ int channels ;
128+ long count, total ;
129+ float *data ;
130+} TEST_CB_DATA ;
131+
132+static long
133+test_callback_func (void *cb_data, float **data)
134+{ TEST_CB_DATA *pcb_data ;
135+
136+ long frames ;
137+
138+ if ((pcb_data = cb_data) == NULL)
139+ return 0 ;
140+
141+ if (data == NULL)
142+ return 0 ;
143+
144+ if (pcb_data->total - pcb_data->count > 0)
145+ frames = pcb_data->total - pcb_data->count ;
146+ else
147+ frames = 0 ;
148+
149+ *data = pcb_data->data + pcb_data->count ;
150+ pcb_data->count += frames ;
151+
152+ return frames ;
153+} /* test_callback_func */
154+
155+static void
156+callback_reset_test (int converter)
157+{ static TEST_CB_DATA test_callback_data ;
158+
159+ static float output [BUFFER_LEN] ;
160+
161+ SRC_STATE *src_state ;
162+
163+ double src_ratio = 1.1 ;
164+ long read_count, read_total ;
165+ int k, error ;
166+
167+ printf ("\tcallback_reset_test (%-28s) ....... ", src_get_name (converter)) ;
168+ fflush (stdout) ;
169+
170+ for (k = 0 ; k < ARRAY_LEN (data_one) ; k++)
171+ { data_one [k] = 1.0 ;
172+ data_zero [k] = 0.0 ;
173+ } ;
174+
175+ if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL)
176+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
177+ exit (1) ;
178+ } ;
179+
180+ /* Process a bunch of 1.0 valued samples. */
181+ test_callback_data.channels = 1 ;
182+ test_callback_data.count = 0 ;
183+ test_callback_data.total = ARRAY_LEN (data_one) ;
184+ test_callback_data.data = data_one ;
185+
186+ read_total = 0 ;
187+ do
188+ { read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
189+ read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
190+ read_total += read_count ;
191+ }
192+ while (read_count > 0) ;
193+
194+ /* Check for errors. */
195+ if ((error = src_error (src_state)) != 0)
196+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
197+ exit (1) ;
198+ } ;
199+
200+ /* Reset the state of the converter.*/
201+ src_reset (src_state) ;
202+
203+ /* Process a bunch of 0.0 valued samples. */
204+ test_callback_data.channels = 1 ;
205+ test_callback_data.count = 0 ;
206+ test_callback_data.total = ARRAY_LEN (data_zero) ;
207+ test_callback_data.data = data_zero ;
208+
209+ /* Now process some zero data. */
210+ read_total = 0 ;
211+ do
212+ { read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
213+ read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
214+ read_total += read_count ;
215+ }
216+ while (read_count > 0) ;
217+
218+ /* Check for errors. */
219+ if ((error = src_error (src_state)) != 0)
220+ { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
221+ exit (1) ;
222+ } ;
223+
224+ /* Finally make sure that the output data is zero ie reset was sucessful. */
225+ for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
226+ if (output [k] != 0.0)
227+ { printf ("\n\nLine %d : output [%d] should be 0.0, is %f.\n\n", __LINE__, k, output [k]) ;
228+ save_oct_float ("output.dat", data_one, ARRAY_LEN (data_one), output, ARRAY_LEN (output)) ;
229+ exit (1) ;
230+ } ;
231+
232+ /* Make sure that this function has been exported. */
233+ src_set_ratio (src_state, 1.0) ;
234+
235+ /* Delete converter. */
236+ src_state = src_delete (src_state) ;
237+
238+ puts ("ok") ;
239+} /* callback_reset_test */
240+
241+
115242 /*
116243 ** Do not edit or modify anything in this comment block.
117244 ** The arch-tag line is a file identity tag for the GNU Arch

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t