The officially official Devuan Forum!

You are not logged in.

#1 Yesterday 23:06:22

stultumanto
Member
Registered: 2023-12-12
Posts: 95  

Output lag routing OBS through apulse

OBS Studio only supports PulseAudio for output monitoring, so I'm using apulse to route its output to ALSA. It works OK, but there is an unusual amount of audio lag; it sounds like several hundred milliseconds. I've tested looping back my microphone through ALSA using sox, and there's almost no latency at all. Either apulse or OBS is causing the lag, but I can't tell which. I was wondering if anyone else had any experience with latency issues using these two programs. My searches didn't turn up anything specific.

Offline

#2 Yesterday 23:19:10

g4sra
Member
Registered: 2018-12-12
Posts: 68  

Re: Output lag routing OBS through apulse

I used apulse with firefox for a while and suffered with bad latency, I assumed it was firefox. After having a hissy fit and purging apulse after my headset refused to work I forgot I had done so and launched firefox to discover the latency was greatly reduced. Not conclusive, but if you can find a method to resize apuls'es buffers it might be worth the effort to try it.

Offline

#3 Yesterday 23:38:51

stultumanto
Member
Registered: 2023-12-12
Posts: 95  

Re: Output lag routing OBS through apulse

Thanks for sharing that data point. I just tried using apulse with Firefox ESR on a Debian installation. (The Firefox packaged with mainline Debian no longer supports ALSA directly.) I observed exactly what you describe. It seems apulse is the source of the high latency. What's odd is that, according to the documentation, apulse simply wraps the ALSA mixing tools dmix, dsnoop, and plug. Logically, then, it would seem these tools must be the source of the latency.

I actually did find some discussions by people who claimed to have latency issues with the ALSA userspace utilities. Perhaps there is a buffer setting in these tools I can adjust. If that doesn't work, though, I may just give in and install PipeWire, as it appears more and more applications are coming to rely on it.

Offline

#4 Today 00:41:26

igorzwx
Member
Registered: 2024-05-06
Posts: 384  

Re: Output lag routing OBS through apulse

stultumanto wrote:

The Firefox packaged with mainline Debian no longer supports ALSA directly.

It is not true. Firefox-esr works with ALSA. To reduce latency, you have to disable pulse-rust backend and recompile libasound2-plugins with --disable-pulseaudio
_https://dev1galaxy.org/viewtopic.php?id=7523

It is not difficult to compile Firefox without pulseaudio.

Firefox uses 32-bit floating-point audio format by default. If your sound card does not natively support this format, direct hw:device access will not work. You must use the ALSA plug plugin for format conversion. Configure your ALSA default device to use type plug with slave.pcm "hw:X,Y" for automatic format conversion.

Last edited by igorzwx (Today 00:59:41)

Offline

#5 Today 07:58:23

stultumanto
Member
Registered: 2023-12-12
Posts: 95  

Re: Output lag routing OBS through apulse

It is not true. Firefox-esr works with ALSA.

No argument here; I was only testing the PulseAudio version to help troubleshoot my issues with apulse and OBS Studio. I appreciate the detailed instructions for recompiling Firefox; however, there doesn't appear to be an equivalent way to coerce OBS into support ALSA for output monitoring. It seems this feature is only available if one installs PulseAudio or PipeWire, which is strange, as OBS supports ALSA input sources without issue.

Offline

#6 Today 11:41:11

igorzwx
Member
Registered: 2024-05-06
Posts: 384  

Re: Output lag routing OBS through apulse

To achieve full functionality with ALSA, proper configuration is essential, especially on systems where default setups may not suffice.

EXAMPLE:

$ cat ~/.asoundrc
# ALSA library configuration file managed by arateconf.
#
# MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN!
#
# Manual changes to the ALSA library configuration should be implemented
# by editing the ~/.asoundrc file, not by editing this file.

#=====================================================
# Configuration for system
#-----------------------------------------------------

# Perform dmixer
pcm.dmixer_system
{
	type			dmix
	ipc_key			1024
	ipc_perm		0666

	hint
	{
		show		off
		description	"Direct mixing of multiple audio streams (system)"
	}

	slave
	{
		pcm		"hw:system,0"

		rate		48000
		channels	2
		format		S16_LE

		period_size	1920
		buffer_size	7680
	}
}

# Perform dsnooper
pcm.dsnooper_system
{
	type			dsnoop
	ipc_key			1025
	ipc_perm		0666

	hint
	{
		show		off
		description	"Recording from the same device for several applications simultaneously (system)"
	}

	slave
	{
		pcm		"hw:system,0"

		rate		48000
		format		S16_LE

		period_size	1920
		buffer_size	7680
	}
}

# Perform duplex
pcm.duplex_system
{
	type			asym
	playback.pcm		"dmixer_system"
	capture.pcm		"dsnooper_system"

	hint
	{
		show		off
		description	"Full duplex for simultaneous playback and recording (system)"
	}
}

# Perform convert
pcm.convert_system
{
	type			rate
	converter		fftrate

	hint
	{
		show		off
		description	"Sample rate converter (system)"
	}

	slave
	{
		pcm	"duplex_system"
		rate	48000
		format	S16_LE
	}
}

# Perform plug device
pcm.primary_system
{
	type			plug
	slave.pcm		"convert_system"
	hint.description	"Default device (system)"
}

#=====================================================
# Configuration for PCH
#-----------------------------------------------------

# Perform dmixer
pcm.dmixer_PCH
{
	type			dmix
	ipc_key			1026
	ipc_perm		0666

	hint
	{
		show		off
		description	"Direct mixing of multiple audio streams (PCH)"
	}

	slave
	{
		pcm		"hw:PCH,0"

		rate		192000
		channels	2
		format		S32_LE

		period_size	7680
		buffer_size	30720
	}
}

# Perform dsnooper
pcm.dsnooper_PCH
{
	type			dsnoop
	ipc_key			1027
	ipc_perm		0666

	hint
	{
		show		off
		description	"Recording from the same device for several applications simultaneously (PCH)"
	}

	slave
	{
		pcm		"hw:PCH,0"

		rate		192000
		format		S32_LE

		period_size	7680
		buffer_size	30720
	}
}

# Perform duplex
pcm.duplex_PCH
{
	type			asym
	playback.pcm		"dmixer_PCH"
	capture.pcm		"dsnooper_PCH"

	hint
	{
		show		off
		description	"Full duplex for simultaneous playback and recording (PCH)"
	}
}

# Perform convert
pcm.convert_PCH
{
	type			rate
	converter		fftrate

	hint
	{
		show		off
		description	"Sample rate converter (PCH)"
	}

	slave
	{
		pcm	"duplex_PCH"
		rate	192000
		format	S32_LE
	}
}

#=====================================================
# Configuration for default audio device
#-----------------------------------------------------

# Perform plug device
pcm.!default
{
	type			plug
	slave.pcm		"convert_PCH"
	hint.description	"Default device"
}

Notice:

"Full duplex for simultaneous playback and recording (system)"

Debian/Devuan has already dmix configured and enabled by default, but it might not be suitable for your needs.

Last edited by igorzwx (Today 11:45:57)

Offline

Board footer