rtsynth

command
v0.6.19 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 15 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

rtsynth

Renders audio from a Go thread promoted to the Mach real-time scheduling class (x/mach.Thread.SetTimeConstraint) and joined to the audio device's workgroup (kAudioDevicePropertyIOThreadOSWorkgroup + os_workgroup_join).

A dedicated Go OS thread synthesizes an additive tone into a ~21 ms lock-free ring; the AudioUnit render callback drains the ring on Core Audio's IO thread. Underruns are zero-filled, counted, and audible.

The A/B

Load every core, then run both scheduling classes:

for i in $(seq $(sysctl -n hw.ncpu)); do yes > /dev/null & done
go run . -dur 4s -harmonics 1024                # promoted
go run . -dur 4s -harmonics 1024 -no-promote    # default class

-harmonics is the CPU-cost dial: one math.Sin per harmonic per sample.

Measured, 2026-08-11

16-core arm64, macOS 26.x, go1.26.3, all cores loaded with yes:

harmonics promoted default class
1024 0 underruns / 375 pulls 46 underruns / 375 pulls
4096 148 / 375 316 / 375

At 1024 harmonics the promotion is the whole difference: silent vs audibly glitching. At 4096 the synthesis exceeds the physical CPU budget and both classes fail — promotion buys scheduling, not cycles.

Exit status is 1 if any underrun occurred, so the run is scriptable as a gate.

Documentation

Overview

Command rtsynth renders audio from a Go thread promoted to the real-time scheduling class and joined to the audio device's workgroup.

A dedicated Go OS thread synthesizes samples into a short lock-free ring; the AudioUnit render callback drains the ring on Core Audio's IO thread. The ring is deliberately shallow, so if the synth thread misses its cadence the callback underruns and the gap is audible as a dropout.

Run it twice to hear what promotion buys:

go run . -harmonics 64                # promoted: survives CPU load
go run . -harmonics 64 -no-promote    # default class: glitches under load

with something like "yes > /dev/null &" per CPU in another terminal. Underruns are counted and reported either way.

Jump to

Keyboard shortcuts

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