How ableton/audioperflab works
Project type and purpose
• This is a single‐product iOS application (“AudioPerfLab”) for real‐time audio performance exploration on iPhone and iPad.
File structure
• Top‐level Xcode project (AudioPerfLab.xcodeproj) with an iOS app target.
• AudioPerfLab/ contains Swift UI code (ViewController.swift, storyboards, Swift view subclasses) plus mixed C++/Objective‐C++ engine (Engine.hpp/.mm, ParallelSineBank.cpp, etc.) bridged via AudioPerfLab-Bridging-Header.h.
• Base/ is a C++ utility library (threading primitives, queues, semaphores, workgroup support) shared by the engine.
• CI config (.travis.yml), formatting, and license files.
README for additional insights
• CoreAudio I/O is driven by a “driver thread” with configurable modes.
• Worker threads process sine‐wave “partials” in parallel, using either OS workgroups (iOS 14+) or private APIs (iOS 13).
• Busy threads run low‐priority loops to manipulate the performance controller.
• UI allows toggling presets, buffer sizes, thread counts, work interval, busy‐thread parameters, and visualizations of load, cores, work distribution, and energy.
Main components and relationships
a. Components
• UI Layer (Swift + Storyboards + View subclasses)
• Audio Engine (Engine.mm, ParallelSineBank, Partial.cpp)
• Base Library (threading, synchronization, queueing, workgroup support)
• CoreAudio / Workgroup API (external iOS frameworks)
• Busy Threads subsystem
• Visualizations (data collectors + drawing code in Swift)
• User settings / Controls (PresetChooser, Sliders)
b. Interactions
1. User taps UI controls → Swift controllers update Engine configuration (buffer size, thread counts, presets).
2. Engine initializes CoreAudio I/O (AudioHost in Base) → driver thread callback fires each buffer period.
3. Driver thread delegates processing tasks to worker threads, managed by Base’s thread and queue classes.
4. Worker threads execute DSP (ParallelSineBank → Partial computations) and report timing metrics back to Engine.
5. Busy Threads run independently, calling Base primitives to modulate CPU load/energy.
6. Engine collects metrics (per‐thread timing, core scheduling, energy estimates) and forwards them to Swift UI.
7. UI renders visualizations (load graph, cores, energy, distribution) based on data stream.
c. Architectural patterns & principles
• Separation of concerns: Swift UI vs. C++ DSP vs. threading/OS integration.
• Producer‐consumer pattern: driver thread publishes tasks to a lock‐free queue (Base::FixedSPSCQueue), worker threads consume.
• Bridge pattern: Objective‐C++ bridging between Swift and C++.
• Strategy for managing real‐time threads: configurable driver mode, work interval vs. busy threads.
d. Key technologies
• Swift + UIKit/Storyboards for UI
• Objective‐C++ and C++17 for DSP/engine (.mm files, Standard Library)
• CoreAudio / AudioToolbox for audio I/O
• Custom Base library (threads, semaphores, work intervals)
• iOS Workgroup API (AudioToolbox workgroup_management) or private API fallback
• Low‐level synchronization (condition variables, semaphores)