History

Add an expected_peaks parameter to function calculate_snr() and fix knock on effects.

Erik de Castro Lopo committed 22 years ago

Commit a95c1611 parent f5b513c6 files · +17 −17Browse files

Unified · Split

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

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