| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
-odac ;;;realtime audio out |
| 5 |
;-iadc ;;;uncomment -iadc if realtime audio input is needed too |
| 6 |
; For Non-realtime ouput leave only the line below: |
| 7 |
; -o joystick-2.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
sr = 44100 |
| 12 |
ksmps = 32 |
| 13 |
nchnls = 2 |
| 14 |
;0dbfs = 1 |
| 15 |
|
| 16 |
instr 1 |
| 17 |
|
| 18 |
kmask joystick 0, 1 |
| 19 |
kaxes init 0 |
| 20 |
kbuttons init 0 |
| 21 |
kx0 init 0 ; first two entries are # of axes and # of buttons, |
| 22 |
ky0 init 0 ; then axes, then buttons |
| 23 |
vtabk 0, 1, kaxes, kbuttons, kx0, ky0 |
| 24 |
kidx = 2+kaxes |
| 25 |
|
| 26 |
buttons: |
| 27 |
kcheck = kmask & 1<<kidx ; if the button was just now pressed and... |
| 28 |
kres tab kidx, 1 ; if button value is one, start a note |
| 29 |
schedkwhen kres*kcheck, 1, 20, 2, 0, 60000, kidx, kx0, ky0 |
| 30 |
kidx = kidx+1 |
| 31 |
if kidx < (kaxes+kbuttons+2) kgoto buttons |
| 32 |
|
| 33 |
endin |
| 34 |
|
| 35 |
instr 2 ; play a tone until the button is released |
| 36 |
|
| 37 |
kstop tab p4, 1 ; when this button is released, we fade out |
| 38 |
ihz init cpsoct(((p5+32767)/9362)+5) ; ~ 30 hz to 4khz |
| 39 |
print ihz |
| 40 |
ito init ampdb(((p6+32767)/2184)+60) ; ~ 60 - 90 db |
| 41 |
kenv init 0 |
| 42 |
kdelta init ito/(kr*10) |
| 43 |
if kstop == 1 kgoto output |
| 44 |
if kdelta < 0 kgoto output |
| 45 |
kdelta = kdelta*-1 |
| 46 |
|
| 47 |
output: |
| 48 |
kenv = kenv+kdelta |
| 49 |
kenv limit kenv, 0, ito |
| 50 |
aout oscils 1, ihz, 0 |
| 51 |
aout = kenv*aout |
| 52 |
outs aout, aout |
| 53 |
if kenv != 0 kgoto noexit |
| 54 |
if kdelta > 0 kgoto noexit |
| 55 |
turnoff |
| 56 |
noexit: |
| 57 |
|
| 58 |
endin |
| 59 |
</CsInstruments> |
| 60 |
<CsScore> |
| 61 |
f1 0 32 7 0 7 0 ; will hold the joystick data |
| 62 |
|
| 63 |
i1 0 60000 |
| 64 |
|
| 65 |
e |
| 66 |
</CsScore> |
| 67 |
</CsoundSynthesizer> |