--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
67459828true17017012734265102844{c78fe040-5e65-420d-b2e9-6a5a1c246a82}true0-3lefttop
Lucida Grande
143000255255255border11731169135{88e79c48-0673-477d-a115-f7d04204ceed}true0-3centertop
Lucida Grande
183000255255255noborder10sine3516117896{68005a17-b635-4078-be03-673ffa62bade}true0-3-11.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetrue2901169135{91e8697e-5aaf-48d2-a95f-defaadd72ba2}true0-3centertop
Lucida Grande
183000255255255noborder10saw25216117896{3140cb8b-1f05-4840-8595-32029e2eca6c}true0-3-21.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetrue5091159135{56cf2d07-56f6-49fe-abc7-3ce66f6b2a83}true0-3centertop
Lucida Grande
183000255255255noborder10square47116017896{60aff4f8-815b-4521-b4ae-2b319cb36061}true0-3-31.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetrue7131159135{e2f82f20-56ac-44a8-b4cc-45cffd649263}true0-3centertop
Lucida Grande
183000255255255noborder10triangle67516017896{8f679e7c-bf7c-4f0d-b94a-8bf64810686d}true0-3-41.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetrue9221149135{1daab3c6-caf8-4eaa-91fe-870e8e734f92}true0-3centertop
Lucida Grande
183000255255255noborder10impulse88415917896{32dc8bf3-b96c-49a8-8170-a598ba708d3d}true0-3-51.000000001.000000001.000000001.00000000autoautotruetruetruetruetruetruetruenp_saw3142725928{ca28f6b6-0abe-49d3-8eda-2c18152c10da}true00right
Noto Sans
100002552552551.00000000-1e+121e+12false4np_squ5332715928{1c5e78fb-58f0-44c9-b827-d979c4f2a0fa}true00right
Noto Sans
100002552552551.00000000-1e+121e+12false4np_tri7402725928{07e0476d-82a2-43f1-b9e7-78fc4839c681}true00right
Noto Sans
100002552552551.00000000-1e+121e+12false4np_imp9492725928{792834f1-858e-4c59-8b6b-6098fdb9a549}true00right
Noto Sans
100002552552551.00000000-1e+121e+12false426407766165{d218dd29-950b-46e9-9fa4-dbe79b43364c}true0-3-1.00000000scope1.000000001.000000001.000000001.000000000.00000000NoTriggerhor2182440531166{529f7ef1-188b-4816-a742-a00eb9eb314b}true0-3amp_sin0.000000001.000000000.000000001.000000000.322581000.47590361fill10.00000000jumpnoborder#00FF0002340false000truehor2185540531166{001606e5-a61c-4861-8d9b-8f2245e92778}true0-3amp_saw0.000000001.000000000.000000001.000000000.322581000.37349398fill10.00000000jumpnoborder#00FF0002340false000truehor2188640531166{8df519d9-fceb-4bee-bab6-e8920dab3e9c}true0-3amp_squ0.000000001.000000000.000000001.000000000.322581000.26506024fill10.00000000jumpnoborder#00FF0002340false000truehor2191740531166{45360760-17bc-4a53-904b-ea9039ce6540}true0-3amp_tri0.000000001.000000000.000000001.000000000.322581000.40963855fill10.00000000jumpnoborder#00FF0002340false000truehor2194740531166{ec94c846-1373-4777-b0c6-74f7ce1c6855}true0-3amp_imp0.000000001.000000000.000000001.000000000.322581000.35542169fill10.00000000jumpnoborder#00FF0002340false000true82434514854{30b21d15-4d8e-4a8a-b539-3c332d94cddb}true0-3centertop
Lucida Grande
143000255255255noborder10vol100840622165{0bd55494-42a9-46a4-b774-aaaa9267bd8b}true0-30.000000002.000000001.26060606lincontinuous-1.00000000falseout103942418147{adfe8e43-acf9-42b6-88ed-d02595ea2f7d}true00out0.000000001.000000000.000000001.00000000-inf-inffill10.00000000jumpnoborder#00FF0002340false000trueoutover10394061823{e4f880e1-6ed1-415f-bac9-bab6acafe0cf}true00outover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000true9993466455{844aa0e6-9920-48ca-98e9-0ea1a86a5053}true0-3centertop
Lucida Grande
143000255255255noborder106336821433{4d4b0f09-79f1-4b34-a9ca-11c2330fb7ae}true0-3centertop
Lucida Grande
143000255255255noborder10_Play3723639127{56f09abb-7aea-4e8b-b0ad-277959bb0509}true0-3value1.00000000START/i1 0 10falsefalsefalse10_Stop4863639127{f614c0aa-47ce-4432-ae75-060ffcb50831}true0-3value1.00000000STOP/i1 0 10falsefalsefalse103527317629{a545b53f-b0fa-41b1-9ec1-779e5d7d29c5}true0-3centertop
Lucida Grande
143000255255255noborder10915990353{ecc85f21-bdeb-481a-b8d7-da7b9ac1a05b}true0-3centertop
Lucida Grande
143000255255255noborder101901171243{ca9a41af-9fb7-4c38-afab-561d2b5b88aa}true0-3centertop
Lucida Grande
223000255255255noborder1059236319928{fcd042ab-a450-40eb-a76c-b68af24c380d}true0-3event1.00000000MAKE AUDIO/i2 0 3 440 0.2falsefalsefalse10i 1 0 3