modmatrixMiscellaneousmodmatrixmodmatrix
Modulation matrix opcode with optimizations for sparse matrices.
Description
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.
Syntaxmodmatrix iresfn, isrcmodfn, isrcparmfn, imodscale, inum_mod, \\
inum_parm, kupdateInitializationiresfn -- 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.
Performancekupdate -- 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:
cps1cps2cutoffisrcparmfn4008003
... while the modulator variables have these values:
lfo1lfo2isrcmodfn0.5-0.2
The scaling/routing coefficients used:
imodscalecps1cps2cutofflfo1400-2lfo2-501003
... and the resulting output values:
cps1cps2cutoffiresfn4307801.4lfo2-501003
The output value for "cps1" is calculated as
400+(0.5*40)+(-0.2*-50), similarly for "cps2"
800+(0.5*0)+(-0.2*100), and for cutoff: 3+(0.5*-2)+(-0.2*3)
The imodscale ftable may be specified in the score like this:
f1 0 8 -2 200 0 2 50 300 -1.5
Or more conveniently using ftgen in the orchestra:
gimodscale ftgen 0, 0, 8, -2, 200, 0, 2, 50, 300, -1.5
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.See the sections Real-time Audio and Command Line Flags for more information on using command line flags.See alsoMiscellaneous opcodesCreditsBy:Oeyvind Brandtsegg and Thom JohansenNew in version 5.12