Granular Attention Re-synthesis — User Guide
Attention-weighted self-resynthesis: candidate grains are scored, hard-gated, and sampled from an active-only softmax distribution. Low alpha gives a broad self-remix; high alpha concentrates repeatedly on the strongest surviving grains.
What this does
This script implements a Granular Attention Re-synthesis engine in which candidate grains compete for being selected, not for gain. The source is converted to mono, analyzed as a bank of overlapping candidate grains, and reconstructed from those same moments according to an attention distribution derived from energy and/or energy-change features.
🎯 What is attention-based grain selection?
- Candidate grains are extracted from the mono source at regular candidate-hop intervals.
- Each candidate is Hann-windowed for analysis, matching the windowed content that reaches the resynthesis path.
- Each candidate receives a score: RMS energy, onset slope, energy-edge slope, or a mixed score.
- Hard attention gate: candidates below the floor are removed from competition entirely.
- Active-only softmax: only surviving grains receive non-zero probability.
- Attention_sharpness_alpha: higher values sharpen the probability distribution; lower values flatten it.
- Recency penalty: the last three selected grains are attenuated before each draw and the distribution is renormalized.
- True normalized Hann OLA: grains are placed in a buffer at real output times, with an accumulated Hann envelope used for normalization.
The result is a self-remix that can move from broad textural redistribution to concentrated self-quotation and stutter.
Key Features:
- 7 preset strategies — Self-Remix, Crystallize, Motif Extract, Onset Harvest, Shimmer, Slabs, Cloud, plus Custom
- 4 score types — RMS, Onsets, Energy edges, Mixed
- Active-only gate — rejected grains receive exactly zero probability
- Attention sharpness control — alpha directly controls concentration
- 3-step recency penalty — recent selections are progressively attenuated
- Real time jitter — output onset moves around the nominal hop
- Varispeed pitch jitter — pitch, speed, and grain duration change together
- Normalized buffer OLA — arbitrary multi-grain overlaps are summed and divided by the accumulated Hann envelope
- Reproducible randomness — Random_seed > 0 reproduces the stochastic sequence
- Suite-standard visualization — attention landscape, real resynthesis map, usage distribution, and summary strip
Technical implementation: (1) convert source to mono and keep an unmodified-level dry reference; (2) peak-normalize a working mono copy; (3) extract Hann-windowed candidate grains and score them; (4) apply a hard active mask and softmax over survivors only; (5) repeatedly draw grains with recency-adjusted probabilities; (6) apply optional varispeed before the Hann window; (7) place each grain at its actual jittered onset into output and envelope buffers; (8) divide by accumulated envelope; (9) trim/fade to source duration; (10) blend wet with the dry source; (11) peak-scale the final mono output to 0.99.
Quick start
- In Praat, select exactly one Sound object, at least 50 ms long.
- Run script… →
Granular_Attention_Resynth.praat. - Choose a preset. Self-Remix is a good starting point.
- For Custom, set grain size, synthesis hop, candidate hop, attention sharpness, floor, score type, jitter, recency, wet percentage, and Random_seed.
- Enable visualization if you want to inspect the attention landscape and actual output-to-source read map.
- Click OK. The result appears as
<source>_GAR_<preset>.
Attention Selection Theory
The Attention Gate and Softmax
🧮 Active-only attention distribution
Important terminology: the control is Attention_sharpness_alpha, not “temperature”. Higher alpha sharpens the distribution. In conventional softmax notation softmax(z/T), higher temperature would do the opposite.
Score Types
📊 Four Scoring Methods
| Score Type | Definition | Musical tendency |
|---|---|---|
| RMS | Hann-windowed RMS², normalized by maximum RMS² | Louder candidate regions compete more strongly |
| Onsets | Positive change in RMS² only, normalized by maximum positive slope | Rising-energy events and attacks are favored |
| Energy edges | Absolute change in RMS², normalized by maximum absolute slope | Both attacks and decays can be emphasized |
| Mixed | (1-w) * RMS_norm + w * positiveSlope_norm | Blend of energy and onset emphasis |
Mixed mode uses the positive-slope transient measure, not the absolute energy-edge score.
Recency Penalty
The blue probability curve in the visualization shows the base active-only softmax. Actual usage also reflects the per-draw recency penalty, so usage does not have to match the blue line exactly.
Musical Effects by Attention Sharpness α
| α Range | Behavior | Musical Result | Example |
|---|---|---|---|
| 1–3 | Broad competition | Textural self-remix; many active grains remain plausible | Self-Remix, Shimmer |
| 5–10 | Moderate concentration | High-score moments dominate more strongly | Onset Harvest, Slabs |
| 12+ | Strong concentration | Crystallization, self-quotation, repeated motifs | Crystallize, Motif Extract |
True Hann Overlap-Add
Varispeed Pitch Jitter
Preset Strategies
Preset 2: Self-Remix
🌱 Gentle Textural Remix
Grain: 60 ms | Hop: 30 ms | Candidate: 20 ms
Alpha: 3.0 | Floor: -3 dB | Score: RMS
Time jitter: ±8 ms | Pitch: 0 st | Recency: 0.3 | Wet: 100%
Preset 3: Crystallize
💎 Crystallized Texture
Grain: 40 ms | Hop: 20 ms | Candidate: 15 ms
Alpha: 12.0 | Floor: +3 dB | Score: RMS
Time jitter: ±3 ms | Pitch: 0 st | Recency: 0.4 | Wet: 100%
Preset 4: Motif Extract
🔁 Strong Motif Concentration
Grain: 30 ms | Hop: 15 ms | Candidate: 10 ms
Alpha: 25.0 | Floor: +6 dB | Score: RMS
Time jitter: ±1 ms | Pitch: 0 st | Recency: 0.6 | Wet: 100%
Preset 5: Onset Harvest
⚡ Positive-Slope Attack Focus
Grain: 50 ms | Hop: 25 ms | Candidate: 15 ms
Alpha: 8.0 | Floor: +2 dB | Score: Onsets (positive slope only)
Time jitter: ±5 ms | Pitch: 0 st | Recency: 0.4 | Wet: 100%
Preset 6: Shimmer
✨ Shimmering Texture
Grain: 20 ms | Hop: 10 ms | Candidate: 10 ms
Alpha: 2.0 | Floor: -6 dB | Score: RMS
Time jitter: ±4 ms | Varispeed: ±0.3 st | Recency: 0.2 | Wet: 85%
Preset 7: Slabs
🧱 Large-Grain Mosaic
Grain: 300 ms | Hop: 150 ms | Candidate: 50 ms
Alpha: 10.0 | Floor: +2 dB | Score: RMS
Time jitter: ±15 ms | Pitch: 0 st | Recency: 0.5 | Wet: 100%
Preset 8: Cloud
☁️ Drifting Cloud
Grain: 600 ms | Hop: 300 ms | Candidate: 80 ms
Alpha: 4.0 | Floor: -3 dB | Score: Mixed (transient weight 0.4)
Time jitter: ±30 ms | Pitch: 0 st | Recency: 0.3 | Wet: 90%
Parameters & Controls
Custom Defaults
| Parameter | Default | Validation / meaning |
|---|---|---|
| Grain_size_ms | 150.0 | Clamped to 5–1000 ms and then to source duration |
| Synthesis_hop_ms | 50.0 | Minimum 1 ms; capped to half the effective grain duration; may be raised to keep total hops ≤ 20,000 |
| Candidate_hop_ms | 20.0 | Minimum 1 ms; capped to effective grain duration |
| Attention_sharpness_alpha | 1.0 | Internal minimum 0.01; higher = sharper active distribution |
| Floor_dB | 0.0 | Threshold relative to mean score in dB: mean × 10^(dB/10) |
| Score_type | RMS | RMS / Onsets / Energy edges / Mixed |
| Transient_weight | 0.5 | Clamped to 0–1; used only by Mixed |
| Time_jitter_ms | 5.0 | Negative → 0; capped to one effective synthesis hop |
| Pitch_jitter_semitones | 0.0 | Clamped to 0–4 st; varispeed, not duration-preserving pitch shift |
| Recency_penalty | 0.5 | Clamped to 0–1 |
| Wet_percent | 100.0 | Clamped to 0–100 |
| Random_seed | 0 | 0 = unpredictable; positive integer = reproducible random draws |
| Draw_visualization | 1 | Draw v2.1 diagnostic page |
| Play_result | 1 | Audition final output |
Wet / Dry Behavior
Visualization & Analysis
v2.1 Diagnostic Page
Applications
Generative Self-Remix
Use Self-Remix or Cloud to redistribute the source's own salient regions across its original duration. The script does not extend duration: the wet path is trimmed to source length.
Rhythmic & Glitch Effects
- Motif Extract: high alpha concentrates strongly on the highest-scoring active grains.
- Crystallize: strong energy competition with slightly broader behavior.
- Onset Harvest: positive energy slopes emphasize attack-like regions rather than decays.
- Energy edges: use Custom when both attacks and decays should compete.
Shimmer and Varispeed Texture
Shimmer adds a small varispeed range before the grain window is applied. This changes pitch and temporal scale together and can create a lightweight drifting texture without pretending to be a phase-vocoder pitch shifter.
Source Navigation / Self-Quotation
The v2.1 resynthesis map makes the process useful analytically as well as compositionally: diagonal clusters indicate near-identity reading, while horizontal or repeated source-time bands reveal recurrent self-quotation.
Research & Education
The visualization can demonstrate active gating, softmax concentration, recency-modified sampling, stochastic usage, and overlap-add normalization. For conceptual accuracy, describe this as an attention-inspired grain-selection mechanism, not as a neural attention model.
Troubleshooting Common Issues
Floor_dB may be too high. If no candidate passes the threshold, the script intentionally activates only the single strongest grain.
Reduce Attention_sharpness_alpha, lower Floor_dB, and/or increase Recency_penalty.
Raise alpha or raise the floor so fewer candidates remain active.
Increase Candidate_hop_ms to reduce the candidate pool and/or increase Synthesis_hop_ms to reduce output events. Decreasing either hop creates more work, not less.
Pitch jitter is varispeed. Downward shifts lengthen grains; upward shifts shorten them. The buffer OLA accepts variable-length grains directly.
This is intentional in the current script. Stereo and multichannel input are summed to mono before analysis/resynthesis, and the output is mono.
Advanced Techniques
The current score block can be adapted to other features, but the shipped v2.1 implementation uses only energy, positive energy slope, absolute energy slope, or their defined mixture.
If you modify the script, remember the correct direction: low alpha = broad/exploratory; high alpha = sharp/crystallized.