| @@ -29,6 +29,7 @@ · 28 unmodified lines |
| 29 | #define CB_READ_LEN 256 | 29 | #define CB_READ_LEN 256 |
| 30 | | 30 | |
| 31 | static void callback_test (int converter, double ratio) ; | 31 | static void callback_test (int converter, double ratio) ; |
| | 32 | static void end_of_stream_test (int converter) ; |
| 32 | | 33 | |
| 33 | int | 34 | int |
| 34 | main (void) | 35 | main (void) |
| @@ -54,6 +55,12 @@ main (void) · 19 unmodified lines |
| 54 | | 55 | |
| 55 | puts ("") ; | 56 | puts ("") ; |
| 56 | | 57 | |
| | 58 | puts (" End of stream test :") ; |
| | 59 | end_of_stream_test (SRC_ZERO_ORDER_HOLD) ; |
| | 60 | end_of_stream_test (SRC_LINEAR) ; |
| | 61 | end_of_stream_test (SRC_SINC_FASTEST) ; |
| | 62 | |
| | 63 | puts ("") ; |
| 57 | return 0 ; | 64 | return 0 ; |
| 58 | } /* main */ | 65 | } /* main */ |
| 59 | | 66 | |
| @@ -63,6 +70,7 @@ main (void) · 3 unmodified lines |
| 63 | typedef struct | 70 | typedef struct |
| 64 | { int channels ; | 71 | { int channels ; |
| 65 | long count, total ; | 72 | long count, total ; |
| | 73 | int end_of_data ; |
| 66 | float data [BUFFER_LEN] ; | 74 | float data [BUFFER_LEN] ; |
| 67 | } TEST_CB_DATA ; | 75 | } TEST_CB_DATA ; |
| 68 | | 76 | |
| @@ -105,6 +113,7 @@ callback_test (int converter, double src_ratio) · 36 unmodified lines |
| 105 | | 113 | |
| 106 | test_callback_data.channels = 2 ; | 114 | test_callback_data.channels = 2 ; |
| 107 | test_callback_data.count = 0 ; | 115 | test_callback_data.count = 0 ; |
| | 116 | test_callback_data.end_of_data = 0 ; |
| 108 | test_callback_data.total = ARRAY_LEN (test_callback_data.data) ; | 117 | test_callback_data.total = ARRAY_LEN (test_callback_data.data) ; |
| 109 | | 118 | |
| 110 | if ((src_state = src_callback_new (test_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL) | 119 | if ((src_state = src_callback_new (test_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL) |
| @@ -141,3 +150,94 @@ callback_test (int converter, double src_ratio) · 30 unmodified lines |
| 141 | return ; | 150 | return ; |
| 142 | } /* callback_test */ | 151 | } /* callback_test */ |
| 143 | | 152 | |
| | 153 | /*===================================================================================== |
| | 154 | */ |
| | 155 | |
| | 156 | static long |
| | 157 | eos_callback_func (void *cb_data, float **data) |
| | 158 | { |
| | 159 | TEST_CB_DATA *pcb_data ; |
| | 160 | long frames ; |
| | 161 | |
| | 162 | if (data == NULL) |
| | 163 | return 0 ; |
| | 164 | |
| | 165 | if ((pcb_data = cb_data) == NULL) |
| | 166 | return 0 ; |
| | 167 | |
| | 168 | /* |
| | 169 | ** Return immediately if there is no more data. |
| | 170 | ** In this case, the output pointer 'data' will not be set and |
| | 171 | ** valgrind should not warn about it. |
| | 172 | */ |
| | 173 | if (pcb_data->end_of_data) |
| | 174 | return 0 ; |
| | 175 | |
| | 176 | if (pcb_data->total - pcb_data->count > CB_READ_LEN) |
| | 177 | frames = CB_READ_LEN / pcb_data->channels ; |
| | 178 | else |
| | 179 | frames = (pcb_data->total - pcb_data->count) / pcb_data->channels ; |
| | 180 | |
| | 181 | *data = pcb_data->data + pcb_data->count ; |
| | 182 | pcb_data->count += frames ; |
| | 183 | |
| | 184 | /* |
| | 185 | ** Set end_of_data so that the next call to the callback function will |
| | 186 | ** return zero ocunt without setting the 'data' pointer. |
| | 187 | */ |
| | 188 | if (pcb_data->total < 2 * pcb_data->count) |
| | 189 | pcb_data->end_of_data = 1 ; |
| | 190 | |
| | 191 | return frames ; |
| | 192 | } /* eos_callback_data */ |
| | 193 | |
| | 194 | |
| | 195 | static void |
| | 196 | end_of_stream_test (int converter) |
| | 197 | { static TEST_CB_DATA test_callback_data ; |
| | 198 | static float output [BUFFER_LEN] ; |
| | 199 | |
| | 200 | SRC_STATE *src_state ; |
| | 201 | |
| | 202 | double src_ratio = 0.3 ; |
| | 203 | long read_count, read_total ; |
| | 204 | int error ; |
| | 205 | |
| | 206 | printf ("\t%-30s ........... ", src_get_name (converter)) ; |
| | 207 | fflush (stdout) ; |
| | 208 | |
| | 209 | test_callback_data.channels = 2 ; |
| | 210 | test_callback_data.count = 0 ; |
| | 211 | test_callback_data.end_of_data = 0 ; |
| | 212 | test_callback_data.total = ARRAY_LEN (test_callback_data.data) ; |
| | 213 | |
| | 214 | if ((src_state = src_callback_new (eos_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL) |
| | 215 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| | 216 | exit (1) ; |
| | 217 | } ; |
| | 218 | |
| | 219 | read_total = 0 ; |
| | 220 | do |
| | 221 | { /* We will be throwing away output data, so just grab as much as possible. */ |
| | 222 | read_count = ARRAY_LEN (output) / test_callback_data.channels ; |
| | 223 | read_count = src_callback_read (src_state, src_ratio, read_count, output) ; |
| | 224 | read_total += read_count ; |
| | 225 | } |
| | 226 | while (read_count > 0) ; |
| | 227 | |
| | 228 | if ((error = src_error (src_state)) != 0) |
| | 229 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| | 230 | exit (1) ; |
| | 231 | } ; |
| | 232 | |
| | 233 | src_state = src_delete (src_state) ; |
| | 234 | |
| | 235 | if (test_callback_data.end_of_data == 0) |
| | 236 | { printf ("\n\nLine %d : test_callback_data.end_of_data should not be 0." |
| | 237 | " This is a bug in the test.\n\n", __LINE__) ; |
| | 238 | exit (1) ; |
| | 239 | } ; |
| | 240 | |
| | 241 | puts ("ok") ; |
| | 242 | return ; |
| | 243 | } /* end_of_stream_test */ |