Confused about latency vs buffer size vs data availability

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
hjhmusic
Established Member
Posts: 18
Joined: Mon Nov 07, 2016 3:24 am
Been thanked: 1 time

Confused about latency vs buffer size vs data availability

Post by hjhmusic »

Hi,

Not a concrete tuning question -- something I've been confused about for a while.

latency = block size * periods / sample rate.

But I've been trying to understand the data flow.

1. Mic/line input coming into the ADC.

2. Communication A: Input block --> driver, output block --> DAC.

3. Computer calculates the output block for the next cycle. Input is still coming into ADC.

4. Communication B: Input block --> driver, output block --> DAC.

etc.

At step 3, the output block is being calculated based on the input received in step 2 (A). This output block hits the DAC in step 4 (B). The input corresponding to this output must have been completely received by the ADC before communication A, and the output cannot start streaming out of the DAC until after communication B.

Wouldn't this mean that the actual latency is twice the hardware buffer size?

latency = 2 * block size * periods / sample rate?

That is, unless I'm misunderstanding something, in the table below, input data I0-4 are not available for processing until the first transfer point. But I can't see how the transfer point would wait for client applications to finish processing. The transfer must hand over the previously-completed block. It's at the second transfer point that the calculated output block B5-9 starts to stream out of the DAC... but this is two cycles after the input actually occurred. The "buffer size" in the table is 5 units, but I don't see how the latency could be anything other than 10.

But, every audio software I've ever used contradicts my reasoning here. So I think I must be misunderstanding what is happening in the driver's data transfer.

Does somebody understand this better than I do?

Thanks,
James

Code: Select all

| Time | Input     | Output       | Calc            |
|------+-----------+--------------+-----------------|
|    0 | I0        |              | Calc block A0-4 |
|    1 | I1        |              |                 |
|    2 | I2        |              |                 |
|    3 | I3        |              |                 |
|    4 | I4        |              |                 |
| <--> | Rec'v 0-4 | Send A: Hear |                 |
|    5 | I5        | A0           | Calc block B5-9 |
|    6 | I6        | A1           | (based on I0-4) |
|    7 | I7        | A2           |                 |
|    8 | I8        | A3           |                 |
|    9 | I9        | A4           |                 |
| <--> | Rec'v 5-9 | Send B: Hear |                 |
|   10 | I10...    | B5 <--> I0   |                 |
|   11 |           | B6 <--> I1   |                 |
|   12 |           | B7 <--> I2   |                 |
|   13 |           | B8 <--> I3   |                 |
|   14 |           | B9 <--> I4   |                 |
Post Reply