Csound Opcodes for Scanned Synthesis
Scanned synthesis is a variant of physical modeling, where a network of masses connected 
by springs is used to generate a dynamic waveform.  The opcode scanu defines the 
mass/spring network and sets it in motion.  The opcode scans follows a predefined path 
(trajectory) around the network and outputs the dynamic waveform.  Several scans instances 
may follow different paths around the same network.

These are highly efficient mechanical modeling algorithms for both synthesis and sonic 
animation via algorithmic processing. They should run in real-time. Thus, the output is 
useful either directly as audio, or as controller values for other parameters. 

Please note that the generated dynamic wavetables are very unstable. Certain values for 
masses, centering, damping can cause the system to "blow up" and the most "interesting" 
sounds to emerge from your loudspeakers...

SCANU

The syntax for scanu is:

	scanu	    init, irate, ifnvel, ifnmass, ifnstif, ifncentr, ifndamp, kmass, kstif, \     
                                kcentr, kdamp, ileft, iright, kx, ky, ain, idisp, id

init: The initial position of the masses.  If this is a negative number, then the absolute of init 
signifies the table to use as a hammer shape.  If init > 0, the length of it should be the same 
as the number of masses (128),  otherwise it can be anything.

irate:  The amount of time between successive updates of the mass state.  Kind of like the 
sample period of the system.  If the number is big the string will update at a slow rate 
showing little timbral variability, otherwise it will change rapidly resulting in a more 
dynamic sound.

ifnvel: The number of the ftable that contains the initial velocity for each mass.  It should 
have the same size as the number of masses (128).

ifnmass: The number of the ftable that contains the mass of each mass.  It should have the 
same size as the number of masses (128).

ifnstif: The number of the ftable that contains the spring stiffness of each connection.  It 
should have the same size as the square of the number of masses (16384).  The data 
ordering is a row after row dump of the connection matrix of the system.

ifncentr: The number of the ftable that contains the centering force of each mass.  It should 
have the same size as the number of masses (128).

ifndamp: The number of the ftable that contains the damping factor of each mass.  It should 
have the same size as the number of masses (128).

kmass: Scales the masses.

kstif: Scales the spring stiffness.

kcentr: Scales the centering force.

kdamp: Scales the damping.

ileft: If init < 0, the position of the left hammer (ileft = 0 is hit at leftmost, ileft = 1 is hit at 
rightmost).

iright: If init < 0, the position of the right hammer (iright = 0 is hit at leftmost, iright = 1 is 
hit at rightmost).

kx: The position of an active hammer along the string (0 leftmost,1 rightmost).  The shape of 
the hammer is determined by init.  The power it pushes with is ky.

ky: The power that the active hammer uses.

ain:  The audio input that adds to the velocity of the masses.

idisp: If 0 then there is no display. If 1 then display the dynamic evolution of the masses.

id:  The ID of the opcode.  This will be used to point the scanning opcode (scans) to the 
proper waveform maker.  If this value is negative, it indicates the wavetable on which to write 
the waveshape.  That wavetable can be used later from another opcode to generate sound.  
Note: The initial contents of this table will be destroyed, so donąt rely on them being there.


SCANS

The syntax for scans is:

ar	scans	     kamp, kfreq, ifntraj, id[, korder]

kamp: The output amplitude.  Note that the resulting amplitude is also dependent to the state 
of the wavetable.  

kfreq: The frequency of the scan rate.

ifntraj: The number of the ftable that contains the scanning trajectory.  This is a series of 
numbers that contains addresses of masses - the order of these addresses is used as the 
scan path.  It shouldnąt contain more values than the number of masses (128), and it should 
not contain negative numbers.

id: The ID number of the scanu waveform to use.

korder: The order of interpolation used internally.  It can take any value in the range 1 to 4, 
and defaults to 4, which is quartic interpolation.  2 is quadratic and 1 is linear.  The higher 
numbers are slower, but not necessarily better.


MATRICES


To produce the matrices, the file format is straightforward.  For example, for 4 masses we 
would have the following grid describing the connections:


  | 1 | 2 | 3 | 4 |
-------------------
1 |   |   |   |   |
-------------------
2 |   |   |   |   |
-------------------
3 |   |   |   |   |
-------------------
4 |   |   |   |   |
-------------------

Whenever two masses are connected then the point they define is 1, so for a unidirectional 
string we would have the following connections, (1,2), (2,3), (3,4) (if it was bi-directional we 
would also have (2,1), (3,2), (4,3)).  So we fill these out with ones and the rest with zeros 
and we get:

  | 1 | 2 | 3 | 4 |
-------------------
1 | 0 | 1 | 0 | 0 |
-------------------
2 | 0 | 0 | 1 | 0 |
-------------------
3 | 0 | 0 | 0 | 1 |
-------------------
4 | 0 | 0 | 0 | 0 |
-------------------


Similarly for the other shapes, we find the connections and fill them out.  This gets saved in 
an ASCII file, column by column.  Thus, the string shown above would be saved as:

0.
1.
0.
0.
0.
0.
1.
0.
0.
0.
0.
1.
0.
0.
0.
0.

COPYRIGHT

The scanned synthesis source code files scansyn.c, scansyn.h and related files 
are Copyright © 1999 by Interval Research, Inc.  
Coded by Paris Smaragdis.
From an algorithm by Bill Verplank, Max Mathews, and Rob Shaw.

Permission to use, copy, or modify these programs and their documentation for educational 
and research purposes only and without fee is hereby granted, provided that this copyright 
and permission notice appear on all copies and supporting documentation. For any other 
uses of this software, in original or modified form, including but not limited to distribution 
in whole or in part, specific prior permission from Interval Research must be obtained. 
Interval Research, Inc. makes no representations about the suitability of this software for 
any purpose. It is provided "as is" without express or implied warranty.