Wavefolder (Foldback) — User Guide
Memoryless nonlinear wavefolding with input/output gain, repeated folds, optional asymmetric thresholds, continuous soft saturation, DC removal, and attenuation-only peak protection.
What this does
The script copies one selected Sound object and applies a static nonlinear transfer function. Samples that cross a fold threshold are reflected back with a slope controlled by Fold depth. The same fold can be reapplied for multiple iterations. Optional smoothing adds a continuous saturating curve after the folding stage.
The processor is sample-domain and memoryless apart from the file-level DC-removal and peak-protection stages. It does not analyse pitch or spectrum, and it does not model a specific analog circuit.
Quick start
- Select exactly one Sound object in Praat.
- Run
Wavefolder_Foldback.praat. - Choose a preset, or choose Custom (use settings below) to use the entered DSP values.
- Choose whether to remove DC, draw the visualization, and play the result.
- Click OK. The processed Sound remains selected.
Processing pipeline
1. Gain and thresholds
The input Sound is copied, then multiplied by inputGain.
2. Folding
For each fold iteration, the current sample value is transformed once.
The positive and negative branches in bipolar mode are mutually exclusive. A sample folded across zero is therefore not folded a second time by the opposite branch within the same iteration.
Fold depth sets the slope beyond a threshold. At 1.0 the excess is mirrored with slope −1; values below 1 reduce the return slope. The code does not clamp this field, so values outside the labelled 0–1 range are possible in Custom mode.
3. Continuous smoothing
If Smoothing > 0, the script applies a continuous odd-symmetric saturation after all fold iterations:
For Smoothing = 0.5, s = 0 and the stage becomes x / (1 + |x|). A non-positive Smoothing value disables this stage.
4. Output conditioning
- Multiply by
outputGain. - If DC offset removal is enabled, run Praat's
Subtract mean. - Measure the final positive and negative extrema with Sinc70 interpolation.
- If the absolute peak is greater than 0.99, attenuate the complete Sound so that the peak becomes 0.99. If the peak is 0.99 or lower, no normalization is applied.
Presets
There are nine menu choices: Custom plus eight fixed presets. Values shown below are the exact assignments made by the script.
| Preset | Threshold | In gain | Depth | Asym. | Iterations | Bipolar | Smoothing | Out gain |
|---|---|---|---|---|---|---|---|---|
| Custom | form | form | form | form | form | form | form | form |
| Soft Fold (Subtle) | 0.70 | +3 dB | 0.60 | 0.00 | 1 | yes | 0.30 | −3 dB |
| Hard Fold (Aggressive) | 0.30 | +12 dB | 1.00 | 0.00 | 1 | yes | 0.00 | −6 dB |
| Bipolar Fold | 0.50 | +6 dB | 1.00 | 0.00 | 2 | yes | 0.10 | −4 dB |
| Asymmetric Fold | 0.60 | +8 dB | 0.85 | +0.60 | 1 | yes | 0.15 | −5 dB |
| Multi-Fold (Harmonics) | 0.40 | +10 dB | 1.00 | 0.00 | 3 | yes | 0.00 | −8 dB |
| Tape Saturation Style | 0.65 | +4 dB | 0.50 | +0.20 | 1 | yes | 0.50 | −2 dB |
| Digital Crush | 0.25 | +15 dB | 1.00 | 0.00 | 2 | no | 0.00 | −10 dB |
| Oscillating Fold | 0.55 | +7 dB | 0.90 | −0.30 | 2 | yes | 0.20 | −5 dB |
Parameters
| GUI field | Type | Default | Actual behavior |
|---|---|---|---|
| Preset | optionmenu | Custom | Selects Custom or one of eight fixed parameter sets. |
| Threshold_(0-1) | real | 0.5 | Base fold threshold. The 0–1 text is a label, not a code clamp. |
| Input_gain_dB | real | 0.0 | Gain before folding. |
| Fold_depth_(0-1) | real | 1.0 | Return slope magnitude beyond the threshold. The 0–1 label is not enforced. |
| Asymmetry_(-1_to_1) | real | 0.0 | Changes positive/negative thresholds only when Bipolar folding is enabled. The labelled range is not clamped. |
| Fold_iterations | natural | 1 | Number of times the same fold stage is reapplied; Praat's natural field requires a positive integer. |
| Bipolar_folding | boolean | yes | Yes = separate positive/negative thresholds; No = shared symmetric threshold. |
| Smoothing_(0-1) | real | 0.0 | Controls the post-fold continuous saturation. Values ≤ 0 disable it; the 0–1 label is not clamped. |
| Output_gain_dB | real | 0.0 | Gain after folding and smoothing, before DC removal and peak protection. |
| DC_offset_removal | boolean | yes | Runs Subtract mean after output gain. |
| Draw_visualization | boolean | yes | Draws the Picture-window diagnostic page. |
| Play_result | boolean | yes | Plays the processed Sound after rendering. |
Visualization
When enabled, the script draws a suite-style Picture page containing:
- the complete original waveform;
- the complete processed waveform;
- separate original and processed zooms over the first
min(20 ms, duration); - a static input/output transfer curve over input values −1.2 to +1.2, with threshold markers;
- a parameter panel and a three-line summary strip.
The transfer curve includes input gain → fold iterations → smoothing → output gain. It deliberately excludes DC removal and the final peak limiter because those depend on the complete file rather than on an individual input value. Its vertical range is expanded when needed instead of clipping the displayed transfer curve.
Outputs and limits
- Object name:
<source>_fold_<presetName>, where presetName isCustom,SoftFold,HardFold,Bipolar,Asymmetric,MultiFold,TapeSat,DigitalCrush, orOscillating. - Duration: unchanged.
- Sample rate: unchanged.
- Channels: unchanged; Formula operations are applied to the copied Sound without downmixing or channel remapping.
- Final level: only peaks above 0.99 are attenuated to 0.99. Quieter outputs are not boosted.