| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-i adc -o dac -m128 |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 1 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
/****** UDO definitions ******/ |
| 12 |
opcode createBuffer, i, i |
| 13 |
ilen xin |
| 14 |
ift ftgen 0, 0, ilen*sr, 2, 0 |
| 15 |
xout ift |
| 16 |
endop |
| 17 |
opcode recordBuffer, 0, aik |
| 18 |
ain, ift, krec xin |
| 19 |
setksmps 1 ;k=a here in this UDO |
| 20 |
kndx init 0 ;initialize index |
| 21 |
if krec == 1 then |
| 22 |
tablew ain, a(kndx), ift |
| 23 |
kndx = (kndx+1) % ftlen(ift) |
| 24 |
endif |
| 25 |
endop |
| 26 |
opcode keyPressed, k, kki |
| 27 |
kKey, kDown, iAscii xin |
| 28 |
kPrev init 0 ;previous key value |
| 29 |
kOut = (kKey == iAscii || (kKey == -1 && kPrev == iAscii) ? 1 : 0) |
| 30 |
kPrev = (kKey > 0 ? kKey : kPrev) |
| 31 |
kPrev = (kPrev == kKey && kDown == 0 ? 0 : kPrev) |
| 32 |
xout kOut |
| 33 |
endop |
| 34 |
opcode playBuffer, a, ik |
| 35 |
ift, kplay xin |
| 36 |
setksmps 1 ;k=a here in this UDO |
| 37 |
kndx init 0 ;initialize index |
| 38 |
if kplay == 1 then |
| 39 |
aRead table a(kndx), ift |
| 40 |
kndx = (kndx+1) % ftlen(ift) |
| 41 |
endif |
| 42 |
endop |
| 43 |
|
| 44 |
|
| 45 |
instr RecPlay |
| 46 |
iBuffer = createBuffer(3) ;buffer for 3 seconds of recording |
| 47 |
kKey, kDown sensekey |
| 48 |
recordBuffer(inch(1), iBuffer, keyPressed(kKey,kDown,114)) |
| 49 |
out playBuffer(iBuffer, keyPressed(kKey,kDown,112)) |
| 50 |
endin |
| 51 |
|
| 52 |
</CsInstruments> |
| 53 |
<CsScore> |
| 54 |
i 1 0 1000 |
| 55 |
</CsScore> |
| 56 |
</CsoundSynthesizer> |
| 57 |
;example written by joachim heintz |