Filters

In the early days of electronic music synthesis, prior to about 1980, the raw tones that synthesizers could produce were quite limited. Analog synths were capable of generating only a few basic waveforms, sawtooth, pulse, triangle, and sine waves being the most common. Consequently, the filter was the most potent sound-shaping tool in the sound designer’s toolbox. The mythology of filters—the legendary “fat” Moog filter, for instance—dates from this period.

Today, digital synthesizers can create tones of far greater complexity and interest. Consequently, the role of filters is somewhat reduced in importance. Nonetheless, filters remain an essential component in many types of sound design. Csound provides an almost bewildering variety of filters, which may be suitable for different purposes or different tastes.

A filter is a frequency-dependent amplifier. That is, it processes an audio signal by attenuating (reducing the amplitude of) the sound energy within some range of frequencies, while allowing the sound energy in other frequency ranges to pass through without attenuation. It may also boost the level of the sound energy in some range of frequencies.

Most sounds consist of or can be analyzed as a number of discrete sine waves, each with its own frequency and amplitude. These sine waves are called partials. A filter will typically alter the amplitudes of some of the partials in a signal, but not others. Noise signals are a special case, in that they contain (in theory) an infinite number of partials, each of which is randomly changing in amplitude. Nonetheless, noise contains sound energy at many different frequencies, so a filter can attenuate portions of the frequency spectrum of a noise signal.

The filter family also includes a specialized device called an allpass filter (implemented in Csound by the alpass opcode), which neither reduces nor boosts the sound level in any frequency range. Instead, it changes the phase relationships of various partials within the signal. Allpass filters are used in constructing reverb modules; by themselves, they have little or no effect on a tone passing through them, because the human ear is not sensitive to phase changes.


image

Filter Terminology

image Bandpass filter. A filter that attenuates both low and high frequencies, allowing frequencies that lie between the stop-bands to pass through. A bandpass filter has two stop-bands, one below the pass-band and one above it.

image Bandwidth. The width of the pass-band in a bandpass filter.

image Cutoff frequency. The frequency that defines the transition point between a filter’s pass-band and its stop-band. At the cutoff frequency, the filter should attenuate the signal by 3 dB.

image Highpass filter. A filter that attenuates low frequencies while allowing high frequencies to pass through.

image Lowpass filter. A filter that attenuates high frequencies while allowing low frequencies to pass through.

image Multimode filter. A filter with several outputs (either simultaneous or switchable). One output provides a lowpass response, another a highpass response, and so on. Typically, all of the outputs share a common cutoff frequency and resonance amount.

image Notch (band-reject) filter. A filter that attenuates a selected band of frequencies while allowing frequencies both below and above the stop-band to pass through.

image Pass-band. The range of frequencies that a filter allows to pass without attenuation.

image Pole. A term from circuit design that designates the sharpness of the rolloff slope of a filter. Each pole increases the rolloff slope by 6 dB per octave, so a two-pole filter has a rolloff slope of 12 dB per octave and a four-pole filter a rolloff slope of 24 dB per octave.

image Q. See resonance.

image Resonance. The amount by which a narrow band of frequencies lying near the cutoff frequency of a resonant filter is boosted. Resonance imparts a characteristic nasal or “peaky” quality to the tone of a filter. With high resonance settings, a filter may self-oscillate, producing something like a sine wave near the cutoff frequency.

image Rolloff slope. A measurement of the amount by which frequencies in the stop-band of a filter are attenuated. Frequencies farther into the stop-band with respect to the cutoff frequency will be attenuated further, and the amount by which a given frequency will be attenuated depends on both its distance from the cutoff frequency and the sharpness of the rolloff slope. When the rolloff slope is shallow (6 dB per octave), partials that lie further into the stop-band will still be audible, though at a lower amplitude. When the rolloff slope is steeper (24 dB per octave), partials within the stop-band will be more attenuated and may no longer be audible.

image State-variable filter. A filter whose output can vary continuously from one mode (such as lowpass) to another mode (such as highpass).

image Stop-band. The range of frequencies that is attenuated by a filter.



image

More about Q There are two ways of specifying the pass-band of a bandpass filter or the emphasized frequency region of a resonant filter: We can talk about bandwidth, or we can talk about Q. (Q is an abbreviation for “quality,” but nobody talks about “filter quality.” The abbreviation is always used.) Some Csound filters have an input for bandwidth, and some have an input for Q.

