FILTER [ cutFrequency ] [ , [ lowPass ] [ , [ bandPass ] [ , [ highPass ] [ , resonance ] ] ] ]
State management. Define filter parameters that may be used by sounds generated with PLAY and SOUND.
FILTER sets one or more parameters that define the state of the SID filter. The SID filter settings may be applied to any/all/none of the
voices by using the 'X' parameter of PLAY. If a voice is using the SID filter, it will affect not only "notes" generated by PLAY but also any "effects" generated by SOUND.Be aware that BASIC never initializes the parameters
cutFrequency nor resonance. All three filter channels (lowPass, bandPass, and highPass) are disabled (only) by the BASIC reset routine. In particular, RUN does not (re)set any of the parameters so a program using PLAY or SOUND should include a FILTER statement if filtering is needed. If filtering is not needed, a program using PLAY or SOUND should at least use the X parameter of PLAY to be sure none of the voices are being routed through the SID filter. Otherwise the previous (perhaps "random") values will be used causing undesired sound/music. On a related note, BASIC provides no way to determine any of the current FILTER parameters. If you need to read any, you will have to PEEK one or more secret variables and (most likely) do some math.The
cutFrequency is a machine-specific value that determines the location of the "knee" in a filter graph. I won't try to explain the details of filtering here, but it is the key frequency used in the three different filter modes (discussed below). Unfortunately, the cutFrequency does not use the same scale as frequency that is used by SOUND (or generated internally by PLAY). A more serious issue is the technical specifications for the SID chip (6581 NMOS and 8580 HMOS-II versions, written by Commodore Semiconductor Group, hereafter CSG) do not provide a precise forumula, but instead makes the vague statement
The C64 and C128 Programmer's Reference Guides both make a similar vague claim, that the cut-off frequency ranges from approximately 30Hz to 12kHz; however, no known CBM machine using a SID chip actually uses capacitors of 6800 pF! For example, the schematics for the C128 specify 470 pF. (Of course this does not mean a C128 will actually have 470 pF capacitors connected to SID). To make things more convoluted, the effects of the SID filter also depend on internal resistances which vary quite a bit between production runs.
As you might guess from the above, the effects of the FILTER are not easy to precisely determine. Thus, several programs relying on the SID filter provide a way for the user to adjust the filter settings in some way. Anyway, the "key frequency" (measured in Hertz) is theoretically:
Hertz = 30 +
cutFrequency * 5.86The filter provides three modes of operation (actually channels). Because each channel is independent, multiple modes may be selected at the same time. Each mode (filter channel) is either enabled or not by a value of 1 or 0 (respectively) for each of the three modes. Although these act as boolean flags, the 0 / 1 requirements are incompatible with many BASIC operators and functions which return -1 for true. You can use the expression
value AND 1 to make a legal value for any of the mode parameters.The
lowPass parameter selectively enables low-pass filtering. In this mode, frequencies of a voice much below the cut-off frequency will pass through unchanged (100% amplitude). There will be a moderate amount of reduction in amplitude for frequencies near the cut-off value (in theory, 70.7% will pass at the cut-off frequency when resonance is zero). As freqencies get higher, the the amplitude will be progressively diminished. CSG states the fall-off is 12 dB/octave which is approximately 40 dB/decade or, as I like to think of it, 1/4 per double-f. For example if the amplitude was 50% at a frequency twice the cut-off (2*f), then it would(should) be 50%/4 = 12.5% when the frequency is twice greater (4*f). Math note: 10 * Log_{10}(4^{2}) = 12.04 db/octave = 40 dB/decade. In summary, low frequencies pass and high frequencies are reduced.The
bandPass parameter selectively enables band-pass filtering. In this mode, frequencies of a voice which are either below or above the cut-off frequency will be progressively diminished in amplitude (the greater the "distance" the more the reduction). The maximum amount of amplitude passes at the cut-off frequency, but it is not 100%; it is (in theory) 70.7% when the resonance is zero. CSG states the fall-off is 6 dB/octave which is approximately 20 dB/decade or, as I like to think of it, 1/2 per double-f (or half-f). For example if the amplitude was 50% at a frequency twice the cut-off (2*f), then it would(should) be 50%/2 = 25% when the frequency is twice greater (4*f). Math note: 10 * Log_{10}(2^{2}) = 6.02 db/octave = 20 dB/decade. In summary, mid-band frequencies pass (mostly) unchanged while high and low frequencies are reduced.An inverted form of the band-pass filter, called a notch-reject filter, is possible by enabling both the
lowPass and highPass filters. In this case, frequencies of a voice substantiantialy far from the cut-off frequency will not be affected (100% amplitude). As frequencies approach the cut-off, the voice starts being reduced in amplitude. The greatest reduction in amplitude occurs at the cut-off frequency; in theory, 70.7% of maximum when resonance is zero. In summary, mid-band frequencies are reduced and others are passed.The
highPass parameter selecively enables high-pass filtering. In this mode, frequencies of a voice much above the cut-off frequency will pass through unchanged (100% amplitude). There will be a moderate amount of reduction in amplitude for frequencies near the cut-off value (in theory, 70.7% will pass at the cut-off frequency when resonance is zero). As freqencies get lower, the amplitude will be progressively diminished. CSG states the fall-off is 12 dB/octave which is approximately 40 dB/decade or, as I like to think of it, 1/4 per half-f. For example if the amplitude was 50% at a frequency half the cut-off (1/2*f), then it would(should) be 50%/4 = 12.5% when the frequency is half of that (1/4*f). Math note: 10 * Log_{10}(4^{2}) = 12.04 db/octave = 40 dB/decade. In summary, high frequencies pass and low frequencies are reduced.The final parameter,
resonance, controls the amount of feedback a filter receives from itself. A zero value gives "standard" filter behavior. Greater values provide more feedback. This results in less reduction than normal for frequencies near the cut-off. Less reduction means more "virtual" gain; thus it has been described as a "peaking" effect. Anyway, it makes the effect of the filter mode(s) more obvious for frequencies near the cut-off. If you thought the cut-off frequency has poor documentation / consistancy, then "you ain't seen nothin' yet" because CSG doesn't give any technical description of resonance, they simply say it ranges from 0 to 15 (with zero being equivalent to 70.7%).In several of the previous paragraphs, vague terms like "frequencies near the cut-off" were used. Disregarding the variance of SID chips and their associated capacitors for a moment, this is actually well-defined. Using the
lowPass mode as an example, once a frequency is double (2*f) the cut-off, the reduction in power proceeds at a near linear rate (when using a log-2 [octave] scale). For frequencies less than half (1/2*f) the cut-off, their is virtually no reduction in power. Frequency values between half and double the cut-off frequency (0.5 ~ 2.0 f), or equivalently within one octave of the cut-off frequency, are considered "near". In this region, the reduction in power is not linear. The reduction in amplitude is approximately inverse-quadratic when using a log-2 [octave] scale. Amplitude is proportional to the square-root of power. In particular, at the cut-off frequency, the amplitude which passes is (in theory) 70.7% when resonance is zero. Note the magic value of 70.7% is the square root of 1/2 times 100%... that is, 1/2 the power of the unfiltered version.A doubling of frequency is referred to stupidly as an octave (stupid because it has nothing to do with the number 8, although music teachers will swear there are 8 notes in an octave, but really there is only 7 [or 12 if you count sharps]). So you might see terms like "percent per octave" or more commonly "decibels per octave". Another term you may run accross is "decibels per decade" which is nearly useless because a frequency 10x greater than another is almost never considered in sound/music. A very brief review of Voltage Controlled Filters (which SID uses) is available on Wikipedia. Their graph, however, is not in linear amplitude and log-2 (octave) in frequency, as discussed here, but the less meaningful decibels (power) per decade. Power and amplitude are both meaningful depending on context. For numerical calculations or when making voltage measurements, amplitude or "real" physical quanity is common; power is the square of the amplitude, and is relevant to the perceived loudness.
If any parameter has an invalid expression, no parameters are given, or any extra parameters are given, then SYNTAX ERROR is generated. If any parameter is not numeric, TYPE MISMATCH ERROR occurs; you may manually converted a string with VAL. Floating-point numbers are converted automatically with INT. If the result is not a Legal Value (see table above) then ILLEGAL QUANTITY ERROR occurs.
A great article about the SID chip can be found found here. It is an interview with the lead designer, Bob Yannes.
Examples:
© H2Obsession, 2014 |