GEN44

GEN44 — Generates a stiffness (connection) matrix for use in scanu/scanu2.

Description

Generates a stiffness matrix from a text file of triples numbers.

Syntax

f # time size -44  "filename"
f # time size -44  num

Performance

The file named in version 1 or the file stiff.num in the second case is read to create the matrix.

Matrix Format

The first line of the file should be <MATRIX size=integer> and it creates a square matrix of the indicated size. This is followed by lines of two or three numbers, the first two denoting a connection from the first to the second. The third number is a weight; a weight of 2 is like having two links so more information gets distributed, while a zero weight means no link. If this third number is omitted it is taken as value 1. The list is terminated by a </MATRIX> line or end of file.

Example of this matrix format:

<MATRIX size=16>
1 2  2
2 3  1
3 4  3
4 5  1
5 6  4
6 7  1
7 8  5
8 9  6
9 10  7
10 11 6
11 12 5
12 13 4
13 14 3
14 15 2
15 16 1
16 1  9
14 13 2
10 3  6
6 4  2
2 14  7
</MATRIX>
        

can be given as zero in which case a size*size table is created. If the size in the gen statememt is too small for the matrix then space is re-allocated to the required size.

Note: to avoid confusion with other matrix formats, it is best to save this matrix format file using the extension file.matrxT.

Examples

Here is an example of the GEN44 generator. It uses the file gen44.csd.

Example 1326. Example of the GEN44 generator.

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 gen44.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr scan

a0 init 0

irate = .01

kmass line 2,p3,5
kstiff line 30,p3,45
kcenter line .08,p3,.01
kdamp line .01,p3,.08
kpos line 0,p3,16
kdisplace line 0,p3,.5

;scanu2 init,irate,ifndisplace,ifnmass,ifnmatrix,ifncentr,ifndamp,kmass,kmtrxstiff,
; kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id
scanu2 -1, irate, 6, 2, 3, 4, 5, kmass, kstiff, kcenter, kdamp, .2, .7, kpos, kdisplace, a0, 1, 2

;ar scans kamp, kfreq, ifntraj, id
a1 scans ampdbfs(p4), cpspch(p5), 7, 2
a1 dcblock2 a1
out a1
endin

</CsInstruments>
<CsScore>
; Initial displacement condition
f1 0 16 10 1         ; sine hammer
f2 0 16 -7 1 16 1    ; Masses
f3 0 0 -44 "string_with_extras-16.matrxT"   ; Spring matrices
f4 0 16 -7 1 16 1    ; Centering force, uniform initial centering
f5 0 16 -7 1 16 1    ; Damping, uniform damping
; Initial displacement - (displacement, vel, and acceleration
; Acceleration is from stiffness matrix pos effect - increases acceleration
f6 0 16 -7 .01 16 .01 ; uniform initial velocity-displacement
f7 0 16 -5 .001 16 16 ; Trajectories

i"scan" 0 2 -6 7.00
i"scan" 2 2 -6 5.00
i"scan" 4 2 -6 6.00
i"scan" 6 2 -6 8.00
i"scan" 8 2 -6 10.00

e
</CsScore>
</CsoundSynthesizer>


Here is another example of GEN44. It uses the file gen44-2.csd. The matrix file has 1024 masses.

Example 1327. Second example of the GEN44 generator.

<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 gen44-2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; by Menno Knevel 2024

instr 1	                                                    ; move the grain table

initial ftgenonce 1, 0, 1024, 10, 1                         ; initial position = sine wave
idispl  ftgenonce 2, 0, 1024, -7, .01, 1024, .01            ; displace
imass   ftgenonce 3, 0, 1024, -7, 5, 1024, 5                ; masses
icent   ftgenonce 4, 0, 1024, -7, .01, 1024, .1             ; centering
idamp   ftgenonce 5, 0, 1024, -7, -.1, 1024, -.21           ; damping
itraj   ftgenonce 6, 0, 1024, -7, 0, 1024, 1024             ; trajectory
iw	ftgenonce 7, 0, 1024, 20, 2                         ; Hanning window for GEN20

a0 = 0                                                      ; no audio injection
kline line .07, p3, 0                                       ; simple envelope
;scanu2 init, irate, ifndisplace, ifnmass, imatrix, ifncentr, ifndamp, kmass, kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id
scanu2   1,   .003,     2,          3,       100,       4,       5,      10,      6,       0.1,    .9,     .5,    .1,     0,      0,     a0,    0,   -1
aL grain2 p4, p4, 2, 25, 1, 7
aR grain2 p4, p4, 2, 25, 1, 7
aL  dcblock aL 
aR  dcblock aR 
outs aL * kline, aR * kline

endin

</CsInstruments>
<CsScore>
f100 0  0   -44  "circularstring_1024.matrxT"    ; text matrix, to be found in manual/examples

i1  0  20  466.16376098248423	
e
</CsScore>
</CsoundSynthesizer>


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: John ffitch

New in Version 6.16

June 2021