Mathematically, the two are roughly reciprocal: A higher Q setting is equivalent to a narrower bandwidth, and a lower Q is equivalent to a wider bandwidth. A Q setting of 1.5 gives the pass-band or emphasized region of the filter a width of about one octave, while a Q of 2.5 narrows this to about a perfect fifth.

Because bandwidth is usually specified in Hz rather than in a musical intervals, a filter with a fixed bandwidth will be effectively narrower (in a musical interval sense) when the center frequency is higher. If the bandwidth of a filter is 200 Hz, for instance, when the center frequency is also 200 Hz the pass-band will be an octave and a fifth wide (from 100 Hz to 300 Hz). When the center frequency of this filter is raised to 2 kHz (2,000 Hz), a bandwidth of 200 Hz will pass only a small fraction of an octave (from 1.9 kHz to 2.1 kHz). A filter with a Q parameter should behave differently. A given Q setting should produce a bandwidth of the same musical interval, irrespective of the center frequency. However, there’s no guarantee that all Csound filters will be implemented in this way. As always when using filters, you should be guided by your ears, not by the theory.


Resonant Lowpass Filters

The first filter you may want to try, if you’re familiar with analog synthesis, is moogvcf. This is a resonant lowpass filter, and it has a rather fat sound. The sound of moogladder is very similar. These filters have inputs for an audio signal and control signals governing cutoff frequency and resonance. Here is a basic instrument that uses moogvcf:


  instr 1
  iCos ftgen 0, 0, 8192, 11, 1
  iamp = 0.6
  ifreq = 50
  asig gbuzz 1, ifreq, 95, 1, 1, iCos
  ifiltrise = p3 * 0.01
  ifiltdecay = p3 * 0.99
  kfiltenv linseg 300, ifiltrise, 4500, ifiltdecay, 300
  afilt moogvcf asig, kfiltenv, 0.7
  aout linen afilt * iamp, 0.01, p3, 0.1
  outs aout, aout
  endin


image

The Wrong Trousers Diagnosing problems with Csound can be tricky, because a problem may show up in an unexpected or misleading place. When I started writing the section on filters, I decided to use gbuzz as an oscillator. When I sent the signal from gbuzz into moogvcf, I found that moogvcf was blowing up when the cutoff frequency and resonance were set even moderately high. But the problem wasn’t with moogvcf. I posted a “help” message to the Csound mailing list, complete with the source code for my instrument, and Iain McCurdy quickly spotted the problem: I was using a sine wave as the source waveform for gbuzz, but gbuzz expects to use a cosine wave. The fact that gbuzz appeared to work fine when its output was processed by other filter opcodes was an illusion. When I replaced the source waveform with a cosine, which was as simple as using GEN 11 rather than GEN 10, the apparent problem with moogvcf vanished.

The moral of the story—well, it has two morals: First, read the manual carefully. (The page for gbuzz does indeed say a cosine wave should be used.) Second, be careful about making assumptions. What appears to be a bug in a Csound opcode will sometimes turn out to be user error.


The cutoff frequency of moogvcf can be modulated at a-rate, but in my experiments the sound produced by modulating it with an audio-range sine wave oscillator was rather thin. It didn’t produce the rich, swirling sidebands that I remember when doing the equivalent patch on a Mini-moog. I got better results with moogladder. However, the cutoff frequency of moogladder can only be modulated at k-rate. If you want this type of sound, you’ll get the smoothest results by setting ksmps = 1 in the orchestra header. Here is an example instrument that gets fairly close to the classic Minimoog sound. Play it with a note about 10 seconds long.


  sr = 44100
  ksmps = 1
  nchnls = 2
  0dbfs = 1

  instr 1
  iSine ftgen 0, 0, 8192, 10, 1
  iCos ftgen 0, 0, 8192, 11, 1
  iamp = 0.4
  ifreq = 300

  asig gbuzz 1, ifreq, 75, 1, 0.9, iCos
  ifiltrise = p3 * 0.1
  ifiltdecay = p3 * 0.9
  kfiltmod oscil 800, ifreq * 2, iSine
  kfiltenv linseg 300, ifiltrise, 2500, ifiltdecay, 500
  afilt moogladder asig, kfiltenv + kfiltmod, 1

  asine oscil 0.3, 500, iSine
  abal balance afilt, asine
  aout linen abal * iamp, 0.01, p3, 0.1
  outs aout, aout
  endin

