Buffers, Blocks & Latency
Audio feels continuous. A computer sees a stream of samples — and very often hands them to an algorithm in groups.
We've already been using this idea
Sampling
A buffer stored a collection of samples so we could play, scrub and interpolate them.
RMS / Detection
We measured more than one sample to describe energy over a short period of time.
Convolution / DSP
Algorithms repeatedly use stored samples, coefficients and chunks of data to calculate an output.
1 · One stream → many blocks
The sample rate tells us how many samples exist per second. The block size tells us how many samples are grouped together for a processing call.
2 · Change the block size
The workload meter is deliberately qualitative: real CPU cost depends on the algorithm, host, hardware and scheduling. The block timing calculations are real.
3 · Where does latency come from?
For an algorithm that must wait for a complete block, it cannot calculate that block until the required samples have arrived.
At 48 kHz, a 256-sample block represents about 5.33 ms of audio. A 1024-sample block represents about 21.33 ms.
4 · Why not make every block enormous?
| Smaller blocks | Larger blocks |
|---|---|
| Less time represented by each block | More time represented by each block |
| Potentially lower buffering delay | Potentially greater buffering delay |
| More processing calls / scheduling overhead | Fewer processing calls / less scheduling overhead |
| Less data available to block-based analysis | More data available to block-based analysis |
So block size is a trade-off, not a quality knob.
5 · And why not process exactly one sample at a time?
Some DSP can operate sample by sample. We've already described plenty of it that way:
But other jobs make much more sense when the algorithm can inspect a collection of samples. Analysis is the obvious example: one isolated sample cannot tell us whether we're looking at a 100 Hz sine, a 1 kHz sine, a snare transient or a chord.
We need some time before we can ask questions about frequency.
6 · Block size is NOT sample rate
How densely time is sampled
How many samples are handed over together
Change 64 samples to 1024 samples and a 48 kHz stream is still a 48 kHz stream. We have changed the packaging, not the underlying sample rate.
We now have a block of samples. What can we learn from it?
We've been showing spectrum analysers for ages. Next, we find out how the computer gets from a waveform through time to a description of frequency.