Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Editing Spatial Audio with an audio mix

At a glance

Item Summary
Purpose Add Spatial Audio editing capabilities with the Audio Mix API in the Cinematic framework.
App architecture A Swift sample centered on SpatialAudioCLI, with direct use of Cinematic, AVFoundation, ArgumentParser.
Main patterns Actor-isolated state
Project style 4 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── SpatialAudioCLI/
│   ├── SpatialAudioCLI.swift
│   ├── SpatialUtility.swift
│   ├── Actions.swift
│   └── AudioUnitHost.swift
├── Configuration/
│   └── SampleCode.xcconfig
└── SpatialAudioCLI.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 9 source declaration(s).

Overall architecture

Reference code

SpatialAudioCLI/SpatialAudioCLI.swift:12 — architecture anchor

@main
struct SpatialAudioCLI: AsyncParsableCommand {
    // ...
}

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

Ownership and state

Ownership evidence

SpatialAudioCLI/SpatialAudioCLI.swift:15 — stored dependency or nearest verified ownership anchor

@main
struct SpatialAudioCLI: AsyncParsableCommand {
    // ...
}
Owner Object or state Relationship Mutation authority
SpatialAudioCLI CommandConfiguration (configuration) creates and retains Initialized by the owner; the binding is immutable
SpatialAudioCLI String (action) owns value state App/module collaborators
SpatialAudioCLI URL (inputFile) owns value state App/module collaborators
SpatialAudioCLI Float (duration) 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

SpatialAudioCLI/SpatialAudioCLI.swift:13 — representative type boundary

struct SpatialAudioCLI: AsyncParsableCommand {
    // ...
}
Type Responsibility Depends on or conforms to
SpatialAudioCLI Represents a feature value or composable behavior AsyncParsableCommand
SpatialUtility Represents a feature value or composable behavior Concrete collaborators/imported frameworks
PreviewInput Represents a feature value or composable behavior Concrete collaborators/imported frameworks
BakeInput Represents a feature value or composable behavior Concrete collaborators/imported frameworks
ProcessInput Represents a feature value or composable behavior Concrete collaborators/imported frameworks
SetupAudioMixInput Represents a feature value or composable behavior Concrete collaborators/imported frameworks
RuntimeError Represents feature failure conditions LocalizedError
Actions Represents a feature value or composable behavior Concrete collaborators/imported frameworks
AudioUnitHost Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks

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
auAudioMix (SpatialAudioCLI/AudioUnitHost.swift:13) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
SpatialUtility (SpatialAudioCLI/SpatialUtility.swift:8) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.

Reference code

SpatialAudioCLI/AudioUnitHost.swift:13 — representative boundary

class AudioUnitHost {
    // ...
    public var auAudioMix = AVAudioUnitEffect()
    // ...
}

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
Feature and framework orchestration SpatialAudioCLI The sample keeps the demonstrated path in its primary concrete type.

Design patterns

Pattern Source evidence Purpose or tradeoff
Actor-isolated state SpatialAudioCLI/Actions.swift:11 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: feature-specific names rather than reusable layer suffixes.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: validate, run, verifyCNSpatialAudioRenderingStyle, verifyAudioOutput, deleteFiles, preview, bake, bakeReadWrite.
  • Files: SpatialAudioCLI/SpatialAudioCLI.swift, SpatialAudioCLI/SpatialUtility.swift, SpatialAudioCLI/Actions.swift, SpatialAudioCLI/AudioUnitHost.swift.

Architecture takeaways

  • SpatialAudioCLI is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Cinematic, AVFoundation, ArgumentParser 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
SpatialAudioCLI/SpatialAudioCLI.swift SpatialAudioCLI
SpatialAudioCLI/SpatialUtility.swift SpatialUtility, PreviewInput, BakeInput, ProcessInput, SetupAudioMixInput, RuntimeError
SpatialAudioCLI/Actions.swift Actions
SpatialAudioCLI/AudioUnitHost.swift AudioUnitHost