Brightness Sorted Grains — User Guide
Randomly samples short grains from a Sound, measures each grain's spectral centre of gravity, optionally exaggerates spectral differences, and reorders the grains from dark to bright or bright to dark.
What this does
Brightness Sorted Grains creates a new mono sound from short excerpts sampled at random positions in the source. Each grain is analyzed in the frequency domain, assigned a spectral-brightness value, and then optionally reordered by that value. The result can form a trajectory from darker to brighter spectra or the reverse.
The script is a sampling and reordering process, not a conventional time-stretcher. Source positions are random, so the original chronology is not preserved even when Sort_grains is off.
What is brightness?
In timbre perception, brightness usually describes how strongly a sound is weighted toward higher frequencies. A common numerical correlate is the spectral centroid, or spectral centre of gravity: a spectrum with more high-frequency energy tends to have a higher centroid.
This script uses Praat's Spectrum: Get centre of gravity... with Power = 2. Praat therefore computes the average frequency weighted by the power spectrum:
The value is measured in hertz. It is used here as the ordering variable for the grains. It is a useful correlate of perceived brightness, but it is not a complete model of timbre or brightness perception.
Quick start
- Select exactly one Sound object in Praat.
- Run
Brightness_Sorted_Grains.praat. - Choose a preset, or keep Custom.
- Set the base grain size and choose Fixed or Random grain duration.
- Use Analysis_overlap and Density_factor to control how many random grains are drawn.
- Choose Dark to bright or Bright to dark.
- Use Exaggerate_spectral if you want the spectral differences pushed farther apart before sorting.
- Set the silence gap between output grains and run the script.
Processing pipeline
1. Mono source and random grain sampling
Multichannel input is converted to mono. Each grain is extracted from a uniformly random valid source position. Non-zero Sound time domains are handled correctly: random positions are zero-based offsets internally, then converted back to the Sound's absolute time domain for extraction.
2. Grain count
The target is clamped to a maximum of 500 grains. Analysis_overlap is not an output overlap or crossfade. It only changes the nominal analysis hop used to determine how many random source excerpts are generated.
3. Grain duration and window
In Fixed mode, every grain uses the base duration. In Random mode, a uniform random variation in ±Grain_size_variation_ms is added, then the duration is constrained to a practical range. If the entered variation exceeds the base grain size, the script first reduces it to 80% of the base size.
The extraction window can be Rectangular, Triangular, or Parabolic. The default is Triangular.
4. Initial brightness measurement
Every extracted grain is converted to a Spectrum and measured with Praat's power-weighted centre of gravity. Silent or undefined measurements are stored as 0 Hz.
5. Source-adaptive spectral exaggeration
If exaggeration is enabled, the script first computes a brightness pivot: the mean of all valid original grain centroids. It then pushes grains away from that source-specific pivot:
After this spectral modification, the grain is converted back to Sound and its centroid is measured again. The measured post-processing value — not an estimated multiplier — becomes the brightness used for sorting.
6. Reverse and gain scatter
When Reverse_grains is enabled, each grain has a 30% probability of being reversed. Reversal does not alter its stored brightness because time reversal does not change the magnitude spectrum.
Every non-silent grain is then peak-normalized to 0.30. After that, Gaussian gain scatter is applied in dB:
This separates brightness from systematic loudness differences while still allowing controlled random level variation.
7. Sorting and assembly
When sorting is enabled, grains are sorted by their measured post-exaggeration centroid. Dark to bright uses ascending centroid; Bright to dark uses descending centroid. When sorting is disabled, the random generation order is retained.
Copies of the grains are created in final order and concatenated in one pass. A mono silence object is inserted between adjacent grains when Gap_between_grains_ms is greater than zero.
Presets
| Preset | Grain | Mode | Analysis overlap | Density | Gain scatter | Gap | Exaggeration | Reverse |
|---|---|---|---|---|---|---|---|---|
| Gentle Sweep | 200 ±30 ms | Fixed | 0.2 | 0.8 | 0.5 dB | 80 ms | Subtle 1.2× | Off |
| Dense Cloud | 100 ±40 ms | Random | 0.5 | 2.5 | 1.5 dB | 20 ms | Moderate 1.5× | 30% |
| Micro Grains | 50 ±20 ms | Random | 0.4 | 3.0 | 2.0 dB | 10 ms | Off | Off |
| Long Drones | 400 ±100 ms | Random | 0.6 | 0.5 | 0.25 dB | 150 ms | Subtle 1.2× | Off |
| Extreme Sort | 120 ±50 ms | Random | 0.3 | 2.0 | 2.5 dB | 40 ms | Strong 2.0× | 30% |
All named presets sort Dark to bright. Visualization and playback switches are not changed by the presets.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
| Preset | Custom | Custom or five named parameter sets. |
| Grain_size_ms | 150 | Base grain duration. Must be at least two samples and no longer than the source. |
| Grain_size_variation_ms | 50 | Uniform ± duration variation in Random mode; must be non-negative. |
| Grain_size_mode | Fixed | Fixed or Random grain duration. |
| Analysis_overlap | 0.3 | 0 ≤ value < 1. Controls nominal analysis hop and therefore target grain count. |
| Density_factor | 1.5 | Positive multiplier for target grain count. |
| Gain_scatter_dB | 1.0 dB | Gaussian per-grain gain variation after 0.30 peak normalization. |
| Reverse_grains | Off | When On, each grain has a 30% chance of reversal. |
| Window_type | Triangular | Rectangular, Triangular, or Parabolic extraction window. |
| Sort_grains | On | Sort by measured final centroid; Off preserves random generation order. |
| Sort_direction | Dark to bright | Ascending or descending centroid. |
| Gap_between_grains_ms | 50 | Silence inserted between successive output grains. |
| Exaggerate_spectral | On | Pushes grain spectra away from the source-adaptive brightness pivot. |
| Exaggeration_intensity | Moderate | Spectral boost of 1.2×, 1.5×, or 2.0×. |
| Show_spectrograms | Off | Shows an output spectrogram instead of the output waveform in the Picture window. |
| Draw_visualization | On | Draw the transformation map. |
| Play_result | On | Play the result after processing. |
Visualization
The Picture window follows the transformation itself:
- Source: mono source waveform. Multichannel sources are folded to mono for display, matching processing.
- Brightness sort map: each vertical stem connects the original centroid (grey point) to the measured post-exaggeration centroid (coloured point). Colour encodes only brightness.
- Order ribbon: shows final concatenation order; colour = brightness and cell width = grain duration.
- Output: waveform by default, or a spectrogram when Show_spectrograms is enabled. The spectrogram ceiling is limited to 5 kHz or 95% of Nyquist, whichever is lower.
- Summary: preset, grain count, brightness range, sorting direction, exaggeration, grain settings, gain scatter, reversal, and duration.
When the Output panel is a waveform, Source and Output use the same amplitude scale.
Output behavior
- The processed result is mono.
- The output object is named
<source>_brightness_sorted_<presetName>. - The output duration is the sum of all rendered grain durations plus the inserted gaps; it is not constrained to the source duration.
- The final non-silent result is always peak-normalized to 0.9.
- No overlap-add or crossfade is used between output grains. Continuity depends on the extraction window and the chosen gap.
- The source Sound remains unchanged; temporary grain objects are removed after rendering.