v1.3.0 release: graceful-release fix, quickstart template + demo, documentation accuracy pass
- Fixed: SynthesizerBase subclasses' release/free now dispatch correctly (gated synths were hard-freed instead of released). - New: quickstart project template + LyrebirdQuickstartDemo. - Docs: every example typechecked or provably illustrative (426->542); ~20 wrong-API examples fixed; root docs brought under the compile guard. - Fixed: NRT/Score demo Package.swift build from terminal again. See RELEASES.md for details.
This commit is contained in:
@@ -81,7 +81,7 @@ Mono sources are unaffected — they return one channel and write only `bus`.
|
||||
|
||||
## Multi-channel Expansion
|
||||
|
||||
`GeneratorArray` wraps N generators and returns an N-channel `[[LyrebirdFloat]]`.
|
||||
`GeneratorArray` wraps N generators and returns an N-channel `[[Double]]`.
|
||||
Create one with the `expand()` helper in `build()`:
|
||||
|
||||
```swift
|
||||
|
||||
@@ -47,7 +47,7 @@ final class SPSCQueue<T> {
|
||||
private let writeIdx = Atomic<Int>(0)
|
||||
private let readIdx = Atomic<Int>(0)
|
||||
|
||||
init(capacity: Int) { ... } // capacity rounded up to next power of 2
|
||||
init(capacity: Int) { ... } // capacity MUST be a power of two — precondition, not rounded
|
||||
|
||||
// Called from producer (main thread) only
|
||||
func enqueue(_ value: T) -> Bool
|
||||
@@ -117,13 +117,33 @@ currentBlockStart = engine.currentTime
|
||||
|
||||
Events scheduled before `currentBlockStart` (i.e., in the past) are applied immediately at `offset = 0`.
|
||||
|
||||
## Per-Block Event Budget — `maxEventsPerBlock`
|
||||
|
||||
Step 2's drain and the future-event **carry-over** are both hard-capped so the RT thread never reallocates its staging arrays mid-render. The cap is `maxEventsPerBlock`, a `SynthesisEngine.init` parameter (default `lyrebirdDefaultMaxEventsPerBlock = 256`, a power of two is *not* required — only `> 0`). Also settable via `SynthesisEngineConfig` / `EngineHost`.
|
||||
|
||||
It bounds **two** things per block:
|
||||
|
||||
- **Events firing this block** — how many `targetTime ∈ [blockStart, blockEnd)` events apply in one block.
|
||||
- **Look-ahead depth** — how many future-dated events the engine carries across a block boundary. Events scheduled further out than the current block sit in a `carryOverEvents` buffer capped at the same value; anything beyond it is **dropped**, not deferred.
|
||||
|
||||
This is the ceiling that governs whether a large batch of pre-scheduled events survives — **not** `eventQueueCapacity` (which only bounds the SPSC ring's in-flight occupancy). The two are independent: `maxEventsPerBlock` may legitimately exceed `eventQueueCapacity`, because carry-over accumulates across blocks (e.g. under a just-in-time NRT feed) while the ring only ever holds a per-drain burst.
|
||||
|
||||
### When events are dropped
|
||||
|
||||
Dropping is silent to the audio path but instrumented off the RT thread:
|
||||
|
||||
- **`engine.perBlockEventDropCount: UInt64`** — monotonic count of events dropped for exceeding the cap since start (or since `resetPerBlockEventDropCount()`). Distinct from `pendingQueueDroppedCount` (which counts main-thread *enqueue* failures against `eventQueueCapacity`).
|
||||
- **Console warning** — a one-line `[Lyrebird] Warning: … exceeded maxEventsPerBlock …` is printed at most once per drain interval. The RT thread only sets a relaxed counter + a `.releasing` latch (no allocation / lock / `print`); a non-RT drain (`freeWorker` timer, `stop()`, and the end of `NRTDriver.start()`) prints and clears the latch.
|
||||
|
||||
Raising the cap costs only pre-allocated staging memory (three arrays × `maxEventsPerBlock` `ScheduledEvent`s), reserved once in `start()` — no RT cost. Alternatively, keep the cap and **spread scheduling over time** (e.g. a JIT feed driven by a `TriggerListener` in NRT) so no single block's onset density or look-ahead exceeds the budget.
|
||||
|
||||
## Generator Interface — count Parameter
|
||||
|
||||
Because segments are variable length, generators produce `count` samples rather than always `blockSize`:
|
||||
|
||||
```swift
|
||||
protocol Generator {
|
||||
func calculatedSamples(graph: SynthGraph, count: Int) -> [[LyrebirdFloat]]
|
||||
func calculatedSamples(graph: SynthGraph, count: Int) -> [[Double]]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user