Wrapping

Similar to hard clip in the use of a processing threshold, but in this case we wrap the signal when it exceeds the threshold. Wrapping means that any part of the signal that exceeds the positive wrapping threshold is wrapped around to the negative side (creating a sharp discontinuity at the wrap point), and vice versa. The signal is unmodified below the clipping threshold. This technique has no direct eqivalent in the analog processing domain, but we can use it to create purely digital distortion effects.

Signal flow

Audio signal graphs

A Sine wave
Wrapping

Sound examples


440 Hz Sine wave, clean

440 Hz Sine wave, wrapped at a threshold of 0.9

440 Hz Sine wave, wrapped at a threshold of 0.6

440 Hz Sine wave, wrapped at a threshold of 0.3

Csound code

The following Csound code generates a sine wave and processes it by wrapping. The wrapping threshold is set as a fraction of full level, so a threshold of 0.5 wraps at 50% of full signal level. The output amplitude is adjusted with the use of makeup gain, so the output amplitude shouuld equal the input amplitude regardless of clipping threshold.

;***************************************************
; Wrapping 
;***************************************************
	instr	1

	iamp		= ampdbfs(p4)	; Amp in -dB
	icps		= p5		; Frequency for the tone generator
	iWrap		= p6		; Wrapping threshold 
					; (as fraction of full level, e.g. 0.5 clips at 50%)
	iMakeupGain	= 1/iClip	; Make up for gain loss in clipping stage

; audio generator
	a1		oscili	1, icps, giSine

; hard clip
	a1		wrap a1, -iWrap, iWrap     ; wrap signal at threshold

; output gain
	a1		= a1*iamp*iMakeupGain

; audio out
	out		a1

	endin
;***************************************************