modmatrix
Modulation matrix opcode with optimizations for sparse matrices.
The opcode can be used to let a large number of k-rate modulator variables modulate a large number of k-rate parameter variables, with arbitrary scaling of each modulator-to-parameter connection. Csound ftables are used to hold both the input (parameter) variables, the modulator variables, and the scaling coefficients. Output variables are written to another Csound ftable.
Syntax
Initialization
iresfn -- ftable number for the parameter output variables
isrcmodfn -- ftable number for the modulation source variables
isrcparmfn -- ftable number for the parameter input variables
imodscale -- scaling/routing coefficient matrix. This is also a csound ftable, used as a matrix of inum_mod rows and inum_parm columns.
inum_mod -- number of modulation variables
inum_parm -- number of parmeter (input and output) variables.
The arguments inum_mod and inum_parm do not have to be set to power-of-two values.
Performance
kupdate -- flag to update the scaling coefficients. When the flag is set to a nonzero value, the scaling coefficients are read directly from the imodscale ftable. When the flag is set to zero, the scaling coefficients are scanned, and an optimized scaling matrix stored internally in the opcode.
For each modulator in isrcmodfn, scale it with the coefficient (in imodscale) determining to what degree it should influence each parameter. Then sum all modulators for each parameter and add the resulting modulator value to the input parameter value read from iscparmfn. Finally, write the output parameter values to table iresfn.
The following tables give insight into the processing performed by the modmatrix opcode, for a simplified example using 3 parameter and 2 modulators. Let’s call the parameters "cps1", "cps2", and "cutoff", and the modulators "lfo1" and "lfo2".
The input variables may at a given point in time have these values:
cps1 | cps2 | cutoff | |
---|---|---|---|
isrcparmfn | 400 | 800 | 3 |
... while the modulator variables have these values:
lfo1 | lfo2 | |
---|---|---|
isrcmodfn | 0.5 | -0.2 |
The scaling/routing coefficients used:
imodscale | cps1 | cps2 | cutoff |
---|---|---|---|
lfo1 | 40 | 0 | -2 |
lfo2 | -50 | 100 | 3 |
... and the resulting output values:
cps1 | cps2 | cutoff | |
---|---|---|---|
iresfn | 430 | 780 | 1.4 |
lfo2 | -50 | 100 | 3 |
The output value for "cps1" is calculated as 400+(0.540)+(-0.2-50), similarly for "cps2" 800+(0.50)+(-0.2100), and for cutoff: 3+(0.5-2)+(-0.23)
The imodscale ftable may be specified in the score like this:
Or more conveniently using ftgen in the orchestra:
Obviously, the parameter and modulator variables need not be static values, and similarly, the scaling routing coefficient table may be continuously rewritten using opcodes like tablew.
Examples
Here is an example of the modmatrix opcode. It uses the file modmatrix.csd.
Example of the modmatrix opcode. | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
See also
Credits
By:
Oeyvind Brandtsegg and Thom Johansen
New in version 5.12