pdhalfy
Distorts a phasor for reading two unequal portions of a table in equal periods.
The pdhalfy opcode is a variation on the phase distortion synthesis method of the pdhalf opcode. It is useful for distorting a phasor in order to read two unequal portions of a table in the same number of samples.
Syntax
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 distorted.
aout -- the output signal.
kShapeAmount -- the amount of distortion applied to the input. Must be between negative one and one (-1 to 1). An amount of zero means no distortion.

The pdhalfy opcode calculates a transfer function that is composed of two linear segments (see the graph). These segments meet at a "pivot point" which always lies on the same vertical axis. (In unipolar mode, the axis is x = 0.5, and for bipolar mode it is the y axis). So, pdhalfy is a variation of the pdhalf opcode that places the pivot point of the phase distortion pattern on a vertical axis instead of a horizontal axis.
The kShapeAmount parameter specifies where on the vertical axis this point falls. When kShapeAmount is zero, the pivot point is in the middle of the output range, forming a straight line for the transfer function and thus causing no change in the input signal. As kShapeAmount changes from zero (0) to negative one (-1), the pivot point downward towards the bottom of the graph. As it changes from zero (0) to positive one (1), the pivot point moves upward, producing an inverted pattern.
If the input to pdhalfy is a phasor and the output is used to index a table, the use of pdhalfy will divide the table into two segments of different sizes with each segment being mapped to half of the oscillator period. Values for kShapeAmount that are less than zero will cause less than half of the table to be read in the first half of the period of oscillation. The rest of the table will be read in the second half of the period. The reverse is true for values of kShapeAmount greater than zero. Note that the frequency of the phasor is always unchanged. Thus, this method of phase distortion can only produce higher partials in a harmonic series. It cannot produce inharmonic sidebands in the way that frequency modulation does. pdhalfy tends to have a milder quality to its distortion than pdhalf.
pdhalfy can work in either unipolar or bipolar modes. Unipolar mode is appropriate for signals like phasors that range between zero and some maximum value (selectable with ifullscale). Bipolar mode is appropriate for signals that range above and below zero by roughly equal amounts such as most audio signals. Applying pdhalfy directly to an audio signal in this way results in a crude but adjustable sort of waveshaping/distortion.
Examples
A typical example of the use of pdhalfy is
Here is an example of the pdhalfy opcode. It uses the file pdhalfy.csd.
See also
More information about phase distortion on Wikipedia: http://en.wikipedia.org/wiki/Phase_distortion_synthesis
Credits
Author: Anthony Kozar
January 2008
New in Csound version 5.08