RF Concatenative — Random Forest Corpus Synthesis
Activity-aware, microphrase-based concatenative synthesis guided by a multi-target Random Forest and compositional trajectories. Version 0.5.1 introduces source-contiguous phrases, neighborhood novelty, and optional energy/brightness rendering.
What this does
RF Concatenative reorganises a source recording into a new audio sequence. It extracts a 17-dimensional timbral description for each overlapping grain, trains a multi-output RandomForestRegressor to estimate local feature-state transitions X(t) → X(t+k), and combines those predictions with a chosen trajectory in standardised corpus-feature space.
Unlike versions that could jump to a new source grain on every output hop, v0.5 selects a starting point for a short, source-contiguous microphrase, then advances through neighboring grains before making another jump. A coarse activity schedule, neighborhood-level novelty penalty, and weighted timbral matching help the result develop rather than collapse into repeated isolated fragments. The engine preserves the source sample rate and channel count; the output duration is set independently.
What changed in v0.5 / v0.5.1?
- Activity-aware selection: allocate active and low-energy source material using a configurable output activity target.
- Source-contiguous microphrases: choose runs rather than restarting the corpus search at every grain.
- Neighborhood novelty: discourage returning immediately to the same part of the recording, including nearby highly overlapping grains.
- Feature weighting: give RMS and brightness priority while adjusting the influence of secondary MFCC descriptors.
- Independent trajectory rendering: optional post-concatenation level and high-frequency contour for crescendo or spectral descent.
- Stronger diagnostic separation: alongside bootstrap OOB statistics, the Python engine computes an additional chronologically held-out forecasting skill with a separation guard.
- v0.5.1: corrects the Praat form's
Mfcc_weightvariable reference; it does not change the synthesis algorithm.
Quick start
- In Praat, open a recording and select exactly one Sound in the Objects window.
- Open and run
RF_Concatenative_v0.5.1.praatusing Open Praat script and Run. - Choose one of the five presets, or Custom to set the grain/forest/trajectory controls directly.
- Set
Target_duration_s; this andSeedare not overridden by the presets. - Optionally adjust the v0.5 controls (
Activity_target, phrase durations,Mfcc_weight,Render_strength). The presets do not override these v0.5 fields. - Run the process. A new
rf_concatenativeSound appears in Praat; optional plots and playback are controlled by the output checkboxes.
numpy, scipy, librosa, scikit-learn, and soundfile. Install them using python -m pip install numpy scipy librosa scikit-learn soundfile (or python3 -m pip ..., according to your system). The Praat script includes the Python engine, so a separate engine file is not required. It may use a compatible external rf_engine_v0.5.py if one is found.The Praat front end automatically attempts python on Windows, and common python3 locations on macOS or Linux. Input is passed through a temporary 32-bit WAV; temporary files are removed after processing.
Five presets
These are the actual preset values in the v0.5.1 Praat script. All five retain the existing names and basic grain/trajectory/forest settings. The new experimental controls remain independently adjustable.
| Preset | Grain / hop (ms) | Trajectory | Traj. weight | Repeat penalty | Trees / depth / k | Musical tendency |
|---|---|---|---|---|---|---|
| Flowing Crescendo | 120 / 30 | crescendo_brightening | 0.65 | 0.60 | 100 / 15 / 1 | Progressively brighter, more active, and louder. |
| Spectral Descent | 100 / 25 | spectral_descent | 0.70 | 0.65 | 100 / 15 / 1 | Movement from brighter toward darker material. |
| Organic Wander | 140 / 35 | random_walk | 0.45 | 0.90 | 120 / 18 / 1 | Varied timbral exploration without a forced output-level ramp. |
| Tight Continuity | 80 / 20 | random_walk | 0.25 | 0.45 | 150 / 20 / 1 | More forest-led selection with a lighter target pull. |
| Fragmented Mosaic | 60 / 15 | random_walk | 0.85 | 1.60 | 80 / 12 / 2 | Shorter-grain mosaic and stronger novelty pressure. |
Each preset can still sound quite continuous at the microphrase scale; Fragmented Mosaic is a stylistic description, not a guarantee of click-like stuttering. spectral_descent affects spectral brightness, not fundamental-frequency pitch.
New v0.5 controls
| Praat field | Default | What it changes | Practical note |
|---|---|---|---|
Activity_target | 0.78 | Approximate fraction of output hops scheduled as active. | Uses a corpus-relative RMS proxy, not voice recognition. With an all-active source, the engine keeps the output active rather than manufacturing rests. |
Min_phrase_ms | 140 | Minimum intended duration of a run of adjacent source grains. | Converted to hop counts. Actual phrases may end sooner at activity boundaries or the end of the source. |
Max_phrase_ms | 420 | Maximum intended microphrase duration. | Shorter ranges encourage more jumps; longer ranges preserve more of each source gesture. |
Mfcc_weight | 0.12 | Relative distance weight of MFCCs 2–13 in candidate matching. | RMS, centroid, flatness, ZCR and MFCC1 have fixed separate weights. This does not remove MFCCs from RF training. |
Render_strength | 1.0 | Scales the final trajectory-driven energy and high-frequency contour. | 0 disables this rendering stage; selection still follows the trajectory. random_walk has no additional render envelope. |
Other important controls
Trajectory_weight (default 0.6) balances the RF continuation estimate against the target on the actively guided feature dimensions. Repeat_penalty (default 0.5) scales the neighborhood novelty cost. Match_input_RMS (on by default) applies a global post-rendering RMS adjustment, with upward gain capped at roughly +12 dB; Safety_peak (0.99 by default) attenuates peaks above the chosen ceiling.
The script clamps user inputs to supported ranges; phrase lengths are discretised by the hop size. A global RMS adjustment does not eliminate the within-file crescendo contour.
Processing pipeline
1 — Load and choose the analysis channel
Read the recording at its native sample rate and preserve all source channels. Mono input is analysed directly; multichannel input is analysed through the actual channel with the highest RMS, not a channel average. The resulting source-grain indices are later applied to all channels.
2 — Extract and standardise grain features
Segment the selected channel into overlapping windows; calculate RMS, spectral centroid, flatness, zero-crossing rate and MFCCs 1–13. Standardise the resulting 17-column corpus using StandardScaler. The STFT is reused for the spectral features.
3 — Learn feature-state transitions
Train a multi-target Random Forest on pairs Z[t] → Z[t+k]. Report overlap-biased OOB diagnostics and a separate chronological test with a gap to reduce overlapping-frame leakage. These are forecasting diagnostics, not subjective measures of musical success.
4 — Build the target and activity schedule
Construct crescendo_brightening, spectral_descent or random_walk over the requested output duration. A smoothed source-level contour defines where active or low-energy material is preferred. In the crescendo mode, the scheduler also biases activity toward later portions of the output.
5 — Select microphrases
At each new phrase boundary, blend the forest prediction with the relevant trajectory features. Score candidate source starts by weighted feature distance, a short future-feature average, activity agreement, join cost and a decaying ~350 ms source-neighborhood novelty penalty. Continue with adjacent source hops until the phrase expires, activity changes, or the corpus ends.
6 — Resynthesise and render
Use periodic Hann windows and overlap-add with window-envelope compensation. Trim to the exact target duration; apply final edge fades; optionally render an energy/spectral-tilt trajectory; then perform optional global RMS matching and attenuation-only peak safety. Write a 32-bit floating-point audio file for the Praat handoff.
7 — Return result and report statistics
Praat imports a Sound named rf_concatenative and can generate input/output waveforms, a grain map, match distances, optional spectrograms and a parameter summary. The engine also writes additional statistical fields to its temporary report.
Feature space — 17 dimensions
RMS energy
Amplitude-related measure; emphasised in candidate scoring and used to estimate activity.
Spectral centroid
Broad indicator of spectral brightness; a principal target in crescendo and descent trajectories.
Spectral flatness
Distinguishes spectrally flat/noisy material from more tonal spectra.
Zero-crossing rate
Time-domain proxy that can correlate with noisiness and high-frequency content.
MFCCs 1–13
Descriptor of spectral-envelope shape; coefficient 0 is excluded. MFCC1 has its own matching weight; MFCCs 2–13 share Mfcc_weight.
spectral_descent option is a brightness descent, not a transposition algorithm.Trajectory rendering and the crescendo
Selection can alter loudness and brightness indirectly by choosing different grains. Version 0.5 also offers a separate, controllable post-concatenation rendering stage that shapes output energy and high-frequency content over time. It is enabled at Render_strength = 1.0 and applied before RMS matching and the safety ceiling.
| Trajectory | Additional gain contour (strength 1) | High-frequency contour (strength 1) |
|---|---|---|
crescendo_brightening | −4.5 → +4.5 dB | −7 → +7 dB |
spectral_descent | No programmed level ramp | +7 → −7 dB |
random_walk | No additional rendering | No additional rendering |
The contours follow a smoothstep curve; the spectral treatment emphasises or attenuates a high-passed component (cutoff normally 1.8 kHz, or lower at low sample rates). The figures describe the programmed processing, not guaranteed measured output changes, because source selection, RMS matching and peak limiting also affect the final result.
The crescendo is intentional
On speech, a pronounced rise toward the end may be unexpected. On percussion loops and repetitive attacks, that same rise in energy, brightness and activity can supply a compelling sense of forward motion. For that reason, v0.5.1 keeps the crescendo behavior instead of automatically flattening the ending. To compare without the separate rendering stage, set Render_strength = 0 under Custom while retaining crescendo_brightening.
Creative applications
Percussion loops → evolving gestures
Use Flowing Crescendo to reassemble attacks into short source-contiguous gestures while building energy and spectral brightness. Try a rhythmic loop with diverse timbres or a longer percussion performance. The algorithm does not perform beat tracking or tempo locking.
Voice → microphrase recomposition
Use Organic Wander to preserve small voice gestures while relocating them in time. Adjust Activity_target and phrase lengths to balance articulation, pauses and reordering.
Instrumental texture → spectral descent
Spectral Descent prioritises darker material as the output progresses, supplemented by a decreasing high-frequency contour. It does not shift musical pitch directly.
Field recording → corpus exploration
Organic Wander or Fragmented Mosaic reorders environmental fragments with different balances of natural continuity, novelty and short-grain activity.
Target_duration_s and Seed constant when switching presets or changing only Render_strength. This helps separate changes caused by phrase selection from those caused by final spectral/level rendering.Diagnostics and visualisation
- Input/output waveforms: shared amplitude scaling allows direct level comparison.
- Source-time grain map: source position versus output time, up to 500 plotted points. Diagonal stretches indicate adjacent source grains; jumps indicate recomposition.
- Match-distance trace: mismatch measured using weighted feature distance, not the old unweighted metric.
- Optional spectrograms: inspect spectral direction and compare input and output.
- Praat summary: trees, lookahead, OOB statistics, grain diversity, immediate repeats, trajectory, RMS gain, peak limit and runtime.
- Python engine report/log: microphrase count, mean phrase duration, consecutive source-hop percentage, source/target/selected activity, neighborhood suppression and chronologically held-out RF forecasting skill.
The additional v0.5 diagnostic fields are currently recorded by the Python engine; not all are displayed in the Praat visual summary panel.
Troubleshooting
| Issue | What to check |
|---|---|
| Python does not start | Verify a working Python interpreter on the PATH (Windows: python; macOS/Linux: python3) and install the required packages in that interpreter. |
| Unexpectedly quiet or pause-heavy output | Examine Activity_target and the input recording's pauses; try a higher target for more active material. Also check input and output RMS, the +12 dB gain ceiling, and whether peak limiting subsequently attenuated the result. |
| Too many abrupt jumps | Increase Min_phrase_ms / Max_phrase_ms for more source-contiguous material. Keep adequate grain overlap (e.g. a hop of about one quarter of the grain length). |
| Not enough variation | Try shorter microphrases, higher Repeat_penalty, or a different Trajectory_weight. A stationary source cannot provide novelty it does not contain. |
| Output grows louder toward its end | This is an intended part of Flowing Crescendo: the source selection, activity schedule and Render_strength work together to create a rise. Use Render_strength = 0 for a comparison, or choose Organic Wander for no forced output gain ramp. |
| Negative RF diagnostic skill | The model is not outperforming persistence under that diagnostic. It is not necessarily a rendering failure. Check the separate chronological test and assess the musical output by listening. |
| Grain map has few visible points | For long renderings, Praat displays a subsample of up to 500 selections; it is an overview rather than a point for every grain. |