sr = 44100 ksmps = 16 nchnls = 2 0dbfs = 1 /*****Playing a soundfile 2b: Play from a buffer with more features*****/ ;written by joachim heintz and andres cabrera ;mar 2009 opcode PlayBuf, ak, iiikiki /*Plays a buffer (function table) with a known length, and gives the time in the range 0-1.*/ /*input: ifn: name or nummer of the function table ifnlen: its length in samples resp. indices ifnsr: its samplerate kspeed: speed of reading (1 = normal) iskip: skiptime in seconds kvol: volume multiplier (1 = normal) icnvrt: 1 = samplerate conversion if the sr of the soundfile is not the same as in the orchestra; 0 = no conversion */ /*output: asig: audio signal reading the table ktimout: time in the table in seconds */ ifn, ifnlen, ifnsr, kspeed, iskip, kvol, icnvrt xin if ifnsr != sr then setksmps 1; if sr is different, set local ksmps to 1 for best quality endif if icnvrt == 1 then irel = ifnlen / ifnsr else irel = ifnlen / sr endif kcps = kspeed / irel iphs = iskip / irel asig poscil3 kvol, kcps, ifn, iphs ktim phasor kcps, iphs ktimout = ktim * irel xout asig, ktimout endop opcode ShowLED_a, 0, Sakik ;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) ;idb: 1 = show in dB, 0 = show in raw amplitudes (both in the range 0-1) ;idbrange: 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, ktrig, idb, kdbrange xin kdispval max_k asig, ktrig, 1 if idb != 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 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, 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 instr 1; always on gkpaus init 0; status of the pause button gkspeed init 1; speed for reading the buffer gkconvertsr invalue "convertsr" kdb invalue "db"; gain value in dB gkskip invalue "skip"; skiptime in sec gkloop invalue "loop"; value 1 if checked ;volume display gkmult = ampdbfs(kdb) Sdb_disp sprintfk "%+.2f dB", kdb outvalue "db_disp", Sdb_disp endin instr 2 ;play Sfile invalue "_Browse1"; get the name (look at the example in Examples->Reserved Channels) gilen filelen Sfile; duration of the file gichn filenchnls Sfile; is the file mono or stereo gifilesr filesr Sfile ;reading the data in the buffers (function tables) giL ftgen 0, 0, 0, -1, Sfile, 0, 0, 1 gilenbuf = ftlen(giL) if gichn == 2 then giR ftgen 0, 0, 0, -1, Sfile, 0, 0, 2 endif ;send a message if the sr of the file doesn't match the sr of the orchestra if gifilesr != sr then if i(gkconvertsr) == 1 then Swarn sprintf "Warning:\nSamplerate of the file is %d, but samplerate of the orchestra is %d. Samplerate will be converted by changing speed of reading.", gifilesr, sr outvalue "message", Swarn else Swarn sprintf "Warning:\nSamplerate of the file is %d, but samplerate of the orchestra is %d. Samplerate will not be converted, so you will have changes in tempo and pitch.", gifilesr, sr outvalue "message", Swarn endif else Smess sprintf "Length = %.3f\nSamplerate = %d\nChannels = %d", gilen, gifilesr, gichn outvalue "message", Smess endif if gkpaus == 1 then ;if pause event "i", 4, 0, .1; call the pause instr else event "i", 10, 0, 1 endif turnoff endin instr 3; stop turnoff2 1, 0,0 endin instr 4; pause/resume if gkpaus == 0 then gkspeed = 0 gkpaus = 1 else gkspeed = 1 gkpaus = 0 endif turnoff endin instr 10; playing iloop = i(gkloop) iskip = i(gkskip) icnvrt = i(gkconvertsr) kdbrange invalue "dbrange" ;dB range for the meters kpeakhold invalue "peakhold" ;Duration of clip indicator hold in seconds idur = (iloop == 1 ? 9999 : gilen - iskip) p3 = idur if gichn == 1 then aL, ktimout PlayBuf giL, gilenbuf, gifilesr, gkspeed, iskip, gkmult, icnvrt aR = aL else aL, ktimout PlayBuf giL, gilenbuf, gifilesr, gkspeed, iskip, gkmult, icnvrt aR, knix PlayBuf giR, gilenbuf, gifilesr, gkspeed, iskip, gkmult, icnvrt endif ;show output kTrigDisp metro 10 ShowLED_a "outL", aL, kTrigDisp, 1, kdbrange ShowLED_a "outR", aR, kTrigDisp, 1, kdbrange ShowOver_a "outLover", aL, kTrigDisp, kpeakhold ShowOver_a "outRover", aR, kTrigDisp, kpeakhold ;read and show time ktimouthor = int(ktimout / 3600) Shor sprintfk "%02d", ktimouthor ktimoutmin = int(ktimout / 60) Smin sprintfk "%02d", ktimoutmin ktimoutsec = int(ktimout % 60) Ssec sprintfk "%02d", ktimoutsec ktimoutms = frac(ktimout) * 1000 Sms sprintfk "%03d", ktimoutms outvalue "hor", Shor outvalue "min", Smin outvalue "sec", Ssec outvalue "ms", Sms outs aL, aR endin i 1 0 36000; don't listen to music longer than 10 hours e 0 0 483 539 true 120 138 170 _Browse1 15 95 345 24 {16aca12d-8e44-4b5c-9e02-6db2c75f57e3} true 0 0 _Browse1 362 92 100 30 {903e3360-4b33-4c1e-8063-1d4c05bb242a} true 0 -3 value 1.00000000 /home/linux/Joachim/Materialien/SamplesKlangbearbeitung/PassageMono.aiff Open File / false false db 110 235 160 31 {79bc1456-4022-44f7-8e0d-225f5e96526b} true 0 -3 -18.00000000 18.00000000 -0.45000000 lin continuous -1.00000000 false db_disp 270 235 120 31 {0150cd3e-fcf9-4433-a8a2-e43791847383} true 0 0 left DejaVu Sans 18 3 0 0 0 255 255 255 noborder 1 1 13 138 78 26 {a291df2a-9d8b-4a45-ab3d-c4bb52537abb} true 0 -3 event 1.00000000 Play / i 2 0 .1 false false _Stop 221 138 80 25 {e3508832-4264-4f71-becd-61be2a132d5b} true 0 -3 value 1.00000000 Stop / i 3 0 .1 false true skip 13 203 87 25 {d6f2a1f3-eb8b-4082-8b03-eca92a7db848} true 0 -3 right Lucida Grande 10 0 0 0 255 255 255 0.00100000 -1e+12 1e+12 false 0 115 137 80 25 {0e7e868a-bb71-4ed9-9f5c-8a5168d53620} true 0 -3 event 1.00000000 Pause / i 4 0 .1 false false loop 141 200 20 20 {18e70fdf-dbab-4cf7-9c33-f7e5db09ad56} true 0 -3 false min 331 296 37 30 {427186bf-14a9-4b64-8a19-d22cce59633d} true 0 -3 right Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 sec 378 296 35 31 {5d54bf1a-4ba9-4a73-8b1c-821429894ba6} true 0 -3 right DejaVu Sans 18 3 0 0 0 255 255 255 noborder 1 1 366 296 14 29 {ad04bd24-c15e-48bd-b79a-aef90a60f8c0} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 11 172 88 30 {0989bcfd-9791-4812-b5c8-9d564434be8d} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 120 174 59 30 {8a1f863a-148c-4eea-897d-f8c4ae5bb01f} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 12 234 88 30 {e58f4db9-254f-430c-9d75-6f57d504fbe5} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 message 9 399 464 131 {a5c41213-116d-4c3b-b779-b0f2db33cb7b} true 0 0 11 364 462 30 {057ac2d1-8533-4178-a423-87cdc6ea13fc} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 outL 10 273 250 19 {41760197-5e26-4055-8358-c6a1e7d58fa3} true 0 -3 out1_post 0.00000000 1.00000000 0.00000000 1.00000000 0.50617135 0.52631600 fill 1 0.00000000 jump 0 234 0 false 0 0 0 outLover 258 273 21 19 {e082e5d1-8e6a-4662-8b3f-2e8cb50814e5} true 0 -3 outLover 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 fill 1 0.00000000 jump 196 14 12 false 0 0 0 outR 10 300 250 19 {9530a3d5-9c8f-4e3f-a369-37d31ce808d8} true 0 -3 out2_post 0.00000000 1.00000000 0.00000000 1.00000000 0.50617135 0.52631600 fill 1 0.00000000 jump 0 234 0 false 0 0 0 outRover 258 300 21 19 {8487174c-0be1-472d-bbd7-3910cb0ee79b} true 0 -3 outRover 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 fill 1 0.00000000 jump 196 14 12 false 0 0 0 dbrange 96 330 80 25 {e56c5ecf-8dd6-4ab6-a692-0d0af432ec5e} true 0 -3 left Lucida Grande 10 0 0 0 255 255 255 0.10000000 -1e+12 1e+12 false 48 11 329 81 27 {fdb9a176-d48a-47d5-a4f5-8d8206a668f0} true 0 0 left Nimbus Sans L 14 3 0 0 0 255 255 255 noborder 1 1 peakhold 348 331 57 25 {2eec9b56-b85e-4c82-8b51-e852c51d13f3} true 0 -3 left Lucida Grande 10 0 0 0 255 255 255 1.00000000 -1e+12 1e+12 false 3 218 329 131 27 {a2a86f3a-03d7-4069-b13c-aa66c4e1a1f2} true 0 -3 left DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 1 convertsr 216 201 20 20 {9a016013-437a-42fb-bec6-c8b6b26161cb} true 0 -3 false 192 174 62 30 {877b025c-3d7a-4143-b0b2-8bffe7ae7591} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 hor 289 295 32 32 {728567e2-f821-4f99-bc41-86d8d09ca29f} true 0 -3 right Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 ms 424 297 44 30 {bdf71544-8723-4843-aa62-5bd7463479fa} true 0 -3 right DejaVu Sans 18 3 0 0 0 255 255 255 noborder 1 1 320 297 14 29 {c5db02d0-f14f-491a-85e3-0ae9a9fb2e17} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 411 296 14 29 {3be38656-011b-4f94-b4b4-4aaf49e4c2f7} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 286 268 39 29 {1defe710-4b95-4b28-a441-add693fb143b} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 331 268 39 29 {3e752ddf-02ab-4d1e-a8b6-75166f26b6c5} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 377 268 39 29 {f51e465c-fa73-4ab7-861d-310f7f1cdb90} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 426 268 39 29 {28af6ecc-132b-43f2-a5df-4bafbc2e9716} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 256 173 218 54 {b4ded076-4eba-4e14-a816-056de35c4eaa} true 0 -3 center Lucida Grande 12 3 0 0 0 255 255 255 noborder 1 1 15 9 450 46 {d03f29ef-2f75-435d-922b-27d8b592105d} true 0 -3 center Lucida Grande 26 3 0 0 0 255 255 255 noborder 1 1 14 51 450 46 {17681a9f-a482-46f8-8a5e-77ad193c08ce} true 0 -3 center Lucida Grande 22 3 0 0 0 255 255 255 noborder 1 1