Unified · Split
| @@ -25,7 +25,8 @@ · 24 unmodified lines | |||
| 25 | 25 | ||
| 26 | #include "util.h" | 26 | #include "util.h" |
| 27 | 27 | ||
| 28 | #define BUFFER_LEN 10000 | 28 | #define BUFFER_LEN 90000 |
| 29 | #define CB_READ_LEN 256 | ||
| 29 | 30 | ||
| 30 | #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0]))) | 31 | #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0]))) |
| 31 | 32 | ||
| @@ -66,8 +67,8 @@ main (void) · 34 unmodified lines | |||
| 66 | 67 | ||
| 67 | typedef struct | 68 | typedef struct |
| 68 | { int channels ; | 69 | { int channels ; |
| 69 | long total_frames ; | 70 | long count, total ; |
| 70 | float data [1024] ; | 71 | float data [BUFFER_LEN] ; |
| 71 | } TEST_CB_DATA ; | 72 | } TEST_CB_DATA ; |
| 72 | 73 | ||
| 73 | static long | 74 | static long |
| @@ -82,14 +83,13 @@ test_callback_func (void *cb_data, float **data) · 8 unmodified lines | |||
| 82 | if (data == NULL) | 83 | if (data == NULL) |
| 83 | return 0 ; | 84 | return 0 ; |
| 84 | 85 | ||
| 85 | *data = pcb_data->data ; | 86 | if (pcb_data->total - pcb_data->count > CB_READ_LEN) |
| 86 | 87 | frames = CB_READ_LEN ; | |
| 87 | if (ARRAY_LEN (pcb_data->data) / pcb_data->channels > pcb_data->total_frames) | ||
| 88 | frames = pcb_data->total_frames ; | ||
| 89 | else | 88 | else |
| 90 | frames = ARRAY_LEN (pcb_data->data) / pcb_data->channels ; | 89 | frames = pcb_data->total - pcb_data->count ; |
| 91 | 90 | ||
| 92 | pcb_data->total_frames -= frames ; | 91 | *data = pcb_data->data + pcb_data->count ; |
| 92 | pcb_data->count += frames ; | ||
| 93 | 93 | ||
| 94 | return frames ; | 94 | return frames ; |
| 95 | } /* test_callback_func */ | 95 | } /* test_callback_func */ |
| @@ -97,9 +97,9 @@ test_callback_func (void *cb_data, float **data) · 1 unmodified line | |||
| 97 | 97 | ||
| 98 | static void | 98 | static void |
| 99 | callback_test (int converter, double src_ratio) | 99 | callback_test (int converter, double src_ratio) |
| 100 | { static float output [BUFFER_LEN] ; | 100 | { static TEST_CB_DATA test_callback_data ; |
| 101 | static float output [BUFFER_LEN] ; | ||
| 101 | 102 | ||
| 102 | TEST_CB_DATA test_callback_data ; | ||
| 103 | SRC_STATE *src_state ; | 103 | SRC_STATE *src_state ; |
| 104 | 104 | ||
| 105 | long read_count, read_total ; | 105 | long read_count, read_total ; |
| @@ -127,7 +127,8 @@ callback_test (int converter, double src_ratio) · 21 unmodified lines | |||
| 127 | } ; | 127 | } ; |
| 128 | 128 | ||
| 129 | test_callback_data.channels = 1 ; | 129 | test_callback_data.channels = 1 ; |
| 130 | test_callback_data.total_frames = input_len ; | 130 | test_callback_data.count = 0 ; |
| 131 | test_callback_data.total = input_len ; | ||
| 131 | 132 | ||
| 132 | if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL) | 133 | if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL) |
| 133 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; | 134 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| @@ -135,10 +136,12 @@ callback_test (int converter, double src_ratio) · 1 unmodified line | |||
| 135 | } ; | 136 | } ; |
| 136 | 137 | ||
| 137 | read_total = 0 ; | 138 | read_total = 0 ; |
| 138 | while ((read_count = src_callback_read (src_state, src_ratio, BUFFER_LEN, output)) > 0) | 139 | do |
| 139 | { | 140 | { read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ; |
| 141 | read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ; | ||
| 140 | read_total += read_count ; | 142 | read_total += read_count ; |
| 141 | } ; | 143 | } |
| 144 | while (read_count > 0) ; | ||
| 142 | 145 | ||
| 143 | if ((error = src_error (src_state)) != 0) | 146 | if ((error = src_error (src_state)) != 0) |
| 144 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; | 147 | { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| @@ -148,7 +151,9 @@ callback_test (int converter, double src_ratio) · 3 unmodified lines | |||
| 148 | src_state = src_delete (src_state) ; | 151 | src_state = src_delete (src_state) ; |
| 149 | 152 | ||
| 150 | if (fabs (read_total - src_ratio * input_len) > 2) | 153 | if (fabs (read_total - src_ratio * input_len) > 2) |
| 151 | { printf ("\n\nLine %d : read_total %ld %g\n\n", __LINE__, read_total, src_ratio * input_len) ; | 154 | { printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ; |
| 155 | printf (" input len : %d\n", input_len) ; | ||
| 156 | printf (" output len : %ld (should be %g +/- 2)\n\n", read_total, floor (0.5 + src_ratio * input_len)) ; | ||
| 152 | exit (1) ; | 157 | exit (1) ; |
| 153 | } ; | 158 | } ; |
| 154 | 159 | ||