resonr — A bandpass filter with variable frequency response.
Implementations of a second-order, two-pole two-zero bandpass filter with variable frequency response.
The optional initialization variables for resonr are identical to the i-time variables for reson.
iscl (optional, default=0) -- coded scaling factor for resonators. A value of 1 signifies a peak response factor of 1, i.e. all frequencies other than kcf are attenuated in accordance with the (normalized) response curve. A value of 2 raises the response factor so that its overall RMS value equals 1. This intended equalization of input and output power assumes all frequencies are physically present; hence it is most applicable to white noise. A zero value signifies no scaling of the signal, leaving that to some later adjustment (see balance). The default value is 0.
iskip (optional, default=0) -- 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.
asig -- input signal to be filtered
kcf -- cutoff or resonant frequency of the filter, measured in Hz
kbw -- bandwidth of the filter (the Hz difference between the upper and lower half-power points)
resonr and resonz are variations of the classic two-pole bandpass resonator (reson). Both filters have two zeroes in their transfer functions, in addition to the two poles. resonz has its zeroes located at z = 1 and z = -1. resonr has its zeroes located at +sqrt(R) and -sqrt(R), where R is the radius of the poles in the complex z-plane. The addition of zeroes to resonr and resonz results in the improved selectivity of the magnitude response of these filters at cutoff frequencies close to 0, at the expense of less selectivity of frequencies above the cutoff peak.
resonr and resonz are very close to constant-gain as the center frequency is swept, resulting in a more efficient control of the magnitude response than with traditional two-pole resonators such as reson.
resonr and resonz produce a sound that is considerably different from reson, especially for lower center frequencies; trial and error is the best way of determining which resonator is best suited for a particular application.
Here is an example of the resonr and resonz opcodes. It uses the file resonr.csd.
Example 395. Example of the resonr and resonz opcodes.
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 No messages -odac -iadc -d ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o resonr.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> /* Written by Sean Costello */ ; Orchestra file for resonant filter sweep of a sawtooth-like waveform. ; The outputs of reson, resonr, and resonz are scaled by coefficients ; specified in the score, so that each filter can be heard on its own ; from the same instrument. sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 idur = p3 ibegfreq = p4 ; beginning of sweep frequency iendfreq = p5 ; ending of sweep frequency ibw = p6 ; bandwidth of filters in Hz ifreq = p7 ; frequency of gbuzz that is to be filtered iamp = p8 ; amplitude to scale output by ires = p9 ; coefficient to scale amount of reson in output iresr = p10 ; coefficient to scale amount of resonr in output iresz = p11 ; coefficient to scale amount of resonz in output ; Frequency envelope for reson cutoff kfreq linseg ibegfreq, idur * .5, iendfreq, idur * .5, ibegfreq ; Amplitude envelope to prevent clicking kenv linseg 0, .1, iamp, idur - .2, iamp, .1, 0 ; Number of harmonics for gbuzz scaled to avoid aliasing iharms = (sr*.4)/ifreq asig gbuzz 1, ifreq, iharms, 1, .9, 1 ; "Sawtooth" waveform ain = kenv * asig ; output scaled by amp envelope ares reson ain, kfreq, ibw, 1 aresr resonr ain, kfreq, ibw, 1 aresz resonz ain, kfreq, ibw, 1 out ares * ires + aresr * iresr + aresz * iresz endin </CsInstruments> <CsScore> /* Written by Sean Costello */ f1 0 8192 9 1 1 .25 ; cosine table for gbuzz generator i1 0 10 1 3000 200 100 4000 1 0 0 ; reson output with bw = 200 i1 10 10 1 3000 200 100 4000 0 1 0 ; resonr output with bw = 200 i1 20 10 1 3000 200 100 4000 0 0 1 ; resonz output with bw = 200 i1 30 10 1 3000 50 200 8000 1 0 0 ; reson output with bw = 50 i1 40 10 1 3000 50 200 8000 0 1 0 ; resonr output with bw = 50 i1 50 10 1 3000 50 200 8000 0 0 1 ; resonz output with bw = 50 e </CsScore> </CsoundSynthesizer>
resonr and resonz were originally described in an article by Julius O. Smith and James B. Angell.1 Smith and Angell recommended the resonz form (zeros at +1 and -1) when computational efficiency was the main concern, as it has one less multiply per sample, while resonr (zeroes at + and - the square root of the pole radius R) was recommended for situations when a perfectly constant-gain center peak was required.
Ken Steiglitz, in a later article 2, demonstrated that resonz had constant gain at the true peak of the filter, as opposed to resonr, which displayed constant gain at the pole angle. Steiglitz also recommended resonz for its sharper notches in the gain curve at zero and Nyquist frequency. Steiglitz's recent book 3 features a thorough technical discussion of reson and resonz, while Dodge and Jerse's textbook 4 illustrates the differences in the response curves of reson and resonz.
Smith, Julius O. and Angell, James B., "A Constant-Gain Resonator Tuned by a Single Coefficient," Computer Music Journal, vol. 6, no. 4, pp. 36-39, Winter 1982.
Steiglitz, Ken, "A Note on Constant-Gain Digital Resonators," Computer Music Journal, vol. 18, no. 4, pp. 8-10, Winter 1994.
Ken Steiglitz, A Digital Signal Processing Primer, with Applications to Digital Audio and Computer Music. Addison-Wesley Publishing Company, Menlo Park, CA, 1996.
Dodge, Charles and Jerse, Thomas A., Computer Music: Synthesis, Composition, and Performance. New York: Schirmer Books, 1997, 2nd edition, pp. 211-214.