| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-iadc -odac |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 2 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
seed 0; random seed different each time |
| 12 |
|
| 13 |
instr 1; master instrument |
| 14 |
ichoose = p4; 1 = real time audio, 2 = random amplitude movement |
| 15 |
ithresh = -12; threshold in dB |
| 16 |
kstat init 1; 1 = under the threshold, 2 = over the threshold |
| 17 |
;;CHOOSE INPUT SIGNAL |
| 18 |
if ichoose == 1 then |
| 19 |
ain inch 1 |
| 20 |
else |
| 21 |
kdB randomi -18, -6, 1 |
| 22 |
ain pinkish ampdb(kdB) |
| 23 |
endif |
| 24 |
;;MEASURE AMPLITUDE AND TRIGGER SUBINSTRUMENTS IF THRESHOLD IS CROSSED |
| 25 |
afoll follow ain, .1; measure mean amplitude each 1/10 second |
| 26 |
kfoll downsamp afoll |
| 27 |
if kstat == 1 && dbamp(kfoll) > ithresh then; transition down->up |
| 28 |
event "i", 2, 0, 1; call instr 2 |
| 29 |
printks "Amplitude = %.3f dB%n", 0, dbamp(kfoll) |
| 30 |
kstat = 2; change status to "up" |
| 31 |
elseif kstat == 2 && dbamp(kfoll) < ithresh then; transition up->down |
| 32 |
event "i", 3, 0, 1; call instr 3 |
| 33 |
printks "Amplitude = %.3f dB%n", 0, dbamp(kfoll) |
| 34 |
kstat = 1; change status to "down" |
| 35 |
endif |
| 36 |
endin |
| 37 |
|
| 38 |
instr 2; triggered if threshold has been crossed from down to up |
| 39 |
asig poscil .2, 500 |
| 40 |
aenv transeg 1, p3, -10, 0 |
| 41 |
outs asig*aenv, asig*aenv |
| 42 |
endin |
| 43 |
|
| 44 |
instr 3; triggered if threshold has been crossed from up to down |
| 45 |
asig poscil .2, 400 |
| 46 |
aenv transeg 1, p3, -10, 0 |
| 47 |
outs asig*aenv, asig*aenv |
| 48 |
endin |
| 49 |
|
| 50 |
</CsInstruments> |
| 51 |
<CsScore> |
| 52 |
i 1 0 1000 2 ;change p4 to "1" for live input |
| 53 |
e |
| 54 |
</CsScore> |
| 55 |
</CsoundSynthesizer> |
| 56 |
;example by joachim heintz |