scanu2 — Compute the waveform and the wavetable for use in scanned synthesis.
Plugin opcode in scansyn.
Compute the waveform and the wavetable for use in scanned synthesis.
scanu2 init, irate, ifndisplace,
ifnmass, ifnmatrix, ifncentr, ifndamp, kmass, kmtrxstiff, kcentr,
kdamp, ileft, iright, kpos, kdisplace, 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 intended mass number, otherwise it can be anything. If init is not an integer the initial state is white noise with the fractional part being a scaling..
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.
ifndisplace -- the ftable that contains the initial velocity for each mass. It should have the same size as the intended mass number.
ifnmass -- ftable that contains the mass of each mass. It should have the same size as the intended mass number.
ifnmatrix -- ftable that contains the spring stiffness of each connection. It should have the same size as the square of the intended mass number. The data ordering is a row after row dump of the connection matrix of the system.
ifncentr -- ftable that contains the centering force of each mass. It should have the same size as the intended mass number.
ifndamp -- the ftable that contains the damping factor of each mass. It should have the same size as the intended mass number.
ileft -- If init < 0, the position of the positive pluck in the range 0 to 1. Ignored when init > 0.
iright -- If init < 0, the position of the negative pluck in the range 0 to 1. Ignored when init > 0.
If ileft is the same as iright a single positive pluck is used as initial state.
idisp -- If 0, no display of the masses is provided.
id -- If positive, the ID of the opcode. This will be used to point the scanning opcode to the proper waveform maker. If this value is negative, the absolute of this value is the wavetable on which to write the waveshape. That wavetable can be used later from an other opcode to generate sound. The initial contents of this table will be destroyed.
kmass -- scales the masses
kmtrxstiff -- scales the spring stiffness. Note that larger numbers slow the evolution of the vibration, which is the reciprocal of the coresponding parameter in scanu.
kcentr -- scales the centering force
kdamp -- scales the damping
kpos -- position of an active hammer along the string (kpos = 0 is leftmost, kpos = 1 is rightmost). The shape of the hammer is determined by init and the power it pushes with is kdisplace.
kdisplace -- power that the active hammer uses.
ain -- audio input that adds to the velocity of the masses. Amplitude should not be too great.
Note | |
---|---|
Both scanu and scanu2 are capable of reading the binary (.matrxB) and text (.matrxT) matrix format. However, using scanu2 is to be preferred because of its accuracy and better sound quality. |
Here is an example of the scanu2 opcode. It uses the file scanu2.csd.
Example 947. Example of the scanu2 opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac --limiter=0.95 ;;;realtime audio out & and limit loud sounds ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o scanu2.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ; by Menno Knevel 2024 instr 1 a0 init 0 ; no audio injection irate = .01 kenv adsr .0001, 1, .7, .1 ; envelope if (p6 == 1) then prints "\ninitial displacement condition = ramp" elseif (p6 == 11) then prints "\ninitial displacement condition = sine (hammer???)" else prints "\ninitial displacement condition = a pluck that is 10 points wide on the surface" endif if (p7 == 3) then prints "\n (binary matrix)\n\n" else prints "\n (text matrix)\n\n" endif ; scanu init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass, ; kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id scanu2 p6, irate, 6, 2, p7, 4, 5, 2, 9, .01, .01, .1, .9, 0, 0, a0, 1, 2 ;ar scans kamp, kfreq, ifntraj, id asig scans ampdb(p4)*kenv, cpspch(p5), 7, 2 outs asig*.00004, asig*.00004 ; lower volume due to 0dbfs=1 endin </CsInstruments> <CsScore> ; Initial displacement condition f1 0 128 -7 0 64 1 64 0 ; ramp f11 0 128 10 1 ; sine hammer f111 0 128 -7 0 28 0 2 1 2 0 96 0 ; a pluck that is 10 points wide on the surface ; Masses f2 0 128 -7 1 128 1 ; Spring matrices f3 0 16384 -23 "/manual/examples/string-128.matrxB" f33 0 16384 -44 "/manual/examples/cylinder_128.matrxT" ; Centering force f4 0 128 -7 1 128 1 ; uniform initial centering ; 0 128 -7 .001 128 1 ; ramped centering ; Damping f5 0 128 -7 1 128 1 ; uniform damping ; Initial velocity - (displacement, vel, and acceleration ; Acceleration is from stiffness matrix pos effect - increases acceleration f6 0 128 -7 .01 128 .01 ; uniform initial velocity ; exponential Trajectory f7 0 128 -5 .001 128 128 i1 0 6 88 7.00 1 3 i1 7 2 88 5.00 1 3 i1 9 2 88 6.00 1 3 i1 12 6 86 7.00 11 3 i1 19 2 86 5.00 11 3 i1 21 2 86 6.00 11 3 i1 24 6 90 7.00 111 3 i1 31 2 90 5.00 111 3 i1 33 2 90 6.00 111 3 i1 37 6 88 7.00 1 33 i1 44 2 88 5.00 1 33 i1 46 2 88 6.00 1 33 i1 49 6 85 7.00 11 33 i 156 2 85 5.00 11 33 i1 58 2 85 6.00 11 33 i1 61 6 92 7.00 111 33 i1 68 2 92 5.00 111 33 i1 70 2 92 6.00 111 33 e </CsScore> </CsoundSynthesizer>
Here is another example of the scanu2 opcode. It uses the file scanu2-2.csd.
Example 948. Second example of the scanu2 opcode.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac --limiter=0.95 ;;;realtime audio out & and limit loud sounds ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o scanu2-2.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ; by Menno Knevel 2024 instr 1 ; play with k-rate parameters a0 init 0 irate = .2 kmass line 10, p3, 1 kstiff line .30, p3, .7 kcenter line .3, p3, .01 kdamp line -.01, p3, -.1 kdisplace line 0, p3, 1 scanu2 1, irate, 6, 2, 3, 4, 5, kmass, kstiff, kcenter, kdamp, .1, .7, 1, kdisplace, a0, 1, 5 asig scans ampdbfs(p4), cpspch(p5), 7, 5 asig dcblock2 asig asigL, asigR reverbsc asig, asig, .6, 10000, sr, .5, 1 ; add some reverb outs asigL+asig, asigR+asig endin </CsInstruments> <CsScore> ; Initial displacement condition f1 0 1024 10 1 ; sine f2 0 1024 -7 1 1024 1 ; Masses ; Spring text matrix f3 0 0 -44 "circularstring_1024.matrxT" ; text matrix, to be found in manual/examples f4 0 1024 -7 1 1024 1 ; uniform initial centering f5 0 1024 -7 1 1024 1 ; uniform damping ; Initial displacement - (displacement, vel, and acceleration ; Acceleration is from stiffness matrix pos effect - increases acceleration f6 0 1024 -7 .01 1024 .01 ; uniform initial velocity-displacement f7 0 1024 -5 .001 1024 1024 ; Trajectory i1 0.0 6.5 -6 7.00 i1 6.5 6.5 -9 7.07 ; 2 notes i1 6.5 6.5 -9 7.04 e </CsScore> </CsoundSynthesizer>
Yet another example of the scanu2 opcode. It uses the file scanu2-3.csd.
Example 949. Third example of the scanu2 opcode.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac --limiter=0.95 ;;;realtime audio out & and limit loud sounds ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o scanu2-3.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ; by Richard Boulanger 2024 instr scan ; show the pluck options a0 init 0 irate = .04 kmass line 2,p3,1 kstiff line 10,p3,10 kcenter line 5,p3,6 kdamp line 1,p3,2 kpos line .4,p3,.5 ;scanu2 init,irate,ifndisplace,ifnmass,ifnmatrix,ifncentr,ifndamp,kmass,kmtrxstiff, ; kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id scanu2 p6, irate, 6, 2, 3, 4, 5, kmass, kstiff, kcenter, kdamp, p7, p8, kpos, .02, a0, 1, 2 a1 scans ampdbfs(p4), cpspch(p5), 7, 2 a1 dcblock2 a1 outs a1, a1 endin </CsInstruments> <CsScore> f1 0 16 10 1 ; Sine Hammer f11 0 16 10 1 .5 .3 .2 .1 .01 ; Sawlike hammer f111 0 16 10 1 0 .73 0 .53 0 .45 0 .17 0 .02 0 .002 ; Pulselike hammer f2 0 16 -7 8 16 8 ; Masses f3 0 0 -44 "/manual/examples/string_with_extras-16.matrxT" ; Spring matrix, to be found in the examples folder of the manual f4 0 16 -7 .07 16 .07 ; Centering force, uniform initial centering f5 0 16 -7 .04 16 .04 ; Damping, uniform damping f6 0 16 -7 .01 16 .01 ; uniform initial velocity-displacement f7 0 16 -5 15 16 1 ; Trajectory i"scan" 0 3 6 7.00 -1 .5 .5 ; pluck in middle s i"scan" 0 3 2 7.00 -1 .1 .1 ; pluck at left s i"scan" 0 3 0 7.00 -1 .2 -.8 ; 2 plucks up left and down right s i"scan" 0 3 -6 7.00 1 .2 .8 ; sine hammer - ignore pluck position s i"scan" 0 3 -6 7.00 11 .8 .2 ; sawlike hammer - ignore pluck position s i"scan" 0 3 -6 7.00 111 .1 .6 ; pulselike hammer - ignore pluck position e </CsScore> </CsoundSynthesizer>
More information on the Scanned Synthesis opcodes: Working with Scanned Synthesis, written by Steven Yi, and some tutorials by Richard Boulanger.