Debian Codegraph @

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