csound / manual

Csound Reference Manual (English)
Other
46 stars 29 forks source link

improved example for scanmap #615

Closed tjingboem closed 1 year ago

tjingboem commented 2 years ago

proposal for an improved example

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac      ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o scanmap.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2

instr scan

a0 init 0
irate = .05                               ; scanning rate

; scanu2 init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass,
scanu2     1,  irate,      6,         2,         3,        4,        5,     2,\
           9,      .01,    .01,   .1,    .9,    0,     0,     a0,    0,   2
 ;    kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id

kps, kvelo  scanmap 2, 1000, p6, 64  ; scan & change parameters of node 64 (halfway the shape)       
printks "changing amplitude of node 64 = %f5.2\n", .5, kvelo
a1  scans ampdb(p4), cpspch(p5), 7,    2
a2  vco2 kvelo + 20000, kps                 ; amplitude offset = 20000 
outs a1, a2                                 ; left = scanned synth, rigth = sawwave
endin

</CsInstruments>
<CsScore>
; Initial displacement condition
;f1 0 128 -7 0 64 1 64 0 ; ramp shape
;f1 0 128 10 1 ; sine shape
f1 0 128 -7 0 28 0 2 1 2 0 96 0     ; a pluck that is 10 points wide on the surface
f2 0 128 -7 1 128 1                 ; Masses
f3 0 16384 -23 "string-128.matrxB"  ; Spring matrix

; Centering force
f4 0 128 -7 1 128 1 ; uniform initial centering
;f4 0 128 -7 .001 128 1             ; ramped centering

; Damping
f5 0 128 -7 1 128 1                 ; uniform damping
;f5 0 128 -7 .1 128 1               ; ramped 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
f7 0 128 -5 .001 128 128            ; trajectory

i"scan" 0 10 90 7.00 10             ; p6 = change amplitude of kvelo value      
i"scan" 12 10 90 7.00 500000
e
</CsScore>
</CsoundSynthesizer>
tjingboem commented 2 years ago

regarding the example above:

AsterixMusic commented 2 years ago

I do not understand exactly scanned synthesis. In this example I converted the amplitude values to 0dbfs = 1

Rendering two wave files with different p6 values I get the same result. (Invert phase of 1 file = null output)

Screenshot 2022-02-20 at 20 19 36


<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac      ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o scanmap.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr scan

a0 init 0
irate = .05                               ; scanning rate

; scanu2 init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass,
scanu2     1,  irate,      6,         2,         3,        4,        5,     2,\
           9,      .01,    .01,   .1,    .9,    0,     0,     a0,    0,   2
 ;    kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id

kcps, kvelo  scanmap 2, 1000, p6, 64  ; scan & change parameters of node 64 (halfway the shape)       
printks "changing amplitude of node 64 = %f5.2\n", .5, kvelo
a1  scans p4, cpspch(p5), 7,    2

outs a1, a1                          
endin

</CsInstruments>
<CsScore>
; Initial displacement condition
;f1 0 128 -7 0 64 1 64 0 ; ramp shape
;f1 0 128 10 1 ; sine shape
f1 0 128 -7 0 28 0 2 1 2 0 96 0     ; a pluck that is 10 points wide on the surface
f2 0 128 -7 1 128 1                 ; Masses
f3 0 16384 -23 "string-128.matrxB"  ; Spring matrix

; Centering force
f4 0 128 -7 1 128 1 ; uniform initial centering
;f4 0 128 -7 .001 128 1             ; ramped centering

; Damping
f5 0 128 -7 1 128 1                 ; uniform damping
;f5 0 128 -7 .1 128 1               ; ramped 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
f7 0 128 -5 .001 128 128            ; trajectory

i"scan" 0  10 0.6 7.00 0.2             ; p6 = change amplitude of kvelo value      
;i"scan" 0 10 0.6 7.00 0.5
e
</CsScore>
</CsoundSynthesizer>

´´´
AsterixMusic commented 2 years ago

we should perhaps point out in the manual that an undesirable effect of the scanned synthesis could be a dc offset or a "slowly changing DC" I'm not sure but I tried adding dcblok2 and you can see the difference in the waveform

Screenshot 2022-02-20 at 20 31 39

.

tjingboem commented 2 years ago

yes i agree. A note for every manual page that says something like: "The Scanned Synthesis system can produce unexpected dynamic and loud signals. It is advised to add a DC blocker and a limiter to prevent out-of-control results."

And then add dcblock and --limiter==0.95 to all the Scanned examples of the manual.

There is already an issue where this is stated: re-examine all Scanned Synthesis examples #535 but this issue is getting a bit complex. I was wanting to attack the Scanned opcodes one by one now.

DCblocker and limiter are added to the ToDo list above.

tjingboem commented 2 years ago

in the example i get, for p6, variations in amplitude. The vco in my example follows this nicely.

Here is a new example (as an example) that includes 0dbfs=1, DC blocking and limiter:

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac   --limiter=0.95   ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o scanmap.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; by Menno Knevel - 2022

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

instr scan

a0 init 0                                 ; no external sound input
irate = .05                               ; scanning rate

; scanu2 init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass,
scanu2     1,  irate,      6,         2,         3,        4,        5,     2,\
           9,      .01,    .01,   .1,    .9,    0,     0,     a0,    0,   1
 ;    kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id

