• Home
  • Raw
  • Download

Lines Matching refs:bat

47 static void get_snr_thd_db(struct bat *bat, char *thd)  in get_snr_thd_db()  argument
56 fprintf(bat->err, _("Invalid threshold '%s':%d\n"), thd, err); in get_snr_thd_db()
59 bat->snr_thd_db = thd_db; in get_snr_thd_db()
63 static void get_snr_thd_pc(struct bat *bat, char *thd) in get_snr_thd_pc() argument
72 fprintf(bat->err, _("Invalid threshold '%s':%d\n"), thd, err); in get_snr_thd_pc()
75 bat->snr_thd_db = 20.0 * log10f(100.0 / thd_pc); in get_snr_thd_pc()
78 static int get_duration(struct bat *bat) in get_duration() argument
85 duration_f = strtof(bat->narg, &ptrf); in get_duration()
91 duration_i = strtol(bat->narg, &ptri, 10); in get_duration()
96 bat->frames = duration_f * bat->rate; in get_duration()
98 bat->frames = duration_i; in get_duration()
100 bat->frames = -1; in get_duration()
102 if (bat->frames <= 0 || bat->frames > MAX_FRAMES) { in get_duration()
103 fprintf(bat->err, _("Invalid duration. Range: (0, %d(%fs))\n"), in get_duration()
104 MAX_FRAMES, (float)MAX_FRAMES / bat->rate); in get_duration()
111 fprintf(bat->err, _("Duration overflow/underflow: %d\n"), err); in get_duration()
116 static void get_sine_frequencies(struct bat *bat, char *freq) in get_sine_frequencies() argument
122 bat->target_freq[1] = bat->target_freq[0] = atof(optarg); in get_sine_frequencies()
125 bat->target_freq[0] = atof(optarg); in get_sine_frequencies()
126 bat->target_freq[1] = atof(tmp1 + 1); in get_sine_frequencies()
130 static void get_format(struct bat *bat, char *optarg) in get_format() argument
133 bat->format = BAT_PCM_FORMAT_S16_LE; in get_format()
134 bat->rate = 44100; in get_format()
135 bat->channels = 2; in get_format()
136 bat->sample_size = 2; in get_format()
138 bat->format = BAT_PCM_FORMAT_S16_LE; in get_format()
139 bat->rate = 48000; in get_format()
140 bat->channels = 2; in get_format()
141 bat->sample_size = 2; in get_format()
143 bat->format = BAT_PCM_FORMAT_U8; in get_format()
144 bat->sample_size = 1; in get_format()
146 bat->format = BAT_PCM_FORMAT_S16_LE; in get_format()
147 bat->sample_size = 2; in get_format()
149 bat->format = BAT_PCM_FORMAT_S24_3LE; in get_format()
150 bat->sample_size = 3; in get_format()
152 bat->format = BAT_PCM_FORMAT_S32_LE; in get_format()
153 bat->sample_size = 4; in get_format()
155 bat->format = BAT_PCM_FORMAT_UNKNOWN; in get_format()
156 fprintf(bat->err, _("wrong extended format '%s'\n"), optarg); in get_format()
161 static inline int thread_wait_completion(struct bat *bat, in thread_wait_completion() argument
174 static void test_loopback(struct bat *bat) in test_loopback() argument
182 (void *) bat->playback.fct, bat); in test_loopback()
184 fprintf(bat->err, _("Cannot create playback thread: %d\n"), in test_loopback()
194 err = pthread_create(&capture_id, NULL, (void *) bat->capture.fct, bat); in test_loopback()
196 fprintf(bat->err, _("Cannot create capture thread: %d\n"), err); in test_loopback()
202 err = thread_wait_completion(bat, playback_id, &thread_result_playback); in test_loopback()
204 fprintf(bat->err, _("Cannot join playback thread: %d\n"), err); in test_loopback()
212 fprintf(bat->err, _("Exit playback thread fail: %d\n"), in test_loopback()
217 fprintf(bat->log, _("Playback completed.\n")); in test_loopback()
222 err = thread_wait_completion(bat, capture_id, &thread_result_capture); in test_loopback()
224 fprintf(bat->err, _("Cannot join capture thread: %d\n"), err); in test_loopback()
231 fprintf(bat->log, _("Capture canceled.\n")); in test_loopback()
237 fprintf(bat->err, _("Exit capture thread fail: %d\n"), in test_loopback()
241 fprintf(bat->log, _("Capture completed.\n")); in test_loopback()
246 static void test_playback(struct bat *bat) in test_playback() argument
254 (void *) bat->playback.fct, bat); in test_playback()
256 fprintf(bat->err, _("Cannot create playback thread: %d\n"), in test_playback()
262 err = thread_wait_completion(bat, playback_id, &thread_result); in test_playback()
264 fprintf(bat->err, _("Cannot join playback thread: %d\n"), err); in test_playback()
271 fprintf(bat->err, _("Exit playback thread fail: %d\n"), in test_playback()
275 fprintf(bat->log, _("Playback completed.\n")); in test_playback()
280 static void test_capture(struct bat *bat) in test_capture() argument
287 err = pthread_create(&capture_id, NULL, (void *) bat->capture.fct, bat); in test_capture()
289 fprintf(bat->err, _("Cannot create capture thread: %d\n"), err); in test_capture()
296 err = thread_wait_completion(bat, capture_id, &thread_result); in test_capture()
298 fprintf(bat->err, _("Cannot join capture thread: %d\n"), err); in test_capture()
305 fprintf(bat->err, _("Exit capture thread fail: %d\n"), in test_capture()
309 fprintf(bat->log, _("Capture completed.\n")); in test_capture()
313 static void usage(struct bat *bat) in usage() argument
315 fprintf(bat->log, in usage()
340 fprintf(bat->log, _("Recognized sample formats are: ")); in usage()
341 fprintf(bat->log, _("U8 S16_LE S24_3LE S32_LE\n")); in usage()
342 fprintf(bat->log, _("The available format shotcuts are:\n")); in usage()
343 fprintf(bat->log, _("-f cd (16 bit little endian, 44100, stereo)\n")); in usage()
344 fprintf(bat->log, _("-f dat (16 bit little endian, 48000, stereo)\n")); in usage()
347 static void set_defaults(struct bat *bat) in set_defaults() argument
349 memset(bat, 0, sizeof(struct bat)); in set_defaults()
352 bat->rate = 44100; in set_defaults()
353 bat->frame_size = 2; in set_defaults()
354 bat->sample_size = 2; in set_defaults()
355 bat->format = BAT_PCM_FORMAT_S16_LE; in set_defaults()
356 bat->convert_float_to_sample = convert_float_to_int16; in set_defaults()
357 bat->convert_sample_to_float = convert_int16_to_float; in set_defaults()
358 bat->frames = bat->rate * 2; in set_defaults()
359 bat->target_freq[0] = 997.0; in set_defaults()
360 bat->target_freq[1] = 997.0; in set_defaults()
361 bat->sigma_k = 3.0; in set_defaults()
362 bat->snr_thd_db = SNR_DB_INVALID; in set_defaults()
363 bat->playback.device = NULL; in set_defaults()
364 bat->capture.device = NULL; in set_defaults()
365 bat->buf = NULL; in set_defaults()
366 bat->local = false; in set_defaults()
367 bat->buffer_size = 0; in set_defaults()
368 bat->period_size = 0; in set_defaults()
369 bat->roundtriplatency = false; in set_defaults()
371 bat->channels = 2; in set_defaults()
372 bat->playback.fct = &playback_tinyalsa; in set_defaults()
373 bat->capture.fct = &record_tinyalsa; in set_defaults()
375 bat->channels = 1; in set_defaults()
376 bat->playback.fct = &playback_alsa; in set_defaults()
377 bat->capture.fct = &record_alsa; in set_defaults()
379 bat->playback.mode = MODE_LOOPBACK; in set_defaults()
380 bat->capture.mode = MODE_LOOPBACK; in set_defaults()
381 bat->period_is_limited = false; in set_defaults()
382 bat->log = stdout; in set_defaults()
383 bat->err = stderr; in set_defaults()
386 static void parse_arguments(struct bat *bat, int argc, char *argv[]) in parse_arguments() argument
407 bat->logarg = optarg; in parse_arguments()
410 bat->playback.file = optarg; in parse_arguments()
413 bat->debugplay = optarg; in parse_arguments()
416 bat->local = true; in parse_arguments()
419 bat->standalone = true; in parse_arguments()
422 bat->roundtriplatency = true; in parse_arguments()
425 get_snr_thd_db(bat, optarg); in parse_arguments()
428 get_snr_thd_pc(bat, optarg); in parse_arguments()
431 if (bat->playback.device == NULL) in parse_arguments()
432 bat->playback.device = optarg; in parse_arguments()
433 if (bat->capture.device == NULL) in parse_arguments()
434 bat->capture.device = optarg; in parse_arguments()
437 if (bat->capture.mode == MODE_SINGLE) in parse_arguments()
438 bat->capture.mode = MODE_LOOPBACK; in parse_arguments()
440 bat->playback.mode = MODE_SINGLE; in parse_arguments()
441 bat->playback.device = optarg; in parse_arguments()
444 if (bat->playback.mode == MODE_SINGLE) in parse_arguments()
445 bat->playback.mode = MODE_LOOPBACK; in parse_arguments()
447 bat->capture.mode = MODE_SINGLE; in parse_arguments()
448 bat->capture.device = optarg; in parse_arguments()
451 bat->narg = optarg; in parse_arguments()
454 get_sine_frequencies(bat, optarg); in parse_arguments()
457 bat->channels = atoi(optarg); in parse_arguments()
460 bat->rate = atoi(optarg); in parse_arguments()
463 get_format(bat, optarg); in parse_arguments()
466 bat->sigma_k = atof(optarg); in parse_arguments()
469 bat->periods_total = atoi(optarg); in parse_arguments()
470 bat->period_is_limited = true; in parse_arguments()
474 bat->buffer_size = err >= MIN_BUFFERSIZE in parse_arguments()
479 bat->period_size = err >= MIN_PERIODSIZE in parse_arguments()
484 usage(bat); in parse_arguments()
490 static int validate_options(struct bat *bat) in validate_options() argument
496 if ((bat->local == true) && (bat->capture.file == NULL)) { in validate_options()
497 fprintf(bat->err, _("no input file for local testing\n")); in validate_options()
502 if (bat->channels > MAX_CHANNELS || bat->channels < MIN_CHANNELS) { in validate_options()
503 fprintf(bat->err, _("%d channels not supported\n"), in validate_options()
504 bat->channels); in validate_options()
509 if ((bat->playback.mode == MODE_SINGLE) in validate_options()
510 && (bat->capture.mode == MODE_SINGLE)) { in validate_options()
511 fprintf(bat->err, _("single ended mode is simplex\n")); in validate_options()
517 freq_high = bat->rate * RATE_FACTOR; in validate_options()
518 for (c = 0; c < bat->channels; c++) { in validate_options()
519 if (bat->target_freq[c] < freq_low in validate_options()
520 || bat->target_freq[c] > freq_high) { in validate_options()
521 fprintf(bat->err, _("sine wave frequency out of")); in validate_options()
522 fprintf(bat->err, _(" range: (%.1f, %.1f)\n"), in validate_options()
531 static int bat_init(struct bat *bat) in bat_init() argument
538 if (bat->logarg) { in bat_init()
539 bat->log = NULL; in bat_init()
540 bat->log = fopen(bat->logarg, "wb"); in bat_init()
542 if (bat->log == NULL) { in bat_init()
543 fprintf(bat->err, _("Cannot open file: %s %d\n"), in bat_init()
544 bat->logarg, err); in bat_init()
547 bat->err = bat->log; in bat_init()
551 if (bat->narg) { in bat_init()
552 err = get_duration(bat); in bat_init()
558 if (bat->playback.device == NULL && bat->capture.device == NULL) in bat_init()
559 bat->playback.device = bat->capture.device = DEFAULT_DEV_NAME; in bat_init()
562 if (bat->local) { in bat_init()
563 bat->capture.file = bat->playback.file; in bat_init()
569 fprintf(bat->err, _("Fail to create record file: %d\n"), in bat_init()
574 bat->capture.file = strdup(name); in bat_init()
576 if (bat->capture.file == NULL) in bat_init()
583 if (bat->playback.file == NULL) { in bat_init()
585 if (bat->frames) { in bat_init()
586 if (bat->playback.mode == MODE_SINGLE) { in bat_init()
588 bat->sinus_duration = bat->frames; in bat_init()
592 bat->sinus_duration = bat->rate * in bat_init()
594 bat->sinus_duration += in bat_init()
595 (bat->frames + bat->frames / 2); in bat_init()
600 bat->sinus_duration = 0; in bat_init()
601 bat->playback.mode = MODE_SINGLE; in bat_init()
604 bat->fp = fopen(bat->playback.file, "rb"); in bat_init()
606 if (bat->fp == NULL) { in bat_init()
607 fprintf(bat->err, _("Cannot open file: %s %d\n"), in bat_init()
608 bat->playback.file, err); in bat_init()
611 err = read_wav_header(bat, bat->playback.file, bat->fp, false); in bat_init()
612 fclose(bat->fp); in bat_init()
617 bat->frame_size = bat->sample_size * bat->channels; in bat_init()
620 switch (bat->sample_size) { in bat_init()
622 bat->convert_float_to_sample = convert_float_to_uint8; in bat_init()
623 bat->convert_sample_to_float = convert_uint8_to_float; in bat_init()
626 bat->convert_float_to_sample = convert_float_to_int16; in bat_init()
627 bat->convert_sample_to_float = convert_int16_to_float; in bat_init()
630 bat->convert_float_to_sample = convert_float_to_int24; in bat_init()
631 bat->convert_sample_to_float = convert_int24_to_float; in bat_init()
634 bat->convert_float_to_sample = convert_float_to_int32; in bat_init()
635 bat->convert_sample_to_float = convert_int32_to_float; in bat_init()
638 fprintf(bat->err, _("Invalid PCM format: size=%d\n"), in bat_init()
639 bat->sample_size); in bat_init()
648 struct bat bat; in main() local
651 set_defaults(&bat); in main()
658 fprintf(bat.log, _("%s version %s\n\n"), PACKAGE_NAME, PACKAGE_VERSION); in main()
660 parse_arguments(&bat, argc, argv); in main()
662 err = bat_init(&bat); in main()
666 err = validate_options(&bat); in main()
671 if (bat.roundtriplatency) { in main()
673 fprintf(bat.log, in main()
675 roundtrip_latency_init(&bat); in main()
676 test_loopback(&bat); in main()
678 if (bat.latency.xrun_error == false) in main()
683 bat.period_size += bat.rate / 1000; in main()
684 bat.buffer_size = in main()
685 bat.period_size * DIV_BUFFERSIZE; in main()
689 if (bat.period_size > bat.rate * 0.2) in main()
700 if (bat.playback.mode == MODE_SINGLE) { in main()
701 test_playback(&bat); in main()
706 if (bat.capture.mode == MODE_SINGLE) { in main()
707 test_capture(&bat); in main()
712 if (bat.local == false) in main()
713 test_loopback(&bat); in main()
717 if (!bat.standalone || snr_is_valid(bat.snr_thd_db)) in main()
718 err = analyze_capture(&bat); in main()
720 fprintf(bat.log, _("No libfftw3 library. Exit without analysis.\n")); in main()
723 fprintf(bat.log, _("\nReturn value is %d\n"), err); in main()
725 if (bat.logarg) in main()
726 fclose(bat.log); in main()
727 if (!bat.local) in main()
728 free(bat.capture.file); in main()