If you replace moogladder in the code above with moogvcf, without making any other changes, you’ll find that the difference in tone color is very noticeable.


image

Caution Note the use of the balance opcode in the code for producing audio sidebands with moogladder. The balance opcode is designed to tame an overly loud signal and bring it back into the normal amplitude range. An extra sine wave has been pressed into service for balance to use as a reference signal. If you neglect to use balance, this instrument will be painfully loud and might even damage your speakers. For more on balance, see the section on “Dynamics Control and Panning,” later in this chapter.


Csound’s other lowpass resonant filters include rezzy, lowpass2, lowres, and lpf18. Each has a slightly different sound, so experimenting with them is worthwhile. (For safety, continue to use the balance opcode while doing so.) lpf18 has an input for distortion amount, which can warm up the tone. The resonant peak in lowpass2 is a thin whistle, which sounds rather artificial but might be perfect for some musical situations.

These filters do not necessarily expect to see the same range of values for the resonance amount. Several of them expect a resonance amount between 0 and 1, with 1 producing self-oscillation. lowpass2, on the other hand, looks for a resonance amount between 1 and 500, while the resonance of rezzy should be between 1 and 100. For details on these filters, consult the manual.

State-Variable Filters

Csound’s statevar and svfilter opcodes are not, strictly speaking, state-variable filters. A state-variable filter in an analog synth has a single output, which can be modulated under voltage control to sweep from lowpass response to bandpass and thence to highpass. These two Csound filters are, in fact, more flexible in design: They’re multimode filters with several simultaneous outputs. svfilter has simultaneous lowpass, bandpass, and highpass outputs, while statevar has a fourth output with a notch (band-reject) response. To produce the sound of a state-variable filter, you’ll need to crossfade between two or more of the outputs. Here is an example that does such a crossfade. To hear the result, play this instrument with a note about 10 seconds long.


  instr 1
  iSine ftgen 0, 0, 8192, 10, 1
  iCos ftgen 0, 0, 8192, 11, 1
  iamp = 0.4
  ifreq = 100

  asig gbuzz 0.7, ifreq, 35, 1, 0.95, iCos
  ifiltrise = p3 * 0.01
  ifiltdecay = p3 * 0.99
  kross line 1, p3, 0
  alow, ahigh, aband svfilter asig, 100 + (3000 * kross), 60
  alow = alow * (1 - kross)
  ahigh = ahigh * kross
  afilt = alow + ahigh + (aband * 0.5)

  asine oscil 0.7, 500, iSine
  abal balance afilt, asine
  aout linen abal * iamp, 0.01, p3, 0.1
  outs aout, aout
  endin

The amplitude of the crossfading tone pulses due to phase cancellation, at a speed and intensity that varies depending on how the filter’s cutoff frequency is modulated and how the outputs are mixed.

Basic Tone-Shaping

Basic tone-shaping can be handled in Csound using the tone, atone, butterlp, and butterhp filters. These are not resonant filters. The rolloff slope of the Butterworth filters is steeper than the rolloff slope of tone and atone; the latter provide a fairly gentle sound. While butterbp and butterbr (bandpass and band-reject filters, respectively) are not, technically, resonant filters, they have a bandwidth input. A narrower bandwidth for butterbp will produce a more precise peak in the tone. Here is an example that uses butterbp:


  giCos ftgen 0, 0, 8192, 11, 1

  instr 1
  idur = p3
  iamp = p4
  icps = cpspch(p5)
  kline1 line 0.1, p3, 4.5
  kfco = p6 * kline1
  asig gbuzz iamp, icps, 75, 1, 0.9, giCos
  afilt butterbp asig, kfco, p7
  outs afilt, afilt
  endin

  </CsInstruments>
  <CsScore>

  i 1 0.0 3.0 0.5 6.00 500 300
  i 1 3.0 4.0 0.5 6.03 1000 50

The second event uses a much narrower bandwidth (p7 in the score is only 50), so you’ll hear individual overtones in the upward sweep of the filter. Notice that the amplitude of both of these events is set to greater than 1.0. This doesn’t cause clipping, because butterbp reduces the amplitude of the signal passing through it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.97.187