<p><br>
>><br>
>>>>> 5) The pulseaudio sink code takes the first 10ms of audio out of the<br>
>>>>> loopback buffer,<br>
>>>>> writes it to the alsa buffer and calls snd_pcm_start().<br>
>>>><br>
>>>> If the sink takes something from the loopback buffer, this means that<br>
>>>> the first pop() call has been made. Assuming no time has passed since<br>
>>>> the previous step, the USB bus is still full, and so is the ring<br>
>>>> buffer. Expected delay: 20 ms.<br>
>>><br>
>>> Reported delay is exactly the amount of audio that was written to<br>
>>> the buffer.<br>
>><br>
>> That's the bug that I think should be fixed in alsa if possible (and if<br>
>> it's impossible, I don't see how it could be fixed in pulseaudio<br>
>> either).<br>
><br>
> It can be fixed (or at least be worked around). If you take a time stamp<br>
> at the moment when snd_pcm_start() is called and another when<br>
> the first audio has definitely been played (delay < write_count), then<br>
> the difference between the time stamps corrected by the amount<br>
> of audio that has already been played, gives you exactly that<br>
> missing bit of latency.<br>
> That was what my original question was about - what should I do with<br>
> this extra latency? Currently I am just adding it as an offset to the<br>
> "normal" latency. This however means, that if you configure let's say<br>
> 10ms, you will get in fact around 22ms. (You would get 22ms anyway,<br>
> but the reports would show 10ms with the old code.)<br>
> For HDA the reported delay is even slightly negative, probably because<br>
> the card already starts during the preparation step. Negative delays<br>
> are truncated by my code, no real audio should have been played<br>
> before snd_pcm_start().<br>
></p>
<p>This is because pulseaudio use -1 as start threshold instead of buffer size/boundary, write may start just after first write, some plugin (e.g. multi plugin) return EBADFD when pulseaudio call snd_pcm_start because pcm has already started</p>
<p>do loopback module assume sink is not running when it start source capture?<br></p>
<p>you are using scope to measure the latency, how about the input and output delay from HDA link and the hda codec pins</p>
<p>Some hda codecs (e.g. idt codecs) which have high pass filter, low pass filter, EQ have delays defined in hda audio specification</p>
<p>Input Delay is a 4-bit value representing the number of samples between when the sample is received as an analog signal at the pin and when the digital representation is transmitted on the High Definition Audio Link. This may be a “typical” value. If this is 0, the widgets along the critical path should be queried, and each individual widget must report its individual delay.</p>
<p>Output Delay is a four bit value representing the number of samples between when the sample is received from the Link and when it appears as an analog signal at the pin.</p>
<p>“typical” value. If this is 0, the widgets along the critical path should be queried, and each individual widget must report its individual delay.</p>