On Thu, Nov 04, 2021 at 04:21:12PM +0100, Alexandre Ratchov wrote:
> The current sndiod latency (minimum time between when the program
> plays something and when sound reaches Joe's ears) is too large and
> makes OpenBSD unpleasant to use for telephony, games, and makes
> controls of video players slugish.
> 
> The defaut latency (of 160ms) was set ~10 years ago to workaround
> various problems: KERNEL_LOCK used to block audio processing for very
> long, azalia(4) and uaudio(4) were unable to recover after an error,
> which aggravated the problem.
> 
> The kernel improved a lot the last decade and such large buffers are
> not necessary anymore. I think something between 20ms and 40ms is a
> better default for the average OpenBSD system:
> 
>  * audio-conferencing software and games requires no sndiod_flags
>    tweaks anymore
> 
>  * on modern machines (like my 7 years old i5-2500K) building a kernel
>    doesn't make audio stutterer
> 
>  * sndiod_flags tweaks will still be needed for:
>       - very slow or overloaded machines used for audio
>       - machines running heavy/bogus SMM code
>       - real-time synths & effects (20ms is still too small)
> 
> Please try to switch you system to 40ms buffers (i.e. 1920 samples at
> the default 48kHz rate), for instance either apply diff below or
> simply do:
> 
>       rcctl set sndiod flags -z 480 -b 1920
>       rcctl restart sndiod

This introduces noticable stuttering on my X230 runs a few xterms and
firefox with idle tabs.

The one thing I always use for testing audio is `pkg_add -u' while
playing `mpv songXY.ogg':  whether or not it installs pacakges does not
matter.  A noop run is enough to notice stuffer with this diff while the
current sndio defaults do not produce any stutter.

> then report any significant increase of stuttering, and what
> software/hardware triggers it. If you think 20ms or 30ms (i.e. 960 and
> 1440 sample buffers) are better, let me know as well.

Trying above rcctl lines with `-b 1440' and `-b 960' made it worse:
more stutter and noticably slower sound playback, in increasing order.

^Z the pkg_add process restores audio to normal. `fg' it brings stutter
back, i.e. without `pkg_add' running I hear no difference using any of
the three values.

> Note that OpenBSD is not real-time (neither are programs we run) so
> audio may stutter no matter how large the buffers are. The goal here
> is to get a ballance between disconfort caused by latency and
> probability of stuttering for the average OpenBSD system.
> 
> If we reach a consensus, here's the diff to make above settings the
> default.
> 
> OK?
> 
> Index: sndiod.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/sndiod/sndiod.c,v
> retrieving revision 1.47
> diff -u -p -r1.47 sndiod.c
> --- sndiod.c  1 Nov 2021 14:43:25 -0000       1.47
> +++ sndiod.c  1 Nov 2021 15:28:37 -0000
> @@ -82,7 +82,7 @@
>   * buffer size if neither ``-z'' nor ``-b'' is used
>   */
>  #ifndef DEFAULT_BUFSZ
> -#define DEFAULT_BUFSZ        7680
> +#define DEFAULT_BUFSZ        1920
>  #endif
>  
>  void sigint(int);
> 

So at least for my setup this is not an improvement.

I quickly tried the mid-value between 7680 and 1920, 4800, and with that
I hear no stutter while `pkg_add' is running!

Smaller values probably work but I didn't bisect it to the lowest
possible value.

Reply via email to