DX7-Style FM Synthesis Library for Swift
M2DX-Core is a 6-operator / 32-algorithm FM synthesis library written in Swift. The production target (M2DXCore) is independently implemented from the publicly documented DX7 hardware behavior and the mathematical definition of FM synthesis. A separate test-only C target (DX7Ref) ports reference functions from the Apache-2.0-licensed msfa code so that the Swift implementation can be cross-validated at the bit level — see NOTICE for attribution and scope.
Phase 2 Complete (2026-02-16) — The library extraction is complete: the Swift production target is implemented from spec and cross-validated against the msfa C reference (DX7Ref, test-only). All synthesis components, tests, and CI pipeline are functional. The next phase focuses on public API design and SPM release preparation.
- Apache License 2.0 for the entire repository. Includes attribution to MSFA (Apache 2.0) for the test-only
DX7Refreference target — see NOTICE - Swift 6 — Strict concurrency, value semantics, zero-allocation audio rendering
- MIDI 2.0 Native — 16-bit velocity, 32-bit CC, per-note controllers (MPE-compatible)
- Apple Accelerate — Hardware-accelerated DSP using vDSP (SIMD optimization)
- Lock-Free Architecture — Parameter changes delivered via atomic SPSC ring buffer
- Bit-Accurate DX7 Mode — Int32 fixed-point arithmetic reproduces the original OPS chip
- Clean Float32 Mode — Modern floating-point engine for extensibility
- iOS 18.0+ / macOS 15.0+
- Swift 6.0+
- Xcode 16.0+
# Clone the repository
git clone https://github.com/yourusername/M2DX-Core.git
cd M2DX-Core
# Build the library
swift build
# Run tests
swift test
# Run tests with verbose output
swift test --verboseAll 107 tests should pass. Performance benchmarks may vary depending on your hardware (x86_64 vs ARM).
The library includes comprehensive test coverage across 8 test suites:
| Test Suite | Tests | Coverage |
|---|---|---|
| TableTests | 11 | Sin/Exp2 precision, frequency table, pitch bend, scaling curves |
| EnvelopeTests | 10 | 4-stage ADSR, rate=99 fast attack, noteOff silence verification |
| AlgorithmTests | 32 | All 32 DX7 algorithms carrier count, feedback, bus routing |
| WaveformTests | 8 | renderBlock output, silent voice, feedback modulation effects |
| ConcurrencyTests | 3 | SnapshotRing stress test, SynthEngine concurrent note on/off |
| PerformanceTests | 2 | 16 voices × 512 frames rendering benchmark |
| ReferenceTests | 10 | Operator-level DEXED comparison (ScaleRate, ScaleVelocity, ScaleLevel, exp2, EG, algorithms) |
| VoiceComparisonTests | 14 | Voice-level waveform comparison against DEXED (INIT VOICE, algorithms, feedback, velocity, rate scaling, KLS, detune, E.PIANO) |
Run tests with:
swift test # Run all tests
swift test --verbose # Verbose output with test names
swift test --filter Table # Run only TableTestsM2DX-Core provides two synthesis modes:
| Mode | Arithmetic | Precision | Use Case |
|---|---|---|---|
| DX7 | Int32 fixed-point (Q24/Q30) | Bit-accurate to OPS chip | Authentic reproduction |
| Clean | Float32 | ~24-bit mantissa | Extensibility, custom waveforms |
"Bit-Accurate Soul, Modern Body"
- Soul: The DX7's sonic character — log-domain arithmetic, envelope curves, feedback averaging, 32 algorithm routings — is reproduced at bit-level accuracy.
- Body: Memory management, thread model, and API design are optimized for Apple platforms with modern Swift paradigms.
The production M2DXCore Swift target implements all synthesis logic and tables independently:
- Sin / Exp2 Tables: Generated at compile time from mathematical functions
- Velocity, KLS, EG Rate Tables: Derived from FM synthesis definitions and publicly documented hardware behavior
- 32 Algorithm Routing: Encoded from the operator connection topology described in DX7 service literature
The separate DX7Ref C target (test-only, not linked into production) ports reference functions from the Apache-2.0 msfa code; the Swift implementation is verified bit-for-bit against this reference. See NOTICE for full attribution and modification log.
- Zero-Allocation: No
malloc,retain, orreleasein the audio render loop - Lock-Free SPSC Ring Buffers: UI-thread parameter changes and MIDI events delivered without blocking the audio thread
SnapshotRing<T>: Parameter snapshot delivery (UI → Audio)SPSCRing<T>: MIDI event FIFO queue (UI → Audio, preserves event order)
- Pre-allocated Voice Arrays: All voice structures and scratch buffers allocated at initialization
- Fixed-Size Tuples: Parameter snapshots use fixed-size tuples instead of dynamic arrays to prevent heap deallocation on audio thread
- Caller-Provided Scratch Buffers: DSP operations use pre-allocated scratch space to eliminate internal allocations
- No Locks: All cross-thread communication uses atomic operations (
Synchronization.Atomic) instead of NSLock/pthread_mutex
Apple Accelerate (vDSP) is used for batch DSP operations:
- FIR downsampling (2x oversampling decimation)
- Int32 → Float conversion (DX7 Q24 block output)
- Voice mixing (scale + add, stereo panning)
- Gain application (master volume)
- Hard clipping (output limiter)
| Mode | Slots | Voices/Slot | Description |
|---|---|---|---|
| Single | 1 | 16 | Standard DX7 |
| Dual | 2 | 8 | Layer two patches |
| Split | 2 | 8 | Keyboard split |
| TX816 | 8 | 2 | 8-module monster synth |
| Dependency | Version | Purpose |
|---|---|---|
| Synchronization (stdlib) | Swift 6.0+ | Lock-free atomic operations for SPSC ring buffer |
| Accelerate (system) | — | vDSP batch DSP operations (mixing, clipping, conversion) |
Note: The production target uses only Swift 6.0's built-in Synchronization module and Apple's Accelerate. There are no external Swift package dependencies.
The entire repository is licensed under the Apache License, Version 2.0 (see LICENSE).
| Target | License | Notes |
|---|---|---|
M2DXCore (production) |
Apache 2.0 | Independent Swift implementation from the DX7 hardware spec and FM synthesis math |
DX7Ref (test-only C) |
Apache 2.0 | Ported from MSFA msfa core (Google Inc., 2012). See NOTICE |
When you redistribute this library or a derivative — including statically linked into an application — Apache 2.0 §4(d) requires you to surface the contents of NOTICE somewhere visible to recipients (e.g. an in-app About / Acknowledgements screen).
DX7 is a registered trademark of Yamaha Corporation. M2DX-Core is not affiliated with or endorsed by Yamaha. References to DX7 are nominative use to describe the family of FM synthesis algorithms this library implements.
See TODO.md for the complete roadmap.
- Swift Package with Swift 6.0 strict concurrency
- Self-generated lookup tables (sin, exp2, frequency, scaling)
- Lock-free
SnapshotRing<T>usingSynchronization.Atomic - DX7 presets, algorithms, and SysEx parser
- Full synthesis engine (envelope, operator, voice, polyphony)
- Accelerate-based DSP (downsampler, voice mixer)
- 107 tests across 8 test suites (including voice-level DEXED comparison)
- GitHub Actions CI pipeline
- Bit-exact waveform verification against DEXED reference implementation
- Public API design and documentation
- DocC documentation for all public types
- API stability guarantees
- Apache 2.0 short license headers per source file
- Getting-started tutorial and code examples
- 8-slot voice routing (2-16 voices per slot)
- Keyboard split/layer logic
- Macro controls (brightness, attack, sustain)
- AudioUnit v3 wrapper
- docs/API.md — Complete public API reference
- docs/proposal.md — Full technical specification and design philosophy
- TODO.md — Detailed roadmap and task list
- CHANGELOG.md — Version history
This project is currently in early development. Contributions will be welcomed after the Phase 3 SPM release.
This library is developed as part of the M2DX synthesizer app.
M2DX-Core — Bringing the legendary DX7 sound to modern Swift development.