opus-aac-stream
Offline encode -> packetize -> decode benchmark and verification harness for
macOS AudioToolbox AudioConverter Opus (kAudioFormatOpus) and AAC
(kAudioFormatMPEG4AAC) codecs via x/audiocodec
with CGO_ENABLED=0.
No microphone, CoreAudio IO device, or macOS TCC permission prompt is required.
The program synthesizes a 24 kHz / 48 kHz multi-tone float32 waveform, streams
it in 20 ms chunks through audiocodec.Encoder and audiocodec.Decoder, and
verifies delay-aligned SNR (> 25 dB), compression ratio (>= 8x), per-20 ms
encode+decode latency (< 1 ms), and real-time factor (RTF < 0.05).
Usage
CGO_ENABLED=0 go run ./examples/audiotoolbox/opus-aac-stream
CGO_ENABLED=0 go run ./examples/audiotoolbox/opus-aac-stream -dur 5s
Exit status is 1 if any profile fails a quality, compression, or latency gate.
Measured Output
Apple M4 Max, macOS 26.6.2, go1.27.0 darwin/arm64, CGO_ENABLED=0, -dur 2s:
| Profile |
Packets |
PCM (KB) |
Encoded (KB) |
Ratio |
SNR (dB) |
Lat / 20 ms |
RTF |
| Opus 24kHz mono 64kbps |
101 |
187.5 |
18.9 |
9.92x |
28.73 |
171.91µs |
0.00860 |
| Opus 48kHz mono 48kbps |
101 |
375.0 |
12.6 |
29.75x |
28.66 |
180.808µs |
0.00904 |
| AAC 24kHz mono 48kbps |
49 |
187.5 |
4.2 |
45.10x |
35.11 |
39.807µs |
0.00199 |
| AAC 48kHz mono 64kbps |
96 |
375.0 |
5.9 |
63.27x |
34.36 |
66.581µs |
0.00333 |