Lines Matching refs:bat

60 static int format_convert(struct bat *bat, snd_pcm_format_t *fmt)
65 if (t->format_bat == bat->format) {
70 fprintf(bat->err, _("Invalid format!\n"));
74 static int set_snd_pcm_params(struct bat *bat, struct pcm_container *sndpcm)
87 err = format_convert(bat, &format);
97 fprintf(bat->err, _("Set parameter to device error: "));
98 fprintf(bat->err, _("default params: %s: %s(%d)\n"),
107 fprintf(bat->err, _("Set parameter to device error: "));
108 fprintf(bat->err, _("access type: %s: %s(%d)\n"),
116 fprintf(bat->err, _("Set parameter to device error: "));
117 fprintf(bat->err, _("PCM format: %d %s: %s(%d)\n"), format,
124 params, bat->channels);
126 fprintf(bat->err, _("Set parameter to device error: "));
127 fprintf(bat->err, _("channel number: %d %s: %s(%d)\n"),
128 bat->channels,
134 rate = bat->rate;
136 params, &bat->rate,
139 fprintf(bat->err, _("Set parameter to device error: "));
140 fprintf(bat->err, _("sample rate: %d %s: %s(%d)\n"),
141 bat->rate,
145 if ((float) rate * (1 + RATE_RANGE) < bat->rate
146 || (float) rate * (1 - RATE_RANGE) > bat->rate) {
147 fprintf(bat->err, _("Invalid parameters: sample rate: "));
148 fprintf(bat->err, _("requested %dHz, got %dHz\n"),
149 rate, bat->rate);
153 if (bat->buffer_size > 0 && bat->period_size == 0)
154 bat->period_size = bat->buffer_size / DIV_BUFFERSIZE;
156 if (bat->roundtriplatency && bat->buffer_size == 0) {
161 fprintf(bat->err,
163 fprintf(bat->err, _("buffer size min: %d %s: %s(%d)\n"),
171 fprintf(bat->err,
173 fprintf(bat->err, _("period size min: %d %s: %s(%d)\n"),
178 bat->buffer_size = (int) buffer_size;
179 bat->period_size = (int) period_size;
182 if (bat->buffer_size > 0) {
183 buffer_size = bat->buffer_size;
184 period_size = bat->period_size;
186 fprintf(bat->log, _("Set period size: %d buffer size: %d\n"),
192 fprintf(bat->err, _("Set parameter to device error: "));
193 fprintf(bat->err, _("buffer size: %d %s: %s(%d)\n"),
202 fprintf(bat->err, _("Set parameter to device error: "));
203 fprintf(bat->err, _("period size: %d %s: %s(%d)\n"),
211 fprintf(bat->err,
213 fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
228 fprintf(bat->err, _("Set parameter to device error: "));
229 fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
238 fprintf(bat->err, _("Set parameter to device error: "));
239 fprintf(bat->err, _("period time: %d %s: %s(%d)\n"),
248 fprintf(bat->err, _("Set parameter to device error: "));
249 fprintf(bat->err, _("hw params: %s: %s(%d)\n"),
257 fprintf(bat->err, _("Get parameter from device error: "));
258 fprintf(bat->err, _("period size: %zd %s: %s(%d)\n"),
266 fprintf(bat->err, _("Get parameter from device error: "));
267 fprintf(bat->err, _("buffer size: %zd %s: %s(%d)\n"),
274 fprintf(bat->err, _("Invalid parameters: can't use period "));
275 fprintf(bat->err, _("equal to buffer size (%zd)\n"),
280 fprintf(bat->log, _("Get period size: %d buffer size: %d\n"),
285 fprintf(bat->err, _("Invalid parameters: "));
286 fprintf(bat->err, _("snd_pcm_format_physical_width: %d\n"),
292 sndpcm->frame_bits = sndpcm->sample_bits * bat->channels;
298 fprintf(bat->err, _("Not enough memory: size=%zd\n"),
307 int frames, struct bat *bat)
319 fprintf(bat->err, _("Underrun: %s(%d)\n"),
321 if (bat->roundtriplatency)
322 bat->latency.xrun_error = true;
330 fprintf(bat->err, _("Write PCM device error: %s(%d)\n"),
348 struct bat *bat)
354 bat->latency.is_playing = true;
358 err = handleoutput(bat, sndpcm->buffer, bytes, frames);
362 err = write_to_pcm(sndpcm, frames, bat);
367 if (bat->latency.xrun_error == true)
370 if (bat->latency.state == LATENCY_STATE_COMPLETE_SUCCESS)
373 bat->periods_played++;
376 bat->latency.is_playing = false;
381 static int write_to_pcm_loop(struct pcm_container *sndpcm, struct bat *bat)
389 if (bat->debugplay) {
390 fp = fopen(bat->debugplay, "wb");
393 fprintf(bat->err, _("Cannot open file: %s %d\n"),
394 bat->debugplay, err);
406 err = generate_input_data(bat, sndpcm->buffer, bytes, frames);
410 if (bat->debugplay) {
418 bat->periods_played++;
419 if (bat->period_is_limited
420 && bat->periods_played >= bat->periods_total)
423 err = write_to_pcm(sndpcm, frames, bat);
428 if (bat->debugplay) {
429 update_wav_header(bat, fp, bytes_total);
441 void *playback_alsa(struct bat *bat)
446 fprintf(bat->log, _("Entering playback thread (ALSA).\n"));
451 err = snd_pcm_open(&sndpcm.handle, bat->playback.device,
454 fprintf(bat->err, _("Cannot open PCM playback device: "));
455 fprintf(bat->err, _("%s(%d)\n"), snd_strerror(err), err);
460 err = set_snd_pcm_params(bat, &sndpcm);
466 if (bat->playback.file == NULL) {
467 fprintf(bat->log, _("Playing generated audio sine wave"));
468 bat->sinus_duration == 0 ?
469 fprintf(bat->log, _(" endlessly\n")) :
470 fprintf(bat->log, _("\n"));
472 fprintf(bat->log, _("Playing input audio file: %s\n"),
473 bat->playback.file);
474 bat->fp = fopen(bat->playback.file, "rb");
476 if (bat->fp == NULL) {
477 fprintf(bat->err, _("Cannot open file: %s %d\n"),
478 bat->playback.file, err);
483 err = read_wav_header(bat, bat->playback.file, bat->fp, true);
490 if (bat->roundtriplatency)
491 err = latencytest_process_output(&sndpcm, bat);
493 err = write_to_pcm_loop(&sndpcm, bat);
500 if (bat->playback.file)
501 fclose(bat->fp);
511 int frames, struct bat *bat)
524 fprintf(bat->err, _("Overrun: %s(%d)\n"),
526 if (bat->roundtriplatency)
527 bat->latency.xrun_error = true;
534 fprintf(bat->err, _("Read PCM device error: %s(%d)\n"),
548 static int read_from_pcm_loop(struct pcm_container *sndpcm, struct bat *bat)
554 int bytes_count = bat->frames * bat->frame_size;
557 remove(bat->capture.file);
558 fp = fopen(bat->capture.file, "wb");
561 fprintf(bat->err, _("Cannot open file: %s %d\n"),
562 bat->capture.file, err);
578 err = read_from_pcm(sndpcm, frames, bat);
590 bat->periods_played++;
592 if (bat->period_is_limited
593 && bat->periods_played >= bat->periods_total)
597 update_wav_header(bat, fp, bytes_read);
607 struct bat *bat)
614 int bytes_count = bat->frames * bat->frame_size;
616 remove(bat->capture.file);
617 fp = fopen(bat->capture.file, "wb");
620 fprintf(bat->err, _("Cannot open file: %s %d\n"),
621 bat->capture.file, err);
630 bat->latency.is_capturing = true;
634 err = read_from_pcm(sndpcm, frames, bat);
639 if (bat->latency.xrun_error == true)
642 err = handleinput(bat, sndpcm->buffer, frames);
646 if (bat->latency.is_playing == false)
658 bat->latency.is_capturing = false;
660 update_wav_header(bat, fp, bytes_read);
675 void *record_alsa(struct bat *bat)
682 fprintf(bat->log, _("Entering capture thread (ALSA).\n"));
687 err = snd_pcm_open(&sndpcm.handle, bat->capture.device,
690 fprintf(bat->err, _("Cannot open PCM capture device: "));
691 fprintf(bat->err, _("%s(%d)\n"), snd_strerror(err), err);
696 err = set_snd_pcm_params(bat, &sndpcm);
707 fprintf(bat->log, _("Recording ...\n"));
708 if (bat->roundtriplatency)
709 err = latencytest_process_input(&sndpcm, bat);
711 err = read_from_pcm_loop(&sndpcm, bat);