scanu

scanu — Compute the waveform and the wavetable for use in scanned synthesis.

Description

Plugin opcode in scansyn.

Compute the waveform and the wavetable for use in scanned synthesis.

Syntax

scanu init, irate, ifndisplace,
    ifnmass, ifnmatrix, ifncentr, ifndamp, kmass, kmtrxstiff, kcentr,
    kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id

Initialization

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.

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 left hammer (ileft = 0 is hit at leftmost, ileft = 1 is hit at rightmost). Ignored when init > 0.

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

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.

Performance

kmass -- scales the masses

kmtrxstiff -- scales the spring stiffness.

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] 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.

Examples

Here is an example of the scanu opcode. It uses the files scanu.csd.

Example 945. Example of the scanu 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 scanu.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; by Menno Knevel 2024

instr 1	

a0  = 0     ; no external input
;   scanu init, irate, ifnvel, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass, kstif, kcentr, kdamp, ileft, iright, kpos, kstrngth, ain, idisp, id
    scanu p7,     p6,    6,       2,       3,        4,        5,       2,     .1,    .1,     -.02,  .1,    .5,     0,     0,     a0,  0,     2

if (p7 == -1) then
    prints "\nthe hammer option!\n"
else
    prints  "\ninitial position of the masses...\n"
endif
;ar scans kamp,      kfreq,      ifntraj, id
a1  scans ampdb(p4), cpspch(p5),    7,    2
a2  scans ampdb(p4), cpspch(p5)*1.01, 7,  2           ; slightly out of tune
a1  *= 0.00006                                        ; lower amplitude due to 0dbfs  = 1
a2  *= 0.00006                                      
a1  dcblock2  a1                                      ; remove DC offset
a2  dcblock2  a2                                     
outs a1, a2

endin

</CsInstruments>
<CsScore>

f1 0 128 7 0 64 1 64 0     ; Initial condition
f2 0 128 -7 1 64 .45 64 1  ; Masses
f3 0 16384 -23 "string-128.matrxB" ; Matrix, a binary one. Can be found in manual/examples
f4 0 128 -7 0 64 1 64 0    ; Centering force
f5 0 128 -7 0 64 1 64 0    ; Damping
f6 0 128 -7 0 128 0        ; Initial velocity
f7 0 128 -7 0 64 127 64 0  ; Trajectory

i1	0.0     8	86	6.00	0.001   1
i1	8.0     8	89	6.01	0.001   -1 
i1	17.0	10	86	6.00	0.005   1
i1	27.0	10	89	6.01	0.005   -1
i1	38.0	120	86	6.00	0.1     1
i1	159.0	120	89	6.01	0.1     -1
e
</CsScore>
</CsoundSynthesizer>


Here is another example of the scanu opcode. It uses the file scanu-2.csd.

Example 946. Second example of the scanu 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 scanu-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 sample

a0  	loscil	 .8, p4, 200                                                    ; audio sample with loop points
prints "\nthe drum sample has an frequency of %d\n", p4
outs a0, a0
endin

instr 2	; inject sample

a0  	loscil	 .5, p6, 200                                                    ; audio injection 
prints "...and is injected into the system..."
if (p6 == 0) then
    prints  "sample injection has no effect!"
endif

kenv    linseg    1, p3*.8, .1, p3*.2, 0                                        ; simple envelope
;scanu init, irate, ifnvel, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass, kstif, kcentr, kdamp, ileft, iright, kpos, kstrngth, ain, idisp, id
 scanu  1,   .01,    6,       2,       3,          4,        5,     2,     .1,    .1,     -.02,   .1,    .5,     0,      0,    a0,  0,     2
;ar scans kamp,      kfreq,      ifntraj, id
a1  scans ampdb(p4)*kenv, cpspch(p5), 7,       2
a2  scans ampdb(p4)*kenv, cpspch(p5)*1.01, 7,       2                           ; slightly out of tune (stereo)
a1  *= 0.00005                                                                  ; lower amplitude due to 0dbfs  = 1
a2  *= 0.00005                                      
a1  dcblock2  a1                                                                ; remove DC offset
a2  dcblock2  a2                                     
outs a1, a2
endin

</CsInstruments>
<CsScore>
f1 0 128 7 0 64 1 64 0                               ; Initial condition
f2 0 128 -7 1 64 .45 64 1                            ; Masses
f3 0 16384 -23 "manual/example/string-128.matrxB"    ; Spring matrix
f4 0 128 -7 0 64 1 64 0                              ; Centering force
f5 0 128 -7 0 64 1 64 -0.01                          ; Damping
f6 0 128 -7 0 128 0                                  ; Initial velocity
f7 0 128 -7 0 64 127 64 0                            ; Trajectory
f200 0 0 1 "drumsMlp.wav" 0 0 0  

i1	0.0	4	0
i1	34.0	4	4
i1	68.0	4	18
i2	4.0	30	88	6.00	0
i2	38.0	30	70	6.00	4
i2	72.0	30	65	6.00	18
e
</CsScore>
</CsoundSynthesizer>


A musical example featuring the scanu opcode: Scanu_Shengzheng_Zhang.csd by Shengzheng Zhang. This musical example also needs MIDIpad.mid.

See also

Scanned Synthesis

More information on the Scanned Synthesis opcodes: Working with Scanned Synthesis, written by Steven Yi, and some tutorials by Richard Boulanger.

Credits

Author: Paris Smaragdis
MIT Media Lab
Boston, Massachussetts USA
March 2000

New in Csound version 4.05