Debian Codegraph @

src/Examples/CsoundQt/Synths/Scanned_Synthesis_Sandbox.csd

raw
1 A demo and "Sandbox" for getting started with scanned synthesis.
2
3 Many comments from experiences are added to the code (see instrument "sound" and tables in the score.
4
5 Meant to be run in CsoundQt but the code can be used also in other ways.
6
7 By Tarmo Johannes [email protected] 2013/2016
8
9 <CsoundSynthesizer>
10 <CsOptions>
11 -odac
12 ;-d ; ucomment if you don't want to have output about tables and fft analyse
13 </CsOptions>
14 <CsInstruments>
15
16 sr = 44100
17 ksmps = 32
18 nchnls = 2
19 0dbfs = 1
20
21 chn_k "preset",3
22
23 giTest filelen "../../SourceMaterials/circularstring-128"; to check if it is found, otherwise it will crash scanu in runtime
24
25 ; presets: every preset consist of 5 parameters: fninit, scanning rate, fnmass, fncentr, fn_scanning_trajectory (all of then are table numbers, expect scanning rate)
26
27 giPresets ftgen 0,0,256,-2, \
28 18, 0.03, 22, 40, 71, \ ; preset no 1 for instr preset_call, index 0 in table
29 10, 0.02, 20, 40, 70, \
30 16, 0.01, 21, 40, 71, \
31 12, 0.2, 21, 40, 72, \
32 12, 0.2, 21, 40, 72, \
33 14, 0.002, 22, 42, 72, \
34 19, 0.12, 20, 40, 73, \
35 11, 0.01, 23, 42, 71, \
36 14, 0.003, 22, 43, 74, \
37 19, 0.1, 25, 41, 70, \
38 13, 0.05, 20, 41, 70, \ ; preset 11
39 11, 0.1, 23, 42, 72, \
40 12, 0.3, 25, 42, 70,\
41 14, 0.001, 22, 43, 74, \
42 12, 0.005, 20, 40, 74,\
43 10, 0.01, 22, 41, 74, \
44 12, 0.008, 21, 42, 72, \
45 14, 0.002, 21, 42, 72, \
46 14, 0.002, 21, 40, 72,\
47 14, 0.1, 20, 40, 72,\
48 17, 0.02, 21, 40,72 ,\ ; preset 21
49 15, 0.012, 22,43,70,\
50 18, 0.43, 20, 40, 72,\
51 10, 0.02, 20, 40, 70, \
52 16, 0.015, 22, 41, 71, \
53 12, 0.235, 20, 40, 73, \
54 13, 0.188, 21, 43, 70, \
55 14, 0.0025, 21, 42, 73, \
56 15, 0.128, 20, 41, 73, \
57 18, 0.122, 20, 42, 73 ; 30
58
59
60 ; helping instrument to enable to change preset by midi CC 1
61 alwayson "midireader" ; comment out, if you don't use MIDI control
62 instr midireader
63 kvalue ctrl7 1,1,1,30
64 kvalue = int(kvalue)
65 if (changed(kvalue)==1) then
66 ;printk2 kvalue
67 chnset kvalue, "preset"
68 endif
69 endin
70
71 ; instrument for generating wav files from scanned sounds
72 ; schedule "make_files",0,10,11, 7.07 ; vali 5.07, 7.02
73 ; 10 5.00 5
74 instr make_files
75 icount = 10
76 idur = p3
77 ifreq = p5
78 ibase = p4 ;1 ; 11, 21
79 index = 0
80 looppoint:
81 schedule "preset_call", index*idur+1, idur, -10, ifreq, index+ibase, 21+index
82 loop_lt index, 1, icount, looppoint
83 endin
84
85
86
87 instr preset_call, 1 ; instrument to read data from presets and start sounding instrument. Can be played also from MIDI keyboard
88
89 iamp = (p4<0) ? p4 : dbfsamp( ampmidi(0.6)) ; in dbFS (NB!if given by parameter, should be <0, otherwise MIDI velocity does not work)
90 ifreq = (p5>0) ? cpspch(p5) : cpsmidi() ; given as 8.05 etc. Or from Midi
91 inr = (p6==0) ? chnget:i("preset")-1 : p6-1 ; preset numbers -> index
92 ifileindex = p7 ; if set, forfard it to sound instrument to record the sound with name sounds/soundin.<index>
93 print iamp, ifreq, inr
94 ip1 tab_i inr*5+0, giPresets
95 ip2 tab_i inr*5+1, giPresets
96 ip3 tab_i inr*5+2, giPresets
97 ip4 tab_i inr*5+3, giPresets
98 ip5 tab_i inr*5+4, giPresets
99
100 ;event_i "i","sound",0,p3,iamp,ip1,ip2,ip3,ip4,ip5,ifreq, ifileindex
101 ascanned subinstr "sound", iamp,ip1,ip2,ip3,ip4,ip5,ifreq, ifileindex ; subinstr to be able to play from MIDI
102 outs ascanned, ascanned
103 dispfft ascanned, 0.1, 1024;, 0, 0
104 endin
105
106 instr sound
107 iamp= ampdbfs(p4)
108 ; see manual for scanu about the parameters
109 ; see below by the table deifinitions for comments
110
111 iinit = p5
112 irate = (p6 == 0) ? 0.01 : p6 ; do not allow 0!
113 ; irate - essential influence to the soud. If bigger value, less ondulations, more stable sound. Smaller value - often more interesting (try something like 0.001..0.3)
114
115 ifnvel = 60
116 ifnmass = p7
117 ifnstif = 30 ; matrix of the
118 ifncentr = p8
119 ifndamp = 50
120
121 kmass = 1 ; k-parameters influence the sound supprosingly little (whwn changed in runtime. The most influence I heard by changing kstif
122 kstif = .1
123 kcentr = .1
124 kdamp = -0.001 ; you can make the sound to grow -small positive values (!avoid exploding)- or dampen ( use small negative values)
125 ileft = 0.1 ; did not make so much difference for me
126 iright = 0.5
127 kpos = 0
128 kstrngth = 0
129
130 idisp = 0
131 id = 2
132 itraj = p9
133
134 ifreq = p10
135 ain = 0 ; a nice effect to use some band filtered white noise as ain- works a little bit like EQ boost, but more interesting. Other "beautiful" signals got too cracling for me and the mixture was not so interesting.
136
137 scanu iinit, irate, ifnvel, ifnmass, ifnstif, ifncentr, ifndamp, kmass, kstif, kcentr, kdamp, ileft, iright, kpos, kstrngth, ain, idisp, id
138
139 kenv madsr 0.1,0.1,0.8,0.5
140 a1 scans iamp*kenv, ifreq, itraj, id
141
142 ifileindex = p11
143 if (ifileindex>0) then
144 Sfilename sprintf "sounds/soundin.%d",ifileindex
145 fout Sfilename,4,a1
146 endif
147
148
149 outs a1,a1
150 endin
151
152
153 </CsInstruments>
154 <CsScore>
155
156 ; Initial condition, sometimes said as the shape of "hammerhead" striking against the string - MAJOR INFLUENCE TO SOUND
157 f 10 0 128 7 1 128 0.001 ; With gen7 cleaner beginning than gen5. Gen5 - more overtones
158 f 11 0 128 10 1 0.3 0.2 0.1 ; sine- quite interesting, a lot of overtones, use irate something like 0.05
159 f 12 0 128 20 4 5 7 ;blackman window, intresting also with other forms of gen20
160 f 13 0 128 7 0 40 0.75 42 0.28 36 0.66 10 1 ; different zig-zagd
161 f 14 0 128 7 0.99 35 0.02 27 0.99 20 0.03 46 1
162 f 15 0 128 7 0.99 33 1 28 0.99 20 0.03 15 1 31 1
163 f 16 0 128 7 0 52 0.3 44 0.65 28 0.01 4 1
164 f 17 0 128 7 0 15 0.57 37 0.3 5 0.68 38 0.65 3 0.95 19 0.72 10 1
165 f 18 0 128 7 0 6 0 6 0.51 6 0 40 0 8 0.99 5 0 22 0 10 0.58 6 0 18 0
166 f 19 0 128 5 0.001 128 1 ; exponent up
167
168 ; Masses
169 f 20 0 128 -7 1 128 1 ; OK, if all equal. More interesting if first masses smaller. For example 0.3..0.8
170 ; If masses over 1, the sound is denser and more harmonics.; ; interesting also like 10..12
171 f 21 0 128 -7 0.3 128 0.8
172 f 22 0 128 -7 1 128 1.5
173 f 23 0 128 -7 10 128 12
174 f 24 0 128 -7 1 128 0.2
175 f 25 0 128 -7 10 128 1
176
177 ; Spring matrices
178 f 30 0 16384 -23 "../../SourceMaterials/circularstring-128"
179 ; original: "string-128.matrix"
180 ; grid - quite interesting; string and torus - not big difference
181 ; full - does not function well
182 ; circular - more overtones, spectrum more even that with string
183 ; spiral - quite interesting, buzz-like, many samples out of range
184
185 ; Centering force
186 f 40 0 128 -7 0.01 128 2 ;quite interesting when decreasing - 1..0 - a lot of harmoncis. 0..1 - cleaner sound; all 0 - relatively; kui 0..0.1, more subtle, higher sounding
187 ; quite interesting very small: 0..0.25
188 f 41 0 128 -7 1 128 0
189 f 42 0 128 -7 0 128 0.1
190 f 43 0 128 -5 1 64 0.5 64 1 ; exponent curve down
191 f 44 0 128 -5 0.1 64 0.5 64 0.1 ; eksponent wave
192
193
194 ; Damping
195 f 50 0 128 -7 1 128 1 ;64 1 0 0 64 0 ;1 128 1 ; interesting, if some parts 0 ; does not incluence much 1..1 OK
196
197 ; Initial velocity
198 f 60 0 128 -7 0 128 0 ; 0 128 20 1 ;0 128 -7 0 64 0.5 64 0 ;128 0.8 ; dangerous - can explode. ; gen20 - interesting ;everything 0 - is OK,
199
200 ; Scanning trajectories ; the numbers may not exeed of the number of pints in matrix
201 f 70 0 128 -5 1 64 127 64 1 ; forst half back and forth
202 f 71 0 128 -7 1 128 127 ; mas by mass
203 f 72 0 128 -20 1 127 ; Hanning - interesting
204 f 73 0 128 -7 1 40 92 42 20 36 120 10 127 ; zigzag
205 f 74 0 128 -7 127 40 32 42 64 36 16 10 1
206
207
208 f0 3600 ; wait for live events
209
210 ; preset_call start dur amp freq preset_no
211 ;i "preset_call" 0 4.5 -10 6.00 1
212 ;i . 4 4.5 . 6.02 2
213 ;i . 8 4.5 . 6.00 6
214 ;i . 11 4.5 . 6.04 3
215 ;i . 14 18.5 . 6.03 4
216
217
218 ;i . + . . . 2
219 ;i . + . . . 3
220 ;i . + . . . 4
221 ;etc
222
223
224 </CsScore>
225
226
227 </CsoundSynthesizer>
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262 <bsbPanel>
263 <label>Widgets</label>
264 <objectName/>
265 <x>0</x>
266 <y>0</y>
267 <width>493</width>
268 <height>594</height>
269 <visible>true</visible>
270 <uuid/>
271 <bgcolor mode="background">
272 <r>80</r>
273 <g>80</g>
274 <b>80</b>
275 </bgcolor>
276 <bsbObject version="2" type="BSBLabel">
277 <objectName/>
278 <x>6</x>
279 <y>11</y>
280 <width>479</width>
281 <height>250</height>
282 <uuid>{631d7941-597e-4fe7-b562-bde75ce8db38}</uuid>
283 <visible>true</visible>
284 <midichan>0</midichan>
285 <midicc>0</midicc>
286 <description/>
287 <label>Scanned synthesis sandbox for experiments
288
289 Press Live Events for tweaking different parameteres
290
291 You can also choose preset from widget and press "On/Off" button to hear the sound.
292
293 Or play using MIDI keyboard or Virtual MIDI keyboard
294
295 See csd for comments about different parameters.
296
297 Have fun!
298
299 tarmo</label>
300 <alignment>left</alignment>
301 <valignment>top</valignment>
302 <font>Liberation Sans</font>
303 <fontsize>14</fontsize>
304 <precision>3</precision>
305 <color>
306 <r>235</r>
307 <g>235</g>
308 <b>235</b>
309 </color>
310 <bgcolor mode="nobackground">
311 <r>255</r>
312 <g>255</g>
313 <b>255</b>
314 </bgcolor>
315 <bordermode>false</bordermode>
316 <borderradius>1</borderradius>
317 <borderwidth>0</borderwidth>
318 </bsbObject>
319 <bsbObject version="2" type="BSBSpinBox">
320 <objectName>preset</objectName>
321 <x>78</x>
322 <y>368</y>
323 <width>54</width>
324 <height>25</height>
325 <uuid>{8bab02d9-3429-4e68-bbc2-c5636353bc1f}</uuid>
326 <visible>true</visible>
327 <midichan>0</midichan>
328 <midicc>0</midicc>
329 <description/>
330 <alignment>left</alignment>
331 <font>Liberation Sans</font>
332 <fontsize>10</fontsize>
333 <color>
334 <r>0</r>
335 <g>0</g>
336 <b>0</b>
337 </color>
338 <bgcolor mode="background">
339 <r>255</r>
340 <g>255</g>
341 <b>255</b>
342 </bgcolor>
343 <resolution>1.00000000</resolution>
344 <minimum>1</minimum>
345 <maximum>30</maximum>
346 <randomizable group="0">false</randomizable>
347 <value>30</value>
348 </bsbObject>
349 <bsbObject version="2" type="BSBLabel">
350 <objectName/>
351 <x>13</x>
352 <y>367</y>
353 <width>58</width>
354 <height>25</height>
355 <uuid>{f99002b6-bed6-4f13-bb57-b9b80b2c9da0}</uuid>
356 <visible>true</visible>
357 <midichan>0</midichan>
358 <midicc>-3</midicc>
359 <description/>
360 <label>Preset: </label>
361 <alignment>left</alignment>
362 <valignment>top</valignment>
363 <font>Liberation Sans</font>
364 <fontsize>10</fontsize>
365 <precision>3</precision>
366 <color>
367 <r>235</r>
368 <g>235</g>
369 <b>235</b>
370 </color>
371 <bgcolor mode="nobackground">
372 <r>255</r>
373 <g>255</g>
374 <b>255</b>
375 </bgcolor>
376 <bordermode>false</bordermode>
377 <borderradius>1</borderradius>
378 <borderwidth>0</borderwidth>
379 </bsbObject>
380 <bsbObject version="2" type="BSBButton">
381 <objectName>button3</objectName>
382 <x>146</x>
383 <y>366</y>
384 <width>100</width>
385 <height>30</height>
386 <uuid>{b7ed5a76-2c06-4e35-988e-630c6e7c38d8}</uuid>
387 <visible>true</visible>
388 <midichan>0</midichan>
389 <midicc>0</midicc>
390 <description/>
391 <type>event</type>
392 <pressedValue>1.00000000</pressedValue>
393 <stringvalue/>
394 <text>Note On/Off</text>
395 <image>/</image>
396 <eventLine>i1 0 -1 -10 8.00 0 0</eventLine>
397 <latch>true</latch>
398 <momentaryMidiButton>false</momentaryMidiButton>
399 <latched>false</latched>
400 <fontsize>10</fontsize>
401 </bsbObject>
402 <bsbObject version="2" type="BSBGraph">
403 <objectName/>
404 <x>14</x>
405 <y>401</y>
406 <width>369</width>
407 <height>193</height>
408 <uuid>{9d6c9171-d93b-4630-8cd4-ee4992293e89}</uuid>
409 <visible>true</visible>
410 <midichan>0</midichan>
411 <midicc>-3</midicc>
412 <description/>
413 <value>0</value>
414 <objectName2/>
415 <zoomx>1.00000000</zoomx>
416 <zoomy>1.00000000</zoomy>
417 <dispx>1.00000000</dispx>
418 <dispy>1.00000000</dispy>
419 <modex>lin</modex>
420 <modey>lin</modey>
421 <showSelector>true</showSelector>
422 <showGrid>true</showGrid>
423 <showTableInfo>true</showTableInfo>
424 <showScrollbars>true</showScrollbars>
425 <enableTables>true</enableTables>
426 <enableDisplays>true</enableDisplays>
427 <all>true</all>
428 </bsbObject>
429 <bsbObject version="2" type="BSBLabel">
430 <objectName/>
431 <x>8</x>
432 <y>271</y>
433 <width>480</width>
434 <height>86</height>
435 <uuid>{be249736-2965-4218-b915-49f2cad28998}</uuid>
436 <visible>true</visible>
437 <midichan>0</midichan>
438 <midicc>-3</midicc>
439 <description/>
440 <label>Change preset by the spinbox below or (Virtual) Midi controller Channel 1, CC 1 (mostly modulator wheel).
441
442 New presets apply to new notes, no infulence during playing time.</label>
443 <alignment>left</alignment>
444 <valignment>top</valignment>
445 <font>Liberation Sans</font>
446 <fontsize>10</fontsize>
447 <precision>3</precision>
448 <color>
449 <r>235</r>
450 <g>235</g>
451 <b>235</b>
452 </color>
453 <bgcolor mode="nobackground">
454 <r>255</r>
455 <g>255</g>
456 <b>255</b>
457 </bgcolor>
458 <bordermode>false</bordermode>
459 <borderradius>1</borderradius>
460 <borderwidth>0</borderwidth>
461 </bsbObject>
462 <bsbObject version="2" type="BSBLabel">
463 <objectName/>
464 <x>394</x>
465 <y>398</y>
466 <width>99</width>
467 <height>179</height>
468 <uuid>{6a631529-6fa3-4414-8c12-4d6cd39b1320}</uuid>
469 <visible>true</visible>
470 <midichan>0</midichan>
471 <midicc>-3</midicc>
472 <description/>
473 <label>Have a look at the FFT display (last one in menu)</label>
474 <alignment>left</alignment>
475 <valignment>top</valignment>
476 <font>Liberation Sans</font>
477 <fontsize>10</fontsize>
478 <precision>3</precision>
479 <color>
480 <r>235</r>
481 <g>235</g>
482 <b>235</b>
483 </color>
484 <bgcolor mode="nobackground">
485 <r>255</r>
486 <g>255</g>
487 <b>255</b>
488 </bgcolor>
489 <bordermode>false</bordermode>
490 <borderradius>1</borderradius>
491 <borderwidth>0</borderwidth>
492 </bsbObject>
493 </bsbPanel>
494 <bsbPresets>
495 </bsbPresets>
496 <EventPanel name="tweak parameters of isntr sound" tempo="60.00000000" loop="8.00000000" x="442" y="697" width="655" height="346" visible="false" loopStart="0" loopEnd="0">; ; ; ; ;amp dbFS ;init ;irate ;massed ;centering ;scanning trajectory ;freq
497 i "sound" 0 5 -10 18 0.43 20 40 72 261
498 i . 1 . . . . . . . 100
499 i . 2 . . . . . . . 200
500 i . 3 . . . . . . . 400
501 i . 4 . . . . . . . 800
502 i . 5 . . . . . . . 2000 </EventPanel>
503 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="120" y="455" width="655" height="346" visible="false" loopStart="0" loopEnd="0">; ; ; ; ;amp ;freq ;preset ;save file
504 i "preset_call" 0 4 -10 8.07 3 0
505 ; viimane oli preset 8 </EventPanel>