Skip to content

Commit

Permalink
aplay: Account for delay of frames in fifo and read buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
borine committed Nov 17, 2024
1 parent 741badc commit 0bd2182
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,10 +821,15 @@ 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;

struct timespec ts_now;
/* Rate limit delay updates to 1 update per second. */
Expand Down

0 comments on commit 0bd2182

Please sign in to comment.