Wavefolding and Other Piecewise Symmetry Manipulations

Download the Software

You can download the wavefolder objects and demo files here:


Source code for the wavefolder~, wavestretcher~ and wavecutter~ objects is included in the ekext library for Pure Data:


Note that this technique works well for bass frequencies, but at higher registers there is a significant degree of aliasing. One (crude and expensive) solution to this is to run Pd at high sample rates (e.g 192 KHz) but this is conceptually ugly. I am currently researching oversampling techniques to overcome this. However, in its current form it is particularly good for creating bass sounds.

Wavefolding - an Introduction

Wavefolding takes a ramp signal from 0 to 1 and converts it into an adjustable symmetry waveform. This is based on a threshold (also from 0 to 1) where any portion of the ramp that falls below the threshold becomes the rising part of the waveform, and anything above the threshold becomes the falling part.

(this should read 0.28, not -28.)

At the extremes of the threshold setting the wave becomes either a ramp waveform (the output of phasor~) or a sawtooth (inverted phasor~ output). Since the phasor~ output is a signal from 0 to 1, a bipolar switch is used to convert the output (green) into a waveform from -1 to 1 (purple) so that it is a standard-range audio signal, but it may be disabled if the waveform is used to add a signal to a baseline value (figs. 1 and 2).

Audio-Rate Symmetry Modulation

The symmetry can be controlled by any audio signal. Using a sine wave to modulate the waveshape, much like traditional FM synthesis the relationship between the fundamental frequency and the modulator, the carrier-to-modulator ratio (CMR) determines the harmonic or inharmonic components of the resulting waveform, so for example a CMR of 4 results in a steady, unchanging timbre and a CMR of 3.8523 results in an inharmonic timbre. By setting the frequency of the modulation source to a value slightly above or below an integer relationship with the fundamental frequency, the timbre-evolution of the waveform over time can be finely modulated. If the baseline shape is 0 (triangle waveform) then there is a modulation that sweeps the timbre from bright-to-dark and back again. With the baseline offset from the triangle wave the timbre sweeps from bright-to-dark, or dark-to-bright (fig. 3) depending on which direction away from triangle the baseline shape is set to, and whether the modulator is slightly below or slightly above an integer ratio with the fundamental frequency of the carrier (the frequency of the phasor~ used to drive the wavefolder algorithm). If the modulator amplitude +/- the baseline shape is >1 or <-1, portions of the waveform are clipped to hard copies of ramp or sawtooth (fig. 4).

Pulse-Threshold Modulation

Using a similar technique to traditional pulse-width modulation (PWM), the wavefolded signal has another threshold applied to it so that any signal above or below the threshold is converted into +1 and -1 values. If no audio modulation is applied to the waveshape then the result is similar to PWM, but with the modulated waveshape with a non-integer CMR there is a complex evolving timbre generated (fig. 5). As with all of the techniques described here, the control signal is at audio rate, and any modulator such as a low-frequency oscillator (LFO) or any other audio signal may be used to modulate the threshold.

Even without modulating the pulse-threshold, the evolving timbre created using a non-integer CMR generates timbres that share the complexity of the wavefolded signal, but with more extreme jumps in timbre as peaks in the modulated waveshape cross the threshold.

Note that in the graph above, the Pulse-Threshold Modulated output (PTM) is scaled to 80% for a better graphic representation.


The wavestretcher~ takes the principle of piecewise threshold-based manipulation of a waveform and develops a corner in the waveform at the threshold value above zero, and below the negative value of the threshold. At negative values of the stretch/ squash factor, the portion of the waveform below the threshold becomes shallower, while the portion above is attenuated to reach the extremities of the -1 to +1 range (fig. 6). At positive values of this parameter, the wavestretcher~ does the opposite, that is to say that the segment below the threshold is made steeper while the portion above is shallower (fig. 7).

