- Edited
giuliomoro Thanks for taking a look at the code. I tried different settings of the block size (audio frames). If it works for you, please let me know what was your settings. I'm using the Bela mini. Here's the code:
<CsoundSynthesizer>
<CsOptions>
--daemon --realtime -odac -iadc -d -m0
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1
seed 0
;;;;OPTIONS
;-m0d --daemon --realtime -odac -iadc
giportrelay1 init 14
giportrelay2 init 15
gidel init 2
gain1 init 0
gain2 init 0
gaout1 init 0
gaout2 init 0
gigain init 0 ;in dB
gigainout init 0; dB
instr 9 ;audio in -> out
amic1, amic2 ins
iamp init db(gigain)
ifilter = 6000 ;LPF
afilter1 butterlp amic1 * iamp, ifilter
afilter2 butterlp amic2 * iamp, ifilter
ain1 = afilter1
ain2 = afilter2
vincr gain1, ain1
vincr gain2, ain2
;send input directly to output
igout = db(gigainout)
aout1 = igout * ain1
aout2 = igout * ain2
vincr gaout1, aout1
vincr gaout2, aout2
endin
;===============================================================
instr 10;digital ports ;========================================
ks101 = 0 ;initialize control signal for sensor 1 drum 1 + sensor 1 drum 2
ks102 = 0
ks103 = 0
ks104 = 0
ks105 = 0
ks201 = 0
ks202 = 0
ks203 = 0
ks204 = 0
ks205 = 0
ks301 = 0
ks302 = 0
ks303 = 0
ks304 = 0
ks305 = 0
ks401 = 0
ks402 = 0
ks403 = 0
ks404 = 0
ks405 = 0
ks501 = 0
ks502 = 0
ks503 = 0
ks504 = 0
ks505 = 0
ks340 = 0 ;drum sensor 3 + 4
ks034 = 0
iport00 = 4 ;digital port 1 IN DRUM 1 Sensor 1
iport01 = 3 ;digital port 2 IN DRUM 1 Sensor 2
iport02 = 2 ;digital port 3 IN DRUM 1 Sensor 3
iport03 = 1 ;digital port 4 IN DRUM 1 Sensor 4
iport04 = 0 ;digital port 5 IN DRUM 1 Sensor 5
iport08 = 12 ;digital port 7 IN DRUM 2 Sensor 1
iport09 = 11
iport10 = 10
iport11 = 9
iport12 = 8
ks11 digiInBela iport00 ;drum 1
ks12 digiInBela iport01
ks13 digiInBela iport02
ks14 digiInBela iport03
ks15 digiInBela iport04
ks21 digiInBela iport08 ;drum 1
ks22 digiInBela iport09
ks23 digiInBela iport10
ks24 digiInBela iport11
ks25 digiInBela iport12
; ihtim = 0.01
; ks11 port ks11, ihtim
; ks12 port ks12, ihtim
; ks13 port ks13, ihtim
; ks14 port ks14, ihtim
; ks15 port ks15, ihtim
; ks21 port ks21, ihtim
; ks22 port ks22, ihtim
; ks23 port ks23, ihtim
; ks24 port ks24, ihtim
; ks25 port ks25, ihtim
; CONTROL MATRIX CONTROL MATRIX CONTROL MATRIX CONTROL MATRIX
if (ks11== 1) && (ks21== 1) then ; Rhymthmic light on
ks101 = 1
;; elseif (ks11== 1) && (ks23== 1) then
;; ks103 = 1
;; elseif (ks13== 1) && (ks21== 1) then ; GROUP 3 ------------
;; ks301 = 1
elseif (ks13== 1) && (ks23== 1) then ;stroboscopi both lights LR
ks303 = 1
elseif (ks13== 1) && (ks14== 1) then ;delay on drum 2
ks340 = 1
elseif (ks23== 1) && (ks24== 1) then ;delay on drum 1
ks034 = 1
endif
imin = 0.1
imax = 1
; sensor 3 drum 1 + sensor 3 drum 2 ;STROBOSCOPI ON/OFF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
kson1323 trigger ks303, 0.5, 0
;ksoff1323 trigger ks303, 0.1, 1
;idrum1323 = giportrelay1 ;drum 1
; p4 p5
; drum freq
schedkwhen kson1323, imin, imax, 60, 0, 100, giportrelay1, 10
schedkwhen kson1323, imin, imax, 60, 0, 100, giportrelay2, 10.02659265
;schedkwhen ksoff1323, imin, imax, 61, 0, 0.1 ;turn off stroboscopic lights
;; ; sensor 1 drum 1 + sensor 3 drum 2 ;STROBOSCOPI ON/OFF +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;; kson1123 trigger ks103, 0.5, 0
;; ksoff1123 trigger ks103, 0.1, 1
;; idrum1123 = giportrelay2 ;drum 2
;; ; p4 p5
;; ; drum freq
;; schedkwhen kson1123, imin, imax, 60, 0, 100, idrum1123, 15
;; schedkwhen ksoff1123, imin, imax, 61, 0, 0.1 ;stroboscopic off
;; schedkwhen ksoff1123, imin, imax, 63, 0.1, 0.1, idrum1123 ;stop light
;; ;-----------------------------------------------------------------------------------------------------------------------------
;; ;sensor 3 drum 1 + sensor 1 drum 2 ;STROBOSCOPI ON/OFF+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;; kson1321 trigger ks301, 0.5, 0
;; ksoff1321 trigger ks301, 0.1, 1
;; idrum1321 = giportrelay1
;; ; p4 p5
;; ; drum freq
;; schedkwhen kson1321, imin, imax, 60, 0, 100, idrum1321, 15
;; schedkwhen ksoff1321, imin, imax, 61, 0, 0.1 ;stroboscopic off
;; schedkwhen ksoff1321, imin, imax, 63, 0.1, 0.1, idrum1321 ;stop light
;-----------------------------------------------------------------------------------------------------------------------------
;sensor 2 drum 1 TURN AUDIO IN->OUT ON/OFF ;-------------------------------------------------------------------------------------------------------------
kson1220 trigger ks12, 0.5, 0 ;
ipiezzo1220 = 1
idrum1220 = 2
igain1220 = 1
; piezzo drum input
schedkwhen kson1220, imin, imax, 70, 0, 100, ipiezzo1220, idrum1220;, igain1220
ksoff1220 trigger ks12, 0.1, 1
schedkwhen ksoff1220, imin, imax, 71, 0, 0.1
;-------------------------------------------------------------------------------------------------------------
;sensor 2 drum 2 TURN AUDIO IN->OUT ON/OFF ;-------------------------------------------------------------------------------------------------------------
kson1022 trigger ks22, 0.5, 0
;turn audio on
ipiezzo1022 = 2
idrum1022 = 1
igain1022 = 1
; piezzo drum input
schedkwhen kson1022, imin, imax, 70, 0, 100, ipiezzo1022, idrum1022;, igain1022
ksoff1022 trigger ks22, 0.1, 1
schedkwhen ksoff1022, imin, imax, 71, 0, 0.1
;-------------------------------------------------------------------------------------------------------------
;sensor 4 drum 1 / TURN LIGHT ON on drum 2;-------------------------------------------------------------------------------------------------------------
kson1420 trigger ks14, 0.5, 0
idrum1420 = giportrelay2
; drum
schedkwhen kson1420, imin, 2, 62, 0, 100, idrum1420
;sensor 5 drum 1 / TURN LIGHT OFF on drum 2;-------------------------------------------------------------------------------------------------------------
idrum1520 = giportrelay2
kson1520 trigger ks15, 0.1, 0
schedkwhen kson1520, imin, imax, 79, 0, 0.2
schedkwhen kson1520, imin, 2, 63, 0, 0.1, idrum1520 ;turn off light
;; schedkwhen kson1520, imin, imax, 66, 0, 0.1 ;turn off rhythmic light
;; schedkwhen kson1520, imin, imax, 74, 0, 0.1 ;turn delay off
;; schedkwhen kson1520, imin, imax, 61, 0, 0.1 ;stop stroboscopic light
;-------------------------------------------------------------------------------------------------------------
;sensor 4 drum 2 / TURN LIGHT ON on drum 1
kson1024 trigger ks24, 0.5, 0
idrum1024 = giportrelay1
; drum
schedkwhen kson1024, imin, 2, 62, 0, 100, idrum1024
;sensor 5 drum 2 / TURN LIGHT OFF on drum 1 ALL OFF
idrum1025 = giportrelay1
kson1025 trigger ks25, 0.1, 0
schedkwhen kson1025, imin, imax, 79, 0, 0.2
schedkwhen kson1025, imin, 2, 63, 0, 0.1, idrum1025
;; schedkwhen kson1025, imin, imax, 66, 0, 0.1 ;turn off rhythmic light
;; schedkwhen kson1025, imin, imax, 74, 0, 0.1 ;turn delay off
;; schedkwhen kson1520, imin, imax, 61, 0, 0.1 ;stop stroboscopic light
;-------------------------------------------------------------------------------------------------------------
;sensor 3 + 4 drum 1 / TURN DELAY ON on drum 2 piezzo 2
kson1314 trigger ks340, 0.5, 0
ipiezzo1314 = 1
idrum1314 = 1
igain1314 = .5
; piezzo drum input gain
schedkwhen kson1314, imin, 2, 73, 0, 100, ipiezzo1314, idrum1314, igain1314
;ksoff1314 trigger ks340, 0.5, 1
;schedkwhen ksoff1314, imin, 2, 74, 0.1, 0.1
;sensor 3 + 4 drum 2 / TURN DELAY ON on drum 2 piezzo 2
kson2324 trigger ks034, 0.5, 0
ipiezzo2324 = 2
idrum2324 = 2
igain2324 = .5
; piezzo drum input gain
schedkwhen kson2324, imin, 2, 73, 0, 100, ipiezzo2324, idrum2324, igain2324
;ksoff2324 trigger ks034, 0.5, 1
;schedkwhen ksoff2324, imin, 2, 74, 0.1, 0.1
;sensor 1 drum 1 + sensor 1 drum 2 // RHYTHMIC LIGHT
kson1121 trigger ks101, 0.5, 0
ipan1121 = 0
itempo1121 = 48
; pan tempo
schedkwhen kson1121, imin, 4, 65, 0, 100, ipan1121, itempo1121
endin ;=========================================================
;===============================================================
; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
instr 60 ;stroboscopic light ;stroboscopic light ;stroboscopic light
iportrelay = p4 ;drum port
ifreq = p5
;kstrob oscil 1, kfreq, 2 ;squarewave
kstrob lfo 1, ifreq, 3;type 3 = square unipolar
digiOutBela kstrob, iportrelay
endin
instr 61 ;stop stroboscopic
;kill instr 60 stroboscopic
turnoff2 60, 0, 0
schedule 64, 0.05, 0.1 ;turn off lights
endin
instr 62 ;turn light on ;turn light on ;turn light on ;turn light on
iportrelay = p4
digiOutBela 0, iportrelay
endin
instr 63;turn light off ;turn light off ;turn light off ;turn light off
turnoff2 62, 0, 0
iportrelay = p4
digiOutBela 1, iportrelay
endin
instr 64 ;turn both lights off
digiOutBela 1, giportrelay1
digiOutBela 1, giportrelay2
endin
;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light
instr 65 ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light ;Rhythmic Light
ipan = p4 ;where is the puls
itempo = p5
if ipan == 0 then
irelay1 = giportrelay1
irelay2 = giportrelay2
else
irelay1 = giportrelay2
irelay2 = giportrelay1
endif
ifreq = itempo/60
kpuls metro ifreq
ktrig1 trigger kpuls, 0.5, 0
ildur = 1/ifreq
imin = 0.01
imax = 8
schedkwhen ktrig1, imin, imax, 67, 0, ildur, irelay1
endin
instr 66
turnoff2 65, 0, 0
turnoff2 67, 0, 0 ;turn off rhythmic delay
turnoff2 68, 0, 0
turnoff2 65, 0, 0
turnoff2 73, 0, 0 ;turn off delay
i60 active 60
if i60 > 0 then ;;if stroboscopi light is on then turn both lights off
schedule 61, 0.01, 0.1 ;turn off stroboscopic and turn off both lights
endif
endin
instr 67 ;light on for a short time RHYTHMIC LIGHT
idur = p3
iportrelay = p4
if iportrelay == 0 then
iportrelay1 = giportrelay1
iportrelay2 = giportrelay2
else
iportrelay1 = giportrelay2
iportrelay2 = giportrelay1
endif
ilight = 0.1
iatt = 0.001
irest = p3 - ilight- iatt * 2
if (irest <= 0) then
irest = 0.001
endif
klight linseg 1, iatt, 0, ilight, 0, iatt, 1, irest, 1
digiOutBela klight, iportrelay1
;call delayed light
idel random idur*0.5, idur-0.1
schedule 68, idel, idur, iportrelay2
endin
instr 68 ;delayed light
iportrelay = p4
ilight = 0.1
iatt = 0.001
irest = p3 - ilight- iatt * 2
if (irest <= 0) then
irest = 0.001
endif
klight linseg 1, iatt, 0, ilight, 0, iatt, 1, irest, 1
digiOutBela klight, iportrelay
endin
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
instr 70 ;turn audio amplification on
ipiezzo = p4-1
idrum = p5-1
igain = db(6)
apiezzo sum gain1 * (1-ipiezzo) * igain, gain2 * ipiezzo * igain
kfreq randomi 500, 2000, 4
imaxamp = db(9)
idect = 2
ksamp linsegr 0, 0.001, imaxamp, idect, 1, 1, 1
asin poscil ksamp, kfreq
amic clip apiezzo, 0, db(-6)
arm = asin * amic
aout1 = arm * (1-idrum)
aout2 = arm * idrum
;outs aout1, aout2
vincr gaout1, aout1
vincr gaout2, aout2
;;outch idrum, apiezzo*iamp * asin
endin
instr 71 ;turn audio off
turnoff2 70, 0, 0
endin
instr 73 ;turn delay on
;prints "\n DELAY ON ..."
;don't turn on if one instance is already on
i73 active 73
ifeedback = 0.95
idrum = p4
ipiezzo = p5
igain = p6
ilim = db(-6)
if ipiezzo == 1 then
ain clip gain1, 0, ilim
else
ain clip gain2, 0, ilim
endif
if1 = 20
if2 = 400
if3 = 20
if4 = 300
kdel1 randomh 1/if1, 1/if2, 1
kdel2 randomh 1/if3, 1/if4, .9
abuf1 delayr gidel
adel1 deltap kdel1
delayw ain * igain + (adel1 * ifeedback)
abuf2 delayr gidel
adel2 deltap kdel2
delayw ain * igain + (adel2 * ifeedback)
aout sum adel1, adel2
alim clip aout, 0, db(-3)
if idrum == 1 then
vincr gaout1, alim
else
vincr gaout2, alim
endif
;outch idrum, alim
endin
instr 74 ;turn delay off
;prints "\n DELAY OFF ..."
turnoff2 73, 0, 0
endin
instr 79 ;all off
i60 active 60
i65 active 65
i73 active 73
print i60, i65, i73
if i60 > 0 then ;stroboscopic light
;;turnoff2 60, 0, 0
schedule 61, 0, 0.1
endif
if i65 > 0 then ; ;rhythmic ligth
schedule 66, 0, 0.1
endif
if i73 > 0 then ;delay
turnoff2 73, 0, 0.1
endif
endin
instr 99
aout1 = gaout1
aout2 = gaout2
outs aout1, aout2
clear gain1, gain2, gaout1, gaout2
endin
</CsInstruments>
<CsScore>
f100 0 1024 7 0 24 1 1000 0 ;envelope
;f2 0 1024 -7 0 1 1 511 1 1 0 511 0 ;squarewave
; p4 p5
; drum freq
i60 0 .5 14 8;giportrelay1
i60 .5 .5 15 8; giportrelay2
i61 1 .1
i64 1.5 .1 ;turn both lights off
i10 2 86400 ;play for 24 h
i9 2 86400 ;audio in->out
i99 2 86400 ; Outputs + clear global variables
</CsScore>
</CsoundSynthesizer>