| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
; Audio out Audio in |
| 5 |
-odac -iadc -M0 ;;;RT audio I/O with MIDI in |
| 6 |
</CsOptions> |
| 7 |
<CsInstruments> |
| 8 |
|
| 9 |
; Example by Jonathan Murphy and Charles Gran 2007 |
| 10 |
sr = 44100 |
| 11 |
ksmps = 10 |
| 12 |
nchnls = 2 |
| 13 |
|
| 14 |
; new, and important. Make sure that midi note events are only |
| 15 |
; received by instruments that actually need them. |
| 16 |
|
| 17 |
; turn default midi routing off |
| 18 |
massign 0, 0 |
| 19 |
; route note events on channel 1 to instr 1 |
| 20 |
massign 1, 1 |
| 21 |
|
| 22 |
; Define your midi controllers |
| 23 |
#define C1 #21# |
| 24 |
#define C2 #22# |
| 25 |
#define C3 #23# |
| 26 |
|
| 27 |
; Initialize MIDI controllers |
| 28 |
initc7 1, 21, 0.5 ;delay send |
| 29 |
initc7 1, 22, 0.5 ;delay: time to zero |
| 30 |
initc7 1, 23, 0.5 ;delay: rate |
| 31 |
|
| 32 |
gaosc init 0 |
| 33 |
|
| 34 |
; Define an opcode to "smooth" the MIDI controller signal |
| 35 |
opcode smooth, k, k |
| 36 |
kin xin |
| 37 |
kport linseg 0, 0.0001, 0.01, 1, 0.01 |
| 38 |
kin portk kin, kport |
| 39 |
xout kin |
| 40 |
endop |
| 41 |
|
| 42 |
instr 1 |
| 43 |
; Generate a sine wave at the frequency of the MIDI note that triggered the intrument |
| 44 |
ifqc cpsmidi |
| 45 |
iamp ampmidi 10000 |
| 46 |
aenv linenr iamp, .01, .1, .01 ;envelope |
| 47 |
a1 oscil aenv, ifqc, 1 |
| 48 |
; All sound goes to the global variable gaosc |
| 49 |
gaosc = gaosc + a1 |
| 50 |
endin |
| 51 |
|
| 52 |
instr 198 ; ECHO |
| 53 |
kcmbsnd ctrl7 1, 21, 0, 1 ;delay send |
| 54 |
ktime ctrl7 1, 22, 0.01, 6 ;time loop fades out |
| 55 |
kloop ctrl7 1, 23, 0.01, 1 ;loop speed |
| 56 |
; Receive MIDI controller values and then smooth them |
| 57 |
kcmbsnd smooth kcmbsnd |
| 58 |
ktime smooth ktime |
| 59 |
kloop smooth kloop |
| 60 |
|
| 61 |
imaxlpt = 1 ;max loop time |
| 62 |
; Create a variable reverberation (delay) of the gaosc signal |
| 63 |
acomb vcomb gaosc, ktime, kloop, imaxlpt, 1 |
| 64 |
aout = (acomb * kcmbsnd) + gaosc * (1 - kcmbsnd) |
| 65 |
outs aout, aout |
| 66 |
gaosc = 0 |
| 67 |
endin |
| 68 |
|
| 69 |
</CsInstruments> |
| 70 |
|
| 71 |
<CsScore> |
| 72 |
f1 0 16384 10 1 |
| 73 |
i198 0 10000 |
| 74 |
e |
| 75 |
</CsScore> |
| 76 |
</CsoundSynthesizer> |