-odac
/*
LIVE ACCORDIZER
*/
;example for CsoundQt
;written by joachim heintz
;may 2011
;please send bug reports and suggestions
;to jh at joachimheintz.de
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
gifftsiz = 1024 ;fft size
giovlap = gifftsiz / 4 ;overlap
giwinsiz = gifftsiz * 2 ;window size
giwintyp = 1 ;von hann window
opcode ShowLED_a, 0, Sakkk
;shows an audiosignal in an outvalue channel, in dB or raw amplitudes
;Soutchan: string as name of the outvalue channel
;asig: audio signal to be shown
;kdispfreq: refresh frequency of the display (Hz)
;kdb: 1 = show as db, 0 = show as raw amplitudes (both in the range 0-1)
;kdbrange: if idb=1: which dB range is shown
Soutchan, asig, ktrig, kdb, kdbrange xin
kdispval max_k asig, ktrig, 1
if kdb != 0 then
kdb = dbfsamp(kdispval)
kval = (kdbrange + kdb) / kdbrange
else
kval = kdispval
endif
if ktrig == 1 then
outvalue Soutchan, kval
endif
endop
opcode ShowOver_a, 0, Sakk
;shows if asig has been larger than 1 and stays khold seconds
;Soutchan: string as name of the outvalue channel
;kdispfreq: refresh frequency of the display (Hz)
Soutchan, asig, ktrig, 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, ktrig, 1
if kon == 0 && kmax > 1 && ktrig == 1 then
kstart = ktim
kend = kstart + khold
outvalue Soutchan, kmax
kon = 1
endif
if kon == 1 && ktim > kend && ktrig == 1 then
outvalue Soutchan, 0
kon = 0
endif
endop
opcode Y_x4p_k, k, kkkkk
;calculates y from two given points in x dimension, two in y dimension, and an x input, at i-rate
kx, kx1, kx2, ky1, ky2 xin
kmm = (ky2-ky1) / (kx2-kx1)
knn = ky1 - kmm*kx1
ky = kmm*kx + knn
xout ky
endop
instr 1; master instrument
;;get live input
kinchnl invalue "inchnl"
aLiveInPre inch kinchnl
kingaindb invalue "ingaindb"
kLiveInGain = ampdb(kingaindb)
aLiveInPost = aLiveInPre * kLiveInGain
;;show live input
gkTrigDisp metro 10
gkshowdb invalue "showdb"
gkdbrange invalue "dbrange"
ShowLED_a "LiveInPre", aLiveInPre, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "LiveInPreOver", aLiveInPre, gkTrigDisp, 2
ShowLED_a "LiveInPost", aLiveInPost, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "LiveInPostOver", aLiveInPost, gkTrigDisp, 2
;;get values for transpositions
krmstim invalue "rmstim" ;time in seconds for making rms measurements
kthreshup invalue "threshup" ;db threshold for upper values
kcentup invalue "centup" ;cent distance between single transpositions for upper threshold
kthreshlow invalue "threshlow" ;db threshold for lower values
kcentlow invalue "centlow" ;cent distance between single transpositions for lower threshold
;;analyze rms and show it
ktrig metro 1
krms rms aLiveInPost, 1
kdb = dbamp(krms)
kmeanamp max_k aLiveInPost, ktrig, 1
outvalue "rms", kdb
;;calculate transposition values from current rms
kcent Y_x4p_k kdb, kthreshlow, kthreshup, kcentlow, kcentup
if kcentup < kcentlow then ;change names if kcentlow is larger than kcentup
kcentupcp = kcentup
kcentup = kcentlow
kcentlow = kcentupcp
endif
kcent = (kcent < kcentlow ? kcentlow : (kcent > kcentup ? kcentup : kcent))
;;perform fft and create 6 transposition values
fbas pvsanal aLiveInPost, gifftsiz, giovlap, giwinsiz, giwintyp
ftrans1 pvscale fbas, cent(kcent)
ftrans2 pvscale fbas, cent(2*kcent)
ftrans3 pvscale fbas, cent(3*kcent)
ftrans4 pvscale fbas, cent(-kcent)
ftrans5 pvscale fbas, cent(-2*kcent)
ftrans6 pvscale fbas, cent(-3*kcent)
;;resynthesize and mix
atrans1 pvsynth ftrans1
atrans2 pvsynth ftrans2
atrans3 pvsynth ftrans3
atrans4 pvsynth ftrans4
atrans5 pvsynth ftrans5
atrans6 pvsynth ftrans6
amix = atrans1 + atrans2 + atrans3 + atrans4 + atrans5 + atrans6
;;output
koutgaindb invalue "outgaindb"
aout = amix* ampdb(koutgaindb)
outch 1, aout, 2, aout
;;show output
ShowLED_a "out", aout, gkTrigDisp, gkshowdb, gkdbrange
ShowOver_a "outover", aout, gkTrigDisp, 2
endin
i 1 0 36000
e
203102913622true2202202209988644{2a56f609-3f3a-49a2-8ef2-04e1041ed49f}true00centertop
DejaVu Sans
263000255255255noborder10812189150{49b99e1e-2b4b-4aef-b413-95171c64b350}true00lefttop
DejaVu Sans
123000255255255noborder108173484148{e39c91d6-a0bd-4681-8dbc-e384493e578c}true0-3lefttop
Lucida Grande
183000255255255border11LiveInPre11720533622{7286a833-c0b0-4f55-8ecc-837453106e15}true0-3out1_post0.000000001.000000000.000000001.000000000.099747080.73076900fill10.00000000jumpnoborder#00FF0002340false000trueLiveInPreOver4512052722{42e31476-6cb3-42b4-a1fd-8f48e76892ac}true0-3outLover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000trueLiveInPost11328133622{77fcb44e-b9a2-423d-9764-52f01754d96d}true0-3out2_post0.000000001.000000000.000000001.000000000.105285570.59090900fill10.00000000jumpnoborder#00FF0002340false000trueLiveInPostOver4472812722{3e4c2001-fd4f-4b10-bd75-1766b5d1bbde}true0-3outRover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000true182059328{9dd7688d-d7d4-4863-bbe8-44c1e622f2bd}true0-3lefttop
Lucida Grande
143000255255255noborder10162819729{a6c9d0da-7821-4528-b193-9ee9af3d441f}true0-3lefttop
Lucida Grande
143000255255255noborder10172439331{bdebe2b5-07c1-4f1f-b7cb-d2f29a26a5f8}true0-3lefttop
Lucida Grande
143000255255255noborder10518172380217{e748e0c8-197c-4d4d-b893-9501e50ae02b}true00lefttop
DejaVu Sans
183000255255255border11out52523833824{133bd5e9-655f-4ba7-895d-45c9c8e54eb3}true0-3out0.000000001.000000000.000000001.000000000.259557190.25955719fill10.00000000jumpnoborder#00FF0002340false000trueoutover8602382624{dc5f0c73-a680-4e93-9855-6706fbd5180d}true0-3outRover0.000000001.000000000.000000001.000000000.000000000.00000000fill10.00000000jumpnoborder#00FF001961412false000truedbrange4133337927{81528aba-64e8-4dc7-b127-daa1434195a2}true0-3left
Lucida Grande
140002552552550.1000000011e+12false503263329029{cc0e0187-e5c9-4b44-b8c0-28d00d45cb89}true00righttop
Nimbus Sans L
143000255255255noborder1013733311027{df57c2f7-4a74-460f-9f7f-b3efb8106306}true00righttop
Nimbus Sans L
143000255255255noborder10showdb2463338028{d09ab184-f4b1-4340-8730-e73b870bcf9a}true00raw amps0dB11false522269368105{c385ef49-3efa-4ec3-806a-ff883343cb9c}true0-3-255.00000000scope2.000000001.000000001.000000001.000000000.00000000NoTrigger8400888198{f470cb16-0510-44e6-b6e0-c532a68e3409}true00lefttop
DejaVu Sans
183000255255255border115262059527{dcc76929-4dec-4912-b228-fcab4a27e75f}true0-3lefttop
Lucida Grande
143000255255255noborder10inchnl973344727{2fce6993-35f8-4dd7-bedd-f809c0803989}true00right
DejaVu Sans
140002552552551.0000000011e+12false1-333310229{df02308f-b978-4275-817e-1ad38c5b30d5}true00righttop
Nimbus Sans L
143000255255255noborder1039145226630{0d90798d-f4cd-4370-baf7-d117997cae4e}true00lefttop
DejaVu Sans
143000255255255noborder1036549123524{90dc5bd9-22fd-4aab-ac2a-a6e7cf34778a}true00righttop
Nimbus Sans L
143000255255255noborder10centup6144906427{de281b04-9f42-41a7-9ad2-75515d6cd2e3}true00right
Arial
140002552552551.0000000001e+12false5037351821342{dc562970-3547-4613-b423-f980f4a82ccb}true00righttop
Nimbus Sans L
143000255255255noborder10threshup6145266427{323951d3-56d2-48d5-afdc-c1eb8f54d4f5}true00right
Arial
140002552552551.00000000-500false-204445026630{30f7237e-42cb-49f9-9b89-0896da60f44c}true00lefttop
DejaVu Sans
143000255255255noborder101848923524{635ff1ef-bd61-4e26-9c16-f01fd8ec1a59}true00righttop
Nimbus Sans L
143000255255255noborder10centlow2674886427{618669e3-8f70-44e5-aeb5-89bd7647b97e}true00right
Arial
140002552552551.0000000001e+12false4502651621342{545f1c7f-6f98-4c47-9e3c-a07a88ce7a0f}true00righttop
Nimbus Sans L
143000255255255noborder10threshlow2675246427{e2c3db92-0dd4-4a90-8819-43b132af448c}true00right
Arial
140002552552551.00000000-500false-4070241513642{d4ae25c0-9a81-4fd8-afce-694d22d3a04f}true00lefttop
DejaVu Sans
143000255255255noborder10rmstim7404626427{e459468b-1ea5-4944-a962-65cc28b63eaf}true00right
Arial
140002552552550.001000000.0011false0.00170749613630{ccf95bda-000e-42c9-903d-c7d6d0ce0315}true00centertop
DejaVu Sans
143000255255255noborder10rms7405276829{0d761b7a-0eec-4bd7-a464-fe07f49af4dd}true00righttop
Arial
143000255255255border1196389150{c365e002-1222-4401-bf75-06202dd0bca6}true00lefttop
DejaVu Sans
143000255255255noborder10ingaindb11524426026{64de8264-0345-4faf-b16c-4af284a95268}true00-12.0000000012.000000000.27692308lincontinuous-1.00000000false4532433031{eecbf48f-983f-4ce5-bdcc-e6b1ae657b20}true00righttop
DejaVu Sans
143000255255255noborder10ingaindb3752457627{a44b45c8-8c22-4c53-9442-75339608f708}true00left
Arial
140002552552550.00100000-1e+121e+12false0.276923outgaindb62220515524{2735c656-a8f6-429d-acc3-2fe0db7e078a}true00-12.0000000012.00000000-0.69677419lincontinuous-1.00000000false8582033031{a5947f34-1e11-490f-bd5d-c543d6e4494e}true00righttop
DejaVu Sans
143000255255255noborder10outgaindb7782047627{52bb78bb-8e63-44a1-a86a-5def867d5311}true00left
Arial
140002552552550.00100000-1e+121e+12false-0.696774