Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuttery audio due to underruns #44

Closed
tmigone opened this issue Nov 19, 2020 · 3 comments
Closed

Stuttery audio due to underruns #44

tmigone opened this issue Nov 19, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@tmigone
Copy link
Contributor

tmigone commented Nov 19, 2020

Using this issue to track the underruns investigation. The warning that gets logged:

W: [pulseaudio] module-loopback.c: Too many underruns, increasing latency to 320.00 ms

Related links:

@tmigone tmigone added the bug Something isn't working label Nov 19, 2020
@tmigone
Copy link
Contributor Author

tmigone commented Nov 19, 2020

As seen in adjust_rates function here the loopback module's latency is increased by 5 msec every time that the underrun count gets to 3, no matter how big the base rate latency is. So as long as underruns keep happening it will keep increasing by 5 msec until it reaches parity.

19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: Loopback overall latency is 63.32 ms + 150.91 ms + -13.99 ms = 200.14 ms
19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: Loopback latency at base rate is 200.14 ms
19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: [alsa_output.bcm2835-jack.stereo-fallback] Updated sampling rate to 44100 Hz.
19.11.20 18:47:03 (-0300)  audio  W: [pulseaudio] module-loopback.c: Too many underruns, increasing latency to 320.00 ms
19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: Loopback overall latency is 315.03 ms + 43.36 ms + -8.81 ms = 349.46 ms
19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: Loopback latency at base rate is 349.50 ms
19.11.20 18:47:03 (-0300)  audio  D: [pulseaudio] module-loopback.c: [snapcast] Updated sampling rate to 44200 Hz.

This seems to be happening usually with the loopback module that hast snapcast as sink (so sadly another instance of the FIFO pipe file/snapcast slowing things down):

Module #26
	Name: module-loopback
	Argument: source="balena-sound.input.monitor" sink="snapcast"
	Usage counter: n/a
	Properties:
		module.author = "Pierre-Louis Bossart"
		module.description = "Loopback from source to sink"
		module.version = "13.0"

@tmigone
Copy link
Contributor Author

tmigone commented Nov 19, 2020

Workaround

Loopback modules use 200 msec as the starting latency (code, docs). That value can be overridden by setting the latency_msec when the loopback module is declared. In the case of balenaSound this needs to be adjusted here with a latency value that matches whatever value it stabilised at.

Note that this workaround is not fixing the problem but rather hiding it.

@tmigone
Copy link
Contributor Author

tmigone commented Nov 23, 2020

Resolution

This affects each application differently so there is no changes to be made to the audio block.

For balenaSound, PR #356 addresses this problem:

  • Changes FIFO stream source to ALSA stream source in multiroom
  • Adds SOUND_INPUT_LATENCY environment variable which directly adjusts latency_msec parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant