· 4 years ago · Feb 18, 2021, 09:00 PM
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <title>Canvas Boilerplate | Chris Courses</title>
6 <style>
7 body {
8 margin: 0;
9 }
10 </style>
11 <style type="text/css">
12 html,
13 body {
14 font-family: Monospace;
15 color: #000000;
16 background-color: #ffffff;
17 }
18
19 #console {
20 font-family: Monospace;
21 color: #b5b6ff;
22 background-color: #000000;
23 font-size: 16px;
24 width: 805px;
25 display: flex;
26 align-items: center;
27 justify-content: center;
28 border-style: solid;
29 padding: 20px 0px;
30 }
31
32 H1 {
33 font-size: 36px;
34 }
35
36 #controls {
37 width: 100px;
38 font-size: 16px;
39 text-align:center
40 }
41
42 input[type=range] {
43 height: 10px;
44 -webkit-appearance: none;
45 margin: 10px 0;
46 width: 100%;
47 background: #ffffff;
48 }
49
50 input[type=range]:focus {
51 outline: none;
52 }
53
54 input[type=range]::-webkit-slider-runnable-track {
55 width: 100%;
56 height: 10px;
57 cursor: pointer;
58 animate: 0.2s;
59 box-shadow: 0px 0px 0px #000000;
60 background: #ffffff;
61 border-radius: 25px;
62 border: 1px solid #000000;
63 position: relative;
64 }
65 /*
66 input[type=range]::-webkit-slider-thumb {
67 box-shadow: 1px 1px 1px #000000;
68 border: 1px solid #000000;
69 height: 15px;
70 width: 20px;
71 border-radius: 6px;
72 background: #c0c0c0;
73 cursor: pointer;
74 -webkit-appearance: none;
75 margin-top: -5px;
76 position: relative;
77 }
78
79 input[type=range]:focus::-webkit-slider-runnable-track {
80 background: #b5b6ff;
81 position: relative;
82 }
83 */
84
85 #pause {
86 margin: auto;
87 font-family: Monospace;
88 width: 80px;
89 padding: 10px 0px;
90 font-size: 24px;
91 background-color: #b5b6ff;
92 }
93 </style>
94 <title>WebAudio Csound</title>
95 <script src="js/CsoundObj.js"></script>
96 <script type="text/javascript">
97 // this will get called when WASM is loaded
98 function moduleDidLoad() {
99 clear_console();
100 console.log = print_msg;
101 console.warn = print_msg;
102 csound = new CsoundObj();
103 csound.setMessageCallback(print_msg);
104 csound.compileOrc(document.getElementById('instruments').value);
105 attachListeners();
106 window.addEventListener("unload", function(e) {
107 if (csound != null)
108 csound.destroy();
109 }, false);
110 }
111
112 // clear console
113 function clear_console() {
114 var element = document.getElementById('console');
115 element.value = ' ';
116 document.getElementById('pause').
117 addEventListener('click', pause);
118 }
119
120 // print to console
121 var count = 0;
122
123 function print_msg(message) {
124 var element = document.getElementById('console');
125 element.value += (message + "\n");
126 element.scrollTop = 99999; // focus on bottom
127 count += 1;
128 if (count == 1000) {
129 clear_console();
130 count = 0;
131 }
132 }
133
134 // set parameter
135 function SetParam(name, label, scal, off) {
136 var val = document.getElementById(name).value / scal + off;
137 csound.setControlChannel(name, val);
138 console.log(name + ": " + val + " " + label);
139 }
140
141 var paused = true;
142 var started = false;
143
144 function pause() {
145 if (paused == false) {
146 csound.stop();
147 console.log("pause");
148 document.getElementById('pause').
149 innerText = 'play';
150 paused = true;
151 } else {
152 if (started == false) {
153 CsoundObj.CSOUND_AUDIO_CONTEXT.resume();
154 started = true;
155 }
156 csound.start();
157 document.getElementById('pause').
158 innerText = 'pause';
159 console.log("play");
160 paused = false;
161 }
162 }
163
164 CsoundObj.initialize().then(() => {
165 moduleDidLoad();
166 });
167 </script>
168 <link rel="icon" href="favicon.ico"></head>
169 <body>
170 <canvas></canvas>
171
172 <textarea class="console" cols="55" rows="16" id="console" style="position: absolute; top: 450px; left: 0px">
173 loading...</textarea>
174 <p>
175 <button type="button" id="pause" style="position: absolute; top: 400px; left: 0px"> play </button>
176 </p>
177 <textarea class="code" id="instruments" hidden>
178 /* this is the synthesis code
179 for this example
180 */
181 // Initialize the global variables.
182 ksmps = 32
183 nchnls = 2
184 0dbfs = 1
185
186 // STARTING THE DIFFERNT INSRUMENTS
187 // GLobal Controller Instrument
188
189 // Granular Instrument
190 schedule 2, 0, -1
191
192 // Spectral Instruments
193// schedule 11, 0, -1
194// schedule 12, 0, -1
195// schedule 13, 0, -1
196
197 // Noise Percussion
198 schedule 21, 0, -1
199 schedule 23, 0, -1
200
201 // Paulstretch
202// schedule 31, 0, -1
203
204 // Guitar pluck
205 schedule 41, 0, -1
206 schedule 43, 0, -1
207
208 // Bass-tone
209 schedule 51, 0, -1
210 schedule 53, 0, -1
211
212 // Low-frequent noise
213// schedule 61, 0, -1
214
215
216 // Master instrument
217 schedule 99, 0, -1
218
219
220 //##################################################################################
221 //TEST INSTRUMENT
222 schedule 98, 0, -1
223 //##################################################################################
224
225 // INIT GLOBAL VARIABLES
226 //##################################################################################
227 //GRANULAR
228 ; classic waveforms
229 giSine ftgen 0, 0, 65537, 10, 1 ; sine wave
230 giCosine ftgen 0, 0, 8193, 9, 1, 1, 90 ; cosine wave
231 giTri ftgen 0, 0, 8193, 7, 0, 2048, 1, 4096, -1, 2048, 0 ; triangle wave
232
233 ; grain envelope tables
234 giSigmoRise ftgen 0, 0, 8193, 19, 0.5, 1, 270, 1 ; rising sigmoid
235 giSigmoFall ftgen 0, 0, 8193, 19, 0.5, 1, 90, 1 ; falling sigmoid
236 giExpFall ftgen 0, 0, 8193, 5, 1, 8193, 0.00001 ; exponential decay
237 giTriangleWin ftgen 0, 0, 8193, 7, 0, 4096, 1, 4096, 0 ; triangular window
238
239 // Panning table
240 giPan ftgen 0, 0, 32768, -21, 1 // for panning (random values between 0 and 1)
241
242 //##################################################################################
243 // SPECTRAL PROCCESING
244 // live input buffer table for granular effects processing
245 giLiveFeedLen = 131072 ; 2.95 seconds buffer at 44.1
246 giLiveFeedLenSec = giLiveFeedLen/sr
247 giLiveFeed ftgen 0, 0, giLiveFeedLen+1, 2, 0
248
249 // TEMP AUDIO IN
250 //giFile1 ftgen 0, 0, 0, 1, "water.wav", 0, 0, 0 // soundfile for source waveform
251 //giFile2 ftgen 0, 0, 0, 1, "granulartest.wav", 0, 0, 0 // soundfile for source waveform
252 //##################################################################################
253 // Audio in Paulstretch
254 //giwav ftgen 0, 0, 0, 1, "SS_BRE2_85_keys_loop_kit01_evening_piano_dm.wav", 0, 0, 1
255 //##################################################################################
256
257
258
259
260 //##################################################################################
261 // PARAMETER INSTRUMENT
262 instr 1
263 // LFO1 - GRAINS
264 gklfo_1 lfo 10, 100
265 gklfo_1 += 10
266
267 // LFO2 - FREEZE
268 gklfo_2 lfo 2, 0.02
269 gklfo_2 += 2.5
270
271 // LFO3 - FILTER
272 gklfo_3 lfo 1, 0.04
273 gklfo_3 += 1.01
274
275 // LFO4 - REVERB
276 gklfo_4 lfo 0.05, 0.01
277 gklfo_4 += 0.92
278
279 chnset gklfo_1, "Planet_1"
280 chnset gklfo_2, "Planet_2"
281 chnset gklfo_3, "Planet_3"
282 chnset gklfo_4, "Planet_4"
283
284 gkPlanet_1 chnget "Planet_4"
285
286 endin
287/*
288 //##################################################################################
289 // GRANULAR CONTROLLER INSTRUMENT
290 instr 2
291 // Button on and trigger mechanism
292 kbutton chnget "Granular_on"
293 kbutton = p4 // temp test solution, range 0 (off) - 1 (on)
294 ktrigon trigger kbutton, 0.5, 0
295 ktrigoff trigger kbutton, 0.5, 1
296
297 //ktrigger metro 1
298 //ktrigger = ktrigger // triggers a new score event. If ktrigger = 0, no new event is triggered.
299 kmintim = 0 // minimum time between generated events, in seconds. If kmintim <= 0, no time limit exists. If the kinsnum is negative (to turn off an instrument), this test is bypassed.
300 kmaxnum = 1 // maximum number of simultaneous instances of instrument kinsnum allowed.If the number of existant instances of kinsnum is >= kmaxnum, no new event is generated. If kmaxnum is <= 0, it is not used to limit event generation. If the kinsnum is negative (to turn off an instrument), this test is bypassed.2 = kinsnum = 2// instrument number. Equivalent to p1 in a score i statement.
301 kinsnum = 3 //instrument number
302 kwhen = 0 // start time of the new event. Equivalent to p2 in a score i statement. Measured from the time of the triggering event. kwhen must be >= 0. If kwhen > 0, the instrument will not be initialized until the actual time when it should start performing.
303 kDuration = -1 // starts the granular instrument and keeps a "sustaned note" untill it is turned off
304
305 //p-fields
306 kspeed = 1 // 1 = original speed *** STYRE FRA INTERFACE
307 kGrainRate = 5 //= 4 // grain rate *** STYRE FRA INTERFACE
308 kgrainsize = 250 // grain size in ms *** STYRE FRA INTERFACE
309 kcent = 0 // transposition in cent *** STYRE FRA INTERFACE
310 kposrand = 1 // time position randomness (offset) of the pointer in ms
311 kcentrand = 1200 // transposition randomness in cents *** STYRE FRA INTERFACE
312 kpan = 1 // panning narrow (0) to wide (1)
313 kdist = 0 // grain distribution (0=periodic, 1=scattered) *** STYRE FRA INTERFACE
314
315 schedkwhen ktrigon, kmintim, kmaxnum, kinsnum, kwhen, kDuration,\
316 kspeed, kGrainRate, kgrainsize, kcent, kposrand, kcentrand, kpan, kdist
317
318 schedkwhen ktrigoff, kmintim, kmaxnum, -kinsnum, kwhen, kDuration,\
319 kspeed, kGrainRate, kgrainsize, kcent, kposrand, kcentrand, kpan, kdist
320
321 endin
322*/
323
324 // GRANULAR INSTRUMENT
325 instr 2
326
327 ; select source waveform
328 kwaveform1 = giSine ; source audio waveform 1
329 kwaveform2 = giCosine ; source audio waveform 2
330 kwaveform3 = giTri ; source audio waveform 3
331 kwaveform4 = kwaveform1 ; source audio waveform 4
332
333 kwave1Single = 1 ; flag to set if waveform is single cycle (set to zero for sampled waveforms)
334 kwave2Single = kwave1Single ; flag to set if waveform is single cycle (set to zero for sampled waveforms)
335 kwave3Single = kwave1Single ; flag to set if waveform is single cycle (set to zero for sampled waveforms)
336 kwave4Single = kwave1Single ; flag to set if waveform is single cycle (set to zero for sampled waveforms)
337
338 ; get source waveform length (used when calculating transposition and time pointer)
339 kfilen1 tableng kwaveform1 ; get length of the first source waveform
340 kfilen2 tableng kwaveform2 ; same as above, for source waveform 2
341 kfilen3 tableng kwaveform3 ; same as above, for source waveform 3
342 kfilen4 tableng kwaveform4 ; same as above, for source waveform 4
343 kfildur1 = kfilen1 / sr ; length in seconds, for the first source waveform
344 kfildur2 = kfilen2 / sr ; same as above, for source waveform 2
345 kfildur3 = kfilen3 / sr ; same as above, for source waveform 3
346 kfildur4 = kfilen4 / sr ; same as above, for source waveform 4
347
348 ; original pitch for each waveform, use if they should be transposed individually
349 ; can also be used as a "cycles per second" parameter for single cycle waveforms (assuming that the kwavfreq parameter has a value of 1.0)
350// GRAIN PITCH
351 kPlanet_6_Y chnget "Planet_6_Y"
352 kPlanet_3_X chnget "Planet_3_X"
353
354 kwavekey1 = kPlanet_6_Y-kPlanet_3_X
355 kwavekey2 = 1
356 kwavekey3 = 1
357 kwavekey4 = 1
358
359 ; set original key dependant on waveform length (only for sampled waveforms, not for single cycle waves)
360 kwavekey1 = (kwave1Single > 0 ? kwavekey1 : kwavekey1/kfildur1)
361 kwavekey2 = (kwave2Single > 0 ? kwavekey2 : kwavekey2/kfildur2)
362 kwavekey3 = (kwave3Single > 0 ? kwavekey3 : kwavekey3/kfildur3)
363 kwavekey4 = (kwave4Single > 0 ? kwavekey4 : kwavekey4/kfildur4)
364
365 ; time pointer (phase). This can be independent for each source waveform.
366 isamplepos1 = 0 ; initial phase for wave source 1
367 isamplepos2 = 0 ; initial phase for wave source 2
368 isamplepos3 = 0 ; initial phase for wave source 3
369 isamplepos4 = 0 ; initial phase for wave source 4
370
371 kTimeRate = 1 ; time pointer rate
372 asamplepos1 phasor kTimeRate / kfildur1 ; phasor from 0 to 1, scaled to the length of the first source waveform
373 asamplepos2 phasor kTimeRate / kfildur2 ; same as above, scaled for source wave 2
374 asamplepos3 phasor kTimeRate / kfildur3 ; same as above, scaled for source wave 3
375 asamplepos4 phasor kTimeRate / kfildur4 ; same as above, scaled for source wave 4
376
377 ; mix initial phase and moving phase value (moving phase only for sampled waveforms, single cycle waveforms use static samplepos)
378 asamplepos1 = asamplepos1*(1-kwave1Single) + isamplepos1
379 asamplepos2 = asamplepos2*(1-kwave2Single) + isamplepos2
380 asamplepos3 = asamplepos3*(1-kwave3Single) + isamplepos3
381 asamplepos4 = asamplepos4*(1-kwave4Single) + isamplepos4
382
383 ;*******************************
384 ; granular synthesis parameters
385 ;*******************************
386
387 ; amplitude
388 kamp = ampdbfs(-5) ; output amplitude
389 ; sync
390 async = 0.0 ; set the sync input to zero (disable external sync)
391 ; grain rate
392 kPlanet_4_X chnget "Planet_4_X"
393 kGrainRate = (kPlanet_4_X+kPlanet_6_Y)/2000 ; number of grains per second
394 ; distribution
395 kdistribution = 1 ; grain random distribution in time
396 idisttab = -1// ftgentmp 0, 0, 16, 16, 1, 16, -10, 0 ; probability distribution for random grain masking
397 // Panning
398 ipan = 1
399 imid = .5// center
400 ileftmost = imid - ipan/2
401 irightmost = imid + ipan/2
402 giPanthis ftgen 0, 0, 32768, -24, giPan, ileftmost, irightmost // rescales giPan according to ipan
403 tableiw 0, 0, giPanthis // change index 0 ...
404 tableiw 32766, 1, giPanthis // ... and 1 for ichannelmasks
405 ichannelmasks = giPanthis // ftable for panning
406
407 ; grain rate FM
408 kGrFmFreq = kGrainRate/4 ; FM freq for modulating the grainrate
409 kGrFmIndex = 0.0 ; FM index for modulating the grainrate (normally kept in a 0.0 to 1.0 range)
410 iGrFmWave = giSine ; FM waveform, for modulating the grainrate
411 aGrFmSig oscil kGrFmIndex, kGrFmFreq, iGrFmWave ; audio signal for frequency modulation of grain rate
412 agrainrate = kGrainRate + (aGrFmSig*kGrainRate) ; add the modulator signal to the grain rate signal
413 ; grain shape
414 kPlanet_1_X chnget "Planet_1_X"
415 kGrainDur = kPlanet_1_X ; length of each grain relative to grain rate
416 kduration = (kGrainDur)/kGrainRate //(kGrainDur*1000)/kGrainRate ; grain dur in milliseconds, relative to grain rate
417
418 ienv_attack = giSigmoRise ; grain attack shape (from table)
419 ienv_decay = giSigmoFall ; grain decay shape (from table)
420 ksustain_amount = 0.0 ; balance between enveloped time(attack+decay) and sustain level time, 0.0 = no time at sustain level
421 ka_d_ratio = 0.5 ; balance between attack time and decay time, 0.0 = zero attack time and full decay time
422
423 kenv2amt = 0.0 ; amount of secondary enveloping per grain (e.g. for fof synthesis)
424 ienv2tab = giExpFall ; secondary grain shape (from table), enveloping the whole grain if used
425 ; grain pitch (transpose, or "playback speed")
426 /*transposition*/
427 kcent = 0 // transposition
428 kcentrand rand 1200 // random transposition
429 iorig = 1 // original pitch
430 kwavfreq = iorig * cent(kcent + kcentrand) ; transposition factor (playback speed) of audio inside grains,
431 ; pitch sweep
432 ksweepshape = 0.5 ; grain wave pitch sweep shape (sweep speed), 0.5 is linear sweep
433 iwavfreqstarttab = -1 // ftgentmp 0, 0, 16, -2, 0, 0, 1 ; start freq scalers, per grain
434 iwavfreqendtab = -1 // ftgentmp 0, 0, 16, -2, 0, 0, 1 ; end freq scalers, per grain
435 ; FM of grain pitch (playback speed)
436 kPtchFmFreq = 440 ; FM freq, modulating waveform pitch
437 kPtchFmIndex = 0 ; FM index, modulating waveform pitch
438 iPtchFmWave = giSine ; FM waveform, modulating waveform pitch
439 ifmamptab = -1// ftgentmp 0, 0, 16, -2, 0, 0, 1 ; FM index scalers, per grain
440 ifmenv = giTriangleWin ; FM index envelope, over each grain (from table)
441 kPtchFmIndex = kPtchFmIndex + (kPtchFmIndex*kPtchFmFreq*0.00001) ; FM index scaling formula
442 awavfm oscil kPtchFmIndex, kPtchFmFreq, iPtchFmWave ; Modulator signal for frequency modulation inside grain
443 ; trainlet parameters
444 icosine = giCosine ; needs to be a cosine wave to create trainlets
445 kTrainCps = kGrainRate ; set cps equal to grain freq, creating a single cycle of a trainlet inside each grain
446 knumpartials = 7 ; number of partials in trainlet
447 kchroma = 3 ; chroma, falloff of partial amplitude towards sr/2
448
449 ; masking
450 ; gain masking table, amplitude for individual grains
451 igainmasks = -1// ftgentmp 0, 0, 16, -2, 0, 0, 1
452
453 ; random masking (muting) of individual grains
454 kPlanet_2_X chnget "Planet_2_X"
455 krandommask = kPlanet_2_X/10000
456 ; wave mix masking.
457 ; Set gain per source waveform per grain,
458 ; in groups of 5 amp values, reflecting source1, source2, source3, source4, and the 5th slot is for trainlet amplitude.
459 iwaveamptab = -1// ftgentmp 0, 0, 32, -2, 0, 0, 1,0,0,0,0
460
461 ; system parameter
462 imax_grains = 100 ; max number of grains per k-period
463
464 // GRANULAR SYNTHESIS
465 aGrain_Out_L,aGrain_Out_R,a3,a4,a5,a6,a7,a8 partikkel \ ; (beginner)
466 kGrainRate, \ ; grains per second *
467 kdistribution, idisttab, async, \ ; synchronous/asynchronous
468 kenv2amt, ienv2tab, ienv_attack, ienv_decay, \ ; grain envelope (advanced)
469 ksustain_amount, ka_d_ratio, kduration, \ ; grain envelope *
470 kamp, \ ; amp *
471 igainmasks, \ ; gain masks (advanced)
472 kwavfreq, \ ; grain pitch (playback frequency) *
473 ksweepshape, iwavfreqstarttab, iwavfreqendtab, \ ; grain pith sweeps (advanced)
474 awavfm, ifmamptab, ifmenv, \ ; grain pitch FM (advanced)
475 icosine, kTrainCps, knumpartials, kchroma, \ ; trainlets
476 ichannelmasks, \ ; channel mask (advanced)
477 krandommask, \ ; random masking of single grains *
478 kwaveform1, kwaveform2, kwaveform3, kwaveform4, \ ; set source waveforms * (using only waveform 1)
479 iwaveamptab, \ ; mix source waveforms
480 asamplepos1, asamplepos2, asamplepos3, asamplepos4, \ ; read position for source waves * (using only samplepos 1)
481 kwavekey1, kwavekey2, kwavekey3, kwavekey4, \ ; individual transpose for each source
482 imax_grains ; system parameter (advanced)
483
484 chnset aGrain_Out_L, "Grain_Out_L"
485 chnset aGrain_Out_R, "Grain_Out_R"
486
487 endin
488 //##################################################################################
489
490
491
492
493 //##################################################################################
494 // SPECTRAL INSTRUMENT
495 //audio in
496 instr 11
497 aGrain_L chnget "Grain_Out_L"
498 aGrain_R chnget "Grain_Out_R" // TEMP NOT USED
499 chnset aGrain_L, "audio_in"
500 kmix chnget "mix" // HENTE FRA HTML
501 kdry = tonek(sqrt(1-kmix), 1)
502 aout = aGrain_L * kdry
503 endin
504
505
506 //record input to buffer
507 instr 12
508 a1 chnget "audio_in"
509 a0 = 0
510 chnset a0, "audio_in" ; clear audio chn
511 // FEEDBACK
512 a1Feed chnget "PVSPITCHED" // Feedback from PVS pitching
513 //kFeed chnget "feed" ; feedback gain
514 kFeed = 0 // temporary controll for feedback
515 a1 = a1 + (a1Feed*kFeed) ; mix feedback with live input
516
517 // write audio to table
518 iAudioTable = giLiveFeed
519 kstartFollow tablewa iAudioTable, a1, 0 ; write audio a1 to table
520 kstartFollow = (kstartFollow > giLiveFeedLen ? 0 : kstartFollow) ; reset kstart when table is full
521 tablegpw iAudioTable ; update table guard point (for interpolation)
522 chnset kstartFollow, "kstartFollow" ; output the buffer position to chn
523 endin
524
525
526 // BUFFER PLAYBACK
527 instr 13
528 kFrequency = 1//gkPlanet_2
529 kAmplitude = 1
530 //a1 ,a22 loscil kAmplitude, kFrequency, giFile1, 1, 1 // play audio from file
531
532 aindex phasor 1/giLiveFeedLenSec // read through buffer at the speed of the buffer
533 aBuffer table aindex, giLiveFeed, 1 // play audio from buffer
534
535
536 // outs aBuffer, aBuffer
537
538 // WINDOW DEFINITION
539 ifftsize = 8192 // The FFT size in samples.
540 ioverlap = ifftsize/16 // The distance in samples (“hop size”) between overlapping analysis frames
541 iwinsize = ifftsize // The size in samples of the analysis window filter
542 iwintype = 0 // The shape of the analysis window
543
544 // FFT-analysis
545 fsigin1 pvsanal aBuffer, ifftsize, ioverlap, iwinsize, iwintype
546 //fsigin2 pvsanal a1, ifftsize, ioverlap, iwinsize, iwintype
547
548
549 /*
550 // PVS PITCHING
551 kshift = 100 // shift amount (in Hz, positive or negative).
552 klowest = 0 // lowest frequency to be shifted.
553 kkeepform = 0 // attempt to keep input signal formants; 0: do not keep formants; 1: keep formants using a liftered cepstrum method; 2: keep formants by using a true envelope method (defaults to 0).
554 kgain = 1 // amplitude scaling (defaults to 1).
555 kcoefs = 80 // number of cepstrum coefs used in formant preservation (defaults to 80).
556 fsigin1PITCHED pvshift fsigin1, kshift, klowest, kkeepform, kgain, kcoefs
557 aSig1pitched pvsynth fsigin1PITCHED
558
559 chnset aSig1pitched, "PVSPITCHED"
560 */
561
562 // ALTERNATIVELY
563
564 // PVS SCALING
565 kscal = 2 // scaling ratio.
566 kkeepform = 0 // attempt to keep input signal formants; 0: do not keep formants; 1: keep formants using a liftered cepstrum method; 2: keep formants by using a true envelope method (defaults to 0).
567 kgain = 1 // amplitude scaling (defaults to 1).
568 kcoefs = 80 // number of cepstrum coefs used in formant preservation (defaults to 80).
569
570 fsigin1PITCHED pvscale fsigin1, kscal, kkeepform, kgain, kcoefs
571 aSig1pitched pvsynth fsigin1PITCHED
572 chnset aSig1pitched, "PVSPITCHED"
573
574
575
576 // PVS morph
577 kampint = 0.33 //lfo 0.5, 0.25 // Amplitude interpolation between fsig1 and fsig2
578 kfrqint lfo 0.5, 0.10 // Frequency interpolation between fsig1 and fsig2
579 fProccesedin pvsmorph fsigin1, fsigin1PITCHED, kampint, kfrqint+0.5
580
581 /*
582 // FREEZE
583 kfreq randomh .7, 1.1, 3; probability of freezing freqs: 1/4
584 kamp randomh .7, 1.1, 3; idem for amplitudes
585 fFreezed pvsfreeze fProccesedin, kamp, kfreq; freeze amps or freqs independently
586 */
587
588 // SMOOTH
589 iframetime = (ioverlap/sr) // time per fft frame rate
590 ktimeAmp = 0.8 // smoothing of amplitude
591 ktimeFreq = 0.1 // smoothing of frequency
592 //print iframetime
593 kamountAmp = iframetime/ktimeAmp // smoothing frequency (in fraction of 1/2 fft framerate)
594 kamountFreq = iframetime/ktimeFreq // smoothing frequency (in fraction of 1/2 fft framerate)
595 fProccesedout pvsmooth fsigin1, kamountAmp, kamountFreq
596
597 // ELLER BLUR
598
599 //resynthesis of pvs streams
600 aProccesed pvsynth fProccesedout
601
602 ; Audio out to master instrument
603 kSkal = 5.2
604 aout = aProccesed*kSkal
605
606 chnset aout, "Spectral_Out"
607
608 endin
609 //#################################################################################
610
611
612
613
614 //SYNTH CONTROLLER
615 instr 21
616
617 //Metronome
618 kmetroRandom random 0.1, 0.15
619 ktrigger metro kmetroRandom
620
621 kmintim = 0 // minimum time between generated events, in seconds. If kmintim <= 0, no time limit exists. If the kinsnum is negative (to turn off an instrument), this test is bypassed.
622 kmaxnum = 2 // maximum number of simultaneous instances of instrument kinsnum allowed. If the number of existant instances of kinsnum is >= kmaxnum, no new event is generated. If kmaxnum is <= 0, it is not used to limit event generation. If the kinsnum is negative (to turn off an instrument), this test is bypassed.2 = kinsnum = 2// instrument number. Equivalent to p1 in a score i statement.
623 kinsnum = 22 //instrument number
624 kwhen = 0 // start time of the new event. Equivalent to p2 in a score i statement. Measured from the time of the triggering event. kwhen must be >= 0. If kwhen > 0, the instrument will not be initialized until the actual time when it should start performing.
625 kDuration = 0.25 // STEP LENGHT FRA HTLM // duration of event. Equivalent to p3 in a score i statement. If kDuration = 0, the instrument will only do an initialization pass, with no performance. If kdur is negative, a held note is initiated. (See ihold and i statement.)
626 //ip4, ip5, ...// Equivalent to p4, p5, etc., in a score i statement
627
628 //Frequency-array
629 kArray[] fillarray 440, 523.25, 659.25, 698.46
630 kRandom random 0, 4
631
632 //Parameters
633 kAmplitude random 0.5, 1
634 kFrequency = kArray[kRandom]
635
636 schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kDuration, kDuration, kAmplitude, kFrequency, ktrigger
637
638 endin
639
640
641 ;instrument will be triggered by keyboard widget
642 instr 22
643 kAmplitude = p5 // amplitude *** HENTE FRA HTLM
644 kFrequency = p6 // in Hz *** HENTE FRA HTLM
645 ktrigger = p7
646
647 kEnv madsr .01,0.5,0.3,0.1// i(gkPlanet_3), .2, 0.1
648 aOut pluck kAmplitude, randomh:k(2,10,10), 220, 0, 1, .1, 10
649
650 //Random Pan
651 ktrigon trigger ktrigger, 0.5, 0
652 kPan trandom ktrigon, 0.2, 0.8
653
654 aOut *= sqrt((1 - kPan))*kEnv
655 aOut *= sqrt(kPan)*kEnv
656
657 chnset aOut, "SynthL"
658 chnset aOut, "SynthR"
659 endin
660
661
662 instr 23
663
664 aL chnget "SynthL"
665 aR chnget "SynthR"
666
667 afiltL moogvcf aL, 1500 , 0.5 //gkPlanet_3, 0.5
668 afiltR moogvcf aR, 1500 , 0.5 //gkPlanet_3, 0.5
669 arevl, arevr reverbsc afiltL, afiltR, 0.96, 8000//gkPlanet_4, 8000
670 aoutL = afiltL + arevl
671 aoutR = afiltR + arevr
672
673 chnset aoutL, "Pulse_Out_L"
674 chnset aoutR, "Pulse_Out_R"
675 endin
676
677
678 //##################################################################################
679 //##################################################################################
680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GUITAR PLUCK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
681 //##################################################################################
682
683 //SYNTH CONTROLLER
684 instr 41
685
686 //Metronome
687 kmetroRandom random 0.07, 0.14
688 // printk 1, kmetroRandom
689 ktrigger metro kmetroRandom
690
691 kmintim = 0 // minimum time between generated events, in seconds. If kmintim <= 0, no time limit exists. If the kinsnum is negative (to turn off an instrument), this test is bypassed.
692 kmaxnum = 2 // maximum number of simultaneous instances of instrument kinsnum allowed. If the number of existant instances of kinsnum is >= kmaxnum, no new event is generated. If kmaxnum is <= 0, it is not used to limit event generation. If the kinsnum is negative (to turn off an instrument), this test is bypassed.2 = kinsnum = 2// instrument number. Equivalent to p1 in a score i statement.
693 kinsnum = 42 //instrument number
694 kwhen = 0 // start time of the new event. Equivalent to p2 in a score i statement. Measured from the time of the triggering event. kwhen must be >= 0. If kwhen > 0, the instrument will not be initialized until the actual time when it should start performing.
695 kDuration = 0.25 // STEP LENGHT FRA HTLM // duration of event. Equivalent to p3 in a score i statement. If kDuration = 0, the instrument will only do an initialization pass, with no performance. If kdur is negative, a held note is initiated. (See ihold and i statement.)
696 //ip4, ip5, ...// Equivalent to p4, p5, etc., in a score i statement
697
698 //Frequency-array
699 kArray[] fillarray 783.99, 1174.66, 1318.51, 1567.98
700 kRandom random 0, 4
701
702 //Parameters
703 kAmplitude random 0.75, 1
704 kFrequency = kArray[kRandom]
705
706 schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kDuration, kDuration, kAmplitude, kFrequency, ktrigger
707
708 endin
709
710 ;instrument will be triggered by keyboard widget
711 instr 42
712
713 kAmplitude = p5 // amplitude *** HENTE FRA HTLM
714 kFrequency = p6 // in Hz *** HENTE FRA HTLM
715 ktrigger = p7
716
717 kEnv madsr 0.1, .1, .2, .1
718 aOut pluck kAmplitude, kFrequency, 50, 0, 1, .5, 10
719
720 //Random Pan
721 ktrigon trigger ktrigger, 0.5, 0
722 kPan trandom ktrigon, 0.2, 0.8
723
724 aSigL = aOut * sqrt((1 - kPan))
725 aSigR = aOut * sqrt(kPan)
726
727 aSigL = aSigL * kEnv
728 aSigR = aSigR * kEnv
729
730 chnset aSigL, "Guitar_L"
731 chnset aSigR, "Guitar_R"
732
733 endin
734
735 instr 43
736
737 aSigL chnget "Guitar_L"
738 aSigR chnget "Guitar_R"
739
740 afiltL moogvcf aSigL, 1500 /**gkPlanet_3*/, 0.5
741 afiltR moogvcf aSigR, 1500 /**gkPlanet_3*/, 0.5
742 arevl, arevr reverbsc afiltL, afiltR, 0.7/*0.98*gkPlanet_4*/, 8000
743 // outs (afiltL + arevl), (afiltR + arevr)
744
745
746 aoutL = afiltL + arevl
747 aoutR = afiltR + arevr
748
749 chnset aoutL, "GIT_L"
750 chnset aoutR, "GIT_R"
751
752 endin
753
754
755 //SYNTH CONTROLLER
756 instr 51
757
758 // hente kDuration fra HTLM
759 kmetro random 0.03, 0.08
760 ktrigger metro kmetro
761
762 ktrigger = ktrigger // triggers a new score event. If ktrigger = 0, no new event is triggered.
763 kmintim = 0 // minimum time between generated events, in seconds. If kmintim <= 0, no time limit exists. If the kinsnum is negative (to turn off an instrument), this test is bypassed.
764 kmaxnum = 2 // maximum number of simultaneous instances of instrument kinsnum allowed. If the number of existant instances of kinsnum is >= kmaxnum, no new event is generated. If kmaxnum is <= 0, it is not used to limit event generation. If the kinsnum is negative (to turn off an instrument), this test is bypassed.2 = kinsnum = 2// instrument number. Equivalent to p1 in a score i statement.
765 kinsnum = 52 //instrument number
766 kwhen = 0 // start time of the new event. Equivalent to p2 in a score i statement. Measured from the time of the triggering event. kwhen must be >= 0. If kwhen > 0, the instrument will not be initialized until the actual time when it should start performing.
767 kDuration = 10
768 // STEP LENGHT FRA HTLM // duration of event. Equivalent to p3 in a score i statement. If kDuration = 0, the instrument will only do an initialization pass, with no performance. If kdur is negative, a held note is initiated. (See ihold and i statement.)
769 //ip4, ip5, ...// Equivalent to p4, p5, etc., in a score i statement
770
771 // p4
772 schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kDuration, kDuration
773
774 endin
775
776 instr 52
777
778 //koffset chnget "Synth_Offset"
779 koffset = 5 // *** hente fra HTLM
780 kAmplitude = 0.25 // amplitude *** HENTE FRA HTLM
781 kFrequency = 49.00 // in Hz *** HENTE FRA HTLM
782
783 //SINE OSCILATORS
784 aSine1 oscili kAmplitude, kFrequency
785
786 aSine2 oscili kAmplitude, kFrequency+koffset
787
788 imode = 0 // 0: sawtooth | 2: square/PWM | 4: sawtooth/triangle/ramp *** HENTE FRA HTLM
789 kpw = 0 // the pulse width of the square wave (imode waveform=2) or the ramp characteristics of the triangle wave (imode waveform=4). It is required only by these waveforms and ignored in all other cases. The expected range is 0 to 1, any other value is wrapped to the allowed range.
790
791 aVCO1 vco2 kAmplitude, kFrequency, imode, kpw
792
793 imode = 0 // 0: sawtooth | 2: square/PWM | 4: sawtooth/triangle/ramp *** HENTE FRA HTLM
794 kpw = 0 // the pulse width of the square wave (imode waveform=2) or the ramp characteristics of the triangle wave (imode waveform=4). It is required only by these waveforms and ignored in all other cases. The expected range is 0 to 1, any other value is wrapped to the allowed range.
795 aVCO2 vco2 kAmplitude, kFrequency+koffset, imode, kpw
796
797 // Voice selector *** HENTE kvoice1 og kvoice2 FRA HTLM
798 kvoice1 = 1
799 kvoice2 = 1
800 if kvoice1 = 0 then
801 aOSC1 = aSine1
802 elseif kvoice1 = 1 then
803 aOSC1 = aVCO1
804 endif
805
806 if kvoice2 = 0 then
807 aOSC2 = aSine2
808 elseif kvoice2 = 1 then
809 aOSC2 = aVCO2
810 endif
811
812 //SUM FROM OSCILATORS
813 aOut = (aOSC1+aOSC2)*0.5
814
815 // FILTER *** HENTE FRA HTLM
816 kcf = 200 // filter cutoff frequency
817 kres = 0.3 // resonance, generally < 1, but not limited to it. Higher than 1 resonance values might cause aliasing, analogue synths generally allow resonances to be above 1.
818
819 aOut moogladder2 aOut, kcf, kres// * gkPlanet_3, kres
820
821 // Envelope *** HENTE FRA HTLM
822 iatt = p4*0.1 //0.05// duration of attack phase
823 idec = p4*0.2 //0// duration of decay
824 islev = 1 // level for sustain phase
825 irel = p4*0.7 //0.1// duration of release phase
826
827 kEnvelope adsr iatt, idec, islev, irel
828
829 chnset aOut*kEnvelope, "Bass_Synth"
830
831 endin
832
833
834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
835 ;Low-frequent noise
836 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
837 ;instrument will be triggered by keyboard widget
838 instr 61
839
840 kdensity random 100, 200
841 kcf_1 = 150
842 kcf_2 = 100
843/* FIKSE FIKSE GLOBAL VARIABEL
844 aNoise_1 pinker
845 aNoise_1_Filt moogvcf aNoise_1, kcf_1*gkPlanet_3, 0.5
846
847 aNoise_2 dust2 0.5, kdensity
848 aNoise_2_Filt tone aNoise_2, kcf_2*gkPlanet_3
849*/
850// asum = aNoise_1_Filt + aNoise_2_Filt
851
852 endin
853
854 // TEST OSCILATOR
855 instr 98
856 kcf chnget "Planet_6_X"
857
858 a1 oscili 0.3, kcf
859
860 chnset a1, "test"
861 endin
862
863 //##################################################################################
864 // MASTER OUT INSTRUMENT
865 instr 99
866 // Collect dry from granular instrument
867 aGrain_Out_L chnget "Grain_Out_L"
868 aGrain_Out_R chnget "Grain_Out_R"
869
870 // Collect from Spectral prossecing
871 aSpectral_Out chnget "Spectral_Out"
872
873 // Collect from Pulse instruments
874 aPulse_Out_L chnget "Pulse_Out_L"
875 aPulse_Out_R chnget "Pulse_Out_R"
876
877 // Collect from Git simulator
878 aGIT_L chnget "GIT_L"
879 aGIT_R chnget "GIT_R"
880
881 // Collect from Bass SYNTH
882 aBass chnget "Bass_Synth"
883
884 //test
885 aTest chnget "test"
886
887 // aRevL, aRevR reverbsc aGrain_Out_L, aGrain_Out_R, 0.8*gkPlanet_4, 8000
888
889 // outs aGrain_Out_L+aRevL, aGrain_Out_R+aRevR
890
891 //outs aSpectral_Out*0.5, aSpectral_Out*0.5
892
893 // MAIN OUTPUT
894 outs aPulse_Out_L+aGIT_L+aBass+aGrain_Out_L, aPulse_Out_R+aGIT_R+aBass+aGrain_Out_R
895
896 endin
897
898 </textarea>
899 <script src="./js/canvas.bundle.js"></script></body>
900 <script src="js/canvas.js"></script>
901
902 <script>
903 // Animation Loop
904 function animate() {
905 requestAnimationFrame(animate);
906 c.clearRect(0, 0, canvas.width, canvas.height);
907 c.fillStyle = 'rgb(0, 0, 0)';
908 c.fillRect(0, 0, canvas.width, canvas.height);
909
910 stars.forEach(star => {
911 star.draw();
912 //do something with sound
913 });
914
915 planets.forEach(planet => {
916 planet.update();
917 //console.log(planets[1].x)
918 //PLANET[0] = SUN, NO MOVEMENT
919 csound.setControlChannel("Planet_0_X", planets[0].x);
920 csound.setControlChannel("Planet_0_Y", planets[0].y);
921 csound.setControlChannel("Planet_0_Radian", planets[0].radian);
922 csound.setControlChannel("Planet_1_X", planets[1].x);
923 csound.setControlChannel("Planet_1_Y", planets[1].y);
924 csound.setControlChannel("Planet_1_Radian", planets[1].radian);
925 csound.setControlChannel("Planet_2_X", planets[2].x);
926 csound.setControlChannel("Planet_2_Y", planets[2].y);
927 csound.setControlChannel("Planet_2_Radian", planets[2].radian);
928 csound.setControlChannel("Planet_3_X", planets[3].x);
929 csound.setControlChannel("Planet_3_Y", planets[3].y);
930 csound.setControlChannel("Planet_3_Radian", planets[3].radian);
931 csound.setControlChannel("Planet_4_X", planets[4].x);
932 csound.setControlChannel("Planet_4_Y", planets[4].y);
933 csound.setControlChannel("Planet_4_Radian", planets[4].radian);
934 csound.setControlChannel("Planet_5_X", planets[5].x);
935 csound.setControlChannel("Planet_5_Y", planets[5].y);
936 csound.setControlChannel("Planet_5_Radian", planets[5].radian);
937 csound.setControlChannel("Planet_6_X", planets[6].x);
938 csound.setControlChannel("Planet_6_Y", planets[6].y);
939 csound.setControlChannel("Planet_6_Radian", planets[6].radian);
940 csound.setControlChannel("Planet_7_X", planets[7].x);
941 csound.setControlChannel("Planet_7_Y", planets[7].y);
942 csound.setControlChannel("Planet_7_Radian", planets[7].radian);
943 csound.setControlChannel("Planet_8_X", planets[8].x);
944 csound.setControlChannel("Planet_8_Y", planets[8].y);
945 csound.setControlChannel("Planet_8_Radian", planets[8].radian);
946 //do something with sound
947 //here you can get planet.x , planet.y etc
948 });
949 }
950 animate()
951 </script>
952</html>
953