Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Capturing system audio with Core Audio taps

At a glance

Item Summary
Purpose Use a Core Audio tap to capture outgoing audio from a process or group of processes.
App architecture A C/Objective-C header, Objective-C++, Swift sample with the source-visible chain AudioTapSampleAppContentViewModelAudioRecorderCoreAudio APIs.
Main patterns SwiftUI environment injection, Binding-based state propagation, Publisher-backed observable state
Project style 15 scanned source file(s) across C/Objective-C header, Objective-C++, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.main; none alone proves a background thread.
State/event model Source-visible mechanisms: @Published, ObservableObject, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, CoreAudio, AppKit, AudioToolbox, Foundation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── AudioTapSample/
    ├── AudioTapSampleApp.swift
    ├── Model.swift
    ├── AudioRecorder.mm
    ├── Views/
    │   ├── ContentView.swift
    │   ├── AggregateDeviceView.swift
    │   ├── AudioIOView.swift
    │   ├── AudioProcessView.swift
    │   ├── AudioTapView.swift
    │   └── TapConfigView.swift
    ├── AudioRecorder.h
    ├── AggregateDevice.swift
    └── AudioTap.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C/Objective-C header, Objective-C++, Swift.
  • The verified tree contains 5 project/configuration file(s) and 19 source declaration(s).

Overall architecture

Reference code

AudioTapSample/AudioTapSampleApp.swift:10 — architecture anchor

@main
struct AudioTapSampleApp: App {
    @StateObject private var model = Model()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(model)
        }
    }
}

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Core Audio.

Ownership and state

Ownership evidence

AudioTapSample/AudioTapSampleApp.swift:12 — stored dependency or nearest verified ownership anchor

@main
struct AudioTapSampleApp: App {
    @StateObject private var model = Model()
    // ...
}
Owner Object or state Relationship Mutation authority
AudioTapSampleApp Model (model) owns wrapper-managed state Owning lexical scope
Model AudioObjectID (processSelection) stores or receives App/module collaborators
Model AudioObjectID (tapSelection) stores or receives App/module collaborators
Model TapConfig (tapConfiguration) creates and retains App/module collaborators

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

Concern Source mechanism Verified placement or handoff Evidence
Queue scheduling DispatchQueue.main The source addresses the main dispatch queue. AudioTapSample/AggregateDevice.swift:63

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

Reference code

AudioTapSample/AggregateDevice.swift:63 — representative execution boundary

class AggregateDevice: AudioDevice {
    // ...
        AudioObjectAddPropertyListenerBlock(id, &deviceListAddress, DispatchQueue.main, propertiesChanged)
    // ...
}

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
State propagation @Published A published property can emit owner-controlled changes. AudioTapSample/AggregateDevice.swift:12
State propagation ObservableObject ObservableObject supplies an observation contract. AudioTapSample/AudioDevice.swift:8
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. AudioTapSample/AudioTapSampleApp.swift:12
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. AudioTapSample/AudioTapSampleApp.swift:8
Source import CoreAudio The cited file imports this module; runtime use and architectural role are not inferred. AudioTapSample/AggregateDevice.swift:8
Source import AppKit The cited file imports this module; runtime use and architectural role are not inferred. AudioTapSample/AudioRecorder.h:11
Source import AudioToolbox The cited file imports this module; runtime use and architectural role are not inferred. AudioTapSample/AudioRecorder.h:13
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. AudioTapSample/Model.swift:8

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

AudioTapSample/AudioTapSampleApp.swift:11 — representative type boundary

@main
struct AudioTapSampleApp: App {
    @StateObject private var model = Model()
    // ...
}
Type Responsibility Depends on or conforms to
AudioTapSampleApp Application entry and top-level composition App
Model Feature data or observable state ObservableObject
ContentView User-interface presentation and input forwarding View
AudioRecorder Owns capture or recording work NSObject
AggregateDeviceView User-interface presentation and input forwarding View
AudioIOView User-interface presentation and input forwarding View
AudioProcessView User-interface presentation and input forwarding View
AudioTapView User-interface presentation and input forwarding View
TapConfigView User-interface presentation and input forwarding View
TapMute Defines a closed set of feature states or choices Int, CaseIterable

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
addRemove (AudioTapSample/AggregateDevice.swift:190) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
hash (AudioTapSample/AudioDevice.swift:29) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
hash (AudioTapSample/AudioProcess.swift:51) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
processNameFromPID (AudioTapSample/AudioProcess.swift:97) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.

Reference code

AudioTapSample/AggregateDevice.swift:190 — representative boundary

    private func addRemove(uid: String, action: ModifyAction, type: ListType) {
        var propertyAddress: AudioObjectPropertyAddress
        // ...
    }

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Application entry and top-level composition AudioTapSampleApp The source’s App suffix makes this role explicit.
Feature data or observable state Model The source’s Model suffix makes this role explicit.
Owns capture or recording work AudioRecorder The source’s Recorder suffix makes this role explicit.
User-interface presentation and input forwarding AggregateDeviceView, AudioIOView, AudioProcessView, AudioTapView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
SwiftUI environment injection AudioTapSample/Views/AggregateDeviceView.swift:11 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation AudioTapSample/Views/TapConfigView.swift:12 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Publisher-backed observable state AudioTapSample/AggregateDevice.swift:12 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: AudioTapSampleApp; Model: Model; Recorder: AudioRecorder; View: AggregateDeviceView, AudioIOView, AudioProcessView, AudioTapView, ContentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: registerListeners, unregisterListeners, loadProcessList, processStopped, loadTapList, createTap, destroyTap, loadDeviceList.
  • Files: AudioTapSample/AudioTapSampleApp.swift, AudioTapSample/Model.swift, AudioTapSample/AudioRecorder.mm, AudioTapSample/Views/ContentView.swift, AudioTapSample/AudioRecorder.h, AudioTapSample/Views/AggregateDeviceView.swift.

Architecture takeaways

  • AudioTapSampleApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, CoreAudio, AppKit, AudioToolbox through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
AudioTapSample/AudioTapSampleApp.swift Cited implementation, AudioTapSampleApp, SwiftUI state property wrapper, SwiftUI
AudioTapSample/AggregateDevice.swift Cited implementation, DispatchQueue.main, @Published, CoreAudio, AggregateDevice, ModifyAction, ListType
AudioTapSample/AudioDevice.swift Cited implementation, ObservableObject, AudioDevice
AudioTapSample/AudioProcess.swift Cited implementation, AudioProcess
AudioTapSample/Views/AggregateDeviceView.swift Cited implementation, AggregateDeviceView
AudioTapSample/Views/TapConfigView.swift Cited implementation, TapConfigView
AudioTapSample/AudioRecorder.h AppKit, AudioToolbox, AudioRecorder
AudioTapSample/Model.swift Foundation, Model, TapMute, TapMixdown
AudioTapSample/AudioRecorder.mm AudioRecorder
AudioTapSample/Views/ContentView.swift ContentView, ListType
AudioTapSample/Views/AudioIOView.swift AudioIOView
AudioTapSample/Views/AudioProcessView.swift AudioProcessView
AudioTapSample/Views/AudioTapView.swift AudioTapView
AudioTapSample/AudioTap.swift TapConfig, AudioTap
AudioTapSample/AudioTapSample-Bridging-Header.h Feature implementation