The waveform becomes more pulse-train like, or it progresses towards a squared-off waveform. The settings are at audio rate and can be smoothly modulated with audio signals. When used with the wavefolder~, a further level of complexity may be imposed upon the timbre and its evolution over time.

The Wavecutter~

The wavecutter~ object provides two mathematically simple functions to silence portions of the waveform below and above the threshold values (fig.8) and to transition the negative half of the waveform towards positive values according to the value of a second parameter (fig. 9).

While the former develops more PWM-like wave- forms from any input (preserving the shape only of the geometry outside of the threshold range) the inversion of the negative can be used to transition to a waveform up one octave from the original pitch when used with more horizontally symmetrical waveforms.

With the threshold value set to 0, the inversion happens without any silencing of waveform sections, so that with a symmetrical waveform the total inversion is equivalent to an octave transposition, (fig. 10) although this is less pronounced with more complex waveforms. The inversion modulation only works with bipolar waveforms, and at its extreme develops only positive signal values, but it is possible to normalize and DC-offset the signal to compensate for this.

Synchronization of Timbre Sweeps

One implementation of an instrument featuring wavefolder~ and wavestretcher~ objects is detailed in the next-but-one panel. It is clear that subtle offsets away from an integer CMR result in rhythmic effects, and so an obvious thing to do is to synchronise these effects to a pulse. Commonly used formulae for establishing a frequency based on tempo are used to add a linear offset to the modulator frequency such that, for the example of a single-note pulse:

f = 1 / (60 / ppm)

This is a very common formula in computer music, where PPM is pulses-per-minute. The frequency offset f added to or subtracted from the modulator frequency results in timbre-sweeps synchronised to tempo. Further manipulation of these values allows more complex rhythmic relationships to be established. The tcalc.pd mechanism facilitates these calculations. The tcalc mechanism (fig. 11) generates duration values for an arbitrary number of pulses of a specified subdivision of the beat. This can be easily converted into a frequency value as shown. Timing is in ms, so the calculation becomes 1000/duration.

With this value for duration, it is also possible to synchronize LFO frequencies to the same rhythmic pulse. Since the wave transformations are all driven by the phasor~ object, the phase of both the waveform and the modulator (which could be an osc~ object, or a phasor~ driving a cos~ object) can be set at the start of a note-event, so that rhythmic synchronization with a master clock is accurately implemented. Shown above is the frequency offset and duration for 7 1/5ths of a quarter-note at 132 beats-per-minute (BPM).


This is one possible implementation (click to enlarge) using both wavefolder~ and wavestretcher~ objects. It is possible to freely adjust the CMR, or to set the CMR to an integer + offset so that it is synchronized to a pulse if sync_sweeps is enabled. An LFO, which itself may be an adjustable-symmetry wave, may be used to control the wavestretcher~ parameters and the pulse-threshold modulation.

Setting the rhythmic values and tempo using the tcalc objects, it is possible to synchronise the LFO to this value, and afterwards to set the timbral modulation from wavefolding to a different rhythmic value to obtain more complex rhythmic relationships between the modulations. If the baseline shape parameter is offset from 0, the timbre- sweeps from bright-to-dark or vice-versa may be reversed using the direction control. A complete patch-storage system is implemented, but the tempo and note-length values per-patch may be disabled, so that the patch selection does not override them, or they may be set externally.


For a complete implementation of all three objects, Wavecutter_FX~ adds another LFO which may or may not be synchronized to the previous machine, and a separate set of functions for using the wavecutter~ object.

Inspiration and Credits

The inspiration for these techniques comes from investigations into common approaches to modular analog synthesis design. I am currently working on an implementation of the wavefolder~ using analog electronics, but based on the same algorithm as the software object. Circuits equivalent to the algorithmic components of the code for wavefolder~ have been identified, and a prototype is in development.

I would like to thank the University of the Arts London for making it possible for me to attend the ICMC in Utrecht, September 2016, to demonstrate this set of synthesis techniques.