kps, kvelo  scanmap 1, 1000, p6, 64  ; scan parameters of node 64 (halfway the shape)       
printks "present  amplitude of node 64 = %5.2f\n", .5, kvelo
a1  scans ampdb(p4), cpspch(p5), 7,    1
a2  vco2 kvelo + .2, kps                 ; amplitude offset = .2 
a1  dcblock a1
a2  dcblock   a2
outs a1*.00002, a2                                ; left = scanned synth, rigth = sawwave

endin

</CsInstruments>
<CsScore>
; Initial displacement condition
;f1 0 128 -7 0 64 1 64 0 ; ramp shape
;f1 0 128 10 1 ; sine shape
f1 0 128 -7 0 28 0 2 1 2 0 96 0     ; a pluck that is 10 points wide on the surface
f2 0 128 -7 1 128 1                 ; Masses
f3 0 16384 -23 "string-128.matrxB"  ; Spring matrix

; Centering force
f4 0 128 -7 1 128 1 ; uniform initial centering
;f4 0 128 -7 .001 128 1             ; ramped centering

; Damping
f5 0 128 -7 1 128 1                 ; uniform damping
;f5 0 128 -7 .1 128 1               ; ramped 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
f7 0 128 -5 .001 128 128            ; trajectory

i"scan" 0 10 90 7.00 1             ; p6 = change amplitude of kvelo value      
i"scan" 12 10 90 7.00 10
e
</CsScore>
</CsoundSynthesizer>

and the 2 notes look like this: Screenshot from 2022-02-21 13-57-42

As a side note, it looks like Scanned is not "made" for 0dfs=1 when you look at the line: outs a1*.00002, a2 ?

Furthermore, i'd like to rename a few arguments, from kpos, kvel scanmap iscan, kamp, kvamp [, iwhich] to kpos, kvel scanmap id, kposamp, kvelamp [, iwhich]

tjingboem commented 2 years ago

...slowly getting back to scanned...

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc for RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o scanmap.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr scannode

a0 init 0
irate = .01

kpos line 0, p3, 128
; scanu init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass,
;       kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id
scanu2 1, irate, 6, 2, 3, p5, 5, 2, 9, .01, .01, .1, .9, 0, 0, a0, 0, 2
kpos,kvel scanmap 2, 100, 1, p4     ; amplify the kpos value 100 times
display  kpos, .25                  ; display is updated every .25 of a second
 ;     printk2 k1
asig poscil .3, 400+kpos            ; use moving position of the node 
outs asig, asig
endin

</CsInstruments>
<CsScore>
f1 0 128 10 1                       ; Initial displacement condition: sine
f2 0 128 -7 1 128 1                 ; Masses
f3 0 16384 -23 "string-128.matrxB"  ; Spring matrices

;-------------------------------------
; 2 different Centering forces
f44 0 128 -7 1 128 1                ; uniform initial centering
f4 0 128 -7 .001 128 1              ; ramped centering
;-------------------------------------
f5 0 128 -7 1 128 1                 ; uniform damping
f6 0 128 -7 .01 128 .01             ; uniform initial velocity
f7 0 128 -5 .001 128 128            ; Trajectories

s
i"scannode" 0 10 0      4           ; uniform initial centering
i"scannode" 11 10 64    4           ; reading 3 nodes
i"scannode" 21 10 128   4           ; 0 - 64 - 128
s
i"scannode" 0 10 0      44          ; ramped centering          
i"scannode" 11 10 64    44          ; reading 3 nodes
i"scannode" 21 10 128   44          ; 0 - 64 - 128

e
</CsScore>
</CsoundSynthesizer>
tjingboem commented 1 year ago

i think final example using matrxB

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc for RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o scanmap_matrxB.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr scannode

a0 init 0
irate = .001
; scanu init, irate, ifndisplace, ifnmass, ifnmatrix, ifncentr, ifndamp, kmass,
;       kmtrxstiff, kcentr, kdamp, ileft, iright, kpos, kdisplace, ain, idisp, id
scanu2 1, irate, 6, 2, 3, p5, 5, 2, 9, .01, .01, .1, .9, 0, 0, a0, 0, 2
kpos,kvel scanmap 2, 100,1, p4     ; amplify the kpos value 100 times
display  kpos, .25                  ; display is updated every .25 of a second
asig poscil .5+kvel, 150+kpos       ; use moving velocity and position of the node 
outs asig, asig
endin

</CsInstruments>
<CsScore>
f1 0 128 10 1                       ; Initial displacement condition: sine
f2 0 128 -7 1 128 1                 ; Masses
f3 0 16384 -23 "string-128.matrxB"  ; Spring matrices

;-------------------------------------
; 2 different Centering forces
f44 0 128 -7 1 128 1                ; uniform initial centering
f4 0 128 -7 .001 128 1              ; ramped centering
;-------------------------------------
f5 0 128 -7 1 128 1                 ; uniform damping
f6 0 128 -7 .01 128 .01             ; uniform initial velocity
f7 0 128 -5 .001 128 128            ; Trajectory

s;                node
i"scannode" 0 10   0    4           ; uniform initial centering ramped centering
i"scannode" 11 10  64   4           ; reading 3 nodes
i"scannode" 22 10 127   4           ; 0 - 64 - 127
s;                node
i"scannode" 0 10   0    44          ; uniform initial centering          
i"scannode" 11 10  64   44          ; reading 3 nodes
i"scannode" 22 10 127   44          ; 0 - 64 - 127

e
</CsScore>
</CsoundSynthesizer>
tjingboem commented 1 year ago

implemented