Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
Feature Specification: Professional C++20 DSP Architecture Overhaul, .h/.cpp Modularization & Plugin Scanner Separation
Feature Branch: 030-dsp-architecture-overhaul
Created: 2026-10-19
Status: Implemented
Input: User description: "In this folder you have the Nota DAW code and my DSP optimization patches — plan a rebuild of the entire DSP code into professional C++; it would be good to split the plugin scanner out from the engine itself; we want to keep the whole C ABI of the engine; you may take inspiration from well-written DSP elsewhere; we also want to split the code into sensible folders. Read all Nota project rules and plan this carefully. Try to split things into more .cpp and .h files the way C++ is normally written, and write an implementation spec from it."
Nota Context
Feature area:
- Engine (C++,
src/native/nota.engine) — real-time audio rules apply, seeARCHITECTURE.mdAR table - Managed app (C#,
src/managed/*) — domain, application, infrastructure, presentation - UI (Avalonia,
src/managed/Nota.Presentation) — followDESIGN.md(Studio) - Plugin hosting (
pluginhost/) — the only place JUCE is allowed - Build / packaging / CI (
scripts/,.github/) — seeBUILD.md - Docs only
Nota docs to keep in mind:
ARCHITECTURE.md (AR-4 lock-free queues, AR-5 immutable snapshots, AR-6 audio-thread safety, AR-7 pure C ABI, AR-8 sample-accurate MIDI, AR-9 Transport single source of time),
CONTRIBUTING.md (AGPL-3.0-only SPDX headers, dependency policy, PR expectations),
BUILD.md, DESIGN.md, FEATURES.md.
User Scenarios & Testing (mandatory)
User Story 1 - Idiomatic .h/.cpp Modular Architecture & Domain Folder Organization (Priority: P1) 🎯 MVP
As a C++ audio developer working on Nota's native engine, I want the flat 138-file src/ directory reorganized into domain-driven subdirectories (abi/, dsp/, devices/, engine/, audio_io/, media/) and monolithic header-only classes split into clean declaration headers (.h) and implementation translation units (.cpp), so that compilation parallelizes across CPU cores, include dependencies are minimized, and the codebase follows professional C++20/C++23 engineering standards.
Why this priority:
Currently, all 138 engine files sit in a single flat folder (src/native/nota.engine/src/), and all 25 audio effects, 16 instruments, 6 MIDI effects, and rack containers are written as 500–1,800 line header-only files. Including BuiltinDevices.h or compiling Engine_Devices.cpp forces the compiler to re-parse ~35,000 lines of inline DSP implementation. Splitting declarations (.h) from implementations (.cpp) and organizing files into logical folders is the structural foundation for all subsequent DSP and scanner improvements.
Independent Test:
Build nota_engine and nota-scanworker via ./scripts/build.sh. Verify that incremental edits to a single device .cpp file recompile only that translation unit and re-link in under 2 seconds, all exported symbols match nota_exports.txt / nota_exports.map, and tests/Nota.SmokeTest passes 100%.
Acceptance Scenarios:
- Given
src/native/nota.engine/, When inspecting the directory layout, Then source files are cleanly separated intosrc/abi/,src/dsp/{core,math,primitives,poly}/,src/devices/{racks,effects,instruments,midi_fx}/,src/engine/,src/audio_io/{macos,desktop}/,src/media/, andpluginhost/{bridge,hosting,scanner}/. - Given any non-template DSP device, instrument, MIDI effect, rack, or engine subsystem, When inspecting its source files, Then the
.hfile contains only the class interface, public types, and member declarations, while method bodies and internal helper tables reside in the corresponding.cppfile. - Given the public C ABI header
include/nota/nota_engine.h, When built on macOS, Linux, and Windows, Then 100% of existing C ABI functions, structs, and enums remain intact with zero breaking changes toNota.InfrastructureP/Invoke bindings.
User Story 2 - Standalone Plugin Scanner & Thread-Safe Plugin Catalog Separation (Priority: P1)
As a DAW user scanning VST3 and AudioUnit plugins in the background while browsing or editing a project, I want plugin discovery and catalog management (nota_pluginscanner) separated from the audio engine and in-process plugin hosting (nota_pluginhost), so that background plugin scans are completely thread-safe, resilient to crashing or noisy plugins, and decoupled from real-time engine internals.
Why this priority:
pluginhost/PluginHost.cpp currently mixes out-of-process scanning, XML catalog persistence, scan-path management, JUCE GUI window hosting, and real-time PluginInstrument/PluginEffect audio adapters in one 1,030-line file. Furthermore, catalog() and extraScanPaths() are unsynchronized function-local statics accessed concurrently when C# runs Task.Run(() => catalog.Scan(worker)). Separating the scanner into its own module with thread-safe catalog access and Zrythm-inspired coordinator/worker management eliminates data races and decouples scanning from the engine.
Independent Test:
Run plugin discovery and catalog queries concurrently from multiple threads, test with crashing/hanging/stdout-polluting plugins, and run Nota.SmokeTest (including PluginStoreTests). Verify thread-safe catalog updates, clean separation of CMake targets (nota_pluginscanner, nota_pluginhost, nota-scanworker), and 100% C ABI compatibility for all nota_pluginhost_* functions.
Acceptance Scenarios:
- Given
pluginhost/scanner/, When compiled via CMake, Thennota_pluginscannerbuilds as an independent static library with zero dependencies onEngine,Track,Graph, orDevice. - Given a background scan running via
nota_pluginhost_scan(), When the UI thread concurrently queriesnota_pluginhost_plugin_count(),nota_pluginhost_plugin_desc(), ornota_pluginhost_index_of_id(), Then access is synchronized safely without data races or iterator invalidation. - Given
PluginInstrumentandPluginEffectinpluginhost/hosting/, When processing audio blocks on the real-time thread, Then stereo deinterleaving/interleaving and sidechain gain scaling use vectorized SIMD andFastMathwith zero heap allocations.
User Story 3 - Shared C++20 DSP Primitives, FastMath & Hardware SIMD Acceleration (Priority: P1)
As a music producer running CPU-heavy mixing and synthesis sessions, I want all built-in instruments and audio effects to share a unified, industrial-grade C++20 DSP library (dsp/core, dsp/math, dsp/primitives, dsp/poly) featuring FastMath approximations, ARM NEON / x86 SSE/AVX/FMA vectorization, and deduplicated filter/delay/oscillator/voice building blocks, so that CPU load is minimized while maintaining studio-grade audio transparency ($< 0.05\text{ dB}$ error).
Why this priority:
Eliminating duplicated filter/delay/oscillator code across 40+ devices and replacing per-sample standard library transcendentals (std::sin, std::cos, std::tanh, std::log10, std::pow, std::exp2) and scalar buffer loops with unified FastMath, Simd, and SimdAudio routines delivers 25%–55% CPU savings across effects and polyphonic synths.
Independent Test:
Execute DspOptimizationTests in tests/Nota.SmokeTest, verifying numerical accuracy, frequency response stability, True-Peak SIMD FIR accuracy, absence of NaNs/denormals, and measurable CPU reduction across all built-in effects and instruments.
Acceptance Scenarios:
- Given
src/dsp/math/, When any device or synth evaluates pitch, dB/linear conversion, saturation, or LFOs, Then it usesFastMath.h(exp2f,log2f,dbToLin,linToDb,tanh,tanhPrecise,tanhRatio,sin,cos,tanPrewarp). - Given
src/dsp/math/Simd.handSimdAudio.h, When performing buffer summing, scaling, clamping, NaN/Inf suppression, 16-tap FIR dot products, deinterleaving/interleaving, or peak/RMS/correlation metering, Then hardware SIMD instructions (ARM NEON / x86 SSE/AVX/FMA) execute in 16-sample vector chunks with clean scalar tails. - Given
src/dsp/primitives/andsrc/dsp/poly/, When building filters (SvfFilter,BiquadCascade,LadderFilter), delay lines (DelayLine), convolutions (Convolution), true-peak meters (TruePeakMeter), or polyphonic instruments (PolyVoiceManager,SynthVoice), Then devices reuse these shared.h/.cppclasses instead of duplicating local implementations. - Given real-time audio methods across
dsp/,devices/, andengine/, When compiled with Clang, Then methods are annotated withNOTA_RT_SAFE(noexcept [[clang::nonblocking]]) andNOTA_HOT, andEngine::computeBlockMidi()performs zero runtime vector resizing on the audio thread (fixing AR-6).
User Story 4 - Engine-Wide Hybrid Silence Detection & Auto-Sleep Bypass (Priority: P2)
As a producer working on large arrangements (30–80 tracks) where many tracks are silent at any given bar, I want stateful hysteresis silence detection (SilenceDetector) and automatic device/instrument sleep (isIdle(), hasTail(), wake()), so that silent tracks and decayed time-based effects consume near-zero CPU while waking up instantaneously on sample 0 of any incoming transient.
Why this priority: In typical DAW arrangements, 70%–85% of tracks are silent at any given moment. Skipping silent generators and sleeping effect chains reduces idle and sparse-arrangement CPU usage by 40%–60%.
Independent Test:
Run DspSilenceBypassTests in tests/Nota.SmokeTest, verifying that delay/reverb/chamber/compressor/limiter tails decay naturally below $-100\text{ dBFS}$ before sleeping, memoryless devices bypass zero-blocks immediately, and transient attacks wake devices on sample 0 with zero clicks or truncation.
Acceptance Scenarios:
- Given
SilenceDetectorinsrc/dsp/core/SilenceDetector.h/.cpp, When monitoring track, return, or master buffers, Then it uses single-pass SIMDpeakAndSumSquares, dual-threshold hysteresis ($-80\text{ dBFS}$ attack / $-90.5\text{ dBFS}$ release), and a sample-accurate hold window to prevent chattering. - Given any built-in
DeviceorInstrument, When input is silent and internal tails/voices have decayed below $-100\text{ dBFS}$ for the hangover period, ThenisIdle()returnstrueandEngine_Render.cppskips redundant processing, PDC, and send accumulation while propagatingcurrentSilentdown the chain.
User Story 5 - Multi-Core Parallel Track Rendering & Vectorized Mixer Summing (Priority: P2)
As a user running heavy multi-track sessions on modern multi-core CPUs, I want independent tracks rendered in parallel across a lock-free real-time worker pool (AudioThreadPool) with cache-aligned job slots and per-worker scratch buffers, followed by vectorized SIMD bus summing and master safety processing, so that multi-core headroom scales linearly without priority inversion or audio dropouts.
Why this priority: Single-threaded track rendering bottlenecks on a single CPU core. Lock-free parallel rendering with per-worker scratch buffers and SIMD mixer summing unlocks 2x–4x higher track/plugin counts.
Independent Test:
Render a 16-track project with active instruments, insert chains, group submixes, sidechain route taps, and return sends via Nota.SmokeTest; verify deterministic output matching sequential rendering and zero real-time safety violations.
Acceptance Scenarios:
- Given
AudioThreadPoolinsrc/engine/AudioThreadPool.h/.cpp, WhenEngine::mixGraph()executes Pass 1 leaf tracks, Then independent tracks are dispatched across pre-allocated real-time worker threads using atomic ticket counters,alignas(64)cache-aligned job slots, and per-worker scratch buffers (workerScratch_[workerId]). - Given leaf tracks, group submixes, return buses, and the master bus in
Engine_Render.cpp, When summing audio and computing peak/RMS/stereo map telemetry, Then all gain scaling, route taps (routeBus_,routeBusPre_), and master NaN/Inf suppression + clipping execute via single-pass SIMD routines.
Edge Cases
- Audio-Thread Allocation Hazard in
computeBlockMidi: Track count increases must allocate MIDI event buffers on the message thread duringGraphconstruction/publication, never viastd::vector::resize()on the audio thread. - Concurrent Plugin Scan & UI Browsing: Calling
nota_pluginhost_scan()on a background thread while the UI thread readsnota_pluginhost_plugin_desc()or instantiates a plugin must be protected by thread-safe synchronization inPluginCatalog. - Noisy or Crashing Third-Party Plugins: A plugin that prints arbitrary text to
stdoutduring scanning or crashes/hangs infindAllTypesForFilemust not corrupt the XML catalog or hangnota_pluginhost_scan(). - Non-Finite Floats (NaN / $\pm\infty$): Unstable plugin or feedback signals must be branchlessly squashed to
0.0fviasimd::squashNonFiniteon the master bus before clamping. - Denormals in Filter & Reverb Tails:
ScopedNoDenormals(FTZ/DAZ) must be active on both the main audio callback thread and allAudioThreadPoolworker threads!
Requirements (mandatory)
Functional Requirements
- FR-001: The native engine directory
src/native/nota.engine/MUST be organized into domain subdirectories:src/abi/,src/dsp/{core,math,primitives,poly}/,src/devices/{racks,effects,instruments,midi_fx}/,src/engine/,src/audio_io/{macos,desktop}/,src/media/, andpluginhost/{bridge,hosting,scanner}/. - FR-002: Every non-template class across
dsp/,devices/,engine/,audio_io/,media/, andpluginhost/MUST be split into a declaration header (.h) and an implementation file (.cpp), leaving only small inline performance-critical primitives (FastMath.h,Simd.h,SimdAudio.h,AudioSpan.h,RtAttributes.h,ScopedNoDenormals.h,Hadamard.h,Random.h) and templates (SpscRingBuffer,SnapshotHistory,PolyVoiceManager) in headers. - FR-003: The public C ABI in
include/nota/nota_engine.hand symbol export maps (nota_exports.txt,nota_exports.map) MUST remain 100% backward-compatible. - FR-004: Plugin scanning and catalog management MUST be extracted into a dedicated
nota_pluginscannermodule (pluginhost/scanner/) with thread-safePluginCatalogsynchronization and zero dependencies onEngineorTrack. - FR-005: Real-time audio functions MUST be annotated with
NOTA_RT_SAFE(noexcept [[clang::nonblocking]]) and uphold AR-6 (zero heap allocations, zero locks, zero blocking I/O on the audio thread and worker threads). - FR-006:
ScopedNoDenormalsMUST be applied on the main audio thread and everyAudioThreadPoolworker thread. - FR-007: All built-in effects and instruments MUST use centralized
FastMath.h,Simd.h,SimdAudio.h, and shareddsp/primitives/classes, eliminating duplicated filter/delay/math implementations and decimating UI telemetry ring-buffer atomic writes to block/control rate. - FR-008: All built-in effects and instruments MUST implement the
isIdle()/hasTail()/wake()sleep contract and integrate withSilenceDetectorinEngine_Render.cpp. - FR-009:
Engine_Render.cppMUST execute independent leaf tracks in parallel viaAudioThreadPoolusingalignas(64)job structures and per-worker scratch buffers, and vectorize all mixer bus summing, route taps, and master bus processing.
Key Entities
PluginCatalog&OutOfProcessScanner(pluginhost/scanner/): Thread-safe plugin registry and child-process scan coordinator decoupled fromEngine.FastMath,Simd,SimdAudio(src/dsp/math/): Vectorized and polynomial math primitives for ARM NEON and x86 SSE/AVX/FMA.SvfFilter,BiquadCascade,LadderFilter,DelayLine,Oscillator,Envelope,Oversampler,Convolution,TruePeakMeter(src/dsp/primitives/): Shared C++20 DSP building blocks (.h+.cpp).SynthVoice&PolyVoiceManager(src/dsp/poly/): Reusable polyphonic voice allocation, sample-accurate event rendering, sustain pedal, and MPE management.SilenceDetector(src/dsp/core/): Dual-threshold hysteresis audio activity detector.AudioThreadPool(src/engine/): Lock-free multi-core real-time fork-join task executor with per-worker scratch buffers.
Success Criteria (mandatory)
Measurable Outcomes
- SC-001: 100% of existing C ABI functions in
include/nota/nota_engine.hand all tests intests/Nota.SmokeTest(plus new DSP optimization, silence bypass, and scanner tests) pass on macOS, Linux, and Windows. - SC-002: Incremental compilation of a modified device
.cppfile recompiles only 1 translation unit instead of rebuilding all devices. - SC-003: Polyphonic synthesizer and native effect CPU load is reduced by 25%–50%, and idle/sparse project CPU load is reduced by 40%–60%.
- SC-004: Multi-track rendering throughput on 8+ core CPUs scales by 200%–400% with zero audio-thread heap allocations or mutex locks.
Assumptions
- Target compilers support C++20 (
AppleClang 17+,GCC 13+,MSVC 19.38+). - IEEE-754 32-bit
floatrepresentation is standard across all supported x86_64 and ARM64 targets. - Built-in device parameter order and serialization formats remain 100% unchanged so existing
.notaprojects and factory presets load identically.
Nota Compliance Checklist (review before implementation; re-check in tasks.md)
- Every new source file will carry the AGPL-3.0-only SPDX header (two lines, see CONTRIBUTING.md)
- No new dependency — or: license checked, AGPL-compatible,
LICENSES/third-party.mdrow planned - Audio-thread impact considered: no alloc / lock / I/O on the audio thread (AR-6), command queue for data in (AR-4), immutable snapshots for structural edits (AR-5)
- Managed/native crossings go through the pure C ABI in
nota_engine.honly (AR-7); no JUCE outsidepluginhost/ - Smoke-test impact assessed: engine behaviour change → extend
tests/Nota.SmokeTest - User-visible change →
CHANGELOG.md[Unreleased]entry planned - UI change → N/A (native engine & pluginhost architecture only)