Lines Matching refs:bat

44 static int format_convert(struct bat *bat, struct pcm_config *config)
49 if (t->format_bat == bat->format) {
54 fprintf(bat->err, _("Invalid format!\n"));
58 static int init_config(struct bat *bat, struct pcm_config *config)
60 config->channels = bat->channels;
61 config->rate = bat->rate;
62 if (bat->period_size > 0)
63 config->period_size = bat->period_size;
71 return format_convert(bat, config);
88 static int check_param(struct bat *bat, struct pcm_params *params,
98 fprintf(bat->err,
106 fprintf(bat->err,
118 static int check_playback_params(struct bat *bat,
122 unsigned int card = bat->playback.card_tiny;
123 unsigned int device = bat->playback.device_tiny;
128 fprintf(bat->err, _("Unable to open PCM device %u!\n"),
133 err = check_param(bat, params, PCM_PARAM_RATE,
137 err = check_param(bat, params, PCM_PARAM_CHANNELS,
141 err = check_param(bat, params, PCM_PARAM_SAMPLE_BITS,
142 bat->sample_size * 8, "Bitrate", " bits");
145 err = check_param(bat, params, PCM_PARAM_PERIOD_SIZE,
149 err = check_param(bat, params, PCM_PARAM_PERIODS,
163 static int latencytest_process_output(struct bat *bat, struct pcm *pcm,
167 int frames = bytes / bat->frame_size;
169 fprintf(bat->log, _("Play sample with %d frames buffer\n"), frames);
171 bat->latency.is_playing = true;
175 err = handleoutput(bat, buffer, bytes, frames);
183 if (bat->latency.state == LATENCY_STATE_COMPLETE_SUCCESS)
186 bat->periods_played++;
189 bat->latency.is_playing = false;
197 static int play_sample(struct bat *bat, struct pcm *pcm,
201 int frames = bytes / bat->frame_size;
205 if (bat->debugplay) {
206 fp = fopen(bat->debugplay, "wb");
209 fprintf(bat->err, _("Cannot open file: %s %d\n"),
210 bat->debugplay, err);
222 err = generate_input_data(bat, buffer, bytes, frames);
226 if (bat->debugplay) {
234 bat->periods_played++;
235 if (bat->period_is_limited
236 && bat->periods_played >= bat->periods_total)
244 if (bat->debugplay) {
245 update_wav_header(bat, fp, bytes_total);
251 static int get_tiny_device(struct bat *bat, char *alsa_device,
276 fprintf(bat->err, _("Invalid tiny device: %s\n"), alsa_device);
283 void *playback_tinyalsa(struct bat *bat)
291 fprintf(bat->log, _("Entering playback thread (tinyalsa).\n"));
296 err = get_tiny_device(bat, bat->playback.device,
297 &bat->playback.card_tiny,
298 &bat->playback.device_tiny);
305 err = init_config(bat, &config);
312 err = check_playback_params(bat, &config);
319 pcm = pcm_open(bat->playback.card_tiny, bat->playback.device_tiny,
322 fprintf(bat->err, _("Unable to open PCM device %u (%s)!\n"),
323 bat->playback.device_tiny, pcm_get_error(pcm));
337 if (bat->playback.file == NULL) {
338 fprintf(bat->log, _("Playing generated audio sine wave"));
339 bat->sinus_duration == 0 ?
340 fprintf(bat->log, _(" endlessly\n")) :
341 fprintf(bat->log, _("\n"));
343 fprintf(bat->log, _("Playing input audio file: %s\n"),
344 bat->playback.file);
345 bat->fp = fopen(bat->playback.file, "rb");
347 if (bat->fp == NULL) {
348 fprintf(bat->err, _("Cannot open file: %s %d\n"),
349 bat->playback.file, err);
354 err = read_wav_header(bat, bat->playback.file, bat->fp, true);
361 if (bat->roundtriplatency)
362 err = latencytest_process_output(bat, pcm, buffer, bufbytes);
364 err = play_sample(bat, pcm, buffer, bufbytes);
371 if (bat->playback.file)
372 fclose(bat->fp);
384 static int capture_sample(struct bat *bat, struct pcm *pcm,
390 unsigned int bytes_count = bat->frames * bat->frame_size;
392 remove(bat->capture.file);
393 fp = fopen(bat->capture.file, "wb");
396 fprintf(bat->err, _("Cannot open file: %s %d\n"),
397 bat->capture.file, err);
413 bat->periods_played++;
415 if (bat->period_is_limited
416 && bat->periods_played >= bat->periods_total)
420 err = update_wav_header(bat, fp, bytes_read);
429 static int latencytest_process_input(struct bat *bat, struct pcm *pcm,
435 unsigned int bytes_count = bat->frames * bat->frame_size;
437 remove(bat->capture.file);
438 fp = fopen(bat->capture.file, "wb");
441 fprintf(bat->err, _("Cannot open file: %s %d\n"),
442 bat->capture.file, err);
452 bat->latency.is_capturing = true;
458 err = handleinput(bat, buffer, bytes / bat->frame_size);
462 if (bat->latency.is_playing == false)
468 bat->latency.is_capturing = false;
470 err = update_wav_header(bat, fp, bytes_read);
479 void *record_tinyalsa(struct bat *bat)
489 fprintf(bat->log, _("Entering capture thread (tinyalsa).\n"));
494 err = get_tiny_device(bat, bat->capture.device,
495 &bat->capture.card_tiny,
496 &bat->capture.device_tiny);
503 err = init_config(bat, &config);
510 pcm = pcm_open(bat->capture.card_tiny, bat->capture.device_tiny,
513 fprintf(bat->err, _("Unable to open PCM device (%s)!\n"),
532 fprintf(bat->log, _("Recording ...\n"));
533 if (bat->roundtriplatency)
534 err = latencytest_process_input(bat, pcm, buffer, bufbytes);
536 err = capture_sample(bat, pcm, buffer, bufbytes);