Per-app audio on macOS with Core Audio process taps
Giving every macOS app its own volume, EQ and output device with Core Audio process taps: what the API leaves to you, and the traps on the way.
macOS has one volume control in the menu bar: music, video calls and notification sounds go up and down together. For a long time, per-app volume needed a virtual audio device: install a HAL plug-in, route apps’ audio into it and split it apart again in user space. Since macOS 14.2 there is a public API for this: Core Audio process taps (auricle requires 14.4 or later). auricle, my menu bar mixer, is built entirely on them, with no driver and no third-party dependencies. This note is what I learned writing it: what a tap is, how one becomes a mixer channel, and where the API leaves you on your own.
What a tap is
A process tap is a Core Audio object that receives a copy of the audio a set of processes is sending to output. You describe what you want with a CATapDescription and hand it to AudioHardwareCreateProcessTap, which gives you back an AudioObjectID. Three decisions go into the description. Which processes: a stereo mixdown of a list of processes, or a global tap of everything except a list. What happens to the original sound: muteBehavior. auricle uses .mutedWhenTapped, which silences the app’s direct output while the tap is being read, so the app is not heard twice. And whether other processes can see it: isPrivate.
private func makeAppTapDescription(objectIDs: [AudioObjectID]) -> CATapDescription {
let description = CATapDescription(stereoMixdownOfProcesses: objectIDs)
description.name = "Auricle App Tap"
description.muteBehavior = .mutedWhenTapped
description.isPrivate = true
return description
}
ProcessTapEngine.swift, lines 194–200The “processes” here are not PIDs. Core Audio has its own process objects: the HAL publishes the list as kAudioHardwarePropertyProcessObjectList, and each object reports its PID, its bundle ID and whether it is producing output right now (kAudioProcessPropertyIsRunningOutput). auricle’s process monitor does not poll; it watches the list and each object’s flag with listeners. One app is often several process objects; browsers play sound from helper processes. auricle groups helpers under the app responsible for them. For that it uses a private libsystem symbol looked up at run time, responsibility_get_pid_responsible_for_pid; it treats the symbol as optional, and if it is missing each process simply gets its own row.
A tap is an input; you build the output
A tap gives you samples; it does not play them. To get the sound back to the speakers, auricle builds a private aggregate device for every app it controls: the real output device is the main sub-device, and the tap goes into the aggregate’s tap list. An IOProc installed on that aggregate is called on the HAL’s real-time thread with the tap’s samples as input and the output device’s buffers as output. Whatever the IOProc writes there is what you hear.
- appone or more process objects
- process tapstereo mixdown,
mutedWhenTapped - aggregateprivate; output device + tap
- gain rampvolume × boost, across the buffer
- 10-band EQbiquad cascade, vDSP
- clip±1.0
- outputspeakers, headphones…
gold-framed steps run on the real-time thread, inside the IOProc
let aggregateSuffix = UUID().uuidString
var aggregateDescription: [String: Any] = [
kAudioAggregateDeviceNameKey: "Auricle: \(aggregateSuffix.suffix(8))",
kAudioAggregateDeviceUIDKey: "\(AudioDeviceManager.auricleAggregatePrefix).\(aggregateSuffix)",
kAudioAggregateDeviceIsPrivateKey: true,
kAudioAggregateDeviceIsStackedKey: false,
kAudioAggregateDeviceMainSubDeviceKey: target.uid,
kAudioAggregateDeviceTapAutoStartKey: true,
kAudioAggregateDeviceSubDeviceListKey: [
[kAudioSubDeviceUIDKey: target.uid,
kAudioSubDeviceDriftCompensationKey: 0],
],
]
if let tapUUID {
aggregateDescription[kAudioAggregateDeviceTapListKey] = [
[kAudioSubTapUIDKey: tapUUID.uuidString,
kAudioSubTapDriftCompensationKey: 1],
]
} else {
aggregateDescription[kAudioAggregateDeviceTapListKey] = [[String: Any]]()
}
ProcessTapEngine.swift, lines 316–336Two details in that dictionary matter. The first is the clock: the tap’s clock and the hardware’s clock are not the same clock. The output device is the main sub-device with drift compensation off; the tap has it on. When the two clocks drift apart, it is the tap that gets adjusted, not the hardware. The second is identity: the aggregate’s UID carries a fresh UUID on every build, and the device is private, so it does not appear in other apps’ device lists.
When the target changes, the chain is rebuilt from scratch: when the user routes the app to another device, when the device’s nominal sample rate changes, when the device disappears (kAudioDevicePropertyDeviceIsAlive), and when coreaudiod restarts. The last one is the sneaky one: at that point every object ID in the chain is dead and no longer refers to our objects. They have to be dropped without being destroyed, and the chain rebuilt from the last configuration.
The real-time thread
The IOProc runs on a real-time thread and its deadline is one buffer. auricle asks the aggregate for a 512-frame buffer; at 48 kHz that is about 10.7 ms. Nothing inside may wait: no allocation, no lock that can block, no logging. Every buffer is allocated up front, when the chain is built.
Parameters arrive from the UI through a pending/active pair guarded by an os_unfair_lock. But the render thread only ever calls os_unfair_lock_trylock: if the UI happens to hold the lock, it carries on with the previous buffer’s parameters. A slider move arriving one buffer late is inaudible; a render thread that waits for the UI is not.
var gain = currentGain
var step = (active.targetGain - currentGain) / Float(frames)
vDSP_vrampmul2(workL, workR, 1, &gain, &step, outL, outR, 1, vDSP_Length(frames))
currentGain = active.targetGain
if active.eqEnabled {
eq.process(channels: eqChannels, stride: 1, frameCount: frames)
}
var lowerBound: Float = -1
var upperBound: Float = 1
vDSP_vclip(outL, 1, &lowerBound, &upperBound, outL, 1, vDSP_Length(frames))
vDSP_vclip(outR, 1, &lowerBound, &upperBound, outR, 1, vDSP_Length(frames))
ProcessTapEngine.swift, lines 640–652Gain never jumps; it is ramped across the buffer from the old value to the new one (vDSP_vrampmul2), which is why dragging the volume slider does not click. The EQ is ten peaking filters from 32 Hz to 16 kHz, Q 1.41, ±12 dB per band, with coefficients from the standard peaking filter in the Audio EQ Cookbook. The ten bands run as one cascade through vDSP_biquadm. There is a trap here: a vDSP_biquadm_Setup must not be touched from two threads at once. So new coefficients are computed on the control side, parked behind another trylock, and applied by the render thread itself with vDSP_biquadm_SetTargetsDouble, which moves the coefficients towards their target instead of switching at once. Bands at or above 0.49 of the sample rate, just below Nyquist (0.5), are left as identity, so a device running at a low sample rate cannot make the cascade unstable.
The last stage is a hard clip at ±1.0 (vDSP_vclip). Boost goes up to +12 dB, roughly four times the amplitude, so a source that is already loud will clip with boost on. That is a deliberate trade for simplicity: a hard clip has no state and no latency. On loud material a limiter would sound better; the current code does not have one.
What the API does not do for you
Muted is not invisible. .mutedWhenTapped silences the app’s direct sound to the device, but other taps still hear the process. auricle also has a system-wide chain (master boost and EQ), built on a global tap. Without care, an app with its own chain would be captured by both taps and played twice. So the global tap excludes every process object owned by a per-app engine. The list is updated live: the running tap’s kAudioTapPropertyDescription is rewritten with the same UUID, so the aggregate’s reference to it stays valid; if that fails, the chain is rebuilt. The consequence is written down in the README: master EQ does not stack on top of per-app EQ.
Feedback. The global tap also has to exclude auricle itself, or it captures its own output. But the app’s own process object cannot always be resolved at the moment the chain is built. In that case auricle starts the aggregate and the IOProc first (they produce silence), retries resolving its own process object ten times, 20 ms apart, and attaches the tap afterwards through kAudioAggregateDevicePropertyTapList.
Permission. Taps sit behind the System Audio Recording permission (Privacy & Security → Screen & System Audio Recording). There is no call that tells you up front whether you have it. At launch auricle creates a throwaway, unmuted tap and destroys it right away: that either brings up the prompt or reveals an earlier denial. And it only treats specific OSStatus values (kAudioHardwareIllegalOperationError, kAudioDevicePermissionsError) as a permission problem; anything else, such as the app quitting mid-build, stays an error for that one app. The app’s Info.plist carries NSAudioCaptureUsageDescription, the text shown in the prompt. The grant is tied to the code signature; auricle is ad-hoc signed and not notarized, so a new build may ask again.
Format. The replay path assumes 32-bit float samples. If the target device’s output stream is in any other format, the engine refuses to start and says why, rather than guessing.
Version. auricle requires macOS 14.4 or later and has no fallback for older systems.
What it adds up to
The pieces are small; the work is in the edge cases. Who else is listening, which clock wins, what happens when a device disappears in the middle of a buffer, what the user sees when permission is missing. auricle’s audio never leaves the machine: it records nothing, stores no audio and opens no network connections; samples sit in memory only until they are processed and handed to the output. The lab page lets you hear the per-app idea in the browser; the engine itself is in the files below.