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.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 1.0.1 (2026) Category: Hybrid Systems License: MIT License Repo: Praat AudioTools
Contents:

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.

What makes this different? This is not ordinary parameter automation and not a generic random latent walker. Independent pattern streams become coordinates of motion through a learned acoustic manifold. Different coordinates can run on different clocks and use different interpolation rules, so the latent trajectory itself can be composed contrapuntally.

Key Features:

Quick start

  1. Select exactly one Sound object in Praat.
  2. Run LatentPbind.praat.
  3. For a first run, choose Preset = Polymetric coordinates or Brownian latent walk.
  4. Keep Rendering mode = Decoder, Interpolation = Smooth, and Boundary mode = Reflect.
  5. Leave Output duration = 0 to use the input duration.
  6. Keep Excursion = 1.0 so the pattern works in the robustly normalised data range.
  7. Enable Draw visualisation to inspect the event streams and their movement through the learned latent space.
Good source material: recordings with internal timbral diversity — instrumental phrases, multiphonics, speech, percussion, environmental recordings, extended techniques, or heterogeneous textures. A highly static source can still work, but its learned latent manifold will contain less meaningful acoustic contrast.

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.

Pbind expression ↓ independent event streams ↓ continuous control trajectories ↓ normalised latent coordinates ↓ learned acoustic space ↓ Decoder / Nearest / Barycentric rendering ↓ new 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.

Three layers of time. The tool distinguishes pattern time, latent-trajectory time, and source-read time. Pbind controls when coordinates change; interpolation shapes the movement between events; 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

PatternFunction
PseqSequential list, with optional repetition and offset.
PserRead a list serially for a fixed number of values.
PrandRandom choice from a list.
PxrandRandom choice without immediately repeating the previous item when possible.
PshufShuffle a list once and repeat the shuffled order.
PwrandWeighted random choice.
PwhiteUniform random values.
PexprandExponentially distributed random values between positive bounds.
PbrownBounded Brownian motion with reflection at the limits.
PwalkWalk through a supplied value list.
PseriesArithmetic progression.
PgeomGeometric progression.
PstutterRepeat each generated value a specified number of times.
PnRepeat an embedded pattern.
PlagOne-pole smoothing of a pattern stream.
PholdProbabilistically hold or update a stream value.
PimpulseSparse random impulses with a resting value.
PlogisticLogistic-map sequence for bounded chaotic motion.

Pbind keys

KeyRole
durRequired global event clock in seconds.
z1...z8Normalised latent coordinates. Approximately -1...+1 covers the robust data range before excursion scaling.
clusterSelects / interpolates between k-means identity centroids. Latent z values become offsets around that centroid trajectory.
ampOutput amplitude envelope; values below 0 are clipped to 0.
tempAdds posterior-scaled stochastic jitter to the latent trajectory.
attract0...1 pull toward the nearest encoded source patch.
rateSource-read speed, internally limited to 0...4.
retrigValues above 0.5 restart the source-read pointer at that event.
interpGlobal interpolation: step, linear, cubic, or smooth.
dur_<key>Gives one stream an independent clock.
interp_<key>Gives one stream its own interpolation mode.
Finite streams: a finite pattern on the shared global clock ends the Pbind at the point where that stream is exhausted. A stream with its own 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:

512 → 256 → latent d → 256 → 512

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.

KL-active dimensions are a diagnostic, not labels for z1...zd. The Info window reports how many raw VAE dimensions have KL activity above the internal threshold before PCA rotation. It does not mean that a particular displayed z-axis is individually active or inactive.

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

ControlDefaultFunction
PresetOrdered driftSelects Custom or one of seven supplied algorithmic trajectory designs.
PbindExample expressionCustom event-pattern expression. Named presets replace this text internally.
Output duration0 s0 uses the input duration. A finite shared-clock pattern may end the output earlier.
Rendering modeDecoderDecoder, Nearest event, or Barycentric.
InterpolationSmoothGlobal interpolation used unless a stream provides interp_<key>.
Boundary modeReflectDefines how coordinates behave when they leave the robust data box.
Excursion1.0Scales the Pbind latent offsets before boundary handling.
Random seed1Controls VAE initialization, stochastic patterns, k-means initialization, and other stochastic operations. 0 requests a new seed.
Advanced settingsOffOpens model and rendering parameters.
Draw visualisationOnCreates the multi-panel Praat Picture explanation.
Play resultOnPlays the generated Sound after rendering.

Advanced settings

SettingDefaultFunction
Latent dimensions42...8 latent dimensions.
Patch length120 msNominal duration of each analysis patch.
Analysis hop20 msSpacing between candidate source patches.
Training epochs150Number of beta-VAE training epochs.
Beta0.5KL regularisation weight after warm-up.
Clusters6Requested k-means identity clusters, limited automatically by available patches.
Neighbours K4Number of neighbours in Barycentric mode.
Crossfade40 msEqual-power transition time when source donor voices change.
Phase iterations12Griffin-Lim refinement iterations in Decoder mode.
Decoder detailSource fine structureSource detail adds residual fine spectral structure from the nearest patch. Pure decoder uses decoded magnitude only.
Normalise outputOnNormalises 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.

Decoder hold behavior: the decoded envelope follows the pointer across the patch's eight time cells. If the pointer passes the end of the learned patch, the final decoded cell is held while source fine structure may continue moving forward through the original recording.

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

Requirements & installation

Python dependencies required: numpy and scipy.

Install with:
python -m pip install numpy scipy
ComponentRequirement
PraatPraat 6.3+; Praat 7 may request trust because the tool writes temporary files and launches Python.
PythonPython 3 with NumPy and SciPy.
Python backendPlace latent_pbind.py in plugin_AudioTools/py/. The frontend also accepts the backend next to the Praat script as a fallback.
GPU / neural frameworksNot required. The beta-VAE is implemented in NumPy; PyTorch and TensorFlow are not used.
Network / pretrained modelNot required. The model is learned from the selected Sound for each run.

Limitations

Decoder mode is hybrid spectral resynthesis, not direct waveform generation. The VAE decodes a coarse spectral magnitude representation. Source-derived detail and/or phase reconstruction are still required to obtain the final waveform.

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.

Reproducibility: the Info window reports the seed actually used. If Random seed = 0, enter the reported seed on a later run to reproduce the same stochastic pattern/model realization as far as the implementation permits.

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.