splitrig

splitrig — Split a trigger signal

Description

splitrig splits a trigger signal (i.e. a timed sequence of control-rate impulses) into several channels following a structure designed by the user.

Syntax

splitrig ktrig, kndx, imaxtics, ifn, kout1 [,kout2,...,koutN]

Initialization

imaxtics - number of tics belonging to largest pattern

ifn - number of table containing channel-data structuring

Performance

asig - incoming (input) signal

ktrig - trigger signal

The splitrig opcode splits a trigger signal into several output channels according to one or more patterns provided by the user. Normally the regular timed trigger signal generated by metro opcode is used to be transformed into rhythmic pattern that can trig several independent melodies or percussion riffs. But you can also start from non-isocronous trigger signals. This allows to use some "interpretative" and less "mechanic" groove variations. Patterns are looped and each numtics_of_pattern_N the cycle is repeated.

The scheme of patterns is defined by the user and is stored into ifn table according to the following format:

gi1  ftgen 1,0,1024,  -2 \  ; table is generated with GEN02 in this case
\                           ;
numtics_of_pattern_1, \ ;pattern 1
   tic1_out1, tic1_out2, ... , tic1_outN,\
   tic2_out1, tic2_out2, ... , tic2_outN,\
   tic3_out1, tic3_out2, ... , tic3_outN,\
   .....
   ticN_out1, ticN_out2, ... , ticN_outN,\
\
numtics_of_pattern_2, \ ;pattern 2
   tic1_out1, tic1_out2, ... , tic1_outN,\
   tic2_out1, tic2_out2, ... , tic2_outN,\
   tic3_out1, tic3_out2, ... , tic3_outN,\
   .....
   ticN_out1, ticN_out2, ... , ticN_outN,\
   .....
\
numtics_of_pattern_N,\ ;pattern N
   tic1_out1, tic1_out2, ... , tic1_outN,\
   tic2_out1, tic2_out2, ... , tic2_outN,\
   tic3_out1, tic3_out2, ... , tic3_outN,\
   .....
   ticN_out1, ticN_out2, ... , ticN_outN,\
        

This scheme can contain more than one pattern, each one with a different number of rows. Each pattern is preceded by a a special row containing a single numtics_of_pattern_N field; this field expresses the number of tics that makes up the corresponding pattern. Each pattern's row makes up a tic. Each pattern's column corresponds to a channel, and each field of a row is a number that makes up the value outputted by the corresponding koutXX channel (if number is a zero, corresponding output channel will not trigger anything in that particular arguments). Obviously, all rows must contain the same number of fields that must be equal to the number of koutXX channel. All patterns must contain the same number of rows, this number must be equal to the largest pattern and is defined by imaxtics variable. Even if a pattern has less tics than the largest pattern, it must be made up of the same number of rows, in this case, some of these rows, at the end of the pattern itself, will not be used (and can be set to any value, because it does not matter).

The kndx variable chooses the number of the pattern to be played, zero indicating the first pattern. Each time the integer part of kndx changes, tic counter is reset to zero.

Patterns are looped and each numtics_of_pattern_N the cycle is repeated.

examples 4 - calculate average value of asig in the time interval

This opcode can be useful in several situations, for example to implement a vu-meter

Examples

Here is an example of splitrig opcode. It uses the file splitrig.csd.

Example 998. Example of the splitrig opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
-odac -d -m0
</CsOptions>
<CsInstruments>

; By Stefano Cucchi & Menno Knevel - 2020

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

; table with values 
; 4 lines =  4 kout triggers
; 4 rows = number of tics for every pattern (imaxtics)
gi1  ftgen 1, 0, 1024, -2,   ; Table is generated with GEN02
\            ; Every column represent a kout trigger           
4, \       ; define # of rows of numtics of pattern 0 == index 0
\; k1, k2, k3, k4
   2,  3,  4,  5,\                         
   3,  4,  5,  5,\
   4, 10, 10,  3,\
   5,  2, 10,  4,\
\
4, \     ; define # of rows of numtics of pattern 1 == index 1
\; k1, k2, k3, k4
   6, 10,  7,  8,\
   8,  6,  7,  8,\
   8,  6, 10,  8,\
   9,  6, 10,  8

instr 1

ktrig  metro  4  ; general trigger
; initialize out triggers
k1 init 0
k2 init 0
k3 init 0
k4 init 0
kndx = p4    ;choose pattern 0 or 1
imaxtics = 4 ; number of tics
ifn = 1
splitrig ktrig, kndx, imaxtics, ifn, k1, k2, k3, k4
if (p5 == 1) then
   schedkwhen ktrig, 0, 1, k1, 0, .1  ; 1st column
elseif (p5 == 2) then
   schedkwhen ktrig, 0, 1, k2, 0, .1  ; 2nd column
elseif (p5 == 3) then
   schedkwhen ktrig, 0, 1, k3, 0, .1  ; 3rd column
elseif (p5 == 4) then
   schedkwhen ktrig, 0, 1, k4, 0, .1  ; 4th column
endif
print p5
endin

instr 2

prints "instr 2\n"
ares linen  .3, 0.02, p3, .05 ;envelope 
aout  poscil ares, 200
outs aout, aout
endin

instr 3

prints "instr 3\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 300
outs aout, aout
endin

instr 4

prints "instr 4\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 400
outs aout, aout
endin

instr 5

prints "instr 5\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 500
outs aout, aout
endin

instr 6

prints "instr 6\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 1500
outs aout, aout
endin

instr 7

prints "instr 7\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 2000
outs aout, aout
endin

instr 8

prints "instr 8\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 2500
outs aout, aout
endin

instr 9

prints "instr 9\n"
ares linen  .3, 0.02, p3, .05 
aout  poscil ares, 3000
outs aout, aout
endin

instr 10 ; dummy instrument

prints "instr 10\n"
; silence
endin

</CsInstruments>
<CsScore>
s
i 1 0 4 0 1 ; play the 4 columns of pattern 0
i 1 + 4 0 2
i 1 + 4 0 3
i 1 + 4 0 4
s
i 1 0 4 1 1 ; play the 4 colums of pattern 1
i 1 + 4 1 2
i 1 + 4 1 3
i 1 + 4 1 4
e
</CsScore>
</CsoundSynthesizer>


Credits

Written by Gabriel Maldonado.

New in Csound 5 (Previously available only on CsoundAV)