ar phaser1 asig, kfreq, iord, kfeedback[, iskip] ar phaser2 asig, kfreq, kq, iord, imode, ksep, kfeedback
An implementation of iord number of first-order (phaser1) or second-order (phaser2) allpass filters in series.
iord – the number of allpass stages in series. For phaser1, these are first-order filters, and iord can range from 1 to 4999. For phaser2, these are second-order filters, and iord can range from 1 to 2499. With higher orders, the computation time increases.
iskip – used to control initial disposition of internal data space. Since filtering incorporates a feedback loop of previous output, the initial status of the storage space used is significant. A zero value will clear the space; a non-zero value will allow previous information to remain. The default value is 0.
imode – used in calculation of notch frequencies.
kfreq – frequency (in Hz) of the filter(s). For phaser1, this is the frequency at which each filter in the series shifts its input by 90 degrees. For phaser2, this is the center frequency of the notch of the first allpass filter in the series. This frequency is used as the base frequency from which the frequencies of the other notches are derived.
kq – Q of each notch. Higher Q values result in narrow notches. A Q between 0.5 and 1 results in the strongest "phasing" effect, but higher Q values can be used for special effects.
kfeedback – amount of the output which is fed back into the input of the allpass chain. With larger amounts of feedback, more prominent notches appear in the spectrum of the output. kfeedback must be between -1 and +1. for stability.
ksep - scaling factor used, in conjunction with imode, to determine the frequencies of the additional notches in the output spectrum.
phaser1 implements iord number of first-order allpass sections, serially connected, all sharing the same coefficient. Each allpass section can be represented by the following difference equation:
y(n) = C * x(n) + x(n-1) - C * y(n-1)
where x(n) is the input, x(n-1) is the previous input, y(n) is the output, y(n-1) is the previous output, and C is a coefficient which is calculated from the value of kfreq, using the bilinear z-transform.
By slowly varying kfreq, and mixing the output of the allpass chain with the input, the classic "phase shifter" effect is created, with notches moving up and down in frequency. This works best with iord between 4 and 16. When the input to the allpass chain is mixed with the output, 1 notch is generated for every 2 allpass stages, so that with iord = 6, there will be 3 notches in the output. With higher values for iord, modulating kfreq will result in a form of nonlinear pitch modulation.
phaser2 implements iord number of second-order allpass sections, connected in series. The use of second-order allpass sections allows for the precise placement of the frequency, width, and depth of notches in the frequency spectrum. iord is used to directly determine the number of notches in the spectrum; e.g. for iord = 6, there will be 6 notches in the output spectrum.
There are two possible modes for determining the notch frequencies. When imode = 1, the notch frequencies are determined the following function:frequency of notch N = kbf + (ksep * kbf * N-1)
For example, with imode = 1 and ksep = 1, the notches will be in harmonic relationship with the notch frequency determined by kfreq (i.e. if there are 8 notches, with the first at 100 Hz, the next notches will be at 200, 300, 400, 500, 600, 700, and 800 Hz). This is useful for generating a "comb filtering" effect, with the number of notches determined by iord. Different values of ksep allow for inharmonic notch frequencies and other special effects. ksep can be swept to create an expansion or contraction of the notch frequencies. A useful visual analogy for the effect of sweeping ksep would be the bellows of an accordion as it is being played - the notches will be seperated, then compressed together, as ksep changes.
When imode = 2, the subsequent notches are powers of the input parameter ksep times the initial notch frequency specified by kfreq. This can be used to set the notch frequencies to octaves and other musical intervals. For example, the following lines will generate 8 notches in the output spectrum, with the notches spaced at octaves of kfreq:
aphs phaser2 ain, kfreq, 0.5, 8, 2, 2, 0 aout = ain + aphs
When imode = 2, the value of ksep must be greater than 0. ksep can be swept to create a compression and expansion of notch frequencies (with more dramatic effects than when imode = 1).
; Orchestra for demonstration of phaser1 and phaser2 sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 ; demonstration of phase shifting abilities of phaser1. ; Input mixed with output of phaser1 to generate notches. ; Shows the effects of different iorder values on the sound idur = p3 iamp = p4 * .05 iorder = p5 ; number of 1st-order stages in phaser1 network. ; Divide iorder by 2 to get the number of notches. ifreq = p6 ; frequency of modulation of phaser1 ifeed = p7 ; amount of feedback for phaser1 kamp linseg 0, .2, iamp, idur - .2, iamp, .2, 0 iharms = (sr*.4) / 100 asig gbuzz 1, 100, iharms, 1, .95, 2 ; "Sawtooth" waveform modulation oscillator for phaser1 ugen. kfreq oscili 5500, ifreq, 1 kmod = kfreq + 5600 aphs phaser1 asig, kmod, iorder, ifeed out (asig + aphs) * iamp endin instr 2 ; demonstration of phase shifting abilities of phaser2. ; Input mixed with output of phaser2 to generate notches. ; Demonstrates the interaction of imode and ksep. idur = p3 iamp = p4 * .04 iorder = p5 ; number of 2nd-order stages in phaser2 network ifreq = p6 ; not used ifeed = p7 ; amount of feedback for phaser2 imode = p8 ; mode for frequency scaling isep = p9 ; used with imode to determine notch frequencies kamp linseg 0, .2, iamp, idur - .2, iamp, .2, 0 iharms = (sr*.4) / 100 asig gbuzz 1, 100, iharms, 1, .95, 2 ; "Sawtooth" waveform exponentially decaying function, to control notch frequencies kline expseg 1, idur, .005 aphs phaser2 asig, kline * 2000, .5, iorder, imode, isep, ifeed out (asig + aphs) * iamp endin ; score file for above f1 0 16384 9 .5 -1 0 ; inverted half-sine, used for modulating phaser1 frequency f2 0 8192 9 1 1 .25 ; cosine wave for gbuzz ; phaser1 i1 0 5 7000 4 .2 .9 i1 6 5 7000 6 .2 .9 i1 12 5 7000 8 .2 .9 i1 18 5 7000 16 .2 .9 i1 24 5 7000 32 .2 .9 i1 30 5 7000 64 .2 .9 ; phaser2, imode=1 i2 37 10 7000 8 .2 .9 1 .33 i2 48 10 7000 8 .2 .9 1 2 ; phaser2, imode=2 i2 60 10 7000 8 .2 .9 2 .33 i2 72 10 7000 8 .2 .9 2 2 e
A general description of the differences between flanging and phasing can be found in Hartmann . An early implementation of first-order allpass filters connected in series can be found in Beigel , where the bilinear z-transform is used for determining the phase shift frequency of each stage. Cronin  presents a similar implementation for a four-stage phase shifting network. Chamberlin  and Smith  both discuss using second-order allpass sections for greater control over notch depth, width, and frequency.
New in Csound version 4.0