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

[Digidesign Mbox 3] Does ucm SplitPCM add latency? #238

Closed
ManuLinares opened this issue Nov 6, 2022 · 15 comments
Closed

[Digidesign Mbox 3] Does ucm SplitPCM add latency? #238

ManuLinares opened this issue Nov 6, 2022 · 15 comments

Comments

@ManuLinares
Copy link
Contributor

#237

I've correctly configured ucm profile, but I notice a small latency added when using UCM vs not using it (having the default alsa analog-surround4.0 profile)

Is this the expected behavior of SplitPCM in UCM?

@perexg
Copy link
Member

perexg commented Nov 6, 2022

Do you use PA ? Do you have installed alsa-lib version 1.2.8 ?

@ManuLinares
Copy link
Contributor Author

pipewire 1:0.3.59-5 (pipewire-jack, pipewire-pulse)
alsa-lib 1.2.8-1

I noticed when using carla to connect my mic to output, using the same latency config, when using UCM a little more lag.

I'm going to measure the latency now.

@ManuLinares
Copy link
Contributor Author

Tested latency.
"speakers -> microphone", measured with "LSP Latency Meter" in carla (Buffer size 64, Sample rate 48000), Latency in ms.

Using UCM:

38.604
38.416
38.437
38.395

Without UCM:

14.312
14.395
13.916
14.375
13.979

@perexg
Copy link
Member

perexg commented Nov 8, 2022

The latency is configurable. For USB profiles, the 10ms period size is the default. You may lower this value in /usr/share/alsa/ucm2/USB-Audio/USB-Audio.conf.

@ManuLinares
Copy link
Contributor Author

The latency is configurable. For USB profiles, the 10ms period size is the default. You may lower this value in /usr/share/alsa/ucm2/USB-Audio/USB-Audio.conf.

Indeed, lowering that variable to 1 lowered the latency to 12ms

Put this below line 233 of USB-Audio.conf
True.Define.SplitPCMPeriodTime 1 # 0.001ms

Gonna test it, and submit a patch if I have no issues.
Thanks.

@perexg
Copy link
Member

perexg commented Nov 8, 2022

The minimal sample chunk size for the USB audio devices is 1ms (1000) and I think that PW expects the total buffer to be more large, so values 4000-6000 may give almost similar results with the lower CPU overhead. Could you test?

@ManuLinares
Copy link
Contributor Author

SplitPCMPeriodTime Latency
4000 28ms
1000 18ms
1 12ms

And actually setting SplitPCMPeriodTime to 1 gives me the lowest cpu usage. 🤷 ¯_(ツ)_/¯

@perexg
Copy link
Member

perexg commented Nov 8, 2022

Could you show output from cat /proc/asound/card0/sub0/pcm0*/hw_params files when the PW is running with value 1? Replace card0 with your USB card...

@ManuLinares
Copy link
Contributor Author

ManuLinares commented Nov 8, 2022

I think the "pcm0*" comes first, sub0 comes after

With 10000

$ cat /proc/asound/card3/pcm0*/sub0/hw_params

cat /proc/asound/card3/pcm0*/sub0/hw_params
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 480
buffer_size: 24000
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 480
buffer_size: 24000

with 1

$ cat /proc/asound/card3/pcm0*/sub0/hw_params
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 24
buffer_size: 24000
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 24
buffer_size: 24000

@ManuLinares
Copy link
Contributor Author

updated my comment

@perexg
Copy link
Member

perexg commented Nov 8, 2022

So the lowest possible value is 500 (0.5ms) -- 1000000/(48000/24). But this is too low value for the normal operation.

If you set the direct profile (or don't use UCM) which values do you see here?

@ManuLinares
Copy link
Contributor Author

Without UCM, the values are as follow:

$ cat /proc/asound/card3/pcm0*/sub0/hw_params
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 32
buffer_size: 32768
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 4
rate: 48000 (48000/1)
period_size: 32
buffer_size: 32768

@perexg
Copy link
Member

perexg commented Nov 8, 2022

So it's setup for 1000000/(48000/32) -- config value approx. 667 . It's really close to 500.

@perexg
Copy link
Member

perexg commented Nov 8, 2022

BTW: Do you use the default pipewire configuration or do you modified the latency (quantum) in PW ? It seems that the configuration is not default where the period size is usually around 1024 samples (21.3ms at 48000Hz rate).

@ManuLinares
Copy link
Contributor Author

I was testing always live with PIPEWIRE_LATENCY="64/48000" carla

So i have (Mic1_in --> "LSP Latency Meter" --> speaker_out) in carla, my physical microphone at 5cm of my speaker.

Carla shows (Buffer size 64, Sample rate 48000)

PD: I really thank you for your help, not very much docs for alsaucm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants