Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Applying biquadratic filters to a music loop

At a glance

Item Summary
Purpose Change the frequency response of an audio signal using a cascaded biquadratic filter.
App architecture A Swift sample with the source-visible chain BiquadCoefficientsCalculatorAppContentViewFilterableMusicProviderAccelerate APIs.
Main patterns Protocol-oriented abstraction, SwiftUI environment injection
Project style 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: async declaration or closure, Task, DispatchQueue.main.async; none alone proves a background thread.
State/event model Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published.
Key frameworks/packages Accelerate, SwiftUI, AVFoundation, Combine; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── vDSP-Biquad-Coefficients-Calculator/
│   ├── BiquadCoefficientsCalculatorApp.swift
│   ├── FilterableMusicProvider.swift
│   ├── ContentView.swift
│   ├── AudioUtilities.swift
│   ├── BiquadCoefficientCalculator.swift
│   └── MagnitudeResponseCalculator.swift
├── Configuration/
│   └── SampleCode.xcconfig
└── vDSP-Biquad-Coefficients-Calculator.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

Structure observations

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

Overall architecture

Reference code

vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift:11 — architecture anchor

@main
struct BiquadCoefficientsCalculatorApp: App {

    @Environment(\.scenePhase) private var scenePhase

    // The `musicProvider` object provides the music loop and exposes an API
    // to filter the music loop using a biquadratic filter.
    let musicProvider = FilterableMusicProvider()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(musicProvider)
                .onChange(of: scenePhase) { phase in
                    if phase == .active {
                        Task(priority: .userInitiated) {
                            try? await musicProvider.loadAudioSamples()
                            try? SignalGenerator(signalProvider: musicProvider).start()
                        }
                    }
                }
        }
    }
}

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-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift:18 — stored dependency or nearest verified ownership anchor

@main
struct BiquadCoefficientsCalculatorApp: App {
    // ...
    let musicProvider = FilterableMusicProvider()
    // ...
}
Owner Object or state Relationship Mutation authority
BiquadCoefficientsCalculatorApp FilterableMusicProvider (musicProvider) creates and retains Initialized by the owner; the binding is immutable
Parameters Filtertype (filterType) stores or receives App/module collaborators
Parameters Frequency (frequency) stores or receives App/module collaborators
Parameters Q (Q) stores or receives 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
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:18
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift:26
Queue scheduling DispatchQueue.main.async The source addresses the main dispatch queue. vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift:172

@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-Biquad-Coefficients-Calculator/AudioUtilities.swift:18 — representative execution boundary

    static func getAudioSamples(forResource: String,
                                withExtension: String) async throws -> (naturalTimeScale: CMTimeScale,
                                                                        data: [Float])? {
        // ...
            return nil
        // ...
    }

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 SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift:14
State propagation ObservableObject ObservableObject supplies an observation contract. vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift:13
State propagation @Published A published property can emit owner-controlled changes. vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift:53
Source import Accelerate The cited file imports this module; runtime use and architectural role are not inferred. vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:9
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift:8
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:8
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift:9

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-Biquad-Coefficients-Calculator/AudioUtilities.swift:160 — representative type boundary

protocol SignalProvider {
    func getSignal() -> [Float]
    var sampleRate: CMTimeScale { get }
}
Type Responsibility Depends on or conforms to
BiquadCoefficientsCalculatorApp Application entry and top-level composition App
SignalProvider Defines a capability or collaboration contract Concrete collaborators/imported frameworks
FilterableMusicProvider Supplies a capability or framework resource ObservableObject
ContentView User-interface presentation and input forwarding View
SignalGenerator Generates feature data or resources Concrete collaborators/imported frameworks
Parameters Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
AudioUtilities Represents a feature value or composable behavior Concrete collaborators/imported frameworks
BiquadCoefficientCalculator Represents a feature value or composable behavior Concrete collaborators/imported frameworks
FilterType Defines a closed set of feature states or choices String, CaseIterable, Identifiable
SectionCoefficients Represents a feature value or composable behavior CustomStringConvertible

The source explicitly defines local protocol relationships: FilterableMusicProviderSignalProvider.

Access control

Symbol Access Verified effect Likely rationale
engine (vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:84) 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.
page (vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:87) 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.
signalProvider (vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:91) 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.
format (vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift:97) 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-Biquad-Coefficients-Calculator/AudioUtilities.swift:84 — representative boundary

class SignalGenerator {
    private let engine = AVAudioEngine()
    // ...
}

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 BiquadCoefficientsCalculatorApp The source’s App suffix makes this role explicit.
Generates feature data or resources SignalGenerator The source’s Generator suffix makes this role explicit.
Supplies a capability or framework resource FilterableMusicProvider, SignalProvider The source’s Provider suffix makes this role explicit.
User-interface presentation and input forwarding ContentView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Protocol-oriented abstraction vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift:212 A local protocol and concrete conformance create an explicit capability boundary.
SwiftUI environment injection vDSP-Biquad-Coefficients-Calculator/ContentView.swift:12 The environment supplies state or a capability without threading it through every initializer.

Naming conventions

  • Types: App: BiquadCoefficientsCalculatorApp; Generator: SignalGenerator; Provider: FilterableMusicProvider, SignalProvider; View: ContentView.
  • Protocols: SignalProvider.
  • Methods: loadAudioSamples, setSelectedSectionCoefficients, getSignal, makeFrequencyDomainWaveform, updatePath, getAudioSamples, start, getSignalElement.
  • Files: vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift, vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift, vDSP-Biquad-Coefficients-Calculator/ContentView.swift, vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift, vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientCalculator.swift, vDSP-Biquad-Coefficients-Calculator/MagnitudeResponseCalculator.swift.

Architecture takeaways

  • BiquadCoefficientsCalculatorApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Accelerate, SwiftUI, AVFoundation 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-Biquad-Coefficients-Calculator/BiquadCoefficientsCalculatorApp.swift Cited implementation, Task, SwiftUI state property wrapper, SwiftUI, BiquadCoefficientsCalculatorApp
vDSP-Biquad-Coefficients-Calculator/AudioUtilities.swift SignalProvider, Cited implementation, async declaration or closure, Accelerate, AVFoundation, AudioUtilities, SignalGenerator
vDSP-Biquad-Coefficients-Calculator/FilterableMusicProvider.swift Cited implementation, DispatchQueue.main.async, ObservableObject, @Published, Combine, FilterableMusicProvider, Parameters
vDSP-Biquad-Coefficients-Calculator/ContentView.swift Cited implementation, ContentView
vDSP-Biquad-Coefficients-Calculator/BiquadCoefficientCalculator.swift BiquadCoefficientCalculator, FilterType, SectionCoefficients
vDSP-Biquad-Coefficients-Calculator/MagnitudeResponseCalculator.swift MagnitudeResponseCalculator