--midi-key-cps=4 --midi-velocity-amp=5 -m128 /*****WAVEFORM MIX*****/ ;example for CsoundQt ;written by joachim heintz ;feb 2010 / oct 2012 sr = 44100 ksmps = 128 nchnls = 2 0dbfs = 1 massign 0, 2; assigns all incoming MIDI to instr 2 opcode SinesToSSTI, i, pooo ;produces the waveforms saw (iwf=1, which is also the default), square (iwf=2), triangle (3), impulse (4) by the addition of inparts sinusoides (default = 10) and returns the result in a function table of itabsiz length (must be a power-of-2 or a power-of-2 plus 1, the default is 1024 points) with number ifno (default = 0 which means the number is given automatically) iwf, inparts, itabsiz, ifno xin inparts = (inparts == 0 ? 10 : inparts) itabsiz = (itabsiz == 0 ? 1024 : itabsiz) iftemp ftgen 0, 0, -(inparts * 3), -2, 0;temp ftab for writing the str-pna-phas vals indx = 1 loop: if iwf == 1 then ; saw = 1, -1/2, 1/3, -1/4, ... as strength of partials tabw_i 1/(indx % 2 == 0 ? -indx : indx), (indx-1)*3, iftemp; writes strength of partial tabw_i indx, (indx-1)*3+1, iftemp; writes partial number elseif iwf == 2 then ; square = 1, 1/3, 1/5, ... for odd partials tabw_i 1/(indx*2-1), (indx-1)*3, iftemp; writes strength of partial tabw_i indx*2-1, (indx-1)*3+1, iftemp; writes partial number elseif iwf == 3 then ; triangle = 1, -1/9, 1/25, -1/49, 1/81, ... for odd partials ieven = indx % 2; 0 = even index, 1 = odd index istr = (ieven == 0 ? -1/(indx*2-1)^2 : 1/(indx*2-1)^2); results in 1, -1/9, 1/25, ... tabw_i istr, (indx-1)*3, iftemp; writes strength of partial tabw_i indx*2-1, (indx-1)*3+1, iftemp; writes partial number elseif iwf == 4 then ; impulse = 1, 1, 1, ... for all partials tabw_i 1, (indx-1)*3, iftemp; writes strength of partial (always 1) tabw_i indx, (indx-1)*3+1, iftemp; writes partial number endif loop_le indx, 1, inparts, loop iftout ftgen ifno, 0, itabsiz, 34, iftemp, inparts, 1; write table with GEN34 ftfree iftemp, 0; remove iftemp xout iftout endop opcode ShowLED_a, 0, Sakkk ;Shows an audio signal in an outvalue channel. You can choose to show the value in dB or in raw amplitudes. ;;Input: ;Soutchan: string with the name of the outvalue channel ;asig: audio signal which is to displayed ;kdispfreq: refresh frequency (Hz) ;kdb: 1 = show in dB, 0 = show in raw amplitudes (both in the range 0-1) ;kdbrange: if idb=1: how many db-steps are shown (e.g. if 36 you will not see anything from a signal below -36 dB) Soutchan, asig, kdispfreq, kdb, kdbrange xin kdispval max_k asig, kdispfreq, 1 if kdb != 0 then kdb = dbfsamp(kdispval) kval = (kdbrange + kdb) / kdbrange else kval = kdispval endif outvalue Soutchan, kval endop opcode ShowOver_a, 0, Sakk ;Shows if the incoming audio signal was more than 1 and stays there for some time ;;Input: ;Soutchan: string with the name of the outvalue channel ;asig: audio signal which is to displayed ;kdispfreq: refresh frequency (Hz) ;khold: time in seconds to "hold the red light" Soutchan, asig, kdispfreq, khold xin kon init 0 ktim times kstart init 0 kend init 0 khold = (khold < .01 ? .01 : khold); avoiding too short hold times kmax max_k asig, kdispfreq, 1 if kon == 0 && kmax > 1 then kstart = ktim kend = kstart + khold outvalue Soutchan, kmax kon = 1 endif if kon == 1 && ktim > kend then outvalue Soutchan, 0 kon = 0 endif endop instr 1;;RECEIVE GUI INPUT AND GENERATE WAVEFORMS iftlen = 4097; length of a function table with the shape of a waveform ;GENERATE SINE WAVEFORM giftsin ftgen 1, 0, iftlen, 10, 1 ;RECEIVE NUMBER OF PARTIALS FOR SAW, SQUARE, TRIANGLE AN IMPULSE knp_saw invalue "np_saw" knp_squ invalue "np_squ" knp_tri invalue "np_tri" knp_imp invalue "np_imp" ;LOOK IF AN OF THIS VALUES HAS CHANGED knewsaw changed knp_saw knewsqu changed knp_squ knewtri changed knp_tri knewimp changed knp_imp ;IF YES GO AGAIN TO THE "new" BLOCK AND RECALCULATE THE WAVEFORMS if knewsaw == 1 then reinit newsaw endif if knewsqu == 1 then reinit newsqu endif if knewtri == 1 then reinit newtri endif if knewimp == 1 then reinit newimp endif ;CALCULATION OF SAW, SQUARE, TRIANGLE AN IMPULSE ACCORDING TO THE DESIRED NUMBER OF PARTIALS newsaw: inp_saw = i(knp_saw) giftsaw SinesToSSTI 1, inp_saw, iftlen, 2 event_i "i", "ShowTables", 0, 1 rireturn newsqu: inp_squ = i(knp_squ) giftsqu SinesToSSTI 2, inp_squ, iftlen, 3 event_i "i", "ShowTables", 0, 1 rireturn newtri: inp_tri = i(knp_tri) gifttri SinesToSSTI 3, inp_tri, iftlen, 4 event_i "i", "ShowTables", 0, 1 rireturn newimp: inp_imp = i(knp_imp) giftimp SinesToSSTI 4, inp_imp, iftlen, 5 event_i "i", "ShowTables", 0, 1 rireturn ;RECEIVE RELATIVE AMPLITUDES, AND MASTER VOLUME FROM THE GUI gkamp_sin invalue "amp_sin" gkamp_saw invalue "amp_saw" gkamp_squ invalue "amp_squ" gkamp_tri invalue "amp_tri" gkamp_imp invalue "amp_imp" gk_vol invalue "vol"; master volume ;SMOOTH AMPLTUDE CHANGES gkamp_sin port gkamp_sin, .1 gkamp_saw port gkamp_saw, .1 gkamp_squ port gkamp_squ, .1 gkamp_tri port gkamp_tri, .1 gkamp_imp port gkamp_imp, .1 gk_vol port gk_vol, .1 endin instr 2;;PLAY ONE NOTE ;GENERATE THE FIVE AUDIO SIGNALS asin poscil p5, p4, giftsin asaw poscil p5, p4, giftsaw asqu poscil p5, p4, giftsqu atri poscil p5, p4, gifttri aimp poscil p5, p4, giftimp ;MIX THEM, APPLY A SIMPLE ENVELOPE AND SEND THE MIX OUT amix sum asin*gkamp_sin, asaw*gkamp_saw, asqu*gkamp_squ, atri*gkamp_tri, aimp*gkamp_imp kenv linsegr 0, .1, 1, p3-.1, 1, .1, 0; simple envelope aenv = amix*kenv*gk_vol; apply alo master volume outs aenv, aenv endin instr 3; SHOW THE SUM OF ALL SINGLE NOTES TO SEE CLIPPING aL,aR monitor kTrigDisp metro 10 ShowLED_a "out", aL, kTrigDisp, 1, 50 ShowOver_a "outover", aL, kTrigDisp, 1 endin instr ShowTables outvalue "sine", -1 outvalue "saw", -2 outvalue "square", -3 outvalue "triangle", -4 outvalue "impulse", -5 turnoff endin i 1 0 36000; play 10 hours i 3 0 36000 e 67 45 98 28 true 170 170 127 34 265 1028 44 {c78fe040-5e65-420d-b2e9-6a5a1c246a82} true 0 -3 73 116 91 35 {88e79c48-0673-477d-a115-f7d04204ceed} true 0 -3 center top Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 0 sine 35 161 178 96 {68005a17-b635-4078-be03-673ffa62bade} true 0 -3 -1 1.00000000 1.00000000 1.00000000 1.00000000 auto auto true true true true true true true 290 116 91 35 {91e8697e-5aaf-48d2-a95f-defaadd72ba2} true 0 -3 center top Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 0 saw 252 161 178 96 {3140cb8b-1f05-4840-8595-32029e2eca6c} true 0 -3 -2 1.00000000 1.00000000 1.00000000 1.00000000 auto auto true true true true true true true 509 115 91 35 {56cf2d07-56f6-49fe-abc7-3ce66f6b2a83} true 0 -3 center top Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 0 square 471 160 178 96 {60aff4f8-815b-4521-b4ae-2b319cb36061} true 0 -3 -3 1.00000000 1.00000000 1.00000000 1.00000000 auto auto true true true true true true true 713 115 91 35 {e2f82f20-56ac-44a8-b4cc-45cffd649263} true 0 -3 center top Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 0 triangle 675 160 178 96 {8f679e7c-bf7c-4f0d-b94a-8bf64810686d} true 0 -3 -4 1.00000000 1.00000000 1.00000000 1.00000000 auto auto true true true true true true true 922 114 91 35 {1daab3c6-caf8-4eaa-91fe-870e8e734f92} true 0 -3 center top Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 0 impulse 884 159 178 96 {32dc8bf3-b96c-49a8-8170-a598ba708d3d} true 0 -3 -5 1.00000000 1.00000000 1.00000000 1.00000000 auto auto true true true true true true true np_saw 314 272 59 28 {ca28f6b6-0abe-49d3-8eda-2c18152c10da} true 0 0 right Noto Sans 10 0 0 0 255 255 255 1.00000000 -1e+12 1e+12 false 4 np_squ 533 271 59 28 {1c5e78fb-58f0-44c9-b827-d979c4f2a0fa} true 0 0 right Noto Sans 10 0 0 0 255 255 255 1.00000000 -1e+12 1e+12 false 4 np_tri 740 272 59 28 {07e0476d-82a2-43f1-b9e7-78fc4839c681} true 0 0 right Noto Sans 10 0 0 0 255 255 255 1.00000000 -1e+12 1e+12 false 4 np_imp 949 272 59 28 {792834f1-858e-4c59-8b6b-6098fdb9a549} true 0 0 right Noto Sans 10 0 0 0 255 255 255 1.00000000 -1e+12 1e+12 false 4 26 407 766 165 {d218dd29-950b-46e9-9fa4-dbe79b43364c} true 0 -3 -1.00000000 scope 1.00000000 1.00000000 1.00000000 1.00000000 0.00000000 NoTrigger hor21 824 405 31 166 {529f7ef1-188b-4816-a742-a00eb9eb314b} true 0 -3 amp_sin 0.00000000 1.00000000 0.00000000 1.00000000 0.32258100 0.47590361 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true hor21 855 405 31 166 {001606e5-a61c-4861-8d9b-8f2245e92778} true 0 -3 amp_saw 0.00000000 1.00000000 0.00000000 1.00000000 0.32258100 0.37349398 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true hor21 886 405 31 166 {8df519d9-fceb-4bee-bab6-e8920dab3e9c} true 0 -3 amp_squ 0.00000000 1.00000000 0.00000000 1.00000000 0.32258100 0.26506024 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true hor21 917 405 31 166 {45360760-17bc-4a53-904b-ea9039ce6540} true 0 -3 amp_tri 0.00000000 1.00000000 0.00000000 1.00000000 0.32258100 0.40963855 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true hor21 947 405 31 166 {ec94c846-1373-4777-b0c6-74f7ce1c6855} true 0 -3 amp_imp 0.00000000 1.00000000 0.00000000 1.00000000 0.32258100 0.35542169 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true 824 345 148 54 {30b21d15-4d8e-4a8a-b539-3c332d94cddb} true 0 -3 center top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 vol 1008 406 22 165 {0bd55494-42a9-46a4-b774-aaaa9267bd8b} true 0 -3 0.00000000 2.00000000 1.26060606 lin continuous -1.00000000 false out 1039 424 18 147 {adfe8e43-acf9-42b6-88ed-d02595ea2f7d} true 0 0 out 0.00000000 1.00000000 0.00000000 1.00000000 -inf -inf fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true outover 1039 406 18 23 {e4f880e1-6ed1-415f-bac9-bab6acafe0cf} true 0 0 outover 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 fill 1 0.00000000 jump noborder #00FF00 196 14 12 false 0 0 0 true 999 346 64 55 {844aa0e6-9920-48ca-98e9-0ea1a86a5053} true 0 -3 center top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 63 368 214 33 {4d4b0f09-79f1-4b34-a9ca-11c2330fb7ae} true 0 -3 center top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 _Play 372 363 91 27 {56f09abb-7aea-4e8b-b0ad-277959bb0509} true 0 -3 value 1.00000000 START / i1 0 10 false false false 10 _Stop 486 363 91 27 {f614c0aa-47ce-4432-ae75-060ffcb50831} true 0 -3 value 1.00000000 STOP / i1 0 10 false false false 10 35 273 176 29 {a545b53f-b0fa-41b1-9ec1-779e5d7d29c5} true 0 -3 center top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 91 59 903 53 {ecc85f21-bdeb-481a-b8d7-da7b9ac1a05b} true 0 -3 center top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 190 11 712 43 {ca9a41af-9fb7-4c38-afab-561d2b5b88aa} true 0 -3 center top Lucida Grande 22 3 0 0 0 255 255 255 noborder 1 0 592 363 199 28 {fcd042ab-a450-40eb-a76c-b68af24c380d} true 0 -3 event 1.00000000 MAKE AUDIO / i2 0 3 440 0.2 false false false 10 i 1 0 3