NMF Granular Spatial Composer

Composing new timbres and spatial gestures from one sound through NMF-derived materials, time-local granulation, and the source's own amplitude envelope.

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

The musical idea: decomposition becomes composition

A recorded sound contains more than one possible musical identity. Its spectral content, movement in time, and changing intensity can be separated and recombined to suggest new materials. NMF Granular Spatial Composer treats a selected sound not as something to reconstruct faithfully, but as a starting point for an offline compositional process.

Non-negative Matrix Factorization (NMF) provides a small collection of spectral patterns and their changing activations. The instrument uses that analysis to generate eight related but different audio materials. It then draws short grains from those materials, keeping each grain near the corresponding moment of the original recording. Finally, the original amplitude envelope shapes the new texture, while individual grains may be distributed independently in stereo or quadraphonic space.

The compositional question is not how accurately can the original sound be reconstructed? but what new sound can emerge when its spectral identities are recomposed into a granular, spatially distributed gesture?

The resulting music may preserve the dynamic contour of speech, an instrumental phrase, or a noisy gesture without retaining the original sound's recognizable timbre. NMF components are algorithmic spectral patterns, not necessarily separate physical sources or instruments.

From one Sound to a spatial composition

Select a single Sound in Praat. The Praat script manages the interface, temporary exchange, output objects, and Picture visualization; a companion Python engine carries out NMF, spectral transformations, grain scheduling, audio rendering, and spatial distribution. No corpus preparation is required.

The spectral dimension

Sound becomes a corpus

Three isolated NMF component signals are joined by five resynthesized transformations, including phase reconstruction, cross-routing, spectral sculpture, and a stationary portrait. The eight materials are generated from the same input.

The temporal dimension

Grains remain locally connected

Each grain is selected around its corresponding moment in the input, rather than from an unrestricted position in the whole corpus. That local relationship, together with the imposed amplitude envelope, helps retain the larger gesture even when the timbre changes.

The source envelope is applied after granular accumulation and spatial distribution. The instrument does not simply widen a finished mono mix: spatial positions are assigned to individual grains as part of the composition.

The eight-source NMF corpus

The reference analysis operates at 16 kHz with a 1024-sample STFT, 256-sample hop, and 12 NMF components. Three of these are selected by their contribution to the decomposition. The other five corpus slots are produced by distinct spectral rendering procedures. The corpus exists internally during processing; it is not a set of files the user must prepare.

SlotCorpus materialHow it is obtainedListening perspective
1–3Component solosThree high-energy NMF components extracted using soft spectral masks and the source's complex STFT.Partial spectral identities and features obscured by the complete source.
4Neutral Griffin-LimReconstruction from the NMF magnitude approximation with estimated phase.An alternative synthetic rendering of the analysis.
5Cross-route / original phaseTemporal activations are reassigned across spectral bases; synthesis uses the source phase.New relationships between spectral identity and temporal behavior.
6Cross-route / Griffin-LimThe same routed magnitude representation is synthesized using estimated phase.A contrasting reconstruction of the same transformed spectrum.
7Spectral SculptureFrequency profiles are stretched and activations are smoothed and shifted.Greater timbral and temporal departure from the original.
8Spectral PortraitA leading spectral basis is held at constant activation and rendered with randomized phase.A relatively stationary spectral color available for granular recomposition.
Component numbers are input-dependent. The three solo slots select the dominant components of the current recording. Their actual NMF component numbers are shown in the processing report and the visualization; the reference experiment's labels are not fixed source identities.

How the granular cloud is formed

Grain onsets follow a Poisson process. Each event chooses one of the eight corpus slots, a duration, a playback speed, and a read position near the corresponding time in the original recording. Samples are interpolated, windowed with a Hann function, and accumulated with overlap normalization.

For the Reference preset, the mean density is 93 grains per second; durations range from 65 to 140 milliseconds; speeds range from 0.92 to 1.08 times the original; and the source-read position is displaced by at most approximately ±0.26 seconds. These are statistical choices rather than a metrical pattern.

The source envelope is derived from a combination of fast and slow RMS measurements. It controls the finished granular texture's dynamics, so the new spectral material may retain the rise, fall, and pauses of its parent recording.

Mono, stereo, and quadraphonic composition

Rendering determines the output channel layout and spatial behavior. It is independent of Preset, which determines how grains are scheduled and selected.

1 channel

Mono Local Granular

All grains accumulate in one channel. The best starting point for evaluating the relationship between NMF material, local granulation, and the source envelope without spatial variation.

2 channels

Stereo Source Islands

Each of the eight corpus sources occupies a characteristic position in the stereo field. Its grains drift gently around that location, creating spatially distinguishable spectral identities.

