Sampling-rate, buffer-size and latency calculator

Samples per channel (frames). A stereo buffer of 480 frames holds 960 samples. The slider covers 1 to 4096.

1 to capture then process, 2 for double buffering.

24-bit samples in 32-bit containers: choose 4.

Latency here counts whole buffers only: add conversion and processing time for the full path.

No buffer to draw.

Show the steps

Interactive calculation is unavailable until JavaScript loads. The formulas, worked examples and references below remain available.

Calculate buffer fill time, block rate, buffering latency and buffer memory from sampling rate and buffer length, or the largest buffer for a latency target.

How to use

Choose From buffer length or From latency target.

Enter the sampling rate per channel and its unit.

Enter the buffer length in samples per channel, or drag its slider, or enter the latency target.

Enter how many full buffers a sample waits through: 1 to capture then process, 2 for double buffering.

Enter channels and bytes per sample to see buffer memory.

Read latency, fill time, block rate and memory. Copy result copies labeled values; Reset restores the starting example.

Science

Block processing collects N samples into a buffer before code runs on them. The first sample of a block has to wait for the whole buffer to fill, so one buffer adds N / f_s of delay, and the code is called f_s / N times per second.

Double buffering lets hardware fill one buffer while software processes the other. A sample then waits through about two buffer times before its result leaves the system, which is why audio interfaces quote latency as a multiple of the period size.

Shorter buffers lower latency but raise the callback rate and the overhead per sample, and every block must still be processed within one buffer time. Power-of-two lengths suit FFTs and some DMA engines but can land well under a latency target.

Limitations: the latency here counts whole buffers only. It omits ADC and DAC conversion delay, filter group delay, processing time, scheduling jitter and transport. Memory counts sample storage only, not descriptors or alignment padding. 24-bit samples stored in 32-bit containers take 4 bytes each.

Formulas

Fill time: t_buf = N / f_s. N is samples per channel, f_s samples per second.

Block rate: r = f_s / N blocks per second.

Latency: L = B × N / f_s. B is the number of full buffers in the path.

Memory: M = B × N × C × s bytes. C channels, s bytes per sample.

Largest buffer: N = floor(L_max × f_s / B); power-of-two rounding uses the largest 2^k not above it.

Examples

48 kHz, 480 samples, 2 buffers, stereo 16-bit: 20 ms latency, 3840 bytes. Each buffer fills in 10 ms; 100 callbacks per second.

44.1 kHz, 1024 samples, 1 buffer: 23.21995465 ms. 1024 / 44100 s; 43.06640625 blocks per second.

44.1 kHz, 10 ms target, 2 buffers: 220 samples, 9.977324263 ms actual. floor(441 / 2) = 220.

48 kHz, 10 ms target, 1 buffer, power of two: 256 samples, 5.333333333 ms. 480 rounds down to 256; the margin is large.

1 kHz, 0.5 ms target: No buffer meets the target. Common mistake: one sample already takes 1 ms.

References

ALSA project: Frames and periods

ALSA library: PCM interface

BIPM: SI prefixes