tablefilter
Filters table values or converts onset times to intervals.
tablefilter reads a source table and writes the result to a destination table on each control cycle. It returns the number of values written.
Syntax
knumpassed is the number of values written, starting at index 0. Values after this count in the destination table stay unchanged.
kouttable is the destination table number.
kintable is the source table number. The destination length sets how many source values the opcode examines. Use tables of equal length to read the source once. If the destination is longer, reading starts again at the beginning of the source.
kmode selects the operation.
| Mode |
Operation |
| 1 |
Keep values whose denominator weight is less than or equal to the threshold weight. |
| 2 |
Keep values whose denominator weight is greater than or equal to the threshold weight. |
| 3 |
Convert nonzero onset times to intervals. |
kparam is an integer whose weight sets the threshold for modes 1 and 2. The opcode approximates each source value as a fraction and compares the denominator's weight with the weight of this integer. Both modes include equal weights. For example, 1/2 passes both filters when the threshold is 2.
The weight follows Clarence Barlow's indigestibility function. It depends on the integer's prime factors and how often they occur. Larger prime factors add more weight.
Onsets to intervals
Mode 3 reads onset times in table order. It skips zero values and subtracts the previous nonzero onset from each remaining onset. The starting point is zero, so the first interval equals the first nonzero onset. Repeated nonzero onsets produce a zero interval.
For example, onsets 0.25, 0.5, 0.75, 1 give four intervals of 0.25. The intervals use the same units as the onsets. They can serve as the durations between notes in a rhythmic pattern.
Mode 3 ignores kparam. Pass 1 for this argument. The source and destination can share a table, which replaces the onsets with their intervals.
For conversion in place, call tablefilter only when you want to replace the current onsets. Calling it again on the next control cycle would convert the intervals themselves. Use a separate destination to keep reading the original onsets on every cycle.
Compatibility
Conversion in place and weights for prime factors above 9973 require the fixes in Csound PR #3278. In builds without these fixes, use a separate destination for mode 3. Modes 1 and 2 can give incorrect results when a denominator or threshold contains a prime factor above 9973.
Examples
The tablefilter.csd example filters a Farey sequence by denominator weight.
| Filter a Farey sequence |
|---|
| <CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
sr=44100
ksmps=10
nchnls=1
0dbfs=1
gifarn init 8 ; initialise integer for Farey Sequence F_8
gires fareyleni gifarn ; calculate length of F_8, returns 23
; the table length won't be a power of 2
; (The length of a Farey Sequence with n > 1 is always odd)
gilen init gires * -1
gifarey ftgen 200, 0, gilen, "farey", gifarn, 0
; initialize destination table with 0s
gifiltered ftgen 0, 0, gilen, 21, 1, 0
; initialize second destination table with 0s
gifiltered2 ftgen 0, 0, gilen, 21, 1, 0
; table filtering opcode: dest. source, mode, threshold
ginumpassed tablefilteri gifiltered, gifarey, 1, 6
; the threshold parameter indicates that denominators whose weights are heavier
; than the weight of 6 do not pass through the filter. Equal weights pass.
; The weight is calculated using
; Clarence Barlow's function of indigestibility of a number. According to this function,
; higher prime numbers contribute to an increased weight of any natural integer they divide.
; ginumpassed is the number of elements from the source table 'gifarey'
; that have passed the test and which have been copied to the destination table 'gifiltered'
; apply a different filter:
ginumpassed2 tablefilteri gifiltered2, gifarey, 2, 5
; In mode=2 we again test the digestibility of the denominators of the
; fractions in the source table.
; The difference to mode=1 is that we now let pass only values from the
; source that are as heavy as the threshold or greater.
instr 4
kndx init 0 ; read out elements of now filtered F_8 sequentially and print to file
if (kndx < ginumpassed) then
kelem tab kndx, gifiltered
fprintks "fareyfilter_lp.txt", "%2.6f\\n", kelem
kndx = kndx+1
endif
endin
instr 5
kndx init 0 ; read out elements and print to file
if (kndx < ginumpassed2) then
kelem tab kndx, gifiltered2
fprintks "fareyfilter_hp.txt", "%2.6f\\n", kelem
kndx = kndx+1
endif
endin
</CsInstruments>
<CsScore>
i4 0 1
i5 0 1
e
</CsScore>
</CsoundSynthesizer>
|
The tablefilter_intervals.csd example converts onset times to intervals at initialization and at performance time. Both forms print four intervals of 0.25.
| Convert onsets to intervals |
|---|
| <CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1
// Onset times in seconds for four evenly spaced notes.
giOnsets ftgen 0, 0, -4, -2, .25, .5, .75, 1
instr 1
// Copy the onsets, then replace the copy with intervals at initialization.
iIntervals ftgen 0, 0, -4, -2, 0
tableicopy iIntervals, giOnsets
iCount tablefilteri iIntervals, iIntervals, 3, 1
iIndex = 0
while iIndex < iCount do
iInterval table iIndex, iIntervals
prints "init interval %d = %.2f seconds\n", iIndex + 1, iInterval
iIndex += 1
od
// Keep the source unchanged when filtering on every control cycle.
iOutput ftgen 0, 0, -4, -2, 0
kCount tablefilter iOutput, giOnsets, 3, 1
if timeinstk() == 1 then
kIndex = 0
while kIndex < kCount do
kInterval table kIndex, iOutput
printf "perf interval %d = %.2f seconds\n", kIndex + 1, kIndex + 1, kInterval
kIndex += 1
od
endif
endin
</CsInstruments>
<CsScore>
i 1 0 .01
e
</CsScore>
</CsoundSynthesizer>
|
See also
tablefilteri, GENfarey, Read/Write Operations
Credits
Author Georg Boenn
University of Glamorgan, UK
New in Csound version 5.13