duplex-voice-loop

command
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

  1. 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.
  2. Lock-Free Float32 RingBuffer: measures Write + Read throughput, Write + Flush + consumer ack latency, and verifies 0 heap allocations.
  3. 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).

Documentation

Rendered for darwin/amd64

Overview

Command duplex-voice-loop benchmarks lock-free 24 kHz float32 full-duplex audio loopback, instant barge-in flush-to-silence latency under synthetic CPU load with x/workgroup thread pinning, ring-buffer throughput (0 allocs/op), and probes host VoiceProcessingIO, CoreAudio devices, and CATapDescription.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL