Why can the audio callback thread not use mutex locks or dynamic memory allocation?
AAudio threads have a lower execution priority that makes locks unavailable
BBoth operations have unpredictable timing — a blocked mutex or heap allocation can cause the callback to miss its deadline, producing audio dropouts
CMemory allocation is prohibited in audio APIs by specification
DMutex locks introduce phase distortion in the audio signal
The audio callback has a hard real-time deadline. Mutex locks can block indefinitely if another thread holds them; heap allocation can trigger garbage collection or OS page faults with unpredictable timing. Both can cause glitches. Pre-allocation and lock-free data structures solve this.
Question 2 True / False
True or false: FFT-based audio processing introduces latency proportional to the FFT block size.
TTrue
FFalse
Answer: True
FFT processing requires a complete block of samples before computation can begin. A 2048-sample FFT at 44.1 kHz introduces approximately 46 ms of algorithmic latency. DAWs compensate for this via plugin delay compensation (PDC).
Question 3 Short Answer
What is a circular buffer, and why is it essential for audio programming?
Think about your answer, then reveal below.
Model answer: A circular buffer is a fixed-size array that wraps around — the write pointer advances and reuses memory from the beginning when it reaches the end. It enables efficient, allocation-free delay lines: the delay length is the distance between the write pointer and read pointer in the circular buffer.
Delay lines are fundamental to many audio effects (delay, reverb, chorus, comb filtering). Circular buffers implement them without requiring shifting or copying the entire buffer for each sample — just move the pointer.
Question 4 Multiple Choice
In a VST plugin, how should parameter changes from the GUI thread be communicated to the audio callback thread safely?
ADirectly modify the audio thread's parameter variables from the GUI thread — modern CPUs handle this safely
BUse a mutex lock to protect shared parameter variables between threads
CUse lock-free data structures (atomic variables or a FIFO message queue) to pass parameter changes to the audio thread
DStore parameter changes in a file that the audio thread polls
Direct modification causes data races (undefined behavior). Mutex locks can block the audio thread (causing dropouts). Lock-free atomics or FIFO queues allow the GUI to post changes that the audio thread reads without blocking, maintaining real-time safety.