duplex-voice-loop
Zero-cgo (CGO_ENABLED=0) full-duplex 24 kHz float32 audio loopback and
instant barge-in flush-to-silence benchmark using x/duplexaudio and
x/workgroup.
What It Measures
- Host Audio Probe (
duplexaudio.Probe): enumerates CoreAudio devices,
default input/output IDs, microphone TCC authorization status (read-only,
never prompts), kAudioUnitSubType_VoiceProcessingIO availability,
AVAudioIONode.setVoiceProcessingEnabled:error: selector availability,
CATapDescription system audio tap support, and x/workgroup support.
- Lock-Free Float32 RingBuffer: measures
Write + Read throughput,
Write + Flush + consumer ack latency, and verifies 0 heap allocations.
- 24 kHz Full-Duplex Loopback + Barge-In Under CPU Load: runs a mono
float32 loopback stream (128-frame / 5.33 ms slices) with
x/workgroup
UserInteractive thread pinning while 8 synthetic CPU load goroutines
contend for cores, firing 10 barge-in flush-to-silence events and measuring
underruns, captured audio energy, and flush-to-silence latency.
Usage
CGO_ENABLED=0 go run ./examples/media/duplex-voice-loop
CGO_ENABLED=0 go run ./examples/media/duplex-voice-loop -workgroup=false
CGO_ENABLED=0 go run ./examples/media/duplex-voice-loop -rate 48000 -frame 256 -dur 2s -barge-ins 20
Flags:
-rate (default 24000): sample rate in Hz (16000, 24000, 48000)
-frame (default 128): frames per render slice
-dur (default 1s): duplex loopback run duration
-barge-ins (default 10): number of barge-in flush-to-silence events
-load-workers (default NumCPU/2): synthetic CPU load goroutines
-workgroup (default true): pin audio threads via x/workgroup
-ring-iters (default 200000): iterations for the ring-buffer throughput check
Tests
CGO_ENABLED=0 go vet ./x/duplexaudio ./examples/media/duplex-voice-loop
CGO_ENABLED=0 go test -v -count=1 ./x/duplexaudio ./examples/media/duplex-voice-loop
CGO_ENABLED=0 go test -run=^$ -bench=. -benchmem ./x/duplexaudio
Measured Results
Measured on Apple M4 Max (macOS 26.6.2, CGO_ENABLED=0, 24 kHz mono
float32, 128-frame = 5.33 ms slices, 8 synthetic CPU load workers, 10 barge-in
events):
Host Probe
- CoreAudio devices: 5 detected (default-in
id=104, default-out id=98)
VoiceProcessingIO AudioUnit (vpio): true
AVAudioIONode.setVoiceProcessingEnabled:error:: true
CATapDescription API: true (active_taps=0)
x/workgroup: true (max_parallel_threads=16, device_wg=true)
Lock-Free RingBuffer (go test -bench=. -benchmem ./x/duplexaudio)
| Benchmark |
ns/op |
Throughput |
Allocs/op |
BenchmarkRingBufferWriteRead-16 (256 f32) |
55.49 ns |
18,454 MB/s |
0 (0 B/op) |
BenchmarkRingBufferFlush-16 (256 f32) |
98.13 ns |
— |
0 (0 B/op) |
In-binary 128-sample microbenchmark: 3084.8 MSamples/s (11.49 GiB/s),
Write+Flush+Ack: 17.6 ns/op, 0 heap allocations.
Full-Duplex Loopback + Barge-In Under 8-Worker CPU Load
| Mode |
Workgroup Active |
Render Callbacks |
Underruns |
Barge-In Min |
Barge-In p50 |
Barge-In p95 / Max |
-workgroup=true |
true |
150 |
4 |
64 µs |
5.12 ms |
27.97 ms |
-workgroup=false |
false |
186 |
4 |
17 µs |
11.10 ms |
56.54 ms |
With x/workgroup UserInteractive pinning, median barge-in flush-to-silence
latency stays aligned with the 5.33 ms audio slice period (5.12 ms p50 vs
11.10 ms unpinned, a ~2.17x p50 and ~2.02x p95/max reduction under CPU load).