2 channels

Stereo Grain Orbit

A shared center moves across the stereo field while each grain is scattered independently around it. The sound field becomes an evolving constellation rather than a fixed left-right mixture.

4 channels

Quad Constellation

Grains occupy regions around the listener and move locally between adjacent speakers using equal-power panning. The four channels are Front Left, Front Right, Back Left, and Back Right.

Conceptual spatial layouts
LCR Source Islands

Corpus slots tend toward their own stereo locations, with small per-grain variation.

FL FR BL BR listener FRONT Quad Constellation

Four independent channels around the listener; the speaker layout must be respected during playback.

These diagrams illustrate the organization of space, not measured locations from a particular render. The Praat Picture visualization uses the actual grain positions recorded by the Python engine.
All Outputs renders Mono, Stereo Islands, Stereo Orbit, and Quad in one pass; with Quad_stereo_preview enabled, it also imports a stereo downmix of Quad. The preview is not binaural and does not reproduce four loudspeakers over headphones.

Getting started

One-time setup. Place NMF_Granular_Spatial_Composer.praat and nmf_granular_spatial_composer.py in the same folder inside Praat AudioTools. Install Python 3.10 or later and the required packages: numpy, scipy, librosa, scikit-learn, and soundfile. The script checks Python and its packages automatically. If automatic discovery fails, an optional nmf_gsc_python.txt file containing the Python executable path can be placed beside the scripts.
  1. Select exactly one Sound in Praat. It may contain speech, instrumental music, noisy material, or a composite sound. The selected original is preserved.
  2. Run NMF_Granular_Spatial_Composer.praat. Leave Preset on Reference for the validated starting configuration.
  3. Choose a Rendering mode. Start with Stereo Source Islands for an immediately spatial result, or choose All Outputs to compare all formats from the same grain events.
  4. Keep Original envelope enabled. It carries the source's dynamic gesture into the granular texture. Try disabling it later to hear what that gesture contributes.
  5. Render, listen, and inspect the Picture. With Draw_visualization enabled, the tool draws the temporal gesture, source activity, and spatial organization. New Sound objects appear in Praat's Objects window.
  6. Repeat with one change. Compare a different preset, spatial mode, or grain seed while keeping the source fixed. Choose Custom to specify individual granular settings.
Selection and duration: exactly one Sound object must be selected. The supported input duration is from 1 second to 10 minutes. The current reference engine analyzes and returns audio at 16 kHz; even higher-sample-rate inputs are rendered at that rate.

Compositional presets

Presets determine the temporal and textural character of the granular cloud. They do not determine the number of output channels. All five preset options work with every Rendering mode.

PresetDensity (grains/s)Grain durationLocalityPlayback speedEnvelope
Reference9365–140 ms±0.26 s0.92–1.08100%
Suspended75140–260 ms±0.35 s0.92–1.0880%
Fragmented12540–85 ms±0.12 s0.85–1.15100%
Diffuse Cloud15090–210 ms±0.55 s0.78–1.2265%
CustomOpens a second dialog for density, minimum/maximum duration, locality, speed range, envelope strength, and random seed. Starts from Reference values.

Reference: the musical baseline

The Reference preset preserves the settings used to establish the successful NMF + local granulation + original-envelope process. Use it to compare spatial renderings and to establish a familiar listening point before changing the grain organization.

Suspended

Longer grains and a slightly wider local search create a starting point for sustained, overlapping textures. Try it with a resonant instrument or an extended vocal sound.

Fragmented

Shorter and more numerous grains offer a starting point for fragmented gestures and rapid micro-events. Try it with consonants, attacks, or percussive material.

Diffuse Cloud

A denser cloud, a wider source search, and a broader playback-speed range invite a less literal relationship with the source's temporal order.

Custom

Use manual values to isolate a particular compositional variable. A fixed nonnegative random seed makes controlled comparisons possible.

Listening status: Reference reflects the previously approved experiment. Suspended, Fragmented, and Diffuse Cloud are proposed exploratory starting points. Their musical effects are intentions, not guaranteed results for every recording, and they have not been validated by the same reference listening experiment.

Controls and output options

ControlWhat it does
PresetReference, Suspended, Fragmented, Diffuse Cloud, or Custom. Controls the statistical organization of grains.
RenderingMono Local Granular, Stereo Source Islands, Stereo Grain Orbit, Quad Constellation, or All Outputs. Default: All Outputs.
Original_envelopeEnabled by default. When unchecked, envelope strength is set to zero regardless of the preset.
Quad_stereo_previewImports a two-channel downmix when Quad is rendered; it is not a binaural simulation.
Draw_visualizationCreates the compositional Picture using real render data and measured RMS curves.
Show_processing_reportReports input, preset, parameters, NMF diagnostics, corpus slot identities, grain counts, and imported outputs in Praat's Info window.
Retain_work_filesKeeps a clearly marked, user-owned folder with generated files and diagnostic data instead of removing them after import.
PlayAuto, a specific mono/stereo result, Quad Preview, or None. Auto prefers Stereo Islands, then Orbit, Quad Preview, and Mono among available outputs.

