Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Equalizing audio with discrete cosine transforms (DCTs)

At a glance

Item Summary
Purpose Change the frequency response of an audio signal by manipulating frequency-domain data.
App architecture A Swift sample with the source-visible chain AudioEqualizationAppContentViewDrumLoopProviderAccelerate APIs.
Main patterns Protocol-oriented abstraction, SwiftUI environment injection, Publisher-backed observable state
Project style 4 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── AudioEqualization/
│   ├── AudioEqualizationApp.swift
│   ├── DrumLoopProvider.swift
│   ├── ContentView.swift
│   ├── AudioUtilities.swift
│   └── AudioEqualization.entitlements
├── Audio-Equalization.xcodeproj/
│   ├── .xcodesamplecode.plist
│   └── project.pbxproj
└── Configuration/
    └── SampleCode.xcconfig

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 4 project/configuration file(s) and 7 source declaration(s).

Overall architecture

Reference code

AudioEqualization/AudioEqualizationApp.swift:10 — architecture anchor

@main
struct AudioEqualizationApp: 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

AudioEqualization/AudioEqualizationApp.swift:17 — stored dependency or nearest verified ownership anchor

@main
struct AudioEqualizationApp: App {
    // ...
    let drumLoopProvider = DrumLoopProvider()
    // ...
}
Owner Object or state Relationship Mutation authority
AudioEqualizationApp DrumLoopProvider (drumLoopProvider) creates and retains Initialized by the owner; the binding is immutable
DrumLoopProvider Array (envelope) owns value state App/module collaborators
DrumLoopProvider Array (equalizedFrequencyDomainSignal) owns value state App/module collaborators
DrumLoopProvider Array (equalizedTimeDomainSignal) 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

AudioEqualization/AudioUtilities.swift:160 — representative type boundary

protocol SignalProvider {
    func getSignal() -> [Float]
    var sampleRate: CMTimeScale { get }
}
Type Responsibility Depends on or conforms to
AudioEqualizationApp Application entry and top-level composition App
SignalProvider Defines a capability or collaboration contract Concrete collaborators/imported frameworks
DrumLoopProvider 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
Mode Defines a closed set of feature states or choices String, CaseIterable, Identifiable
AudioUtilities Represents a feature value or composable behavior Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: DrumLoopProviderSignalProvider.

Access control

Symbol Access Verified effect Likely rationale
scenePhase (AudioEqualization/AudioEqualizationApp.swift:13) 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 (AudioEqualization/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 (AudioEqualization/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 (AudioEqualization/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.

Reference code

AudioEqualization/AudioEqualizationApp.swift:13 — representative boundary

    @Environment(\.scenePhase) private var scenePhase
    
    // The `drumLoopProvider` object provides the drum loop and exposes an API
    // to apply audio equalization.
    let drumLoopProvider = DrumLoopProvider()

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 AudioEqualizationApp 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 DrumLoopProvider, 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 AudioEqualization/DrumLoopProvider.swift:159 A local protocol and concrete conformance create an explicit capability boundary.
SwiftUI environment injection AudioEqualization/ContentView.swift:13 The environment supplies state or a capability without threading it through every initializer.
Publisher-backed observable state AudioEqualization/DrumLoopProvider.swift:57 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: AudioEqualizationApp; Generator: SignalGenerator; Provider: DrumLoopProvider, SignalProvider; View: ContentView.
  • Protocols: SignalProvider.
  • Methods: updateEnvelope, loadAudioSamples, apply, getSignal, updatePath, getAudioSamples, start, getSignalElement.
  • Files: AudioEqualization/AudioEqualizationApp.swift, AudioEqualization/DrumLoopProvider.swift, AudioEqualization/ContentView.swift, AudioEqualization/AudioUtilities.swift.

Architecture takeaways

  • AudioEqualizationApp 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
AudioEqualization/AudioEqualizationApp.swift AudioEqualizationApp
AudioEqualization/DrumLoopProvider.swift DrumLoopProvider, Mode
AudioEqualization/ContentView.swift ContentView
AudioEqualization/AudioUtilities.swift AudioUtilities, SignalGenerator, SignalProvider