Skip to content

Commit

Permalink
aplay: Account for delay due to FIFO and buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
borine authored and arkq committed Nov 17, 2024
1 parent 8235e1b commit e77b82b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/aplay/aplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string.h>
#include <syslog.h>
#include <sys/eventfd.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/time.h>
#include <unistd.h>
Expand Down Expand Up @@ -820,11 +821,19 @@ static void *io_worker_routine(struct io_worker *w) {
ffb_shift(&buffer, frames * w->ba_pcm.channels);

int ret;
if ((ret = snd_pcm_delay(w->snd_pcm,
&pcm_delay_frames[pcm_delay_frames_i++ % ARRAYSIZE(pcm_delay_frames)])) != 0)
snd_pcm_sframes_t delay_frames = 0;
if ((ret = snd_pcm_delay(w->snd_pcm, &delay_frames)) != 0)
warn("Couldn't get PCM delay: %s", snd_strerror(ret));
else {

unsigned int buffered = 0;
ioctl(w->ba_pcm_fd, FIONREAD, &buffered);
buffered += ffb_blen_out(&buffer);
delay_frames += buffered / (w->ba_pcm.channels * pcm_format_size);

pcm_delay_frames[pcm_delay_frames_i % ARRAYSIZE(pcm_delay_frames)] = delay_frames;
pcm_delay_frames_i++;

struct timespec ts_now;
/* Rate limit delay updates to 1 update per second. */
struct timespec ts_delay = { .tv_sec = 1 };
Expand Down

0 comments on commit e77b82b

Please sign in to comment.