Index | Thread | Search

From:
"Omar Polo" <op@omarpolo.com>
Subject:
Re: libsndio: Add an interface to report underruns
To:
Alexandre Ratchov <alex@caoua.org>
Cc:
tech@openbsd.org
Date:
Mon, 29 Dec 2025 17:22:02 +0100

Download raw body.

Thread
Alexandre Ratchov <alex@caoua.org> wrote:
> This diff adds the new sio_onxrun(3) function that can be used to
> register a callback function that will be called on buffer underrun.
> 
> There are cases where a program may use an external audio clock
> (ex. an RTP stream) and resample to make the local audio rate
> match the remote rate to keep the latency constant. To do so,
> the program must measure continuously the clock drift and calculate
> the resampling ratio. Upon underrun, such programs must restart
> the measurements, hence the need for this new interface.
> 
> The audio/sndiortp port will be the first user of this function,
> but other programs could benefit from this as well.
> 
> This function will be necessary to make sndiod combine multiple audio
> devices into a single one (ex. combine webcam's mic with the internal
> speaker).

(looking forward to that!)

> OK?

don't feel confident with the internals to give a proper ok, I can just
say that it reads fine to me.

noticed one minor omission in the manpage, hence the reply:

> RCS file: /cvs/src/lib/libsndio/sio_open.3,v
> diff -u -p -u -p -r1.58 sio_open.3
> --- lib/libsndio/sio_open.3	13 Jun 2025 18:34:00 -0000	1.58
> +++ lib/libsndio/sio_open.3	27 Dec 2025 17:42:51 -0000
> @@ -588,6 +588,21 @@ might overrun; in this case recorded dat
>  Similarly if the application cannot provide data to play
>  fast enough, the play buffer underruns and silence is played
>  instead.

it's missing the sio_onxrun() prototype in the SYNOPSIS?

> +.Pp
> +The
> +.Fn sio_onxrun
> +function can be used to register the
> +.Fn cb
> +callback function called at buffer underrun or overrun.
> +It is called by
> +.Fn sio_read ,
> +.Fn sio_write ,
> +and
> +.Fn sio_revents .
> +The value of the
> +.Fa arg
> +pointer is passed to the callback and can contain anything.
> +.Pp
>  Depending on the
>  .Fa xrun
>  parameter of the


Cheers,
Omar Polo