• Home
  • Raw
  • Download

Lines Matching refs:bat

31 static void check_amplitude(struct bat *bat, float *buf)  in check_amplitude()  argument
37 for (i = 0, sum = 0.0, average = 0.0; i < bat->frames; i++) in check_amplitude()
39 average = sum / bat->frames; in check_amplitude()
42 for (i = 0, sum = 0.0; i < bat->frames; i++) in check_amplitude()
44 amplitude = sum / bat->frames * M_PI / 2.0; in check_amplitude()
47 percent = amplitude * 100 / ((1 << ((bat->sample_size << 3) - 1)) - 1); in check_amplitude()
49 fprintf(bat->log, _("Amplitude: %.1f; Percentage: [%d]\n"), in check_amplitude()
52 fprintf(bat->err, _("ERROR: Amplitude can't be negative!\n")); in check_amplitude()
54 fprintf(bat->err, _("WARNING: Signal too weak!\n")); in check_amplitude()
56 fprintf(bat->err, _("WARNING: Signal overflow!\n")); in check_amplitude()
65 int check_peak(struct bat *bat, struct analyze *a, int end, int peak, float hz, in check_peak() argument
70 float delta_rate = DELTA_RATE * bat->target_freq[channel]; in check_peak()
74 fprintf(bat->log, _("Detected peak at %2.2f Hz of %2.2f dB\n"), hz_peak, in check_peak()
76 fprintf(bat->log, _(" Total %3.1f dB from %2.2f to %2.2f Hz\n"), in check_peak()
80 fprintf(bat->err, _(" WARNING: Found low peak %2.2f Hz,"), in check_peak()
82 fprintf(bat->err, _(" very close to DC\n")); in check_peak()
84 } else if (hz_peak < bat->target_freq[channel] - tolerance) { in check_peak()
85 fprintf(bat->err, _(" FAIL: Peak freq too low %2.2f Hz\n"), in check_peak()
88 } else if (hz_peak > bat->target_freq[channel] + tolerance) { in check_peak()
89 fprintf(bat->err, _(" FAIL: Peak freq too high %2.2f Hz\n"), in check_peak()
93 fprintf(bat->log, _(" PASS: Peak detected")); in check_peak()
94 fprintf(bat->log, _(" at target frequency\n")); in check_peak()
104 static int check(struct bat *bat, struct analyze *a, int channel) in check() argument
106 float hz = 1.0 / ((float) bat->frames / (float) bat->rate); in check()
109 int err = 0, N = bat->frames / 2; in check()
127 if (a->mag[i] > mean + bat->sigma_k * sigma) { in check()
141 err |= check_peak(bat, a, end, peak, hz, mean, in check()
157 fprintf(bat->log, _("Detected at least %d signal(s) in total\n"), in check()
163 static void calc_magnitude(struct bat *bat, struct analyze *a, int N) in calc_magnitude() argument
177 static int find_and_check_harmonics(struct bat *bat, struct analyze *a, in find_and_check_harmonics() argument
181 int err = -ENOMEM, N = bat->frames; in find_and_check_harmonics()
184 a->in = (float *) fftwf_malloc(sizeof(float) * bat->frames); in find_and_check_harmonics()
188 a->out = (float *) fftwf_malloc(sizeof(float) * bat->frames); in find_and_check_harmonics()
192 a->mag = (float *) fftwf_malloc(sizeof(float) * bat->frames); in find_and_check_harmonics()
203 bat->convert_sample_to_float(a->buf, a->in, bat->frames); in find_and_check_harmonics()
206 check_amplitude(bat, a->in); in find_and_check_harmonics()
212 calc_magnitude(bat, a, N); in find_and_check_harmonics()
215 err = check(bat, a, channel); in find_and_check_harmonics()
229 static int calculate_noise_one_period(struct bat *bat, in calculate_noise_one_period() argument
289 static int calculate_noise(struct bat *bat, float *src, int channel) in calculate_noise() argument
293 float freq = bat->target_freq[channel]; in calculate_noise()
297 int nsamples = (int) ceilf(bat->rate / freq); in calculate_noise()
302 int nsection = bat->frames / nsamples - 1; in calculate_noise()
304 fprintf(bat->log, _("samples per period: %d\n"), nsamples); in calculate_noise()
305 fprintf(bat->log, _("total sections to detect: %d\n"), nsection); in calculate_noise()
319 err = generate_sine_wave_raw_mono(bat, na.target, freq, nsamples); in calculate_noise()
336 err = calculate_noise_one_period(bat, &na, src + offset, in calculate_noise()
341 if (na.snr_db > bat->snr_thd_db) { in calculate_noise()
351 fprintf(bat->err, _("Noise detected at %d points.\n"), in calculate_noise()
357 fprintf(bat->log, _("No noise detected.\n")); in calculate_noise()
362 fprintf(bat->log, _("Average SNR is %.2f dB (%.2f %%) at %d points.\n"), in calculate_noise()
373 static int find_and_check_noise(struct bat *bat, void *buf, int channel) in find_and_check_noise() argument
378 source = (float *)malloc(sizeof(float) * bat->frames); in find_and_check_noise()
383 bat->convert_sample_to_float(buf, source, bat->frames); in find_and_check_noise()
386 err = calculate_noise(bat, source, channel); in find_and_check_noise()
395 static int reorder_data(struct bat *bat) in reorder_data() argument
400 if (bat->channels == 1) in reorder_data()
403 p = malloc(bat->frames * bat->frame_size); in reorder_data()
408 for (ch = 0; ch < bat->channels; ch++) { in reorder_data()
409 for (j = 0; j < bat->frames; j++) { in reorder_data()
410 for (i = 0; i < bat->sample_size; i++) { in reorder_data()
411 *p++ = ((char *) (bat->buf))[j * bat->frame_size in reorder_data()
412 + ch * bat->sample_size + i]; in reorder_data()
417 free(bat->buf); in reorder_data()
418 bat->buf = new_bat_buf; in reorder_data()
424 static int truncate_frames(struct bat *bat) in truncate_frames() argument
429 if (bat->frames & (1 << shift)) { in truncate_frames()
430 bat->frames = 1 << shift; in truncate_frames()
437 int analyze_capture(struct bat *bat) in analyze_capture() argument
444 err = truncate_frames(bat); in analyze_capture()
446 fprintf(bat->err, _("Invalid frame number for analysis: %d\n"), in analyze_capture()
447 bat->frames); in analyze_capture()
451 fprintf(bat->log, _("\nBAT analysis: signal has %d frames at %d Hz,"), in analyze_capture()
452 bat->frames, bat->rate); in analyze_capture()
453 fprintf(bat->log, _(" %d channels, %d bytes per sample.\n"), in analyze_capture()
454 bat->channels, bat->sample_size); in analyze_capture()
456 bat->buf = malloc(bat->frames * bat->frame_size); in analyze_capture()
457 if (bat->buf == NULL) in analyze_capture()
460 bat->fp = fopen(bat->capture.file, "rb"); in analyze_capture()
462 if (bat->fp == NULL) { in analyze_capture()
463 fprintf(bat->err, _("Cannot open file: %s %d\n"), in analyze_capture()
464 bat->capture.file, err); in analyze_capture()
469 err = read_wav_header(bat, bat->capture.file, bat->fp, true); in analyze_capture()
473 items = fread(bat->buf, bat->frame_size, bat->frames, bat->fp); in analyze_capture()
474 if (items != bat->frames) { in analyze_capture()
479 err = reorder_data(bat); in analyze_capture()
483 for (c = 0; c < bat->channels; c++) { in analyze_capture()
484 fprintf(bat->log, _("\nChannel %i - "), c + 1); in analyze_capture()
485 fprintf(bat->log, _("Checking for target frequency %2.2f Hz\n"), in analyze_capture()
486 bat->target_freq[c]); in analyze_capture()
487 a.buf = bat->buf + in analyze_capture()
488 c * bat->frames * bat->frame_size in analyze_capture()
489 / bat->channels; in analyze_capture()
490 if (!bat->standalone) { in analyze_capture()
491 err = find_and_check_harmonics(bat, &a, c); in analyze_capture()
496 if (snr_is_valid(bat->snr_thd_db)) { in analyze_capture()
497 fprintf(bat->log, _("\nChecking for SNR: ")); in analyze_capture()
498 fprintf(bat->log, _("Threshold is %.2f dB (%.2f%%)\n"), in analyze_capture()
499 bat->snr_thd_db, 100.0 in analyze_capture()
500 / powf(10.0, bat->snr_thd_db / 20.0)); in analyze_capture()
501 err = find_and_check_noise(bat, a.buf, c); in analyze_capture()
508 fclose(bat->fp); in analyze_capture()
510 free(bat->buf); in analyze_capture()