SPB Git

Repository Public

mixer.md 12.9 KB 167 lines markdown

1# Mixer23The mixer is the part of `RenderCore` that turns four deck signals into a master bus and a cue bus. It is not a separate object: it is the body of `RenderCore.renderChunk`, executed for every chunk of at most 64 frames (see [audio-engine.md](audio-engine.md) for the chunking). This document describes the signal order, every filter and curve with its constants, routing, the limiter and the meters.45Sources:67- [`RenderCore.swift`](../../Packages/ORIXDJCore/Sources/ORIXDJEngine/RenderCore.swift) (`ChannelStrip`, `renderChunk`, `updateFilters`, `crossfaderGains`, `render`)8- [`Primitives.swift`](../../Packages/ORIXDJCore/Sources/ORIXDSP/Primitives.swift) (`BiquadCoefficients`, `StereoBiquad`, `LinearRamp`, `dbToLinear`)9- [`Dynamics.swift`](../../Packages/ORIXDJCore/Sources/ORIXDSP/Effects/Dynamics.swift) (`LimiterEffect`)10- Parameter ranges: [`Schema.swift`](../../Packages/ORIXDJCore/Sources/ORIXScript/Schema.swift)11- UI: [`MixerView.swift`](../../App/Sources/Features/Mixer/MixerView.swift), [`AudioSettingsTab.swift`](../../App/Sources/Features/Settings/AudioSettingsTab.swift)12- Tests: `PlaybackTests` and `DeckFeatureTests` in [`EngineAudioTests.swift`](../../Packages/ORIXDJCore/Tests/ORIXDJEngineTests/EngineAudioTests.swift)1314## Routing1516```mermaid17flowchart TD18    V["DeckVoice output (per deck, x4)"] --> T["Trim (gain ramp)"]19    T --> EQ["EQ: low shelf, mid peak, high shelf (plus low-mid in 4-band mode)"]20    EQ --> HP["High-pass (if active)"]21    HP --> LP["Low-pass (if active)"]22    LP --> RK["Channel effects rack (8 slots)"]23    RK --> PFL{"cue switch"}24    PFL -->|on| CB["Cue bus sum"]25    RK --> FD["Channel fader (volume ramp)"]26    FD --> MT["Channel meter (post-fader)"]27    MT --> XF["Crossfader gain: side A, side B, or through"]28    XF --> SUM["Master sum"]29    SUM --> MR["Master effects rack (8 slots)"]30    MR --> MV["Master volume"]31    MV --> LIM["Limiter (if on)"]32    LIM --> MM["Master meters, clip counter"]33    MM --> REC["Recording tap"]34    MM --> OUTM["Master output pair"]35    MM --> BL["Cue blend: cue x (1 - mix) + master x mix, then cue volume"]36    CB --> BL37    BL --> OUTC["Cue output pair, or right channel in split cue"]38```3940## Channel strip4142Order of processing for each deck, exactly as in `renderChunk`:4344| Step | Parameter (script address) | Range and default | Implementation |45|---|---|---|---|46| 1. Trim | `deck.X.gain` | −24…+12 dB, 0 | `LinearRamp` on the linear gain, applied with `vDSP_vrampmul2` |47| 2. EQ | `deck.X.eq.low`, `eq.mid`, `eq.high` (and `eq.lowMid`) | −26…+6 dB, 0 | cascaded `StereoBiquad`, skipped entirely when every band is at 0 dB |48| 3. High-pass | `deck.X.filter.highpass`, `deck.X.filter` | 20…20 000 Hz, 20 (off) | RBJ high-pass biquad, 12 dB/octave |49| 4. Low-pass | `deck.X.filter.lowpass`, `deck.X.filter` | 20…20 000 Hz, 20 000 (off) | RBJ low-pass biquad, 12 dB/octave |50| 5. Effects rack | `deck.X.fx.<effect>.…` | 8 slots | see [dsp.md](dsp.md) |51| 6. Pre-fader listen | `deck.X.cue` | off | adds the signal to the cue bus |52| 7. Fader | `deck.X.volume` | −60…0 dB, 0 | `LinearRamp`, `vDSP_vrampmul2` |53| 8. Meter | | | post-fader peak and RMS |54| 9. Crossfader | `mixer.crossfader`, `assign` | | per-side gain, ramped across the chunk |5556All gains pass through `dbToLinear`, where −60 dB (`silenceFloorDB`) and below map to exactly zero. `silenceAtFloor` checks that a fader at −60 dB gives a peak of 0.5758Every parameter change is ramped over at least 4 ms (`rampSamples`); callers can ask for a longer ramp. Gains are interpolated linearly within each chunk. `faderTrimAndMasterGainsAreAccurate` checks that fader, trim and master gains add up to the expected level within 0.02 dB.5960A channel that is not playing, has no active effect and whose meter has decayed below 1e-5 takes a shortcut: its ramps and filters are still advanced and its rack still sees the (silent) signal, but nothing is summed.6162### EQ6364Coefficients come from the RBJ Audio EQ Cookbook formulas in `BiquadCoefficients`; filters run in transposed direct form II. Two layouts exist, switched globally by the `eqBands` mixer parameter (the "four-band EQ" application setting):6566| Band | Three-band (default) | Four-band |67|---|---|---|68| Low | low shelf at 200 Hz | low shelf at 100 Hz |69| Low-mid | not present | peaking at 400 Hz, Q 0.9 |70| Mid (labelled Hi-Mid in four-band mode) | peaking at 1000 Hz, Q 0.7 | peaking at 2000 Hz, Q 0.9 |71| High | high shelf at 3000 Hz | high shelf at 8000 Hz |7273Shelves use slope 1. Each band ranges from −26 dB to +6 dB. At the bottom of the range the band becomes a kill: `eqGain` replaces any value at or below −25.9 dB by −80 dB for the shelves, and the peaking bands are set to −40 dB.7475Tested by `eqBandsAndKill` in three-band mode: +6 dB and −12 dB are reached in band within 0.5 to 1 dB, the far bands move by less than 0.3 dB, and a full kill leaves less than −50 dB at 40 Hz (low) and at 12 kHz (high). The four-band layout has no dedicated audio test.7677### Channel filters and the filter knob7879Each strip has one high-pass and one low-pass biquad sharing `deck.X.filter.resonance` (Q, 0.5…10, default 0.9). They can be set explicitly in hertz, or through the bipolar knob `deck.X.filter` (−1…+1), which `updateFilters` maps as follows:8081| Knob position `k` | Effect | Formula |82|---|---|---|83| `k > 0.02` | high-pass sweeping up | `f = 20 * 500^k` Hz: 20 Hz at 0, about 447 Hz at 0.5, 10 kHz at 1 |84| `-0.02 ≤ k ≤ 0.02` | off | dead zone |85| `k < -0.02` | low-pass sweeping down | `f = 20000 * (1/200)^(-k)` Hz: 20 kHz at 0, about 1414 Hz at −0.5, 100 Hz at −1 |8687The knob and the explicit corner combine by taking the more restrictive value (`max` for the high-pass, `min` for the low-pass). A filter is active only when its corner is above 20.5 Hz (high-pass) or below 19 900 Hz (low-pass); when it switches off its state is reset.8889While a filter or EQ parameter ramps, coefficients are recomputed once per chunk (at most every 64 frames), not per sample. The smoothed state-variable filter used by the filter effects in the rack is a different implementation (see [dsp.md](dsp.md)).9091Tested by `channelFilters` with Q 0.707: −3.01 dB at the corner within 0.2 dB, −40 dB a decade below a 1 kHz high-pass within 1 dB, more than 40 dB of attenuation a decade above a 1 kHz low-pass, more than 30 dB of attenuation at the far end for knob positions ±0.8, and a transparent centre within 0.01 dB.9293## Crossfader9495Each strip has an `assign` value: 0 for side A, 1 for side B, 2 for through (not affected by the crossfader). The defaults are A, B, A, B for decks A to D. The channel strips in the interface show this as an A / – / B selector.9697The crossfader position `x` runs from 0 (side A) to 1 (side B). `crossfaderGains` returns the gains of the two sides for the three curves named in `ScriptSchema.crossfaderCurves`:9899| Curve | Gain of side A | Gain of side B | At the centre |100|---|---|---|---|101| `smooth` (default) | `cos(x * π / 2)` | `sin(x * π / 2)` | −3.01 dB each (constant power) |102| `linear` | `min(1, 2 * (1 - x))` | `min(1, 2 * x)` | both at unity |103| `cut` | `1` for `x < 0.95`, else `(1 - x) / 0.05` | `1` for `x > 0.05`, else `x / 0.05` | both at unity; each side falls only in its last 5 % of travel |104105The gains are evaluated at the start and the end of each chunk and interpolated in between (`vDSP_vrampmuladd`), so a crossfader movement does not step.106107Tested by `crossfaderCurves`: smooth gives −3.01 dB on both sides at 0.5 within 0.05 dB and below −100 dB on the closed side; linear gives unity on both sides at 0.5 and −6.02 dB for side A at 0.75; cut is still at unity on both sides at 0.9 and below −100 dB for A at 1.108109## Master section110111After the sum: master effects rack, then `mixer.master.volume` (−60…+6 dB, default 0), then the limiter, then metering, the recording tap ([recording.md](recording.md)) and routing.112113### Limiter114115The master limiter is a `LimiterEffect` instance owned by `RenderCore`, fully wet, with the catalogue defaults: ceiling −1 dBFS, release 100 ms, look-ahead 5 ms (240 samples at 48 kHz). Its algorithm is described in [dsp.md](dsp.md). It is on by default (`mixer.master.limiter`); its ceiling and release are not exposed for the master instance.116117Points that follow from the code:118119- The limiter delays the master by its look-ahead, 5 ms. The unit's own comment states that this latency is not compensated. It is not included in the output latency the application displays ([performance.md](../development/performance.md)), and the cue bus sum is not delayed, so with the limiter on, the master part of the headphone blend is 5 ms behind the cue part.120- Switching it on or off goes through the 12 ms enable cross-fade of `EffectUnit`, between the delayed limited signal and the undelayed dry signal.121- The limiter is primed with silence at construction so that the ceiling holds from the first block.122- With the limiter off, nothing prevents the master from exceeding full scale; the clip counter then increments.123124Tested by `limiterAndClipIndicator`: three decks of sines at amplitude 0.9 summed through give a peak above 1.5 and clipped blocks without the limiter; with it, the peak stays at or below 0.8913 × 1.012, no block is clipped and the reported reduction is below −3 dB.125126## Cue bus and headphones127128The cue bus receives every channel whose `cue` switch is on, taken after the channel rack and before the fader. It is then blended with the master, per sample:129130```131cue = (cue * (1 - mix) + master * mix) * volume132```133134`mixer.cue.mix` runs from 0 (cue only) to 1 (master only), default 0; `mixer.cue.volume` runs from −60 to +6 dB. The master part of the blend is the final master signal, after master volume and limiter.135136### Output routing137138`render` clears every device channel and then writes:139140- **Master** to channels `masterLeft` and `masterRight` (defaults 0 and 1). If both indices are equal the two channels are summed into one.141- **Cue** to channels `cueLeft` and `cueRight` when they are set (default −1, disabled) and do not coincide with a master channel. A cue channel equal to a master channel is skipped, so the cue is never mixed into the master output. The settings screen shows a warning in that configuration whose wording says the cue would be heard in the room; by the code it is simply not output.142- **Split cue**, for stereo-only devices: when `splitCue` is on and no dedicated cue output is set, the left channel carries the mono master `0.5 * (L + R)` and the right channel the mono cue.143144The settings screen offers channel pairs (`Channels 1–2`, `3–4`, …) for master and cue, and offers split cue only when the device has exactly two channels.145146Tested by `routingCueBusAndSplitCue`, rendering four channels offline: the master pair carries deck A, the cue pair carries deck B pre-fader at full level (within 0.05 dB) although its fader is at −60 dB; with cue mix at 1 the cue pair carries the master; in split cue the left channel carries the master and the right the cue. No multi-channel audio interface was available, so four-channel routing has only been verified by this offline render.147148## Metering149150| Value | Where | How it is computed |151|---|---|---|152| Channel peak | `DeckRenderState.peak` | per chunk, maximum magnitude of both channels after the fader, with a fall of 24 dB per second (`peakFall`, applied once per chunk) |153| Channel RMS | `DeckRenderState.rms` | one-pole average (0.9 / 0.1 per chunk) of the left channel's RMS |154| Master peak L / R | `masterPeakL`, `masterPeakR` | per channel, after the limiter, same fall |155| Master RMS | `masterRMS` | same average, left channel only |156| Cue peak | `cuePeak` | left cue channel only |157| Limiter gain reduction | `limiterReductionDB` | smallest gain the limiter applied in the chunk, in dB, held with a 0.97 per-chunk decay |158| Clipped blocks | `clippedBlocks` | number of chunks in which the master exceeded 1.0 after the limiter |159160Notes: the RMS values and the cue peak look at the left channel only. The fall and hold constants are applied per chunk, and chunks are shorter than 64 frames around timed events, so meters fall slightly faster while automation is dense. "Clipped blocks" counts chunks, not device buffers. These are sample-peak meters; there is no true-peak or loudness metering in the mixer (loudness of tracks is measured by the analyser, see [analysis.md](analysis.md)).161162The interface reads these values 30 times per second: channel and master level meters, the `GR` read-out and the `CLIP` / `OK` indicator in `MixerView.swift`, and the counters in Settings → Audio.163164## One parameter space165166The mixer has no API of its own. The interface, MIDI mappings and ORIX Script all write the same addresses through `DJEngine.set(_:_:at:rampSeconds:tracked:)`, which clamps the value to the range in `ScriptSchema`, stores it in the model and pushes one event. The script-side view of these parameters is documented in [mixer-api.md](../orix-script/mixer-api.md) and [deck-api.md](../orix-script/deck-api.md); timing of scripted changes in [automation.md](automation.md).167
Files main
Menu

Theme