The Custom dialog

When Custom is selected, a second dialog offers Density (1–500 grains/s), Grain_min_ms and Grain_max_ms (5–1000 ms), Locality_s (0–5 s), Speed_min and Speed_max (0.25–4.0), Envelope_strength (0–1), and Random_seed (nonnegative integer). The minimum values must not exceed the corresponding maximum values.

Reference and the three exploratory presets use the grain seed 20261029. Within one execution the same grain event list is reused for the requested spatial modes; this makes comparisons between modes more meaningful.

Result objects

Praat Sound name suffixChannelsPurpose
_NMF_Local_Granular1Local granular composition with optional source-envelope shaping.
_NMF_Stereo_Islands2Distinct corpus-source islands across the stereo field.
_NMF_Stereo_Orbit2Granular cloud around a moving stereo center.
_NMF_Quad4Four-channel constellation in FL, FR, BL, BR order.
_NMF_Quad_Preview2Stereo downmix of the quad result, when requested.

All results are returned as Praat Sound objects. Quad stems are also written by the engine as intermediate WAV files, but are not automatically imported as separate Praat Sounds. To preserve these files for routing in a DAW, enable Retain_work_files.

Reading the compositional visualization

When Draw_visualization is enabled, Praat draws a compositional score in its Picture window. Python supplies time-stamped grain events, the positions actually used for spatial rendering, and measured amplitude curves. The picture describes what was produced; it does not modify the synthesis.

Panel A

Temporal Gesture

Displays the input RMS, the output RMS, and the imposed envelope. Each curve is separately scaled to its own maximum, so the panel compares shape, not absolute loudness.

Panel B

Granular Source Map

Shows grain events across eight corpus lanes. Horizontal position marks onset time, line length represents grain duration, and the small vertical shift within each lane reflects the difference between source-read time and output time. Labels show the actual component identities and event counts.

Panel C

Spatial Composition

For Stereo Islands or Orbit, displays the actual grain pan positions through time. Orbit adds the moving center; Islands shows source anchors. For Quad, four speaker-energy curves appear together with the speaker arrangement.

Illustration of the compositional score A · GestureB · Source mapC · Spatial 0 stime →RL
Original RMSOutput RMSImposed envelope
Illustrative diagram only. It shows the type of information the program draws, not data from a particular audio file. In the actual Praat Picture, source activity and spatial positions are based on the rendered grain events. For very dense/long pieces, the map may show a sampled subset of events to remain legible.
When All Outputs is chosen: the main Temporal Gesture and stereo panel describe Stereo Source Islands, and an additional Quad speaker-energy panel is included. The picture does not attempt to display a separate full score for every rendered mode.

The information strip identifies the corpus size, grain-event count, preset, envelope setting, output choice, and random seed. This makes the visualization a useful record for comparing successive renders.

Compositional possibilities

The instrument becomes most informative when one variable is changed at a time. The following are listening experiments rather than guaranteed presets or recipes.

Speech without words

Choose a spoken phrase containing pauses, breaths, and contrasting consonants. Use Reference with Stereo Islands. Listen for the original utterance's dynamic shape emerging as an unfamiliar spectral texture.

The same gesture, different space

Keep Reference and the same source, then compare Islands with Orbit and Quad. Because the grain events are shared, differences can be heard primarily as changes in spatial organization.

Stretching an instrumental resonance

Try Suspended on a sustained instrumental sound, bowed resonance, or long decay. Listen for whether the longer grains expose stable timbral colors or smear recognizable attacks.

A cloud of micro-attacks

Try Fragmented with pitched percussion or short transient-rich phrases. Compare the rhythmic impression with the source's own envelope retained and switched off.

Preserve or dissolve the phrase

With Custom, keep the grain duration fixed while expanding the locality range. Listen for the point at which short-term source relationships become less apparent.

Composition as a family of renders

Keep one random seed, save several preset/space combinations, and arrange them later as contrasting materials. The offline nature of the tool encourages comparison, selection, and revision.

Technical and listening notes

The instrument builds on Python reference experiments combining NMF decomposition, transformed spectral reconstructions, local granular synthesis, source-envelope shaping, and per-grain spatialization. The Reference preset preserves that established processing design; other presets remain exploratory configurations.