| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; real-time audio in and out are both activated |
| 4 |
-iadc -odac -m128 |
| 5 |
</CsOptions> |
| 6 |
<CsInstruments> |
| 7 |
sr = 44100 |
| 8 |
ksmps = 32 |
| 9 |
nchnls = 2 |
| 10 |
0dbfs = 1 |
| 11 |
|
| 12 |
giTabLenSec = 3 ;table duration in seconds |
| 13 |
giBuffer ftgen 0, 0, giTabLenSec*sr, 2, 0; table for audio data storage |
| 14 |
maxalloc 2,1 ; allow only one instance of the recording instrument at a time! |
| 15 |
|
| 16 |
instr 1 ; Sense keyboard activity. Trigger record or playback accordingly. |
| 17 |
prints "Press 'r' to record, 'p' for playback.\n" |
| 18 |
kKey sensekey ; sense activity on the computer keyboard |
| 19 |
if kKey==114 then ; if ASCCI value of 114 ('r') is output |
| 20 |
event "i", 2, 0, giTabLenSec ; activate recording instrument (2) |
| 21 |
endif |
| 22 |
if kKey==112 then ; if ASCCI value of 112 ('p) is output |
| 23 |
event "i", 3, 0, giTabLenSec ; activate playback instrument |
| 24 |
endif |
| 25 |
endin |
| 26 |
|
| 27 |
instr 2 ; record to buffer |
| 28 |
; -- print progress information to terminal -- |
| 29 |
prints "recording" |
| 30 |
printks ".", 0.25 ; print '.' every quarter of a second |
| 31 |
krelease release ; sense when note is in final k-rate pass... |
| 32 |
if krelease==1 then ; then .. |
| 33 |
printks "\ndone\n", 0 ; ... print a message |
| 34 |
endif |
| 35 |
; -- write audio to table -- |
| 36 |
ain inch 1 ; read audio from live input channel 1 |
| 37 |
andx line 0,p3,ftlen(giBuffer); create an index for writing to table |
| 38 |
tablew ain,andx,giBuffer ; write audio to function table |
| 39 |
endin |
| 40 |
|
| 41 |
instr 3 ; playback from buffer |
| 42 |
; -- print progress information to terminal -- |
| 43 |
prints "playback" |
| 44 |
printks ".", 0.25 ; print '.' every quarter of a second |
| 45 |
krelease release ; sense when note is in final k-rate pass |
| 46 |
if krelease=1 then ; then ... |
| 47 |
printks "\ndone\n", 0 ; ... print a message |
| 48 |
endif; end of conditional branch |
| 49 |
; -- read audio from table -- |
| 50 |
aNdx line 0, p3, ftlen(giBuffer) ;create an index for reading from table |
| 51 |
aRead table aNdx, giBuffer ; read audio to audio storage table |
| 52 |
out aRead, aRead ; send audio to output |
| 53 |
endin |
| 54 |
|
| 55 |
</CsInstruments> |
| 56 |
<CsScore> |
| 57 |
i 1 0 3600 ; Sense keyboard activity. Start recording - playback. |
| 58 |
</CsScore> |
| 59 |
</CsoundSynthesizer> |
| 60 |
;example written by Iain McCurdy |