Generating spatial audio from a multichannel audio stream
At a glance
| Item | Summary |
|---|---|
| Purpose | Convert 8-channel audio to 2-channel spatial audio by using a spatial mixer audio unit. |
| App architecture | A C/Objective-C header, Objective-C++, Swift sample with the source-visible chain SpatialAudioRendererApp → ContentView → ChainViewModel → AudioEngine → AudioToolbox APIs. |
| Main patterns | Model-View-ViewModel, SwiftUI environment injection, Publisher-backed observable state |
| Project style | 16 scanned source file(s) across C/Objective-C header, Objective-C++, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | No structured execution marker indexed; callback threading requires source review. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published. |
| Key frameworks/packages | SwiftUI, AudioToolbox, AVFoundation, AudioUnit, string; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── SpatialAudioRenderer/
├── SpatialAudioRendererApp.swift
└── Shared/
├── UI/
│ ├── Models/
│ │ └── ChainViewModel.swift
│ ├── ChainView.swift
│ └── ContentView.swift
├── Audio Engine/
│ ├── AudioEngine.h
│ ├── AudioEngine.mm
│ ├── Nodes/
│ │ ├── AUSMRenderer.h
│ │ ├── AUSMRenderer.mm
│ │ ├── AudioFileReader.mm
│ │ └── AudioFileReader.h
│ └── AudioKernel.h
└── Helpers/
└── AllocatedAudioBufferList.h
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 4 project/configuration file(s) and 12 source declaration(s).
Overall architecture
flowchart LR
N1["SpatialAudioRendererApp"]
N2["ContentView"]
N3["ChainViewModel"]
N4["AudioEngine"]
N5["AudioToolbox APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
SpatialAudioRenderer/SpatialAudioRendererApp.swift:9 — architecture anchor
@main
struct SpatialAudioRendererApp: App {
let model = ChainViewModel()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(model)
}
}
}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 Audio Toolbox.
Ownership and state
classDiagram
SpatialAudioRendererApp *-- ChainViewModel : model
NodeModel *-- Int : id
NodeModel *-- String : name
NodeModel *-- String : subTitle
Ownership evidence
SpatialAudioRenderer/SpatialAudioRendererApp.swift:11 — stored dependency or nearest verified ownership anchor
@main
struct SpatialAudioRendererApp: App {
let model = ChainViewModel()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
SpatialAudioRendererApp |
ChainViewModel (model) |
creates and retains | Initialized by the owner; the binding is immutable |
NodeModel |
Int (id) |
owns value state | App/module collaborators |
NodeModel |
String (name) |
owns value state | App/module collaborators |
NodeModel |
String (subTitle) |
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.
No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.
@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.
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. | SpatialAudioRenderer/Shared/UI/ChainView.swift:11 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift:15 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift:17 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | SpatialAudioRenderer/Shared/UI/Arrow.swift:7 |
| Source import | AudioToolbox |
The cited file imports this module; runtime use and architectural role are not inferred. | SpatialAudioRenderer/Shared/Audio Engine/AudioKernel.h:14 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | SpatialAudioRenderer/Shared/Audio Engine/Nodes/AUSMRenderer.h:13 |
| Source import | AudioUnit |
The cited file imports this module; runtime use and architectural role are not inferred. | SpatialAudioRenderer/Shared/Audio Engine/Nodes/AUSMRenderer.h:12 |
| Source import | string |
The cited file imports this module; runtime use and architectural role are not inferred. | SpatialAudioRenderer/Shared/Audio Engine/AudioKernel.h:17 |
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
SpatialAudioRenderer/SpatialAudioRendererApp.swift:10 — representative type boundary
@main
struct SpatialAudioRendererApp: App {
let model = ChainViewModel()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
SpatialAudioRendererApp |
Application entry and top-level composition | App |
NodeModel |
Feature data or observable state | Identifiable |
ChainViewModel |
UI-facing state and feature coordination | ObservableObject |
AudioEngine |
Owns processing or simulation work | NSObject |
AUSMRenderer |
Owns drawing, GPU, or presentation processing | Concrete collaborators/imported frameworks |
ChainView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
RealtimeInfo |
Represents feature data | Concrete collaborators/imported frameworks |
AudioKernel |
Owns feature behavior and collaborator lifecycle | Concrete collaborators/imported frameworks |
AudioFileReader |
Defines a feature-specific type boundary | NSObject |
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 |
|---|---|---|---|
fileReader (SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.h:13) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
sampleRate (SpatialAudioRenderer/Shared/Audio Engine/Nodes/AudioFileReader.h:18) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
pullAudioBlock (SpatialAudioRenderer/Shared/Audio Engine/Nodes/AudioFileReader.h:19) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
selection (SpatialAudioRenderer/Shared/UI/ChainView.swift:12) |
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
SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.h:13 — representative boundary
@interface AudioEngine : NSObject
// ...
@property (readonly) AudioFileReader * __nullable fileReader;
// ...
@endSwift 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 | SpatialAudioRendererApp |
The source’s App suffix makes this role explicit. |
| Owns processing or simulation work | AudioEngine |
The source’s Engine suffix makes this role explicit. |
| Feature data or observable state | NodeModel |
The source’s Model suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | AUSMRenderer |
The source’s Renderer suffix makes this role explicit. |
| User-interface presentation and input forwarding | ChainView, ContentView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | ChainViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift:15 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| SwiftUI environment injection | SpatialAudioRenderer/Shared/UI/ChainView.swift:11 |
The environment supplies state or a capability without threading it through every initializer. |
| Publisher-backed observable state | SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift:17 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: SpatialAudioRendererApp; Engine: AudioEngine; Model: NodeModel; Renderer: AUSMRenderer; View: ChainView, ContentView; ViewModel: ChainViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
audioSamples,loadAudio,handleRouteChange,init. - Files:
SpatialAudioRenderer/SpatialAudioRendererApp.swift,SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift,SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.h,SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.mm,SpatialAudioRenderer/Shared/Audio Engine/Nodes/AUSMRenderer.h,SpatialAudioRenderer/Shared/UI/ChainView.swift.
Architecture takeaways
SpatialAudioRendererAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, AudioToolbox, AVFoundation, AudioUnit 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 |
|---|---|
SpatialAudioRenderer/SpatialAudioRendererApp.swift |
Cited implementation, SpatialAudioRendererApp |
SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.h |
fileReader, AudioEngine |
SpatialAudioRenderer/Shared/Audio Engine/Nodes/AudioFileReader.h |
sampleRate, pullAudioBlock, AudioFileReader |
SpatialAudioRenderer/Shared/UI/ChainView.swift |
Cited implementation, SwiftUI state property wrapper, ChainView |
SpatialAudioRenderer/Shared/UI/Models/ChainViewModel.swift |
ChainViewModel, Cited implementation, ObservableObject, @Published, NodeModel |
SpatialAudioRenderer/Shared/UI/Arrow.swift |
SwiftUI, Arrow |
SpatialAudioRenderer/Shared/Audio Engine/AudioKernel.h |
AudioToolbox, string, AudioKernel |
SpatialAudioRenderer/Shared/Audio Engine/Nodes/AUSMRenderer.h |
AVFoundation, AudioUnit, AUSMRenderer |
SpatialAudioRenderer/Shared/Audio Engine/AudioEngine.mm |
AudioEngine |
SpatialAudioRenderer/Shared/UI/ContentView.swift |
ContentView |
SpatialAudioRenderer/Shared/Audio Engine/Nodes/AUSMRenderer.mm |
Feature implementation |
SpatialAudioRenderer/Shared/Audio Engine/Nodes/AudioFileReader.mm |
RealtimeInfo, AudioFileReader |
SpatialAudioRenderer/Shared/Helpers/AllocatedAudioBufferList.h |
AllocatedAudioBufferList |
SpatialAudioRenderer/Shared/Audio Engine/Nodes/OutputAU.mm |
Feature implementation |
SpatialAudioRenderer/Shared/Helpers/CoreAudioHelpers.h |
Feature implementation |
SpatialAudioRenderer/Shared/SpatialAudioRenderer-Bridging-Header.h |
Feature implementation |