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
5959
6060 printf ("Time : %5.2f secs.\n", (1.0 * clock_time) / CLOCKS_PER_SEC) ;
6161 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)) ;
6363
6464 return 0 ;
6565 } /* main */
tests/calc_snr.c+6−6
@@ -35,7 +35,7 @@ · 34 unmodified lines
3535
3636 static void log_mag_spectrum (double *input, int len, double *magnitude) ;
3737 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) ;
3939
4040 typedef struct
4141 { double peak ;
@@ -43,7 +43,7 @@ typedef struct · 1 unmodified line
4343 } PEAK_DATA ;
4444
4545 double
46−calculate_snr (float *data, int len)
46+calculate_snr (float *data, int len, int expected_peaks)
4747 { static double magnitude [MAX_SPEC_LEN] ;
4848 static double datacopy [MAX_SPEC_LEN] ;
4949
@@ -67,7 +67,7 @@ calculate_snr (float *data, int len) · 17 unmodified lines
6767 log_mag_spectrum (datacopy, len, magnitude) ;
6868 smooth_mag_spectrum (magnitude, len / 2) ;
6969
70− snr = find_snr (magnitude, len) ;
70+ snr = find_snr (magnitude, len, expected_peaks) ;
7171
7272 return snr ;
7373 } /* calculate_snr */
@@ -144,7 +144,7 @@ peak_compare (const void *vp1, const void *vp2) · 70 unmodified lines
144144 } /* peak_compare */
145145
146146 static double
147−find_snr (const double *magnitude, int len)
147+find_snr (const double *magnitude, int len, int expected_peaks)
148148 { PEAK_DATA peaks [MAX_PEAKS] ;
149149
150150 int k, peak_count = 0 ;
@@ -168,8 +168,8 @@ find_snr (const double *magnitude, int len) · 17 unmodified lines
168168 } ;
169169 } ;
170170
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) ;
173173 return -1.0 ;
174174 } ;
175175
tests/calc_snr.h+1−1
@@ -16,7 +16,7 @@ · 15 unmodified lines
1616 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1717 */
1818
19−double calculate_snr (float *data, int len) ;
19+double calculate_snr (float *data, int len, int expected_peaks) ;
2020 /*
2121 ** Do not edit or modify anything in this comment block.
2222 ** 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
139139 deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
140140
141141 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) ;
143143 if (snr < target_snr)
144144 { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
145145 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
234234 deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
235235
236236 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) ;
238238 if (snr < target_snr)
239239 { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
240240 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
351351 deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
352352
353353 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) ;
355355 if (snr < target_snr)
356356 { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
357357 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
298298 } ;
299299
300300 /* 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) ;
302302
303303 if (snr < 0.0)
304304 { /* 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
287287 } /* generate_source_wav */
288288
289289 static double
290−measure_destination_wav (char *filename, int *output_samples)
290+measure_destination_wav (char *filename, int *output_samples, int expected_peaks)
291291 { static float buffer [124000] ;
292292
293293 SNDFILE *sndfile ;
@@ -318,7 +318,7 @@ measure_destination_wav (char *filename, int *output_samples) · 24 unmodified lines
318318
319319 sf_close (sndfile) ;
320320
321− snr = calculate_snr (buffer, sfinfo.frames) ;
321+ snr = calculate_snr (buffer, sfinfo.frames, expected_peaks) ;
322322
323323 return snr ;
324324 } /* measure_desination_wav */
@@ -359,7 +359,7 @@ measure_snr (RESAMPLE_PROG *prog, int *output_samples, int verbose) · 34 unmodified lines
359359 if ((retval = system (command)) != 0)
360360 printf ("system returned %d\n", retval) ;
361361
362− snr = measure_destination_wav ("destination.wav", &sample_count) ;
362+ snr = measure_destination_wav ("destination.wav", &sample_count, snr_test->pass_band_peaks) ;
363363
364364 *output_samples += sample_count ;
365365
@@ -394,8 +394,8 @@ measure_destination_peak (const char *filename) · 28 unmodified lines
394394 exit (1) ;
395395 } ;
396396
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)) ;
399399 exit (1) ;
400400 } ;
401401

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