| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac |
| 4 |
-m0 |
| 5 |
</CsOptions> |
| 6 |
<CsInstruments> |
| 7 |
|
| 8 |
/* |
| 9 |
|
| 10 |
Dependencies: |
| 11 |
plugins: klib, else |
| 12 |
*/ |
| 13 |
|
| 14 |
sr = 44100 |
| 15 |
ksmps = 64 |
| 16 |
nchnls = 2 |
| 17 |
0dbfs = 1 |
| 18 |
|
| 19 |
gi_refreshRate = 20 |
| 20 |
|
| 21 |
opcode makeCircBuffer, i, i |
| 22 |
idur xin |
| 23 |
; quantize table length to ksmps |
| 24 |
inumsamples = ceil(sr*idur / ksmps) * ksmps |
| 25 |
itable = ftgen(0, 0, inumsamples, 2, 0) |
| 26 |
iobj = dict_new("str:float", "table", itable, "writePointer", 0, "readPointer", 0, "recDur", 0) |
| 27 |
xout iobj |
| 28 |
endop |
| 29 |
|
| 30 |
instr recCircBuffer |
| 31 |
ibuf, ichan passign 4 |
| 32 |
itab = dict_get:i(ibuf, "table") |
| 33 |
itablen = ftlen(itab) |
| 34 |
imaxdur = itablen / sr |
| 35 |
ftset itab, 0 |
| 36 |
ktime = timeinsts() |
| 37 |
asig = inch(ichan) |
| 38 |
aindex = accum:a(1) % itablen |
| 39 |
tablew asig, aindex, itab |
| 40 |
|
| 41 |
if lastcycle() == 1 then |
| 42 |
; stop recording |
| 43 |
dict_set ibuf, "recDur", min(ktime, imaxdur) |
| 44 |
kwritePointer = aindex[ksmps-1] |
| 45 |
dict_set ibuf, "writePointer", kwritePointer |
| 46 |
dict_set ibuf, "readPointer", ktime < imaxdur ? 0 : kwritePointer |
| 47 |
endif |
| 48 |
endin |
| 49 |
|
| 50 |
instr playCircBuffer |
| 51 |
ibuf, ispeed, ichan passign 4 |
| 52 |
idur dict_get ibuf, "recDur" |
| 53 |
itab dict_get ibuf, "table" |
| 54 |
ioffset dict_get ibuf, "readPointer" |
| 55 |
ifade = 0.08 |
| 56 |
asig table3 line:a(0, idur/ispeed, idur*sr), itab, 0, ioffset, 1 |
| 57 |
asig *= linsegr:a(0, ifade, 1, ifade, 0) |
| 58 |
outch ichan, asig |
| 59 |
if timeinsts() > idur/ispeed - ifade - 2*ksmps/sr then |
| 60 |
turnoff2 p1, 4, 1 |
| 61 |
endif |
| 62 |
endin |
| 63 |
|
| 64 |
opcode toggleInstr, 0, SkiOOOOOO |
| 65 |
Sname, kgate, idt, kp4, kp5, kp6, kp7, kp8, kp9 xin |
| 66 |
if changed2(kgate) == 0 kgoto skip |
| 67 |
if kgate == 1 then |
| 68 |
schedulek Sname, idt, -1, kp4, kp5, kp6, kp7, kp8, kp9 |
| 69 |
else |
| 70 |
turnoff2 Sname, 0, 1 |
| 71 |
endif |
| 72 |
skip: |
| 73 |
endop |
| 74 |
|
| 75 |
instr main |
| 76 |
; a circular buffer with a max. recording duration of 20 secs |
| 77 |
ibuf = makeCircBuffer(20) |
| 78 |
if timeinstk() == 1 then |
| 79 |
outvalue "plot", sprintf("@set %d",dict_get:i(ibuf, "table")) |
| 80 |
endif |
| 81 |
krec invalue "record" |
| 82 |
kplay = 1 - krec |
| 83 |
|
| 84 |
toggleInstr "recCircBuffer", krec, 0, ibuf, 1 |
| 85 |
toggleInstr "playCircBuffer", kplay, 0.01, ibuf, /*speed*/ 1, /*outchannel*/ 1 |
| 86 |
|
| 87 |
if metro(gi_refreshRate) == 1 then |
| 88 |
outvalue "plot", "@update" |
| 89 |
endif |
| 90 |
endin |
| 91 |
|
| 92 |
schedule "main", 0, -1 |
| 93 |
|
| 94 |
</CsInstruments> |
| 95 |
<CsScore> |
| 96 |
|
| 97 |
</CsScore> |
| 98 |
</CsoundSynthesizer> |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
<bsbPanel> |
| 104 |
<label>Widgets</label> |
| 105 |
<objectName/> |
| 106 |
<x>0</x> |
| 107 |
<y>0</y> |
| 108 |
<width>610</width> |
| 109 |
<height>288</height> |
| 110 |
<visible>true</visible> |
| 111 |
<uuid/> |
| 112 |
<bgcolor mode="nobackground"> |
| 113 |
<r>255</r> |
| 114 |
<g>255</g> |
| 115 |
<b>255</b> |
| 116 |
</bgcolor> |
| 117 |
<bsbObject type="BSBButton" version="2"> |
| 118 |
<objectName>record</objectName> |
| 119 |
<x>12</x> |
| 120 |
<y>12</y> |
| 121 |
<width>80</width> |
| 122 |
<height>80</height> |
| 123 |
<uuid>{b8ffa76d-0f30-4672-a916-b7fd3942830f}</uuid> |
| 124 |
<visible>true</visible> |
| 125 |
<midichan>0</midichan> |
| 126 |
<midicc>0</midicc> |
| 127 |
<description/> |
| 128 |
<type>value</type> |
| 129 |
<pressedValue>1.00000000</pressedValue> |
| 130 |
<stringvalue/> |
| 131 |
<text>REC</text> |
| 132 |
<image>/</image> |
| 133 |
<eventLine>i1 0 -1</eventLine> |
| 134 |
<latch>true</latch> |
| 135 |
<momentaryMidiButton>false</momentaryMidiButton> |
| 136 |
<latched>false</latched> |
| 137 |
<fontsize>30</fontsize> |
| 138 |
</bsbObject> |
| 139 |
<bsbObject type="BSBTableDisplay" version="2"> |
| 140 |
<objectName>plot</objectName> |
| 141 |
<x>12</x> |
| 142 |
<y>97</y> |
| 143 |
<width>598</width> |
| 144 |
<height>191</height> |
| 145 |
<uuid>{773494f8-6777-408a-89a3-0e7ad186ebda}</uuid> |
| 146 |
<visible>true</visible> |
| 147 |
<midichan>0</midichan> |
| 148 |
<midicc>-3</midicc> |
| 149 |
<description/> |
| 150 |
<color> |
| 151 |
<r>255</r> |
| 152 |
<g>193</g> |
| 153 |
<b>3</b> |
| 154 |
</color> |
| 155 |
<range>1.00</range> |
| 156 |
</bsbObject> |
| 157 |
</bsbPanel> |
| 158 |
<bsbPresets> |
| 159 |
</bsbPresets> |