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.

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 {
    // ...
}

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

    @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.

Class and protocol design

AudioTapSample/AudioTapSampleApp.swift:11 — representative type boundary

struct AudioTapSampleApp: App {
    // ...
}
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) {
        // ...
    }

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 AudioTapSampleApp
AudioTapSample/Model.swift Model, TapMute, TapMixdown
AudioTapSample/AudioRecorder.mm AudioRecorder, AudioRecorder
AudioTapSample/Views/ContentView.swift ContentView, ListType
AudioTapSample/AudioRecorder.h AudioRecorder
AudioTapSample/Views/AggregateDeviceView.swift AggregateDeviceView
AudioTapSample/Views/AudioIOView.swift AudioIOView
AudioTapSample/Views/AudioProcessView.swift AudioProcessView
AudioTapSample/Views/AudioTapView.swift AudioTapView
AudioTapSample/Views/TapConfigView.swift TapConfigView