| 1 |
/*Getting started.. Realtime Interaction: Live Audio Input |
| 2 |
|
| 3 |
Two very common live-electronic uscases are modifying an incoming signal in realtime, or analysing it. |
| 4 |
To avoid acoustic feedbacks, this example, does not output the input-signal! |
| 5 |
|
| 6 |
Here, the input's frequency and amplitude are analysed in realtime and displayed on the Widget-Panel. |
| 7 |
The second instrument can be started, which uses these information to control an oscillator. |
| 8 |
|
| 9 |
(If this is using to much CPU power and does crackle, increase the buffersize in the Preferences Menu(->Run->Buffer Size). |
| 10 |
A good startingpoint is Buffersize (-b)=128; HW Buffersize(-B)=512.) |
| 11 |
|
| 12 |
More information concerning realtime-audio can be found in the Csound-Manual: Using Csound-> Optimizing Audio I/O Latency |
| 13 |
*/ |
| 14 |
|
| 15 |
<CsoundSynthesizer> |
| 16 |
<CsOptions> |
| 17 |
</CsOptions> |
| 18 |
<CsInstruments> |
| 19 |
|
| 20 |
sr = 44100 |
| 21 |
ksmps = 32 |
| 22 |
nchnls = 1 |
| 23 |
0dbfs = 1 |
| 24 |
|
| 25 |
instr 1 |
| 26 |
aInput inch 1 ; read audiohardware channel 1 |
| 27 |
ifftsize = 1024 ; set the buffersize for later fft-analysis |
| 28 |
iwtype = 1 ; hanning window |
| 29 |
fsig pvsanal aInput, ifftsize, ifftsize/4, ifftsize, iwtype ; generate an fsig from the mono audio source |
| 30 |
gkFreq, gkAmp pvspitch fsig, 0.01 ; pitch and amplitude analysis tool |
| 31 |
outvalue "pitch", gkFreq ; send pitch-values to Widget |
| 32 |
outvalue "amp", gkAmp ; send amplitude-values to Widget |
| 33 |
endin |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
instr 2 |
| 38 |
aSrc oscili gkAmp, gkFreq, 1 ; instrument 1 used global k-variables, so they can be read-out here.. |
| 39 |
kFeedback=0.6 ; feedback-amount for the delay |
| 40 |
aDelay delayr 1 |
| 41 |
aWet deltapi 0.2 |
| 42 |
delayw aSrc+(aWet*kFeedback) |
| 43 |
aOut = aSrc+(aWet*0.3) ; mixing the oscillator with the delay |
| 44 |
out aOut |
| 45 |
endin |
| 46 |
|
| 47 |
</CsInstruments> |
| 48 |
<CsScore> |
| 49 |
f 1 0 256 7 0 128 1 0 -1 128 0 |
| 50 |
i 1 0 3600 ; instrument 1 runs for one hour |
| 51 |
e |
| 52 |
</CsScore> |
| 53 |
</CsoundSynthesizer> |
| 54 |
; written by Alex Hofmann (Dec. 2009) - Incontri HMT-Hannover |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
<bsbPanel> |
| 60 |
<label>Widgets</label> |
| 61 |
<objectName/> |
| 62 |
<x>1013</x> |
| 63 |
<y>279</y> |
| 64 |
<width>563</width> |
| 65 |
<height>397</height> |
| 66 |
<visible>true</visible> |
| 67 |
<uuid/> |
| 68 |
<bgcolor mode="background"> |
| 69 |
<r>132</r> |
| 70 |
<g>162</g> |
| 71 |
<b>8</b> |
| 72 |
</bgcolor> |
| 73 |
<bsbObject version="2" type="BSBScrollNumber"> |
| 74 |
<objectName>pitch</objectName> |
| 75 |
<x>22</x> |
| 76 |
<y>81</y> |
| 77 |
<width>80</width> |
| 78 |
<height>25</height> |
| 79 |
<uuid>{2ed22600-54f1-40bd-84c6-8a0812cbfa4f}</uuid> |
| 80 |
<visible>true</visible> |
| 81 |
<midichan>0</midichan> |
| 82 |
<midicc>-3</midicc> |
| 83 |
<alignment>left</alignment> |
| 84 |
<font>Lucida Grande</font> |
| 85 |
<fontsize>10</fontsize> |
| 86 |
<color> |
| 87 |
<r>0</r> |
| 88 |
<g>0</g> |
| 89 |
<b>0</b> |
| 90 |
</color> |
| 91 |
<bgcolor mode="background"> |
| 92 |
<r>255</r> |
| 93 |
<g>255</g> |
| 94 |
<b>255</b> |
| 95 |
</bgcolor> |
| 96 |
<value>0.00000000</value> |
| 97 |
<resolution>1.00000000</resolution> |
| 98 |
<minimum>-999999999999.00000000</minimum> |
| 99 |
<maximum>99999999999999.00000000</maximum> |
| 100 |
<bordermode>border</bordermode> |
| 101 |
<borderradius>1</borderradius> |
| 102 |
<borderwidth>1</borderwidth> |
| 103 |
<randomizable group="0">false</randomizable> |
| 104 |
<mouseControl act="continuous"/> |
| 105 |
</bsbObject> |
| 106 |
<bsbObject version="2" type="BSBLabel"> |
| 107 |
<objectName/> |
| 108 |
<x>23</x> |
| 109 |
<y>45</y> |
| 110 |
<width>135</width> |
| 111 |
<height>23</height> |
| 112 |
<uuid>{6fda8591-4b9d-4494-8336-304c3e3f492b}</uuid> |
| 113 |
<visible>true</visible> |
| 114 |
<midichan>0</midichan> |
| 115 |
<midicc>-3</midicc> |
| 116 |
<label>Input Pitch Detection in Hz</label> |
| 117 |
<alignment>left</alignment> |
| 118 |
<font>Lucida Grande</font> |
| 119 |
<fontsize>10</fontsize> |
| 120 |
<precision>3</precision> |
| 121 |
<color> |
| 122 |
<r>0</r> |
| 123 |
<g>0</g> |
| 124 |
<b>0</b> |
| 125 |
</color> |
| 126 |
<bgcolor mode="nobackground"> |
| 127 |
<r>255</r> |
| 128 |
<g>255</g> |
| 129 |
<b>255</b> |
| 130 |
</bgcolor> |
| 131 |
<bordermode>noborder</bordermode> |
| 132 |
<borderradius>1</borderradius> |
| 133 |
<borderwidth>1</borderwidth> |
| 134 |
</bsbObject> |
| 135 |
<bsbObject version="2" type="BSBButton"> |
| 136 |
<objectName>button1</objectName> |
| 137 |
<x>24</x> |
| 138 |
<y>257</y> |
| 139 |
<width>100</width> |
| 140 |
<height>30</height> |
| 141 |
<uuid>{4d130bbd-90c2-4a9c-9c3c-038cbfd4a569}</uuid> |
| 142 |
<visible>true</visible> |
| 143 |
<midichan>0</midichan> |
| 144 |
<midicc>-3</midicc> |
| 145 |
<type>event</type> |
| 146 |
<pressedValue>1.00000000</pressedValue> |
| 147 |
<stringvalue/> |
| 148 |
<text>Play Synth</text> |
| 149 |
<image>/</image> |
| 150 |
<eventLine>i2 0 20</eventLine> |
| 151 |
<latch>false</latch> |
| 152 |
<latched>false</latched> |
| 153 |
</bsbObject> |
| 154 |
<bsbObject version="2" type="BSBScrollNumber"> |
| 155 |
<objectName>amp</objectName> |
| 156 |
<x>190</x> |
| 157 |
<y>81</y> |
| 158 |
<width>80</width> |
| 159 |
<height>25</height> |
| 160 |
<uuid>{fbe6c4b8-1663-496e-bc07-a60795aa5223}</uuid> |
| 161 |
<visible>true</visible> |
| 162 |
<midichan>0</midichan> |
| 163 |
<midicc>-3</midicc> |
| 164 |
<alignment>left</alignment> |
| 165 |
<font>Lucida Grande</font> |
| 166 |
<fontsize>10</fontsize> |
| 167 |
<color> |
| 168 |
<r>0</r> |
| 169 |
<g>0</g> |
| 170 |
<b>0</b> |
| 171 |
</color> |
| 172 |
<bgcolor mode="background"> |
| 173 |
<r>255</r> |
| 174 |
<g>255</g> |
| 175 |
<b>255</b> |
| 176 |
</bgcolor> |
| 177 |
<value>0.00551000</value> |
| 178 |
<resolution>0.00001000</resolution> |
| 179 |
<minimum>-999999999999.00000000</minimum> |
| 180 |
<maximum>99999999999999.00000000</maximum> |
| 181 |
<bordermode>border</bordermode> |
| 182 |
<borderradius>1</borderradius> |
| 183 |
<borderwidth>1</borderwidth> |
| 184 |
<randomizable group="0">false</randomizable> |
| 185 |
<mouseControl act="continuous"/> |
| 186 |
</bsbObject> |
| 187 |
<bsbObject version="2" type="BSBLabel"> |
| 188 |
<objectName/> |
| 189 |
<x>188</x> |
| 190 |
<y>45</y> |
| 191 |
<width>135</width> |
| 192 |
<height>23</height> |
| 193 |
<uuid>{f49d0afd-2282-4d02-aff1-fbc7140454f5}</uuid> |
| 194 |
<visible>true</visible> |
| 195 |
<midichan>0</midichan> |
| 196 |
<midicc>-3</midicc> |
| 197 |
<label>Amplitude Detection (0-1)</label> |
| 198 |
<alignment>left</alignment> |
| 199 |
<font>Lucida Grande</font> |
| 200 |
<fontsize>10</fontsize> |
| 201 |
<precision>3</precision> |
| 202 |
<color> |
| 203 |
<r>0</r> |
| 204 |
<g>0</g> |
| 205 |
<b>0</b> |
| 206 |
</color> |
| 207 |
<bgcolor mode="nobackground"> |
| 208 |
<r>255</r> |
| 209 |
<g>255</g> |
| 210 |
<b>255</b> |
| 211 |
</bgcolor> |
| 212 |
<bordermode>noborder</bordermode> |
| 213 |
<borderradius>1</borderradius> |
| 214 |
<borderwidth>1</borderwidth> |
| 215 |
</bsbObject> |
| 216 |
<bsbObject version="2" type="BSBLabel"> |
| 217 |
<objectName/> |
| 218 |
<x>23</x> |
| 219 |
<y>162</y> |
| 220 |
<width>151</width> |
| 221 |
<height>31</height> |
| 222 |
<uuid>{db5447c5-b354-4549-962f-ce336996a6a3}</uuid> |
| 223 |
<visible>true</visible> |
| 224 |
<midichan>0</midichan> |
| 225 |
<midicc>-3</midicc> |
| 226 |
<label>Instrument 2</label> |
| 227 |
<alignment>left</alignment> |
| 228 |
<font>Lucida Grande</font> |
| 229 |
<fontsize>18</fontsize> |
| 230 |
<precision>3</precision> |
| 231 |
<color> |
| 232 |
<r>0</r> |
| 233 |
<g>0</g> |
| 234 |
<b>0</b> |
| 235 |
</color> |
| 236 |
<bgcolor mode="nobackground"> |
| 237 |
<r>255</r> |
| 238 |
<g>255</g> |
| 239 |
<b>255</b> |
| 240 |
</bgcolor> |
| 241 |
<bordermode>noborder</bordermode> |
| 242 |
<borderradius>1</borderradius> |
| 243 |
<borderwidth>1</borderwidth> |
| 244 |
</bsbObject> |
| 245 |
<bsbObject version="2" type="BSBLabel"> |
| 246 |
<objectName/> |
| 247 |
<x>23</x> |
| 248 |
<y>7</y> |
| 249 |
<width>151</width> |
| 250 |
<height>31</height> |
| 251 |
<uuid>{86023008-0f06-43e0-b9e9-54af7eb61e2c}</uuid> |
| 252 |
<visible>true</visible> |
| 253 |
<midichan>0</midichan> |
| 254 |
<midicc>-3</midicc> |
| 255 |
<label>Instrument 1</label> |
| 256 |
<alignment>left</alignment> |
| 257 |
<font>Lucida Grande</font> |
| 258 |
<fontsize>18</fontsize> |
| 259 |
<precision>3</precision> |
| 260 |
<color> |
| 261 |
<r>0</r> |
| 262 |
<g>0</g> |
| 263 |
<b>0</b> |
| 264 |
</color> |
| 265 |
<bgcolor mode="nobackground"> |
| 266 |
<r>255</r> |
| 267 |
<g>255</g> |
| 268 |
<b>255</b> |
| 269 |
</bgcolor> |
| 270 |
<bordermode>noborder</bordermode> |
| 271 |
<borderradius>1</borderradius> |
| 272 |
<borderwidth>1</borderwidth> |
| 273 |
</bsbObject> |
| 274 |
<bsbObject version="2" type="BSBLabel"> |
| 275 |
<objectName/> |
| 276 |
<x>21</x> |
| 277 |
<y>196</y> |
| 278 |
<width>156</width> |
| 279 |
<height>61</height> |
| 280 |
<uuid>{8fc51e65-a83f-47b5-9b87-02f6a84812b8}</uuid> |
| 281 |
<visible>true</visible> |
| 282 |
<midichan>0</midichan> |
| 283 |
<midicc>-3</midicc> |
| 284 |
<label>This button plays a synth for 20 seconds, which gets the frequency, from the input-analysis.</label> |
| 285 |
<alignment>left</alignment> |
| 286 |
<font>Lucida Grande</font> |
| 287 |
<fontsize>10</fontsize> |
| 288 |
<precision>3</precision> |
| 289 |
<color> |
| 290 |
<r>0</r> |
| 291 |
<g>0</g> |
| 292 |
<b>0</b> |
| 293 |
</color> |
| 294 |
<bgcolor mode="nobackground"> |
| 295 |
<r>255</r> |
| 296 |
<g>255</g> |
| 297 |
<b>255</b> |
| 298 |
</bgcolor> |
| 299 |
<bordermode>noborder</bordermode> |
| 300 |
<borderradius>1</borderradius> |
| 301 |
<borderwidth>1</borderwidth> |
| 302 |
</bsbObject> |
| 303 |
</bsbPanel> |
| 304 |
<bsbPresets> |
| 305 |
</bsbPresets> |
| 306 |
<EventPanel name="Events" tempo="60.00000000" loop="8.00000000" x="320" y="218" width="513" height="322" visible="true" loopStart="0" loopEnd="0"> </EventPanel> |