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.
Execution model Source-visible boundaries: DispatchQueue.main.async, DispatchQueue(label:); none alone proves a background thread.
State/event model Source-visible mechanisms: ObservableObject, SwiftUI state property wrapper, @Published.
Key frameworks/packages SwiftUI, AudioToolbox, Foundation, CoreAudioKit, CoreMIDI; these are source dependencies, not architecture labels.

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 {
    @ObservedObject private var hostModel = AudioUnitHostModel()

    var body: some Scene {
        WindowGroup {
            ContentView(hostModel: hostModel)
        }
    }
}

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

@main
struct vDSP_audio_unitApp: App {
    @ObservedObject private var hostModel = AudioUnitHostModel()
    // ...
}
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.

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.async The source addresses the main dispatch queue. vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:38
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:59

@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

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

            DispatchQueue.main.async {
                // ...
                            let genericViewController = AUGenericViewController()
                // ...
            }

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 ObservableObject ObservableObject supplies an observation contract. vDSP-audio-unit/Common/MIDI/MIDIManager.swift:10
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. vDSP-audio-unit/ContentView.swift:12
State propagation @Published A published property can emit owner-controlled changes. vDSP-audio-unit/Model/AudioUnitHostModel.swift:17
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. vDSP-audio-unit/Common/UI/ViewControllerRepresentable.swift:8
Source import AudioToolbox The cited file imports this module; runtime use and architectural role are not inferred. vDSP-audio-unit/Common/TypeAliases.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:8
Source import CoreAudioKit The cited file imports this module; runtime use and architectural role are not inferred. vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift:9
Source import CoreMIDI The cited file imports this module; runtime use and architectural role are not inferred. vDSP-audio-unit/Common/MIDI/MIDIManager.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

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) {
        // ...
                            let genericViewController = AUGenericViewController()
        // ...
    }

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 Cited implementation, vDSP_audio_unitApp
vDSP-audio-unitExtension/Common/Parameters/ParameterSpecBase.swift NodeSpec, Cited implementation, ParameterGroupBuilder, ParameterGroupSpec, ParameterTreeSpec, ParameterSpec, func
vDSP-audio-unit/Common/Audio/SimplePlayEngine.swift Cited implementation, DispatchQueue.main.async, DispatchQueue(label:), Foundation, CoreAudioKit, SimplePlayEngine
vDSP-audio-unit/Model/AudioUnitViewModel.swift AudioUnitViewModel
vDSP-audio-unitExtension/Common/UI/AudioUnitViewController.swift AudioUnitViewController
vDSP-audio-unit/Model/AudioUnitHostModel.swift Cited implementation, @Published, AudioUnitHostModel
vDSP-audio-unit/Common/MIDI/MIDIManager.swift ObservableObject, CoreMIDI, MIDIManager
vDSP-audio-unit/ContentView.swift SwiftUI state property wrapper, ContentView, ContentView_Previews
vDSP-audio-unit/Common/UI/ViewControllerRepresentable.swift SwiftUI, WrapperVC, AUViewControllerUI
vDSP-audio-unit/Common/TypeAliases.swift AudioToolbox, Feature implementation
vDSP-audio-unitExtension/Common/UI/ObservableAUParameter.swift ObservableAUParameterNode, func, ObservableAUParameterGroup, ObservableAUParameter, EditingState
vDSP-audio-unitExtension/UI/vDSP_audio_unitExtensionMainView.swift vDSP_audio_unitExtensionMainView
vDSP-audio-unitExtension/Common/Audio Unit/vDSP_audio_unitExtensionAudioUnit.mm vDSP_audio_unitExtensionAudioUnit
vDSP-audio-unitExtension/UI/BiquadCurveDisplay.swift BiquadCurveDisplay, MagnitudeResponseCalculator
vDSP-audio-unitExtension/Common/Audio Unit/vDSP_audio_unitExtensionAudioUnit.h vDSP_audio_unitExtensionAudioUnit
vDSP-audio-unitExtension/UI/ParameterSlider.swift ParameterSlider