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
24 24
25#include "util.h"25#include "util.h"
26 26
27#define BUFFER_LEN 102427#define BUFFER_LEN 2048
28#define CB_READ_LEN 256
28 29
29static void reset_test (int converter) ;30static void process_reset_test (int converter) ;
31static void callback_reset_test (int converter) ;
32
33static float data_one [BUFFER_LEN] ;
34static float data_zero [BUFFER_LEN] ;
30 35
31int36int
32main (void)37main (void)
@@ -35,9 +40,13 @@ main (void) · 2 unmodified lines
35 40
36 puts ("") ;41 puts ("") ;
37 42
38 reset_test (SRC_ZERO_ORDER_HOLD) ;43 process_reset_test (SRC_ZERO_ORDER_HOLD) ;
39 reset_test (SRC_LINEAR) ;44 process_reset_test (SRC_LINEAR) ;
40 reset_test (SRC_SINC_FASTEST) ;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) ;
41 50
42 puts ("") ;51 puts ("") ;
43 52
@@ -45,16 +54,14 @@ main (void) · 1 unmodified line
45} /* main */54} /* main */
46 55
47static void56static void
48reset_test (int converter)57process_reset_test (int converter)
49{ static float data_one [BUFFER_LEN] ;58{ static float output [BUFFER_LEN] ;
50 static float data_zero [BUFFER_LEN] ;
51 static float output [BUFFER_LEN] ;
52 59
53 SRC_STATE *src_state ;60 SRC_STATE *src_state ;
54 SRC_DATA src_data ;61 SRC_DATA src_data ;
55 int k, error ;62 int k, error ;
56 63
57 printf ("\treset_test (%-28s) ....... ", src_get_name (converter)) ;64 printf ("\tprocess_reset_test (%-28s) ....... ", src_get_name (converter)) ;
58 fflush (stdout) ;65 fflush (stdout) ;
59 66
60 for (k = 0 ; k < BUFFER_LEN ; k++)67 for (k = 0 ; k < BUFFER_LEN ; k++)
@@ -111,7 +118,127 @@ reset_test (int converter) · 50 unmodified lines
111 src_state = src_delete (src_state) ;118 src_state = src_delete (src_state) ;
112 119
113 puts ("ok") ;120 puts ("ok") ;
114} /* reset_test */121} /* process_reset_test */
122
123/*==============================================================================
124*/
125
126typedef struct
127{ int channels ;
128 long count, total ;
129 float *data ;
130} TEST_CB_DATA ;
131
132static long
133test_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
155static void
156callback_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
115/*242/*
116** Do not edit or modify anything in this comment block.243** Do not edit or modify anything in this comment block.
117** The arch-tag line is a file identity tag for the GNU Arch 244** 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