[pulseaudio-discuss] [PATCH v4] Make module loopback honor requested latency

Georg Chini georg at chini.tk
Sun Feb 8 10:45:44 PST 2015


On 08.02.2015 19:33, Alexander E. Patrakov wrote:
> 08.02.2015 22:43, Georg Chini wrote:
>> On 08.02.2015 16:52, Alexander E. Patrakov wrote:
>>>
>>> OK, then I think there was some misunderstanding on my side. Could you
>>> please post some log lines with two USB devices to completely clear
>>> this up? I want logs without the stop criterion (which is properly
>>> called a "deadband"), and with both 0.75% and the 2‰ restraints
>>> commented out, and adjust_time of 2 seconds. Just for debugging my
>>> assumptions :)
>>>
>> Here is the log from my webcam to my USB sound card, command line was:
>>
>> pacmd load-module module-loopback rate=44100 latency_msec=150 
>> adjust_time=2
>>
>> pure p-regulator without restrictions and
>> new_rate = base_rate * (1 + latency_difference / u->adjust_time)
>>
>> Feb  8 18:34:21 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 106,47 ms + 76,51 ms + 1,84 ms = 184,61 ms,
>> latency difference: 31,31 ms, rate difference: 0 Hz
>> Feb  8 18:34:21 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44790 Hz.
>> Feb  8 18:34:23 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 106,44 ms + 47,33 ms + 0,21 ms = 153,67 ms,
>> latency difference: 1,19 ms, rate difference: 690 Hz
>> Feb  8 18:34:23 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44179 Hz.
>> Feb  8 18:34:25 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 107,93 ms + 40,54 ms + 0,88 ms = 148,98 ms,
>> latency difference: -3,94 ms, rate difference: 79 Hz
>> Feb  8 18:34:25 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44019 Hz.
>> Feb  8 18:34:27 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 104,25 ms + 47,30 ms + 0,77 ms = 152,18 ms,
>> latency difference: -0,01 ms, rate difference: -81 Hz
>> Feb  8 18:34:27 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44094 Hz.
>> Feb  8 18:34:29 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 106,71 ms + 46,40 ms + 0,06 ms = 152,93 ms,
>> latency difference: 0,81 ms, rate difference: -6 Hz
>> Feb  8 18:34:29 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44117 Hz.
>> Feb  8 18:34:31 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 108,62 ms + 43,59 ms + 0,38 ms = 152,27 ms,
>> latency difference: -0,15 ms, rate difference: 17 Hz
>> Feb  8 18:34:31 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44098 Hz.
>> Feb  8 18:34:33 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 105,39 ms + 45,60 ms + 0,87 ms = 151,79 ms,
>> latency difference: -0,46 ms, rate difference: -2 Hz
>> Feb  8 18:34:33 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44090 Hz.
>> Feb  8 18:34:35 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 107,00 ms + 45,02 ms + 0,35 ms = 152,19 ms,
>> latency difference: -0,09 ms, rate difference: -10 Hz
>> Feb  8 18:34:35 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44097 Hz.
>> Feb  8 18:34:37 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 103,47 ms + 48,14 ms + 0,71 ms = 152,03 ms,
>> latency difference: 0,11 ms, rate difference: -3 Hz
>> Feb  8 18:34:37 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44102 Hz.
>> Feb  8 18:34:39 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 104,88 ms + 46,98 ms + 0,00 ms = 151,48 ms,
>> latency difference: -0,24 ms, rate difference: 2 Hz
>> Feb  8 18:34:39 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44095 Hz.
>> Feb  8 18:34:41 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 108,49 ms + 44,15 ms + 0,05 ms = 152,53 ms,
>> latency difference: 0,65 ms, rate difference: -5 Hz
>> Feb  8 18:34:41 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44114 Hz.
>> Feb  8 18:34:43 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 105,14 ms + 46,45 ms + 0,23 ms = 151,59 ms,
>> latency difference: -0,17 ms, rate difference: 14 Hz
>> Feb  8 18:34:43 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44097 Hz.
>> Feb  8 18:34:45 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 107,01 ms + 44,54 ms + 0,67 ms = 151,93 ms,
>> latency difference: 0,10 ms, rate difference: -3 Hz
>> Feb  8 18:34:45 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44102 Hz.
>> Feb  8 18:34:47 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 104,67 ms + 46,39 ms + 0,51 ms = 151,49 ms,
>> latency difference: -0,23 ms, rate difference: 2 Hz
>> Feb  8 18:34:47 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44095 Hz.
>> Feb  8 18:34:49 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 106,39 ms + 44,59 ms + 0,76 ms = 151,56 ms,
>> latency difference: -0,18 ms, rate difference: -5 Hz
>> Feb  8 18:34:49 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44096 Hz.
>> Feb  8 18:34:51 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 107,63 ms + 43,72 ms + 0,18 ms = 151,24 ms,
>> latency difference: -0,57 ms, rate difference: -4 Hz
>> Feb  8 18:34:51 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44087 Hz.
>> Feb  8 18:34:53 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 105,66 ms + 46,25 ms + 0,92 ms = 152,47 ms,
>> latency difference: 0,68 ms, rate difference: -13 Hz
>> Feb  8 18:34:53 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> [alsa_output.usb-0d8c_USB_Sound_Device-00-Device.analog-stereo] Updated
>> sampling rate to 44114 Hz.
>> Feb  8 18:34:55 mini pulseaudio[25589]: [pulseaudio] module-loopback.c:
>> Loopback overall latency is 108,00 ms + 43,55 ms + 0,56 ms = 151,94 ms,
>> latency difference: 0,05 ms, rate difference: 14 Hz
>>
>>
>> It continues to oscillate slightly around the 44100 Hz base rate.
>>
>> Is this the log you wanted?
>
> Yes, thanks. I was indeed confused by your description of the problem. 
> The use of a deadband in this situation is 100% valid (it is about 
> excessive sensitivity to small latency fluctuations), but
>
> new_rate = base_rate * (1 + 0.1 * latency_difference / u->adjust_time)
>
> may also work :)
>
Yes, it would, but it takes much longer to adjust, especially at a long 
adjust_time and
when your latency is far out. I wanted it to converge as quickly as 
possible without
breaking the restrictions.


More information about the pulseaudio-discuss mailing list