Latent Pbind — Algorithmic Latent-Space Composition
Compose motion through a learned acoustic space with independent SuperCollider-style pattern streams. Latent dimensions become contrapuntal control voices: each can follow its own pattern, clock, and interpolation before the resulting trajectory is rendered through a spectral-envelope decoder, nearest-event navigation, or barycentric resynthesis.
What this does
Latent Pbind trains a compact beta-VAE on spectral patches extracted from one selected Sound, normalises the learned latent space into musically usable coordinates, and lets a Pbind-style event language generate an offline trajectory through that space. Each latent coordinate can be driven by a separate deterministic, stochastic, cyclic, Brownian, chaotic, or nested pattern.
Key Features:
- On-the-fly latent learning — a small NumPy beta-VAE is trained directly from the selected Sound.
- Pbind-style composition — independent pattern streams control
z1...z8, cluster identity, amplitude, temperature, attraction, source-read rate, and retriggering. - Independent clocks —
dur_z1,dur_z2, etc. let latent dimensions behave as separate temporal voices. - Per-key interpolation — Step, Linear, Cubic, or Smooth globally or independently per stream.
- Three rendering modes — spectral-envelope Decoder, Nearest event, and Barycentric resynthesis.
- Four boundary behaviors — Clamp, Reflect, Wrap, and Soft attract.
- Robust latent coordinates — PCA rotation and percentile scaling map the learned data to stable approximately -1...+1 units.
- Identity clusters — k-means++ centroids provide macro-level acoustic regions that can be combined with local latent offsets.
- Reproducible stochastic structure — every pattern key has its own seeded random stream.
- Explanatory Praat Picture visualisation — pattern events, latent trajectories, latent maps, rendering diagnostics, output waveform, and summary.
- CPU-only and offline — no pretrained model, cloud service, API, GPU, PyTorch, or TensorFlow.
Quick start
- Select exactly one Sound object in Praat.
- Run
LatentPbind.praat. - For a first run, choose Preset = Polymetric coordinates or Brownian latent walk.
- Keep Rendering mode = Decoder, Interpolation = Smooth, and Boundary mode = Reflect.
- Leave Output duration = 0 to use the input duration.
- Keep Excursion = 1.0 so the pattern works in the robustly normalised data range.
- Enable Draw visualisation to inspect the event streams and their movement through the learned latent space.
Core concept
Latent Pbind separates the control source from the learned acoustic space. The control source is a compact Pbind-style expression; the target is a latent representation learned from the selected Sound.
The central compositional idea is that latent dimensions can behave like independent voices. One coordinate may drift slowly, another may repeat an asymmetric cycle, a third may make sparse jumps, and a fourth may decay geometrically. Their interaction defines one multidimensional path through the learned sound space.
rate and retrig determine how source material is read while a latent region remains selected.
Pbind language
The parser accepts a compact subset of SuperCollider-inspired pattern syntax. Both keyword style and backslash-key style are accepted.
Pbind(
dur=Pseq([0.25,0.5,0.25,1],inf),
z1=Pwhite(-1,1,inf),
z2=Pwalk([-1,-0.5,0,0.5,1],1),
z3=Pseq([0,0.5,1,-0.5],inf),
interp=cubic
)
Equivalent key/value style is also accepted:
Pbind(\dur, Pseq([0.25,0.5],inf), \z1, Pbrown(-1,1,0.2,inf))
Supported patterns
| Pattern | Function |
|---|---|
Pseq | Sequential list, with optional repetition and offset. |
Pser | Read a list serially for a fixed number of values. |
Prand | Random choice from a list. |
Pxrand | Random choice without immediately repeating the previous item when possible. |
Pshuf | Shuffle a list once and repeat the shuffled order. |
Pwrand | Weighted random choice. |
Pwhite | Uniform random values. |
Pexprand | Exponentially distributed random values between positive bounds. |
Pbrown | Bounded Brownian motion with reflection at the limits. |
Pwalk | Walk through a supplied value list. |
Pseries | Arithmetic progression. |
Pgeom | Geometric progression. |
Pstutter | Repeat each generated value a specified number of times. |
Pn | Repeat an embedded pattern. |
Plag | One-pole smoothing of a pattern stream. |
Phold | Probabilistically hold or update a stream value. |
Pimpulse | Sparse random impulses with a resting value. |
Plogistic | Logistic-map sequence for bounded chaotic motion. |
Pbind keys
| Key | Role |
|---|---|
dur | Required global event clock in seconds. |
z1...z8 | Normalised latent coordinates. Approximately -1...+1 covers the robust data range before excursion scaling. |
cluster | Selects / interpolates between k-means identity centroids. Latent z values become offsets around that centroid trajectory. |
amp | Output amplitude envelope; values below 0 are clipped to 0. |
temp | Adds posterior-scaled stochastic jitter to the latent trajectory. |
attract | 0...1 pull toward the nearest encoded source patch. |
rate | Source-read speed, internally limited to 0...4. |
retrig | Values above 0.5 restart the source-read pointer at that event. |
interp | Global interpolation: step, linear, cubic, or smooth. |
dur_<key> | Gives one stream an independent clock. |
interp_<key> | Gives one stream its own interpolation mode. |
dur_<key> clock can end independently and then hold its last value. The Info report identifies the stream that actually ended the output.Latent model
1. Spectral patches
The input is converted to mono and analysed with an STFT. Each frame is reduced to 64 log-spaced power bands. Overlapping patches are then resampled to 8 time cells, producing a 512-value representation for each non-silent patch.
2. NumPy beta-VAE
A compact fully connected beta-VAE is trained from scratch:
The model uses tanh hidden layers, Adam optimisation, and KL warm-up. The default latent dimensionality is 4 and can be set from 2 to 8.
3. Rotation and robust normalisation
The posterior means are PCA-rotated so z1 is the direction of largest spread, followed by z2, etc. Each axis is sign-oriented so its correlation with spectral centroid is non-negative; this orientation is musically meaningful only when the reported correlation is clearly above zero.
The 2nd and 98th percentiles of each rotated coordinate define the normalised range approximately -1...+1. This prevents a single outlier from defining the user-facing scale.
4. Identity clusters
k-means++ clusters the normalised latent cloud. Cluster centres are ordered along z1, so cluster 0 is the centroid with the lowest z1. A cluster pattern can therefore provide a macro-level identity trajectory while z1...zd provide local offsets around it.
7 Presets + Custom
Custom
Uses the Pbind text entered by the user.
Ordered drift
Long smooth deterministic travel in z1 with alternating z2 positions and no automatic retriggering.
Brownian latent walk
Four bounded Brownian coordinate streams with occasional retriggers.
Polymetric coordinates
Independent repeating cycles of different lengths across z1, z2, and z3. Their changing phase relationship continuously reshapes the latent trajectory.
Sparse identity jumps
Mostly stable cluster identity with occasional jumps, plus small local latent offsets.
Chaotic orbit
Smoothed logistic-map motion on z1 and z2, slower random motion on z3, and added latent temperature.
Cluster pilgrimage
Moves slowly through cluster identities while faster local z1/z2 streams explore each region.
Radical latent counterpoint
Independent clocks, independent interpolation modes, Brownian motion, asymmetric sequences, sparse impulses, geometric decay, and changing source-read rate.
Controls
| Control | Default | Function |
|---|---|---|
| Preset | Ordered drift | Selects Custom or one of seven supplied algorithmic trajectory designs. |
| Pbind | Example expression | Custom event-pattern expression. Named presets replace this text internally. |
| Output duration | 0 s | 0 uses the input duration. A finite shared-clock pattern may end the output earlier. |
| Rendering mode | Decoder | Decoder, Nearest event, or Barycentric. |
| Interpolation | Smooth | Global interpolation used unless a stream provides interp_<key>. |
| Boundary mode | Reflect | Defines how coordinates behave when they leave the robust data box. |
| Excursion | 1.0 | Scales the Pbind latent offsets before boundary handling. |
| Random seed | 1 | Controls VAE initialization, stochastic patterns, k-means initialization, and other stochastic operations. 0 requests a new seed. |
| Advanced settings | Off | Opens model and rendering parameters. |
| Draw visualisation | On | Creates the multi-panel Praat Picture explanation. |
| Play result | On | Plays the generated Sound after rendering. |
Advanced settings
| Setting | Default | Function |
|---|---|---|
| Latent dimensions | 4 | 2...8 latent dimensions. |
| Patch length | 120 ms | Nominal duration of each analysis patch. |
| Analysis hop | 20 ms | Spacing between candidate source patches. |
| Training epochs | 150 | Number of beta-VAE training epochs. |
| Beta | 0.5 | KL regularisation weight after warm-up. |
| Clusters | 6 | Requested k-means identity clusters, limited automatically by available patches. |
| Neighbours K | 4 | Number of neighbours in Barycentric mode. |
| Crossfade | 40 ms | Equal-power transition time when source donor voices change. |
| Phase iterations | 12 | Griffin-Lim refinement iterations in Decoder mode. |
| Decoder detail | Source fine structure | Source detail adds residual fine spectral structure from the nearest patch. Pure decoder uses decoded magnitude only. |
| Normalise output | On | Normalises to approximately -1 dBFS. With normalization off, peak guard still attenuates only when required to avoid clipping. |
Rendering modes
Decoder
This is the default and conceptually central mode. The final normalised trajectory is mapped back through the robust scaling and inverse PCA rotation into VAE latent coordinates, then decoded into a 64-band × 8-cell log-magnitude representation.
This is a latent spectral-envelope decoder, not a neural waveform decoder.
Source fine structure
The decoded broad spectral envelope is combined with fine spectral detail from the nearest source patch. Phase begins from the source voice mixture and can be refined with Griffin-Lim.
Pure decoder
Uses the decoded magnitude only. Phase is still initialised from the source voice mixture and then refined by Griffin-Lim; “pure” therefore refers to magnitude generation, not independent waveform generation.
Nearest event
At every output frame, the nearest encoded source patch is selected in latent space. Its complex STFT content is read through the source-time voice system. This mode reveals the corpus-navigation behavior of the trajectory most directly.
Barycentric
The K nearest source patches are combined according to inverse-distance relationships and converted into equal-power target coefficients before complex STFT mixing. The visualisation reports the actual targeted amplitude coefficients used by this equal-power mix.
Source-time continuity
A separate read pointer measures time since the last retrigger and advances according to rate. A selected donor can therefore continue reading forward through the original source instead of repeatedly looping the same short patch. retrig resets this pointer.
Visualisation
When Draw visualisation is enabled, Latent Pbind creates a multi-panel Praat Picture display designed to explain the entire compositional chain.
1 — Pattern events
One lane per active stream. Event onsets are marked explicitly and each lane shows the normalised event values over time.
2 — Latent trajectories
Plots the final normalised z coordinates after boundary and attraction processing. The shaded -1...+1 band represents the robust data box.
3 — Latent maps
Shows source patches, cluster centres, global event onsets, and the time-coloured trajectory in z1×z2 and, when available, z3×z4.
4 — Rendering diagnostic
Decoder mode shows distance from the training cloud in units of r90. Nearest mode shows source read position. Barycentric mode shows K neighbour positions with darkness proportional to the targeted amplitude coefficient.
5 — Output
Displays the rendered waveform with duration, peak, and RMS.
Summary strip
Reports model geometry, raw-VAE KL activity, patch count, clusters, event count, seed, interpolation, boundary, excursion, out-of-cloud statistics, rendering mode, and the Pbind expression.
Technical behavior
- Processes exactly one selected Sound and never modifies the original.
- Multichannel input is converted to a temporary mono analysis/rendering copy.
- STFT uses a Hann window and 75% overlap; FFT size depends on sample rate.
- Analysis uses 64 triangular log-frequency bands from approximately 40 Hz to the lower of 16 kHz or 95% of Nyquist.
- Low-energy patches more than 60 dB below the strongest patch are excluded from latent training.
- The beta-VAE is implemented directly in NumPy with analytic gradients and Adam.
- Each Pbind key uses an independent seeded RNG derived from the global seed and key name.
- Latent coordinates are PCA-rotated, sign-oriented by spectral-centroid correlation, and robustly scaled by the 2nd...98th percentile range.
- Cluster identities use k-means++ and are ordered along z1.
- Soft-attract navigation uses the geometry of the actual encoded cloud rather than only the rectangular -1...+1 box.
- Decoder output is level-calibrated against the training data and constrained by corpus-derived band and total-energy ceilings.
- Source donor changes use equal-power crossfades.
- Invalid Pbind syntax is parsed before model training, avoiding a wasted training run.
- Per-run temporary filenames include a unique session tag so concurrent Praat runs do not share files.
- All stochastic model and pattern behavior is reproducible from the reported seed as far as the CPU implementation permits.
- The Python engine reports typed errors through a status file and never silently falls back to unrelated behavior.
Requirements & installation
numpy and scipy.Install with:
python -m pip install numpy scipy
| Component | Requirement |
|---|---|
| Praat | Praat 6.3+; Praat 7 may request trust because the tool writes temporary files and launches Python. |
| Python | Python 3 with NumPy and SciPy. |
| Python backend | Place latent_pbind.py in plugin_AudioTools/py/. The frontend also accepts the backend next to the Praat script as a fallback. |
| GPU / neural frameworks | Not required. The beta-VAE is implemented in NumPy; PyTorch and TensorFlow are not used. |
| Network / pretrained model | Not required. The model is learned from the selected Sound for each run. |
Limitations
- Offline only: the trajectory is composed first and rendered afterward. This is not a real-time latent performance instrument.
- Mono output: multichannel source material is mixed to mono for this tool.
- On-the-fly training: every run trains a model, so processing is slower than purely native Praat transformations.
- Latent axes are source-dependent: z1...zd are learned from the selected Sound and do not carry fixed semantic meanings across different source files.
- Axis orientation is diagnostic: the sign convention points toward increasing spectral centroid only where the reported correlation is meaningfully non-zero.
- Cubic overshoot: cubic interpolation can leave the event-value range before boundary processing.
- Out-of-distribution decoding: large excursions can enter regions unsupported by the training cloud. Distance and level-limiting diagnostics are reported for this reason.
- Source dependence remains: Nearest and Barycentric modes directly reuse source patches; Decoder with Source fine structure also borrows local spectral detail from the source.
- Finite shared-clock streams terminate the composition: this follows the tool's Pbind semantics and should be considered when combining finite and infinite patterns.
Outputs
The script creates a new mono Sound named:
<original-name>_LatentPbind
The original Sound remains unchanged. Output duration is determined by the requested duration, the input duration when Output duration = 0, and any finite pattern that terminates the shared event stream earlier.
Applications
Latent counterpoint
Use case: treat latent coordinates as independent compositional voices with different clocks, cycles, stochastic laws, and interpolation.
Starting point: Radical latent counterpoint.
Polymetric timbral trajectories
Use case: run z dimensions on patterns of different cycle lengths so their combined coordinate never repeats at the period of any single stream.
Starting point: Polymetric coordinates.
Algorithmic identity travel
Use case: use cluster as a macro-formal identity sequence while faster z streams explore local regions around each identity.
Starting point: Cluster pilgrimage.
Structured stochastic exploration
Use case: combine Brownian walks, random holds, weighted choices, and smooth interpolation to produce repeatable but non-literal paths through a learned source space.
Starting point: Brownian latent walk.
Chaotic latent motion
Use case: use logistic-map streams and smoothing to create nonlinear trajectories with deterministic structure but complex local behavior.
Starting point: Chaotic orbit.
Compare latent rendering strategies
Use case: keep one Pbind trajectory and compare Decoder, Nearest, and Barycentric rendering. This separates the compositional path from the synthesis mechanism used to sonify it.
Workflow: independent latent voices
Example concept:
z1 = slow Brownian motion
z2 = asymmetric 7-step cycle
z3 = sparse impulses on a faster clock
z4 = geometric decay
The result is not four separately audible parameters. Their simultaneous values define one moving point in the learned acoustic space.