Unified · Split
| @@ -59,7 +59,7 @@ main (void) · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | printf ("Time : %5.2f secs.\n", (1.0 * clock_time) / CLOCKS_PER_SEC) ; |
| 61 | 61 | printf ("Throughput : %d samples/sec\n", (int) floor (src_data.output_frames_gen / ((1.0 * clock_time) / CLOCKS_PER_SEC))) ; |
| 62 | − printf ("SNR : %6.2f dB\n", calculate_snr (output, SNR_LEN)) ; | |
| 62 | + printf ("SNR : %6.2f dB\n", calculate_snr (output, SNR_LEN, 1)) ; | |
| 63 | 63 | |
| 64 | 64 | return 0 ; |
| 65 | 65 | } /* main */ |
| @@ -35,7 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | |
| 36 | 36 | static void log_mag_spectrum (double *input, int len, double *magnitude) ; |
| 37 | 37 | static void smooth_mag_spectrum (double *magnitude, int len) ; |
| 38 | −static double find_snr (const double *magnitude, int len) ; | |
| 38 | +static double find_snr (const double *magnitude, int len, int expected_peaks) ; | |
| 39 | 39 | |
| 40 | 40 | typedef struct |
| 41 | 41 | { double peak ; |
| @@ -43,7 +43,7 @@ typedef struct · 1 unmodified line | ||
| 43 | 43 | } PEAK_DATA ; |
| 44 | 44 | |
| 45 | 45 | double |
| 46 | −calculate_snr (float *data, int len) | |
| 46 | +calculate_snr (float *data, int len, int expected_peaks) | |
| 47 | 47 | { static double magnitude [MAX_SPEC_LEN] ; |
| 48 | 48 | static double datacopy [MAX_SPEC_LEN] ; |
| 49 | 49 | |
| @@ -67,7 +67,7 @@ calculate_snr (float *data, int len) · 17 unmodified lines | ||
| 67 | 67 | log_mag_spectrum (datacopy, len, magnitude) ; |
| 68 | 68 | smooth_mag_spectrum (magnitude, len / 2) ; |
| 69 | 69 | |
| 70 | − snr = find_snr (magnitude, len) ; | |
| 70 | + snr = find_snr (magnitude, len, expected_peaks) ; | |
| 71 | 71 | |
| 72 | 72 | return snr ; |
| 73 | 73 | } /* calculate_snr */ |
| @@ -144,7 +144,7 @@ peak_compare (const void *vp1, const void *vp2) · 70 unmodified lines | ||
| 144 | 144 | } /* peak_compare */ |
| 145 | 145 | |
| 146 | 146 | static double |
| 147 | −find_snr (const double *magnitude, int len) | |
| 147 | +find_snr (const double *magnitude, int len, int expected_peaks) | |
| 148 | 148 | { PEAK_DATA peaks [MAX_PEAKS] ; |
| 149 | 149 | |
| 150 | 150 | int k, peak_count = 0 ; |
| @@ -168,8 +168,8 @@ find_snr (const double *magnitude, int len) · 17 unmodified lines | ||
| 168 | 168 | } ; |
| 169 | 169 | } ; |
| 170 | 170 | |
| 171 | − if (peak_count < MAX_PEAKS / 2) | |
| 172 | − { printf ("\n%s : line %d : bad peak_count (%d).\n\n", __FILE__, __LINE__, peak_count) ; | |
| 171 | + if (peak_count < expected_peaks) | |
| 172 | + { printf ("\n%s : line %d : bad peak_count (%d), expected %d.\n\n", __FILE__, __LINE__, peak_count, expected_peaks) ; | |
| 173 | 173 | return -1.0 ; |
| 174 | 174 | } ; |
| 175 | 175 | |
| @@ -16,7 +16,7 @@ · 15 unmodified lines | ||
| 16 | 16 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | −double calculate_snr (float *data, int len) ; | |
| 19 | +double calculate_snr (float *data, int len, int expected_peaks) ; | |
| 20 | 20 | /* |
| 21 | 21 | ** Do not edit or modify anything in this comment block. |
| 22 | 22 | ** The arch-tag line is a file identity tag for the GNU Arch |
| @@ -139,7 +139,7 @@ simple_test (int converter, int channel_count, double target_snr) · 138 unmodified lines | ||
| 139 | 139 | deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; |
| 140 | 140 | |
| 141 | 141 | for (ch = 0 ; ch < channel_count ; ch++) |
| 142 | − { snr = calculate_snr (output_serial + ch * frames, frames) ; | |
| 142 | + { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; | |
| 143 | 143 | if (snr < target_snr) |
| 144 | 144 | { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; |
| 145 | 145 | save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; |
| @@ -234,7 +234,7 @@ process_test (int converter, int channel_count, double target_snr) · 88 unmodified lines | ||
| 234 | 234 | deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; |
| 235 | 235 | |
| 236 | 236 | for (ch = 0 ; ch < channel_count ; ch++) |
| 237 | − { snr = calculate_snr (output_serial + ch * frames, frames) ; | |
| 237 | + { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; | |
| 238 | 238 | if (snr < target_snr) |
| 239 | 239 | { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; |
| 240 | 240 | save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; |
| @@ -351,7 +351,7 @@ callback_test (int converter, int channel_count, double target_snr) · 110 unmodified lines | ||
| 351 | 351 | deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; |
| 352 | 352 | |
| 353 | 353 | for (ch = 0 ; ch < channel_count ; ch++) |
| 354 | − { snr = calculate_snr (output_serial + ch * frames, frames) ; | |
| 354 | + { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; | |
| 355 | 355 | if (snr < target_snr) |
| 356 | 356 | { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; |
| 357 | 357 | save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; |
| @@ -298,7 +298,7 @@ snr_test (SINGLE_TEST *test_data, int number, int converter, int verbose, double · 297 unmodified lines | ||
| 298 | 298 | } ; |
| 299 | 299 | |
| 300 | 300 | /* Calculate signal-to-noise ratio. */ |
| 301 | − snr = calculate_snr (output, src_data.output_frames_gen) ; | |
| 301 | + snr = calculate_snr (output, src_data.output_frames_gen, test_data->pass_band_peaks) ; | |
| 302 | 302 | |
| 303 | 303 | if (snr < 0.0) |
| 304 | 304 | { /* An error occurred. */ |
| @@ -287,7 +287,7 @@ generate_source_wav (char *filename, double *freqs, int freq_count, int format) · 286 unmodified lines | ||
| 287 | 287 | } /* generate_source_wav */ |
| 288 | 288 | |
| 289 | 289 | static double |
| 290 | −measure_destination_wav (char *filename, int *output_samples) | |
| 290 | +measure_destination_wav (char *filename, int *output_samples, int expected_peaks) | |
| 291 | 291 | { static float buffer [124000] ; |
| 292 | 292 | |
| 293 | 293 | SNDFILE *sndfile ; |
| @@ -318,7 +318,7 @@ measure_destination_wav (char *filename, int *output_samples) · 24 unmodified lines | ||
| 318 | 318 | |
| 319 | 319 | sf_close (sndfile) ; |
| 320 | 320 | |
| 321 | − snr = calculate_snr (buffer, sfinfo.frames) ; | |
| 321 | + snr = calculate_snr (buffer, sfinfo.frames, expected_peaks) ; | |
| 322 | 322 | |
| 323 | 323 | return snr ; |
| 324 | 324 | } /* measure_desination_wav */ |
| @@ -359,7 +359,7 @@ measure_snr (RESAMPLE_PROG *prog, int *output_samples, int verbose) · 34 unmodified lines | ||
| 359 | 359 | if ((retval = system (command)) != 0) |
| 360 | 360 | printf ("system returned %d\n", retval) ; |
| 361 | 361 | |
| 362 | − snr = measure_destination_wav ("destination.wav", &sample_count) ; | |
| 362 | + snr = measure_destination_wav ("destination.wav", &sample_count, snr_test->pass_band_peaks) ; | |
| 363 | 363 | |
| 364 | 364 | *output_samples += sample_count ; |
| 365 | 365 | |
| @@ -394,8 +394,8 @@ measure_destination_peak (const char *filename) · 28 unmodified lines | ||
| 394 | 394 | exit (1) ; |
| 395 | 395 | } ; |
| 396 | 396 | |
| 397 | − if (sfinfo.frames > ARRAY_LEN (data) || sfinfo.frames < ARRAY_LEN (data) - 100) | |
| 398 | − { printf ("Line %d : bad frame count.\n", __LINE__) ; | |
| 397 | + if (sfinfo.frames > ARRAY_LEN (data) + 4 || sfinfo.frames < ARRAY_LEN (data) - 100) | |
| 398 | + { printf ("Line %d : bad frame count (got %d, expected %d).\n", __LINE__, (int) sfinfo.frames, ARRAY_LEN (data)) ; | |
| 399 | 399 | exit (1) ; |
| 400 | 400 | } ; |
| 401 | 401 | |