-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 203 102 913 622 true 220 220 220 9 9 886 44 {2a56f609-3f3a-49a2-8ef2-04e1041ed49f} true 0 0 center top DejaVu Sans 26 3 0 0 0 255 255 255 noborder 1 0 8 121 891 50 {49b99e1e-2b4b-4aef-b413-95171c64b350} true 0 0 left top DejaVu Sans 12 3 0 0 0 255 255 255 noborder 1 0 8 173 484 148 {e39c91d6-a0bd-4681-8dbc-e384493e578c} true 0 -3 left top Lucida Grande 18 3 0 0 0 255 255 255 border 1 1 LiveInPre 117 205 336 22 {7286a833-c0b0-4f55-8ecc-837453106e15} true 0 -3 out1_post 0.00000000 1.00000000 0.00000000 1.00000000 0.09974708 0.73076900 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true LiveInPreOver 451 205 27 22 {42e31476-6cb3-42b4-a1fd-8f48e76892ac} true 0 -3 outLover 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 LiveInPost 113 281 336 22 {77fcb44e-b9a2-423d-9764-52f01754d96d} true 0 -3 out2_post 0.00000000 1.00000000 0.00000000 1.00000000 0.10528557 0.59090900 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true LiveInPostOver 447 281 27 22 {3e4c2001-fd4f-4b10-bd75-1766b5d1bbde} true 0 -3 outRover 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 18 205 93 28 {9dd7688d-d7d4-4863-bbe8-44c1e622f2bd} true 0 -3 left top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 16 281 97 29 {a6c9d0da-7821-4528-b193-9ee9af3d441f} true 0 -3 left top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 17 243 93 31 {bdebe2b5-07c1-4f1f-b7cb-d2f29a26a5f8} true 0 -3 left top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 518 172 380 217 {e748e0c8-197c-4d4d-b893-9501e50ae02b} true 0 0 left top DejaVu Sans 18 3 0 0 0 255 255 255 border 1 1 out 525 238 338 24 {133bd5e9-655f-4ba7-895d-45c9c8e54eb3} true 0 -3 out 0.00000000 1.00000000 0.00000000 1.00000000 0.25955719 0.25955719 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true outover 860 238 26 24 {dc5f0c73-a680-4e93-9855-6706fbd5180d} true 0 -3 outRover 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 dbrange 413 333 79 27 {81528aba-64e8-4dc7-b127-daa1434195a2} true 0 -3 left Lucida Grande 14 0 0 0 255 255 255 0.10000000 1 1e+12 false 50 326 332 90 29 {cc0e0187-e5c9-4b44-b8c0-28d00d45cb89} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 137 333 110 27 {df57c2f7-4a74-460f-9f7f-b3efb8106306} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 showdb 246 333 80 28 {d09ab184-f4b1-4340-8730-e73b870bcf9a} true 0 0 raw amps 0 dB 1 1 false 522 269 368 105 {c385ef49-3efa-4ec3-806a-ff883343cb9c} true 0 -3 -255.00000000 scope 2.00000000 1.00000000 1.00000000 1.00000000 0.00000000 NoTrigger 8 400 888 198 {f470cb16-0510-44e6-b6e0-c532a68e3409} true 0 0 left top DejaVu Sans 18 3 0 0 0 255 255 255 border 1 1 526 205 95 27 {dcc76929-4dec-4912-b228-fcab4a27e75f} true 0 -3 left top Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 0 inchnl 97 334 47 27 {2fce6993-35f8-4dd7-bedd-f809c0803989} true 0 0 right DejaVu Sans 14 0 0 0 255 255 255 1.00000000 1 1e+12 false 1 -3 333 102 29 {df02308f-b978-4275-817e-1ad38c5b30d5} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 391 452 266 30 {0d90798d-f4cd-4370-baf7-d117997cae4e} true 0 0 left top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 365 491 235 24 {90dc5bd9-22fd-4aab-ac2a-a6e7cf34778a} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 centup 614 490 64 27 {de281b04-9f42-41a7-9ad2-75515d6cd2e3} true 0 0 right Arial 14 0 0 0 255 255 255 1.00000000 0 1e+12 false 50 373 518 213 42 {dc562970-3547-4613-b423-f980f4a82ccb} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 threshup 614 526 64 27 {323951d3-56d2-48d5-afdc-c1eb8f54d4f5} true 0 0 right Arial 14 0 0 0 255 255 255 1.00000000 -50 0 false -20 44 450 266 30 {30f7237e-42cb-49f9-9b89-0896da60f44c} true 0 0 left top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 18 489 235 24 {635ff1ef-bd61-4e26-9c16-f01fd8ec1a59} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 centlow 267 488 64 27 {618669e3-8f70-44e5-aeb5-89bd7647b97e} true 0 0 right Arial 14 0 0 0 255 255 255 1.00000000 0 1e+12 false 450 26 516 213 42 {545f1c7f-6f98-4c47-9e3c-a07a88ce7a0f} true 0 0 right top Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 0 threshlow 267 524 64 27 {e2c3db92-0dd4-4a90-8819-43b132af448c} true 0 0 right Arial 14 0 0 0 255 255 255 1.00000000 -50 0 false -40 702 415 136 42 {d4ae25c0-9a81-4fd8-afce-694d22d3a04f} true 0 0 left top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 rmstim 740 462 64 27 {e459468b-1ea5-4944-a962-65cc28b63eaf} true 0 0 right Arial 14 0 0 0 255 255 255 0.00100000 0.001 1 false 0.001 707 496 136 30 {ccf95bda-000e-42c9-903d-c7d6d0ce0315} true 0 0 center top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 rms 740 527 68 29 {0d761b7a-0eec-4bd7-a464-fe07f49af4dd} true 0 0 right top Arial 14 3 0 0 0 255 255 255 border 1 1 9 63 891 50 {c365e002-1222-4401-bf75-06202dd0bca6} true 0 0 left top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 ingaindb 115 244 260 26 {64de8264-0345-4faf-b16c-4af284a95268} true 0 0 -12.00000000 12.00000000 0.27692308 lin continuous -1.00000000 false 453 243 30 31 {eecbf48f-983f-4ce5-bdcc-e6b1ae657b20} true 0 0 right top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 ingaindb 375 245 76 27 {a44b45c8-8c22-4c53-9442-75339608f708} true 0 0 left Arial 14 0 0 0 255 255 255 0.00100000 -1e+12 1e+12 false 0.276923 outgaindb 622 205 155 24 {2735c656-a8f6-429d-acc3-2fe0db7e078a} true 0 0 -12.00000000 12.00000000 -0.69677419 lin continuous -1.00000000 false 858 203 30 31 {a5947f34-1e11-490f-bd5d-c543d6e4494e} true 0 0 right top DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 0 outgaindb 778 204 76 27 {52bb78bb-8e63-44a1-a86a-5def867d5311} true 0 0 left Arial 14 0 0 0 255 255 255 0.00100000 -1e+12 1e+12 false -0.696774