pdclip
Prev | Orchestra Opcodes and Operators | Next

## pdclip

pdclip — Performs linear clipping on an audio signal or a phasor.

## Description

The pdclip opcode allows a percentage of the input range of a signal to be clipped to fullscale. It is similar to simply multiplying the signal and limiting the range of the result, but pdclip allows you to think about how much of the signal range is being distorted instead of the scalar factor and has a offset parameter for assymetric clipping of the signal range. pdclip is also useful for remapping phasors for phase distortion synthesis.

## Syntax

    aout pdclip ain, kWidth, kCenter [, ibipolar [, ifullscale]]

## Initialization

ibipolar -- an optional parameter specifying either unipolar (0) or bipolar (1) mode. Defaults to unipolar mode.

ifullscale -- an optional parameter specifying the range of input and output values. The maximum will be ifullscale. The minimum depends on the mode of operation: zero for unipolar or -ifullscale for bipolar. Defaults to 1.0 -- you should set this parameter to the maximum expected input value.

## Performance

ain -- the input signal to be clipped.

aout -- the output signal.

kWidth -- the percentage of the signal range that is clipped (must be between 0 and 1).

kCenter -- an offset for shifting the unclipped window of the signal higher or lower in the range (essentially a DC offset). Values should be in the range [-1, 1] with a value of zero representing no shift (regardless of whether bipolar or unipolar mode is used).

The pdclip opcode performs linear clipping on the input signal ain. kWidth specifies the percentage of the signal range that is clipped. The rest of the input range is mapped linearly from zero to ifullscale in unipolar mode and from -ifullscale to ifullscale in bipolar mode. When kCenter is zero, equal amounts of the top and bottom of the signal range are clipped. A negative value shifts the unclipped range more towards the bottom of the input range and a positive value shifts it more towards the top. ibipolar should be 1 for bipolar operation and 0 for unipolar mode. The default is unipolar mode (ibipolar = 0). ifullscale sets the maximum amplitude of the input and output signals (defaults to 1.0).

This amounts to waveshaping the input with the following transfer function (normalized to ifullscale=1.0 in bipolar mode):

1| _______ x-axis is input range, y-axis is output
| /
| / width of clipped region is 2*kWidth
-1 |/ 1 width of unclipped region is 2*(1 - kWidth)
-------------------- kCenter shifts the unclipped region
/| left or right (up to kWidth)
/ |
/ |
------ |-1

Bipolar mode can be used for direct, linear distortion of an audio signal. Alternatively, unipolar mode is useful for modifying the output of a phasor before it is used to index a function table, effectively making this a phase distortion technique.

## See Also

pdhalf, pdhalfy, limit, clip, distort1

## Examples

Here is an example of the pdclip opcode. It uses the file pdclip.csd.

Example 554. Example of the pdclip opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o abs.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; test instrument for pdclip opcode
    instr 3

    	idur		= p3
    	iamp		= p4
    	ifreq		= p5
    	ifn			= p6

    	kenv		linseg		0, .05, 1.0, idur - .1, 1.0, .05, 0
    	aosc		oscil		1.0, ifreq, ifn

    	kmod		expseg		0.00001, idur, 1.0
    	aout		pdclip		aosc, kmod, 0.0, 1.0

    				out			kenv*aout*iamp
    endin

    </CsInstruments>
    <CsScore>
    f1 0 16385 10 1
    f2 0 16385 10 1 .5 .3333 .25 .5

    ; pdclipped sine wave
    i3 0 3 15000 440 1
    i3 + 3 15000 330 1
    i3 + 3 15000 220 1
    s

    ; pdclipped composite wave
    i3 0 3 15000 440 2
    i3 + 3 15000 330 2
    i3 + 3 15000 220 2
    e
    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: Anthony Kozar
January 2008

New in Csound version 5.08

Prev | Up | Next
pcount | Home | pdhalf