Sound to Grain — User Guide

Extracts fixed-length grains from random source positions, optionally reverses them, and concatenates them into mono or stereo outputs with several left/right independence strategies.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 2.3 (2026) License: MIT License Repo: GitHub

What this does

Sound to Grain creates a new sequence from one selected Sound. The left-side grain positions are chosen randomly from the legal source range. Depending on the output mode, the right channel can use the same source positions, independent random positions, the same grains in a shuffled order, or a time-offset version of the left positions.

source → random grain positions → Praat extraction window → optional per-grain reversal → L/R ordering according to output mode → sequential concatenation → mono or stereo result → target peak 0.95
Grains are concatenated one after another. There is no overlap-add, density scheduling, automatic crossfade, or silence inserted between grains.

Quick start

  1. Select exactly one Sound object.
  2. Run Sound_to_Grain.praat.
  3. Choose Custom or one of the six named presets.
  4. Set the number and length of grains.
  5. Choose Hanning, Rectangular, or Triangular extraction.
  6. Choose one of the five output modes.
  7. Optionally enable probabilistic grain reversal.
  8. Run the script. The result is named <source>_grains_<preset>.
Play_result controls final playback. Draw_visualization controls the Picture output. Individual grains are not previewed during extraction.

Output modes

ModeLeft channelRight channel
Mono Random grain positions. No right channel.
Stereo — same grains L/R Random positions. Same source positions and same reversal decisions as L, using source channel 2 when available.
Stereo — independent random positions Random positions. Independent random source positions and independent reversal decisions.
Stereo — independent shuffled order Randomly extracted grains, concatenated in extraction order. Grains extracted at the same source positions as L but concatenated in an independent Fisher–Yates permutation; reversal decisions are independent.
Stereo — independent time offset Random positions. Each L source position plus Time_offset_s, wrapped into the legal source-start range; reversal decisions are independent.

Random source positions

maxStart = sourceDuration - Grain_length_s if maxStart > 0: start ~ Uniform(0, maxStart) else: start = 0

A grain can therefore begin anywhere that allows the complete requested grain to fit inside the source. Repeated or nearly repeated source positions are possible.

Input-channel behavior

The script works through private zero-based source copies, so a Sound whose time domain does not begin at 0 is handled without changing the original object.

InputMono outputStereo output modes
MonoMono source used directly.The mono source supplies both L and R.
StereoConverted to mono before grain extraction.Channel 1 supplies L; channel 2 supplies R.
3+ channelsConverted to mono.Only channels 1 and 2 are used; channels 3+ are not included.
In Stereo — same grains L/R, “same grains” means the same temporal source positions and reversal pattern. With stereo input, L and R still contain their corresponding original source channels rather than duplicate mono audio.

Grain extraction windows

Each grain is created with Praat Extract part using the selected window shape and relative width 1.

Window_typeBehavior
HanningPraat Hanning-window extraction over the grain.
RectangularUntapered rectangular extraction.
TriangularPraat triangular-window extraction.
These are per-grain extraction windows. They do not create overlap or crossfades between adjacent grains in the final sequence.

Probabilistic reversal

When Enable_reversal is active, each eligible grain receives a random integer draw from 1 to 100. The grain is reversed when that draw is less than or equal to the corresponding reversal-percent value.

Left channel

Every L grain uses Left_reversal_percent.

Right channel

The percentages are target probabilities, not exact quotas. The actual number reversed in one run can differ. Values are not explicitly clamped to 0–100 by the script.

Stereo Shuffle

In shuffle mode, the right-channel order is generated with an ascending Fisher–Yates permutation:

order = [1, 2, ..., N] for i = 1 ... N-1: j = randomInteger(i, N) swap(order[i], order[j])

The right-channel accumulator is then built explicitly in that stored order. The left channel remains in ordinary extraction order.

The grain map also follows the actual shuffled R order, including the reversal state belonging to the grain that occupies each output position.

Time-offset mode

For every L source start, the R start is initially:

rightStart = leftStart + Time_offset_s

If the result exceeds the legal source-start interval, it wraps:

rightStart = rightStart - floor(rightStart / maxStart) × maxStart

If Grain_length_s == sourceDuration, then maxStart = 0 and the only legal source position for both channels is 0.

The offset is a source-read offset, not a delay between output channels. L and R grains are still concatenated in corresponding output slots.

Presets

PresetGrainsLengthWindowModeReversal
Quick Texture15200 msHanningMonoOff
Dense Cloud50150 msHanningMonoOn, L/R targets 30/30%
Micro Grains8050 msRectangularMonoOff
Long Segments10800 msHanningMonoOff
Stereo Scatter25250 msHanningIndependent random positionsOn, L/R targets 40/60%
Stereo Shuffle30200 msHanningIndependent shuffled orderOn, L/R targets 30/70%

Named presets overwrite grain count, grain length, window, output mode and reversal settings shown above. They do not change Time_offset_s, Draw_visualization, or Play_result.

Parameters & effective limits

ParameterDefaultExact role
PresetCustomCustom plus six named configurations.
Number_of_grains20Internally replaced by floor(value); resulting value must be at least 1.
Grain_length_s0.3 sPositive; may equal but may not exceed the source duration.
Window_typeHanningHanning, Rectangular, or Triangular extraction.
Output_modeMonoOne of the five channel/independence strategies described above.
Time_offset_s0.1 sPositive source-read offset used only by mode 5.
Enable_reversalOffEnable probabilistic per-grain reversal.
Left_reversal_percent50Threshold used for L reversal draws.
Right_reversal_percent50Threshold used for independent R reversal draws where applicable.
Draw_visualizationOnDraw extraction map, report, waveform comparisons and summary.
Play_resultOnPlay the final result.

Concatenation, duration & level

Assembly

The left output is assembled by concatenating L grains in extraction order. Stereo modes build a corresponding R sequence; only Shuffle changes its order.

There is no intentional overlap between successive grains.

Duration

nominal output duration = floor(Number_of_grains) × Grain_length_s

The script measures the actual concatenated duration and reports it in the Info window and visualization.

Final level

After assembly, every non-silent result receives:

Scale peak: 0.95

This is target peak normalization. A quiet non-zero result can be amplified to the 0.95 sample-peak target.

Visualization

The v2.3 Picture view contains:

  1. Grain extraction map: source position on the x-axis and grain/output index vertically. Stereo modes show L above R.
  2. Parameter report: grain count/length/window, output mode, reversal counts and final output statistics.
  3. Zoom overlay: first up-to-500 ms of original and result on one shared local amplitude scale.
  4. Full waveform comparison: original and result on one shared global amplitude scale.
  5. Summary bar: preset, mode, grain settings, input/output duration and measured output peak.

Grain-map colors

Color indicates reversal status, not frequency, amplitude, or source identity. In stereo mode L and R use separate base colors so the two channel rows remain distinguishable.

Shuffle map

For Stereo Shuffle, the lower R map is drawn in the actual output permutation. Its source-position bar and reversal color follow the grain that really occupies that R output slot.

Waveform comparison

Both waveform panels use mono display copies when the audio is stereo. They therefore compare overall waveform shape/level, while the grain map carries the L/R structural information.

The original and result share the same y-axis scale in the full comparison. The zoom panel also shares one scale between the two signals, calculated specifically for the displayed first 500 ms or less.

Output behavior

The Info window reports the source, preset, grain settings, output mode, requested reversal percentages, extraction progress, actual reversal counts, result name and measured duration.