| @@ -24,20 +24,20 @@ · 23 unmodified lines |
| 24 | 24 | |
| 25 | 25 | #include "util.h" |
| 26 | 26 | |
| 27 | | −#define BUFFER_LEN ((1 << 16) - 20) |
| 27 | +#define BUFFER_LEN (1 << 16) |
| 28 | 28 | |
| 29 | 29 | static void varispeed_test (int converter) ; |
| 30 | 30 | |
| 31 | 31 | int |
| 32 | 32 | main (void) |
| 33 | 33 | { |
| 34 | | − puts (" Zero Order Hold interpolator: ") ; |
| 34 | + printf (" Zero Order Hold interpolator : ") ; |
| 35 | 35 | varispeed_test (SRC_ZERO_ORDER_HOLD) ; |
| 36 | 36 | |
| 37 | | − puts (" Linear interpolator: ") ; |
| 37 | + printf (" Linear interpolator : ") ; |
| 38 | 38 | varispeed_test (SRC_LINEAR) ; |
| 39 | 39 | |
| 40 | | − puts (" Sinc interpolator: ") ; |
| 40 | + printf (" Sinc interpolator : ") ; |
| 41 | 41 | varispeed_test (SRC_SINC_FASTEST) ; |
| 42 | 42 | |
| 43 | 43 | return 0 ; |
| @@ -45,37 +45,16 @@ main (void) · 1 unmodified line |
| 45 | 45 | |
| 46 | 46 | static void |
| 47 | 47 | varispeed_test (int converter) |
| 48 | | −{ static float input [BUFFER_LEN], output [BUFFER_LEN] ; |
| 49 | | − double src_ratio ; |
| 48 | +{ static float input [BUFFER_LEN], output [2 * BUFFER_LEN] ; |
| 49 | + double sine_freq ; |
| 50 | 50 | |
| 51 | 51 | SRC_STATE *src_state ; |
| 52 | 52 | SRC_DATA src_data ; |
| 53 | 53 | |
| 54 | | − int input_len, output_len, current_in, current_out ; |
| 55 | | − int k, error, terminate ; |
| 54 | + int error ; |
| 56 | 55 | |
| 57 | | −/* Erik */ |
| 58 | | −for (k = 0 ; k < BUFFER_LEN ; k++) input [k] = k * 1.0 ; |
| 59 | | − |
| 60 | | − /* Calculate maximun input and output lengths. */ |
| 61 | | − if (src_ratio >= 1.0) |
| 62 | | − { output_len = BUFFER_LEN ; |
| 63 | | − input_len = (int) floor (BUFFER_LEN / src_ratio) ; |
| 64 | | − } |
| 65 | | − else |
| 66 | | − { input_len = BUFFER_LEN ; |
| 67 | | − output_len = (int) floor (BUFFER_LEN * src_ratio) ; |
| 68 | | − } ; |
| 69 | | − |
| 70 | | − /* Reduce input_len by 10 so output is longer than necessary. */ |
| 71 | | − input_len -= 20 ; |
| 72 | | − |
| 73 | | − if (output_len > BUFFER_LEN) |
| 74 | | − { printf ("\n\nLine %d : output_len > BUFFER_LEN\n\n", __LINE__) ; |
| 75 | | − exit (1) ; |
| 76 | | − } ; |
| 77 | | − |
| 78 | | − current_in = current_out = 0 ; |
| 56 | + sine_freq = 0.0011 ; |
| 57 | + gen_windowed_sines (1, &sine_freq, 1.0, input, ARRAY_LEN (input)) ; |
| 79 | 58 | |
| 80 | 59 | /* Perform sample rate conversion. */ |
| 81 | 60 | if ((src_state = src_new (converter, 1, &error)) == NULL) |
| @@ -83,102 +62,34 @@ for (k = 0 ; k < BUFFER_LEN ; k++) input [k] = k * 1.0 ; · 1 unmodified line |
| 83 | 62 | exit (1) ; |
| 84 | 63 | } ; |
| 85 | 64 | |
| 86 | | − src_data.end_of_input = 0 ; /* Set this later. */ |
| 65 | + src_data.end_of_input = 1 ; |
| 87 | 66 | |
| 88 | 67 | src_data.data_in = input ; |
| 68 | + src_data.input_frames = ARRAY_LEN (input) ; |
| 89 | 69 | |
| 90 | | − src_data.src_ratio = src_ratio ; |
| 70 | + src_data.src_ratio = 3.0 ; |
| 91 | 71 | |
| 92 | 72 | src_data.data_out = output ; |
| 93 | | − src_data.output_frames = ARRAY_LEN (output) / 10 ; |
| 94 | | − |
| 95 | | − terminate = 1 + (int) ceil ((src_ratio >= 1.0) ? src_ratio : 1.0 / src_ratio) ; |
| 96 | | − |
| 97 | | − while (1) |
| 98 | | − { |
| 99 | | − src_data.input_frames = next_block_length (0) ; |
| 100 | | − src_data.input_frames = MIN (src_data.input_frames, input_len - current_in) ; |
| 101 | | − |
| 102 | | − src_data.output_frames = ARRAY_LEN (output) - current_out ; |
| 103 | | − /*-Erik MIN (src_data.output_frames, output_len - current_out) ;-*/ |
| 104 | | − |
| 105 | | − src_data.end_of_input = (current_in >= input_len) ? 1 : 0 ; |
| 106 | | − |
| 107 | | − if ((error = src_process (src_state, &src_data))) |
| 108 | | − { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 109 | | − printf (" src_data.input_frames : %ld\n", src_data.input_frames) ; |
| 110 | | − printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ; |
| 111 | | − exit (1) ; |
| 112 | | − } ; |
| 113 | | − |
| 114 | | − if (src_data.end_of_input && src_data.output_frames_gen == 0) |
| 115 | | − break ; |
| 116 | | − |
| 117 | | − if (src_data.input_frames_used > src_data.input_frames) |
| 118 | | − { printf ("\n\nLine %d : input_frames_used > input_frames\n\n", __LINE__) ; |
| 119 | | − printf (" src_data.input_frames : %ld\n", src_data.input_frames) ; |
| 120 | | − printf (" src_data.input_frames_used : %ld\n", src_data.input_frames_used) ; |
| 121 | | − printf (" src_data.output_frames : %ld\n", src_data.output_frames) ; |
| 122 | | − printf (" src_data.output_frames_gen : %ld\n\n", src_data.output_frames_gen) ; |
| 123 | | − exit (1) ; |
| 124 | | − } ; |
| 125 | | − |
| 126 | | − if (src_data.input_frames_used < 0) |
| 127 | | − { printf ("\n\nLine %d : input_frames_used (%ld) < 0\n\n", __LINE__, src_data.input_frames_used) ; |
| 128 | | − exit (1) ; |
| 129 | | − } ; |
| 130 | | − |
| 131 | | − if (src_data.output_frames_gen < 0) |
| 132 | | − { printf ("\n\nLine %d : output_frames_gen (%ld) < 0\n\n", __LINE__, src_data.output_frames_gen) ; |
| 133 | | − exit (1) ; |
| 134 | | − } ; |
| 135 | | − |
| 136 | | − current_in += src_data.input_frames_used ; |
| 137 | | − current_out += src_data.output_frames_gen ; |
| 138 | | − |
| 139 | | − if (current_in > input_len + terminate) |
| 140 | | − { printf ("\n\nLine %d : current_in (%d) > input_len (%d + %d)\n\n", __LINE__, current_in, input_len, terminate) ; |
| 141 | | − exit (1) ; |
| 142 | | − } ; |
| 143 | | − |
| 144 | | − if (current_out > output_len) |
| 145 | | − { printf ("\n\nLine %d : current_out (%d) > output_len (%d)\n\n", __LINE__, current_out, output_len) ; |
| 146 | | − exit (1) ; |
| 147 | | − } ; |
| 148 | | − |
| 149 | | − if (src_data.input_frames_used > input_len) |
| 150 | | − { printf ("\n\nLine %d : input_frames_used (%ld) > %d\n\n", __LINE__, src_data.input_frames_used, input_len) ; |
| 151 | | − exit (1) ; |
| 152 | | − } ; |
| 153 | | − |
| 154 | | − if (src_data.output_frames_gen > output_len) |
| 155 | | − { printf ("\n\nLine %d : output_frames_gen (%ld) > %d\n\n", __LINE__, src_data.output_frames_gen, output_len) ; |
| 156 | | − exit (1) ; |
| 157 | | − } ; |
| 158 | | − |
| 159 | | − if (src_data.data_in == NULL && src_data.output_frames_gen == 0) |
| 160 | | − break ; |
| 161 | | − |
| 162 | | − |
| 163 | | − src_data.data_in += src_data.input_frames_used ; |
| 164 | | − src_data.data_out += src_data.output_frames_gen ; |
| 165 | | − } ; |
| 166 | | − |
| 167 | | − src_state = src_delete (src_state) ; |
| 73 | + src_data.output_frames = ARRAY_LEN (output) ; |
| 168 | 74 | |
| 169 | | − if (fabs (current_out - src_ratio * input_len) > terminate) |
| 170 | | − { printf ("\n\nLine %d : bad output data length %d should be %2.1f +/- %d.\n", __LINE__, |
| 171 | | − current_out, src_ratio * input_len, terminate) ; |
| 172 | | − printf ("\tsrc_ratio : %.4f\n", src_ratio) ; |
| 173 | | − printf ("\tinput_len : %d\n\tinput_used : %d\n", input_len, current_in) ; |
| 174 | | − printf ("\toutput_len : %d\n\toutput_gen : %d\n\n", output_len, current_out) ; |
| 75 | + if ((error = src_set_ratio (src_state, 1.0 / src_data.src_ratio))) |
| 76 | + { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 175 | 77 | exit (1) ; |
| 176 | 78 | } ; |
| 79 | + |
| 80 | + if ((error = src_process (src_state, &src_data))) |
| 81 | + { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; |
| 82 | + printf (" src_data.input_frames : %ld\n", src_data.input_frames) ; |
| 83 | + printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ; |
| 84 | + exit (1) ; |
| 85 | + } ; |
| 86 | + |
| 87 | + src_state = src_delete (src_state) ; |
| 177 | 88 | |
| 178 | | − if (current_in != input_len) |
| 89 | + if (src_data.input_frames_used != ARRAY_LEN (input)) |
| 179 | 90 | { printf ("\n\nLine %d : unused input.\n", __LINE__) ; |
| 180 | | − printf ("\tinput_len : %d\n", input_len) ; |
| 181 | | − printf ("\tinput_frames_used : %d\n\n", current_in) ; |
| 91 | + printf ("\tinput_len : %d\n", ARRAY_LEN (input)) ; |
| 92 | + printf ("\tinput_frames_used : %ld\n\n", src_data.input_frames_used) ; |
| 182 | 93 | exit (1) ; |
| 183 | 94 | } ; |
| 184 | 95 | |