Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Creating an audio unit extension using the vDSP library

At a glance

Item Summary
Purpose Add biquadratic filter audio-effect processing to apps like Logic Pro X and GarageBand with the Accelerate framework.
App architecture A C/Objective-C header, Objective-C++, Swift sample with the source-visible chain vDSP_audio_unitAppContentViewAudioUnitViewModelSimplePlayEngineSwiftUI / AudioToolbox APIs.
Main patterns Model-View-ViewModel, View-controller organization, Protocol-oriented abstraction, Builder, Publisher-backed observable state
Project style 22 scanned source file(s) across C/Objective-C header, Objective-C++, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── vDSP-audio-unit/
│   ├── vDSP_audio_unitApp.swift
│   ├── Model/
│   │   ├── AudioUnitViewModel.swift
│   │   └── AudioUnitHostModel.swift
│   ├── ContentView.swift
│   └── Common/
│       ├── Audio/
│       │   └── SimplePlayEngine.swift
│       ├── MIDI/
│       │   └── MIDIManager.swift
│       └── UI/
│           └── ViewControllerRepresentable.swift
└── vDSP-audio-unitExtension/
    ├── Common/
    │   ├── Parameters/
    │   │   └── ParameterSpecBase.swift
    │   ├── UI/
    │   │   ├── ObservableAUParameter.swift
    │   │   └── AudioUnitViewController.swift
    │   └── Audio Unit/
    │       └── vDSP_audio_unitExtensionAudioUnit.mm
    └── UI/
        └── vDSP_audio_unitExtensionMainView.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 6 project/configuration file(s) and 24 source declaration(s).

Overall architecture

Reference code

vDSP-audio-unit/vDSP_audio_unitApp.swift:12 — architecture anchor

@main
struct vDSP_audio_unitApp: 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 Accelerate.

Ownership and state

Ownership evidence

vDSP-audio-unit/vDSP_audio_unitApp.swift:14 — stored dependency or nearest verified ownership anchor

    @ObservedObject private var hostModel = AudioUnitHostModel()

    var body: some Scene {
        WindowGroup {
            ContentView(hostModel: hostModel)
        }
    }
Owner Object or state Relationship Mutation authority
vDSP_audio_unitApp AudioUnitHostModel (hostModel) observes externally owned state The observed object is authoritative
AudioUnitViewModel Bool (showAudioControls) owns value state App/module collaborators
AudioUnitViewModel Bool (showMIDIContols) owns value state App/module collaborators
AudioUnitViewModel String (title) owns value state 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

vDSP-audio-unitExtension/Common/Parameters/ParameterSpecBase.swift:12 — representative type boundary

public protocol NodeSpec {}
Type Responsibility Depends on or conforms to
vDSP_audio_unitApp Application entry and top-level composition App
AudioUnitViewModel UI-facing state and feature coordination Concrete collaborators/imported frameworks
ParameterGroupBuilder Incrementally constructs a framework value or graph Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
SimplePlayEngine Owns processing or simulation work Concrete collaborators/imported frameworks
MIDIManager Long-lived feature or framework coordination Identifiable, ObservableObject
AudioUnitHostModel Feature data or observable state ObservableObject
AudioUnitViewController View lifecycle, callbacks, and feature coordination AUViewController, AUAudioUnitFactory
vDSP_audio_unitExtensionMainView User-interface presentation and input forwarding View
NodeSpec Defines a capability or collaboration contract Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: ParameterGroupSpecNodeSpec, ParameterTreeSpecNodeSpec, ParameterSpecNodeSpec.

Access control

Symbol Access Verified effect Likely rationale
loadAudioUnitViewController (vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:36) fileprivate Use is restricted to this source file. Inference: share with same-file helpers or extensions without exposing the symbol module-wide.
avAudioUnit (vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:56) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
stateChangeQueue (vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:59) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
engine (vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:62) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.

Reference code

vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:36 — representative boundary

    fileprivate func loadAudioUnitViewController(completion: @escaping (ViewController?) -> Void) {
        // ...
    }

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 vDSP_audio_unitApp The source’s App suffix makes this role explicit.
Incrementally constructs a framework value or graph ParameterGroupBuilder The source’s Builder suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination AudioUnitViewController The source’s Controller suffix makes this role explicit.
Owns processing or simulation work SimplePlayEngine The source’s Engine suffix makes this role explicit.
Long-lived feature or framework coordination MIDIManager The source’s Manager suffix makes this role explicit.
Feature data or observable state AudioUnitHostModel The source’s Model suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, vDSP_audio_unitExtensionMainView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel vDSP-audio-unit/Model/AudioUnitViewModel.swift:12 Role-named view models keep UI-facing state or coordination outside view declarations.
View-controller organization vDSP-audio-unitExtension/Common/UI/AudioUnitViewController.swift:15 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction vDSP-audio-unitExtension/Common/Parameters/ParameterSpecBase.swift:28 A local protocol and concrete conformance create an explicit capability boundary.
Builder vDSP-audio-unitExtension/Common/Parameters/ParameterSpecBase.swift:22 A builder-named type owns incremental construction.
Publisher-backed observable state vDSP-audio-unit/Model/AudioUnitHostModel.swift:17 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: vDSP_audio_unitApp; Builder: ParameterGroupBuilder; Controller: AudioUnitViewController; Engine: SimplePlayEngine; Manager: MIDIManager; Model: AudioUnitHostModel; View: ContentView, vDSP_audio_unitExtensionMainView; ViewModel: AudioUnitViewModel.
  • Protocols: NodeSpec.
  • Methods: validateID, buildBlock, createNode, createParameterGroup, createParameter, createAUParameterNodes, createAUParameterTree, create.
  • Files: vDSP-audio-unit/vDSP_audio_unitApp.swift, vDSP-audio-unit/Model/AudioUnitViewModel.swift, vDSP-audio-unit/ContentView.swift, vDSP-audio-unitExtension/Common/UI/ObservableAUParameter.swift, vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift, vDSP-audio-unit/Common/MIDI/MIDIManager.swift.

Architecture takeaways

  • vDSP_audio_unitApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, AudioToolbox, CoreAudioKit, CoreMIDI 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
vDSP-audio-unit/vDSP_audio_unitApp.swift vDSP_audio_unitApp
vDSP-audio-unit/Model/AudioUnitViewModel.swift AudioUnitViewModel
vDSP-audio-unitExtension/Common/Parameters/ParameterSpecBase.swift NodeSpec, ParameterGroupBuilder, ParameterGroupSpec, ParameterTreeSpec, ParameterSpec, func, func, func
vDSP-audio-unit/ContentView.swift ContentView, ContentView_Previews
vDSP-audio-unitExtension/Common/UI/ObservableAUParameter.swift ObservableAUParameterNode, func, ObservableAUParameterGroup, ObservableAUParameter, EditingState
vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift SimplePlayEngine
vDSP-audio-unit/Common/MIDI/MIDIManager.swift MIDIManager
vDSP-audio-unit/Model/AudioUnitHostModel.swift AudioUnitHostModel
vDSP-audio-unitExtension/Common/UI/AudioUnitViewController.swift AudioUnitViewController
vDSP-audio-unitExtension/UI/vDSP_audio_unitExtensionMainView.swift vDSP_audio_unitExtensionMainView