139 lines
5.6 KiB
Markdown
139 lines
5.6 KiB
Markdown
# Lyrebird Extension SDK
|
|
|
|
This document lists the public surface available to **out-of-tree Swift packages** that add
|
|
`Generator` or `Synthesizer` implementations on top of the `Lyrebird` core module.
|
|
|
|
The surface is split into two stability tiers:
|
|
|
|
1. **Stable public API** — covered by Lyrebird's SemVer. Breaking changes only on a MAJOR
|
|
version bump.
|
|
2. **`@_spi(LyrebirdExtensions)` API** — low-level RT helpers that extension packages need
|
|
to implement generators correctly. Signatures may evolve in MINOR releases; pin tightly
|
|
if you depend on these (`.upToNextMinor(from:)`).
|
|
|
|
## Importing
|
|
|
|
```swift
|
|
import LyrebirdSynth // stable public API
|
|
@_spi(LyrebirdExtensions) import LyrebirdSynth // stable + SPI helpers
|
|
```
|
|
|
|
Only declare the SPI import in files that need it. Consumers of your extension package never
|
|
need the SPI import — they import your module and use its public types.
|
|
|
|
## Tier 1 — Stable public API
|
|
|
|
### Generator protocol & base
|
|
|
|
| Symbol | File |
|
|
|---|---|
|
|
| `protocol Generator` | `GeneratorCore/Generator.swift` |
|
|
| `protocol AudioGenerator` | `GeneratorCore/Generator.swift` |
|
|
| `protocol ControlGenerator` | `GeneratorCore/Generator.swift` |
|
|
| `class GeneratorBase` | `GeneratorCore/GeneratorBase.swift` |
|
|
| `protocol GeneratorEnum` | `GeneratorCore/GeneratorTypes.swift` |
|
|
| `enum ProcessingRate` | `GeneratorCore/GeneratorTypes.swift` |
|
|
| `class GeneratorArray` | `GeneratorCore/GeneratorArray.swift` |
|
|
| `+ - * /` operators on `GeneratorArray` | `GeneratorCore/GeneratorArray.swift` |
|
|
| `func expand<G: Generator>(...)` | `GeneratorCore/GeneratorArray.swift` |
|
|
|
|
### Generator input
|
|
|
|
| Symbol | File |
|
|
|---|---|
|
|
| `protocol ValidGeneratorInput` | `GeneratorCore/ValidGeneratorInput.swift` |
|
|
| `protocol ConstantGeneratorInput` | `GeneratorCore/ValidGeneratorInput.swift` |
|
|
| `struct Closure` | `GeneratorCore/ValidGeneratorInput.swift` |
|
|
| `typealias ClosureBody` | `GeneratorCore/ValidGeneratorInput.swift` |
|
|
|
|
### `GeneratorBase` storage (you read/write these in your subclass)
|
|
|
|
| Symbol | Visibility |
|
|
|---|---|
|
|
| `var _segmentSerial: UInt64` | `public` |
|
|
| `var _cachedResult: [[Double]]` | `public` |
|
|
| `var _subBlockBuffer: [[Double]]` | `public` |
|
|
| `func _setupSubBlockBuffer(channels: Int = 1)` | `public` |
|
|
|
|
### Synthesizer side (parameter & graph)
|
|
|
|
| Symbol | File |
|
|
|---|---|
|
|
| `struct SynthGraph` | `Synthesizer/SynthGraph.swift` |
|
|
| `class SynthesisEngine` | `Engine/SynthesisEngine.swift` |
|
|
| `@propertyWrapper struct LiveParam` | `Parameters/LiveParam.swift` |
|
|
| `protocol LiveParameterWrapper` | `Parameters/LiveParam.swift` |
|
|
| `protocol LiveParameterValue` | `Parameters/LiveParam.swift` |
|
|
| `final class ParameterNode` | `Parameters/ParameterNode.swift` |
|
|
|
|
### Resources / data types
|
|
|
|
| Symbol | File |
|
|
|---|---|
|
|
| `struct HRIRFile` | `Buffers/HRIRFile.swift` |
|
|
| `let lyrebirdDefaultResultBufferSize: Int` | `Math/LyrebirdConstants.swift` |
|
|
|
|
## Tier 2 — `@_spi(LyrebirdExtensions)` API
|
|
|
|
These RT-safe helpers are mandatory when implementing new generators. They are SPI to keep
|
|
the public Lyrebird API surface small for application code, but are stable enough to use
|
|
across MINOR versions; pin extension packages to a specific MINOR range and bump explicitly
|
|
when Lyrebird's MINOR rolls over.
|
|
|
|
### MulAdd helpers (`GeneratorCore/MulAdd.swift`)
|
|
|
|
| Symbol | Signature |
|
|
|---|---|
|
|
| `struct MulAddSpec` | stored `mul`/`add` inputs + precomputed identity flag |
|
|
| `MulAddSpec.init(mul:add:)` | call at `init` time |
|
|
| `MulAddSpec.applyIfNeeded(to:graph:count:)` | call at end of `_computeSamples` |
|
|
| `MulAddSpec.apply(to:graph:count:)` | unconditional apply (rare; prefer `applyIfNeeded`) |
|
|
| `MulAddSpec.identity` | static — for generators with no `mul`/`add` knobs |
|
|
| `func extractScalar(_:)` | init-time scalar detection |
|
|
| `func fillRampedResult(into:from:to:mulAdd:graph:count:)` | ControlGenerator ramp helper |
|
|
| `func lastGeneratorSampleOrFloat(_:isGenerator:graph:count:)` | block-constant capture from a generator input |
|
|
|
|
### PRNG (`Generators/Noise/WhiteNoise.swift`)
|
|
|
|
| Symbol | Signature |
|
|
|---|---|
|
|
| `func xorshift64NextRaw(_:)` | raw `UInt64` step |
|
|
| `func xorshift64Next(_:)` | step → `Double` in `[-1, 1]` |
|
|
|
|
### Test-helper hooks (`Engine/SynthesisEngine.swift`)
|
|
|
|
For out-of-tree extension packages building their own `advanceBlock`-style test helpers:
|
|
|
|
| Symbol | Signature |
|
|
|---|---|
|
|
| `SynthesisEngine.segmentSerial` | acquiring load (read-only) |
|
|
| `SynthesisEngine.advanceSegmentSerial()` | wrapping increment — call between back-to-back `calculatedSamples` calls in tests to simulate a block boundary |
|
|
|
|
## Versioning policy
|
|
|
|
Lyrebird 1.x:
|
|
|
|
- Stable public API: SemVer. Breaking change → 2.0.
|
|
- `@_spi(LyrebirdExtensions)` API: signatures may change in MINOR releases. Extension
|
|
packages should pin tightly:
|
|
|
|
```swift
|
|
.package(url: "...Lyrebird", "1.4.0"..<"1.5.0")
|
|
```
|
|
|
|
## Namespacing guidance
|
|
|
|
- **Module name**: prefer `Lyrebird<Vendor>` (e.g. `LyrebirdATK`). Swift module names already
|
|
prevent type collisions; the prefix makes the dependency obvious in `Package.swift`.
|
|
- **Type prefix**: match your domain (`Foa*`, `Hoa*`, `Pd*`, …). Keep it short and consistent
|
|
within the package.
|
|
- **Parameter-key prefix**: when your `Synthesizer` reads parameters by string key, prefix
|
|
them (`"atk.azimuth"`, not `"azimuth"`) to avoid collisions in user code that mixes
|
|
multiple extension packages.
|
|
|
|
## See also
|
|
|
|
- [Writing Generators](writing-generators.md) — full generator-author guide.
|
|
- `docs/extension-authors-guide.md` — end-to-end walkthrough of building and publishing an
|
|
extension package, using `LyrebirdATK` as a worked example.
|