Debian Codegraph @

src/Examples/McCurdy Collection/LiveSampling/sndloop.csd

raw
1 ;Written by Iain McCurdy, 2009
2
3 ; Modified for QuteCsound by René, January 2011
4 ; Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6
7 ;Notes on modifications from original csd:
8
9
10 ;my flags on Ubuntu: -dm0 -iadc -odac -+rtaudio=jack -b16 -B4096 --expression-opt -+rtmidi=alsa -Ma
11 <CsoundSynthesizer>
12 <CsOptions>
13
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100 ;SAMPLE RATE
17 ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
18 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
19
20
21 instr 10 ;GUI
22 ktrig metro 10
23 if (ktrig == 1)then
24 gktrig invalue "Play_Stop"
25 ktrigOn trigger gktrig, 0.5, 0
26 schedkwhen ktrigOn, 0, 0, 2, 0, 0.01
27 gkmute invalue "Mute_Live"
28 gkdur invalue "Duration"
29 gkpitch invalue "Pitch"
30 gkfad invalue "Crossfade"
31 gkInGain invalue "Input_Gain"
32 endif
33 endin
34
35 instr 1 ;MIDI ACTIVATED INSTRUMENT - READS MIDI NOTE VALUES
36 icps cpsmidi ;READ PITCH VALUES (IN HERTZ) FROM A CONNECTED MIDI KEYBOARD
37 ifreqratio = icps/261.626 ;DERIVE A FREQUENCY RATI0 (BASE FREQUENCY IS MIDDLE C)
38 outvalue "Pitch", ifreqratio ;SEND FREQUENCY RATIO VALUE TO 'Pitch' FADER.
39 gkpitch init ifreqratio ;SET gkpitch TO ifreqratio.
40 endin
41
42 instr 2 ;RESTARTS INSTR 3 WHEN RECORD-PLAY/STOP IS PRESSED
43 turnon 3
44 endin
45
46 instr 3 ;SOUND PRODUCING INSTRUMENT
47 krecflag init 0
48
49 ain inch 1 ;READ AUDIO FROM LIVE INPUT CHANNEL 1
50 asig, krec sndloop ain*gkInGain, gkpitch, gktrig, i(gkdur), i(gkfad)
51
52 kupdate changed krec ;IF krec CHANGES, (I.E. STATE CHANGES FROM RECORDING TO PLAYBACK), kupdate WILL BE MOMENTARILY 1
53
54 if kupdate = 1 then
55 outvalue "Recording", krec ;UPDATE 'RECORDING' INDICATOR
56 endif
57
58 krecflag max krec, krecflag
59
60 if gkmute = 1 then
61 if (krecflag == 1 && krec == 0) then
62 outs asig, asig ;SEND AUDIO TO OUTPUT
63 endif
64 else
65 outs asig, asig ;SEND AUDIO TO OUTPUT
66 endif
67 endin
68 </CsInstruments>
69 <CsScore>
70 i 10 0 3600 ;GUI
71
72 i 2 0 3600 ;INSTRUMENT PLAYS FOR 1 HOUR (AND SUSTAINS REALTIME PERFORMANCE)
73 </CsScore>
74 </CsoundSynthesizer>
75 <bsbPanel>
76 <label>Widgets</label>
77 <objectName/>
78 <x>657</x>
79 <y>667</y>
80 <width>1000</width>
81 <height>327</height>
82 <visible>true</visible>
83 <uuid/>
84 <bgcolor mode="nobackground">
85 <r>202</r>
86 <g>202</g>
87 <b>202</b>
88 </bgcolor>
89 <bsbObject version="2" type="BSBLabel">
90 <objectName/>
91 <x>2</x>
92 <y>2</y>
93 <width>512</width>
94 <height>320</height>
95 <uuid>{395a9956-93f5-441f-b0ef-3828f1b2da1c}</uuid>
96 <visible>true</visible>
97 <midichan>0</midichan>
98 <midicc>0</midicc>
99 <label>sndloop</label>
100 <alignment>center</alignment>
101 <font>Liberation Sans</font>
102 <fontsize>18</fontsize>
103 <precision>3</precision>
104 <color>
105 <r>0</r>
106 <g>0</g>
107 <b>0</b>
108 </color>
109 <bgcolor mode="background">
110 <r>181</r>
111 <g>199</g>
112 <b>255</b>
113 </bgcolor>
114 <bordermode>border</bordermode>
115 <borderradius>5</borderradius>
116 <borderwidth>2</borderwidth>
117 </bsbObject>
118 <bsbObject version="2" type="BSBButton">
119 <objectName>Play_Stop</objectName>
120 <x>8</x>
121 <y>42</y>
122 <width>130</width>
123 <height>30</height>
124 <uuid>{c54faf18-3b5b-4a78-b803-69b1c339890e}</uuid>
125 <visible>true</visible>
126 <midichan>0</midichan>
127 <midicc>0</midicc>
128 <type>value</type>
129 <pressedValue>1.00000000</pressedValue>
130 <stringvalue/>
131 <text> Rec-Play / Stop</text>
132 <image>/</image>
133 <eventLine/>
134 <latch>true</latch>
135 <latched>false</latched>
136 </bsbObject>
137 <bsbObject version="2" type="BSBButton">
138 <objectName>Mute_Live</objectName>
139 <x>152</x>
140 <y>42</y>
141 <width>130</width>
142 <height>30</height>
143 <uuid>{63b09b32-866d-4b31-ba3c-fb6f456359dc}</uuid>
144 <visible>true</visible>
145 <midichan>0</midichan>
146 <midicc>0</midicc>
147 <type>value</type>
148 <pressedValue>1.00000000</pressedValue>
149 <stringvalue/>
150 <text> Mute Live Input</text>
151 <image>/</image>
152 <eventLine/>
153 <latch>true</latch>
154 <latched>false</latched>
155 </bsbObject>
156 <bsbObject version="2" type="BSBLabel">
157 <objectName/>
158 <x>516</x>
159 <y>2</y>
160 <width>480</width>
161 <height>320</height>
162 <uuid>{10e7ae72-c151-4c9d-9f49-e6b1585d8386}</uuid>
163 <visible>true</visible>
164 <midichan>0</midichan>
165 <midicc>0</midicc>
166 <label>sndloop</label>
167 <alignment>center</alignment>
168 <font>Liberation Sans</font>
169 <fontsize>18</fontsize>
170 <precision>3</precision>
171 <color>
172 <r>0</r>
173 <g>0</g>
174 <b>0</b>
175 </color>
176 <bgcolor mode="background">
177 <r>181</r>
178 <g>199</g>
179 <b>255</b>
180 </bgcolor>
181 <bordermode>border</bordermode>
182 <borderradius>5</borderradius>
183 <borderwidth>2</borderwidth>
184 </bsbObject>
185 <bsbObject version="2" type="BSBLabel">
186 <objectName/>
187 <x>517</x>
188 <y>17</y>
189 <width>477</width>
190 <height>302</height>
191 <uuid>{97dfe67c-26c1-4af5-b858-e301d6886c2e}</uuid>
192 <visible>true</visible>
193 <midichan>0</midichan>
194 <midicc>0</midicc>
195 <label>---------------------------------------------------------------------------------------------------------------------
196 'sndloop' is an opcode that offers a straightforward method of sampling some live audio and immediately playing it back in a loop with pitch control. The duration of the recording to be undertaken must be defined before recording is activated. A crossfade time can be defined which will create a crossfade between the end and the beginning of the loop which may smooth the transition between the end and the beginning of the loop and therefore prevent clicks. In addition to the audio output from the opcode there is a k-rate switch which indicates when recording has begun and then when playback begins. In this example, this variable is used to activate the red 'RECORDING' indicator.
197 Negative values for 'Pitch' result in reverse playback. This instrument also allows the user to shift the pitch of the loop by playing keys on a connected MIDI keyboard. The 'Input Gain' control controls the level of audio reaching the sndloop opcode therefore must be greater than zero. When not in playback mode after recording the sndloop opcode normally outputs the audio reaching its input, if you wish to mute live audio while recording (and also before recording has first taken place) activate the 'Mute Live Input' button.</label>
198 <alignment>left</alignment>
199 <font>Liberation Sans</font>
200 <fontsize>14</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>8</x>
219 <y>106</y>
220 <width>210</width>
221 <height>30</height>
222 <uuid>{2c897206-0dbc-47b5-ba68-915d83839ab6}</uuid>
223 <visible>true</visible>
224 <midichan>0</midichan>
225 <midicc>0</midicc>
226 <label>Duration of Recording (seconds)</label>
227 <alignment>left</alignment>
228 <font>Liberation Sans</font>
229 <fontsize>10</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="BSBHSlider">
246 <objectName>Duration</objectName>
247 <x>8</x>
248 <y>87</y>
249 <width>500</width>
250 <height>27</height>
251 <uuid>{304e78d8-b320-453a-b28f-86b0ca872b86}</uuid>
252 <visible>true</visible>
253 <midichan>0</midichan>
254 <midicc>0</midicc>
255 <minimum>0.00000000</minimum>
256 <maximum>10.00000000</maximum>
257 <value>4.00000000</value>
258 <mode>lin</mode>
259 <mouseControl act="jump">continuous</mouseControl>
260 <resolution>-1.00000000</resolution>
261 <randomizable group="0">false</randomizable>
262 </bsbObject>
263 <bsbObject version="2" type="BSBDisplay">
264 <objectName>Duration</objectName>
265 <x>448</x>
266 <y>106</y>
267 <width>60</width>
268 <height>30</height>
269 <uuid>{94c7e961-7981-4d21-942f-80bcc647daf5}</uuid>
270 <visible>true</visible>
271 <midichan>0</midichan>
272 <midicc>0</midicc>
273 <label>4.000</label>
274 <alignment>right</alignment>
275 <font>Liberation Sans</font>
276 <fontsize>9</fontsize>
277 <precision>3</precision>
278 <color>
279 <r>0</r>
280 <g>0</g>
281 <b>0</b>
282 </color>
283 <bgcolor mode="nobackground">
284 <r>255</r>
285 <g>255</g>
286 <b>255</b>
287 </bgcolor>
288 <bordermode>noborder</bordermode>
289 <borderradius>1</borderradius>
290 <borderwidth>1</borderwidth>
291 </bsbObject>
292 <bsbObject version="2" type="BSBLabel">
293 <objectName/>
294 <x>8</x>
295 <y>154</y>
296 <width>120</width>
297 <height>30</height>
298 <uuid>{7186de75-bab8-4534-b81d-333dea34bde8}</uuid>
299 <visible>true</visible>
300 <midichan>0</midichan>
301 <midicc>0</midicc>
302 <label>Pitch (ratio)</label>
303 <alignment>left</alignment>
304 <font>Liberation Sans</font>
305 <fontsize>10</fontsize>
306 <precision>3</precision>
307 <color>
308 <r>0</r>
309 <g>0</g>
310 <b>0</b>
311 </color>
312 <bgcolor mode="nobackground">
313 <r>255</r>
314 <g>255</g>
315 <b>255</b>
316 </bgcolor>
317 <bordermode>noborder</bordermode>
318 <borderradius>1</borderradius>
319 <borderwidth>1</borderwidth>
320 </bsbObject>
321 <bsbObject version="2" type="BSBHSlider">
322 <objectName>Pitch</objectName>
323 <x>8</x>
324 <y>135</y>
325 <width>500</width>
326 <height>27</height>
327 <uuid>{21c23ac4-26ce-4b74-88d5-8c36439204d3}</uuid>
328 <visible>true</visible>
329 <midichan>0</midichan>
330 <midicc>0</midicc>
331 <minimum>-4.00000000</minimum>
332 <maximum>4.00000000</maximum>
333 <value>1.00800000</value>
334 <mode>lin</mode>
335 <mouseControl act="jump">continuous</mouseControl>
336 <resolution>-1.00000000</resolution>
337 <randomizable group="0">false</randomizable>
338 </bsbObject>
339 <bsbObject version="2" type="BSBDisplay">
340 <objectName>Pitch</objectName>
341 <x>448</x>
342 <y>154</y>
343 <width>60</width>
344 <height>30</height>
345 <uuid>{0b0ea6ec-a2b7-48a8-beeb-ddc4a43ab18b}</uuid>
346 <visible>true</visible>
347 <midichan>0</midichan>
348 <midicc>0</midicc>
349 <label>1.008</label>
350 <alignment>right</alignment>
351 <font>Liberation Sans</font>
352 <fontsize>9</fontsize>
353 <precision>3</precision>
354 <color>
355 <r>0</r>
356 <g>0</g>
357 <b>0</b>
358 </color>
359 <bgcolor mode="nobackground">
360 <r>255</r>
361 <g>255</g>
362 <b>255</b>
363 </bgcolor>
364 <bordermode>noborder</bordermode>
365 <borderradius>1</borderradius>
366 <borderwidth>1</borderwidth>
367 </bsbObject>
368 <bsbObject version="2" type="BSBLabel">
369 <objectName/>
370 <x>8</x>
371 <y>203</y>
372 <width>310</width>
373 <height>30</height>
374 <uuid>{2e87e987-1738-4cb5-8758-71fae356afeb}</uuid>
375 <visible>true</visible>
376 <midichan>0</midichan>
377 <midicc>0</midicc>
378 <label>Crossfade (seconds) (cannot be longer than Duration)</label>
379 <alignment>left</alignment>
380 <font>Liberation Sans</font>
381 <fontsize>10</fontsize>
382 <precision>3</precision>
383 <color>
384 <r>0</r>
385 <g>0</g>
386 <b>0</b>
387 </color>
388 <bgcolor mode="nobackground">
389 <r>255</r>
390 <g>255</g>
391 <b>255</b>
392 </bgcolor>
393 <bordermode>noborder</bordermode>
394 <borderradius>1</borderradius>
395 <borderwidth>1</borderwidth>
396 </bsbObject>
397 <bsbObject version="2" type="BSBHSlider">
398 <objectName>Crossfade</objectName>
399 <x>8</x>
400 <y>184</y>
401 <width>500</width>
402 <height>27</height>
403 <uuid>{e984c4f5-5ed8-435f-912c-bd859309ae47}</uuid>
404 <visible>true</visible>
405 <midichan>0</midichan>
406 <midicc>0</midicc>
407 <minimum>0.00000000</minimum>
408 <maximum>5.00000000</maximum>
409 <value>1.38000000</value>
410 <mode>lin</mode>
411 <mouseControl act="jump">continuous</mouseControl>
412 <resolution>-1.00000000</resolution>
413 <randomizable group="0">false</randomizable>
414 </bsbObject>
415 <bsbObject version="2" type="BSBDisplay">
416 <objectName>Crossfade</objectName>
417 <x>448</x>
418 <y>203</y>
419 <width>60</width>
420 <height>30</height>
421 <uuid>{75870351-61d9-4470-8865-f2b00c777ff0}</uuid>
422 <visible>true</visible>
423 <midichan>0</midichan>
424 <midicc>0</midicc>
425 <label>1.380</label>
426 <alignment>right</alignment>
427 <font>Liberation Sans</font>
428 <fontsize>9</fontsize>
429 <precision>3</precision>
430 <color>
431 <r>0</r>
432 <g>0</g>
433 <b>0</b>
434 </color>
435 <bgcolor mode="nobackground">
436 <r>255</r>
437 <g>255</g>
438 <b>255</b>
439 </bgcolor>
440 <bordermode>noborder</bordermode>
441 <borderradius>1</borderradius>
442 <borderwidth>1</borderwidth>
443 </bsbObject>
444 <bsbObject version="2" type="BSBLabel">
445 <objectName/>
446 <x>8</x>
447 <y>252</y>
448 <width>100</width>
449 <height>30</height>
450 <uuid>{e7ab5e78-0242-43d4-9a05-6d6260c10833}</uuid>
451 <visible>true</visible>
452 <midichan>0</midichan>
453 <midicc>0</midicc>
454 <label>Input Gain</label>
455 <alignment>left</alignment>
456 <font>Liberation Sans</font>
457 <fontsize>10</fontsize>
458 <precision>3</precision>
459 <color>
460 <r>0</r>
461 <g>0</g>
462 <b>0</b>
463 </color>
464 <bgcolor mode="nobackground">
465 <r>255</r>
466 <g>255</g>
467 <b>255</b>
468 </bgcolor>
469 <bordermode>noborder</bordermode>
470 <borderradius>1</borderradius>
471 <borderwidth>1</borderwidth>
472 </bsbObject>
473 <bsbObject version="2" type="BSBHSlider">
474 <objectName>Input_Gain</objectName>
475 <x>8</x>
476 <y>233</y>
477 <width>500</width>
478 <height>27</height>
479 <uuid>{3159a008-2bd8-4149-b211-649c65101258}</uuid>
480 <visible>true</visible>
481 <midichan>0</midichan>
482 <midicc>0</midicc>
483 <minimum>0.00000000</minimum>
484 <maximum>1.00000000</maximum>
485 <value>0.80000000</value>
486 <mode>lin</mode>
487 <mouseControl act="jump">continuous</mouseControl>
488 <resolution>-1.00000000</resolution>
489 <randomizable group="0">false</randomizable>
490 </bsbObject>
491 <bsbObject version="2" type="BSBDisplay">
492 <objectName>Input_Gain</objectName>
493 <x>448</x>
494 <y>252</y>
495 <width>60</width>
496 <height>30</height>
497 <uuid>{9fc48d5e-b81f-4891-8091-49fdb18566a4}</uuid>
498 <visible>true</visible>
499 <midichan>0</midichan>
500 <midicc>0</midicc>
501 <label>0.800</label>
502 <alignment>right</alignment>
503 <font>Liberation Sans</font>
504 <fontsize>9</fontsize>
505 <precision>3</precision>
506 <color>
507 <r>0</r>
508 <g>0</g>
509 <b>0</b>
510 </color>
511 <bgcolor mode="nobackground">
512 <r>255</r>
513 <g>255</g>
514 <b>255</b>
515 </bgcolor>
516 <bordermode>noborder</bordermode>
517 <borderradius>1</borderradius>
518 <borderwidth>1</borderwidth>
519 </bsbObject>
520 <bsbObject version="2" type="BSBController">
521 <objectName>Recording</objectName>
522 <x>408</x>
523 <y>44</y>
524 <width>100</width>
525 <height>26</height>
526 <uuid>{6418d1d7-3588-4191-bfff-af56034342ed}</uuid>
527 <visible>true</visible>
528 <midichan>0</midichan>
529 <midicc>0</midicc>
530 <objectName2/>
531 <xMin>0.00000000</xMin>
532 <xMax>1.00000000</xMax>
533 <yMin>0.00000000</yMin>
534 <yMax>1.00000000</yMax>
535 <xValue>0.00000000</xValue>
536 <yValue>0.00000000</yValue>
537 <type>fill</type>
538 <pointsize>1</pointsize>
539 <fadeSpeed>0.00000000</fadeSpeed>
540 <mouseControl act="press">jump</mouseControl>
541 <color>
542 <r>255</r>
543 <g>0</g>
544 <b>0</b>
545 </color>
546 <randomizable mode="both" group="0">false</randomizable>
547 <bgcolor>
548 <r>0</r>
549 <g>0</g>
550 <b>0</b>
551 </bgcolor>
552 </bsbObject>
553 <bsbObject version="2" type="BSBLabel">
554 <objectName/>
555 <x>408</x>
556 <y>46</y>
557 <width>100</width>
558 <height>30</height>
559 <uuid>{56201220-76ed-4652-a7e7-e674208835a2}</uuid>
560 <visible>true</visible>
561 <midichan>0</midichan>
562 <midicc>0</midicc>
563 <label>RECORDING</label>
564 <alignment>center</alignment>
565 <font>Liberation Sans</font>
566 <fontsize>12</fontsize>
567 <precision>3</precision>
568 <color>
569 <r>0</r>
570 <g>0</g>
571 <b>0</b>
572 </color>
573 <bgcolor mode="nobackground">
574 <r>255</r>
575 <g>255</g>
576 <b>255</b>
577 </bgcolor>
578 <bordermode>noborder</bordermode>
579 <borderradius>1</borderradius>
580 <borderwidth>1</borderwidth>
581 </bsbObject>
582 </bsbPanel>
583 <bsbPresets>
584 </bsbPresets>