Debian Codegraph @

src/Examples/McCurdy Collection/SoundfilePlayback/lposcilsa.csd

raw
1 ;Written by Iain McCurdy, 2009
2
3 ;Modified for QuteCsound by René, April 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 ; Add Browser for audio file
9
10
11 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
12 <CsoundSynthesizer>
13 <CsOptions>
14 --env:SSDIR+=../../SourceMaterials
15 </CsOptions>
16 <CsInstruments>
17 sr = 44100 ;SAMPLE RATE
18 ksmps = 10 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
20 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
21
22
23 instr 10 ;GUI
24 ktrig metro 10
25 if (ktrig == 1) then
26 gkamp invalue "Amplitude"
27 gkfreqratio invalue "FreqRatio"
28 gkloop invalue "LoopBegin"
29 gkend invalue "LoopEnd"
30 gkphs invalue "InitPhase"
31 endif
32 endin
33
34 instr 1
35 Sfile_new strcpy "" ;INIT TO EMPTY STRING
36 Sfile invalue "_Browse"
37 Sfile_old strcpyk Sfile_new
38 Sfile_new strcpyk Sfile
39 kfile strcmpk Sfile_new, Sfile_old
40
41 kSwitch changed gkphs, kfile ;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
42 if kSwitch=1 then ;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
43 reinit UPDATE ;BEGIN A REINITIALISATION PASS FROM LABEL 'UPDATE'
44 endif
45 UPDATE:
46
47 ifn ftgentmp 0, 0, 0, 1, Sfile,0,0,1 ;READ MONO OR STEREO AUDIO FILE CHANNEL 1
48 ifilelen = nsamp(ifn) ;DERIVE SOUNDFILE LENGTH (IN SAMPLES)
49
50 aamp interp gkamp ;CREATE A-RATE VERSION OF AMPLITUDE SLIDER VALUE (THIS IS DEMANDED BY lposcilsa)
51 ar1, ar2 lposcilsa aamp, gkfreqratio, gkloop*ifilelen, gkend*ifilelen, ifn, i(gkphs)*ifilelen
52 rireturn ;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
53 outs ar1, ar2 ;SEND AUDIO TO OUTPUTS
54 endin
55
56 instr 11 ;INIT
57 outvalue "Amplitude" ,0.5
58 outvalue "FreqRatio" ,1
59 outvalue "LoopBegin" ,0
60 outvalue "LoopEnd" ,1
61 outvalue "InitPhase" ,0
62 endin
63 </CsInstruments>
64 <CsScore>
65 i 10 0 3600 ;GUI
66 i 11 0 0.01 ;INIT
67 </CsScore>
68 </CsoundSynthesizer>
69 <bsbPanel>
70 <label>Widgets</label>
71 <objectName/>
72 <x>72</x>
73 <y>179</y>
74 <width>400</width>
75 <height>200</height>
76 <visible>true</visible>
77 <uuid/>
78 <bgcolor mode="nobackground">
79 <r>202</r>
80 <g>202</g>
81 <b>202</b>
82 </bgcolor>
83 <bsbObject version="2" type="BSBLabel">
84 <objectName/>
85 <x>2</x>
86 <y>2</y>
87 <width>512</width>
88 <height>340</height>
89 <uuid>{395a9956-93f5-441f-b0ef-3828f1b2da1c}</uuid>
90 <visible>true</visible>
91 <midichan>0</midichan>
92 <midicc>0</midicc>
93 <label>lposcilsa</label>
94 <alignment>center</alignment>
95 <font>Liberation Sans</font>
96 <fontsize>18</fontsize>
97 <precision>3</precision>
98 <color>
99 <r>0</r>
100 <g>0</g>
101 <b>0</b>
102 </color>
103 <bgcolor mode="background">
104 <r>181</r>
105 <g>199</g>
106 <b>255</b>
107 </bgcolor>
108 <bordermode>border</bordermode>
109 <borderradius>5</borderradius>
110 <borderwidth>2</borderwidth>
111 </bsbObject>
112 <bsbObject version="2" type="BSBButton">
113 <objectName/>
114 <x>8</x>
115 <y>10</y>
116 <width>100</width>
117 <height>26</height>
118 <uuid>{0a44e1b8-fab4-40c8-8fa1-f1d1d743c45c}</uuid>
119 <visible>true</visible>
120 <midichan>0</midichan>
121 <midicc>0</midicc>
122 <type>event</type>
123 <pressedValue>1.00000000</pressedValue>
124 <stringvalue/>
125 <text> On / Off </text>
126 <image>/</image>
127 <eventLine>i 1 0 -1</eventLine>
128 <latch>true</latch>
129 <latched>false</latched>
130 </bsbObject>
131 <bsbObject version="2" type="BSBLabel">
132 <objectName/>
133 <x>516</x>
134 <y>2</y>
135 <width>350</width>
136 <height>340</height>
137 <uuid>{10e7ae72-c151-4c9d-9f49-e6b1585d8386}</uuid>
138 <visible>true</visible>
139 <midichan>0</midichan>
140 <midicc>0</midicc>
141 <label>lposcilsa</label>
142 <alignment>center</alignment>
143 <font>Liberation Sans</font>
144 <fontsize>18</fontsize>
145 <precision>3</precision>
146 <color>
147 <r>0</r>
148 <g>0</g>
149 <b>0</b>
150 </color>
151 <bgcolor mode="background">
152 <r>181</r>
153 <g>199</g>
154 <b>255</b>
155 </bgcolor>
156 <bordermode>border</bordermode>
157 <borderradius>5</borderradius>
158 <borderwidth>2</borderwidth>
159 </bsbObject>
160 <bsbObject version="2" type="BSBLabel">
161 <objectName/>
162 <x>518</x>
163 <y>18</y>
164 <width>345</width>
165 <height>324</height>
166 <uuid>{97dfe67c-26c1-4af5-b858-e301d6886c2e}</uuid>
167 <visible>true</visible>
168 <midichan>0</midichan>
169 <midicc>0</midicc>
170 <label>-----------------------------------------------------------------------------------
171 'lposcilsa' provides stereo sound file playback (stored in RAM) with interpolation with normal forward looping with k-rate variable start and and loop points. 'lposcilsa' can read from stereo function tables and the size of those function tables can be deferred (given as zero) meaning that Csound calculates the required function table size to store the entire sound file. 'Loop Start Point', 'Loop End Point' and 'Initial Phase' are all given to the opcode in samples but in this example, this calculation is performed within the instrument. Negative values for 'Frequency Ratio' result in reversed playback. Similar to this opcode are lposcila (mono version), lposcil (mono with k-rate amplitude argument, lposcil3 (mono with cubic interpolation and k-rate amplitude control), lposcilsa2 (high speed version that only allows integer values for frequency ratio). If 'Loop Start Point' is beyond 'Loop End Point', no sound is produced.</label>
172 <alignment>left</alignment>
173 <font>Liberation Sans</font>
174 <fontsize>14</fontsize>
175 <precision>3</precision>
176 <color>
177 <r>0</r>
178 <g>0</g>
179 <b>0</b>
180 </color>
181 <bgcolor mode="nobackground">
182 <r>255</r>
183 <g>255</g>
184 <b>255</b>
185 </bgcolor>
186 <bordermode>noborder</bordermode>
187 <borderradius>1</borderradius>
188 <borderwidth>1</borderwidth>
189 </bsbObject>
190 <bsbObject version="2" type="BSBLabel">
191 <objectName/>
192 <x>8</x>
193 <y>157</y>
194 <width>150</width>
195 <height>30</height>
196 <uuid>{2c897206-0dbc-47b5-ba68-915d83839ab6}</uuid>
197 <visible>true</visible>
198 <midichan>0</midichan>
199 <midicc>0</midicc>
200 <label>Loop Begin Point</label>
201 <alignment>left</alignment>
202 <font>Liberation Sans</font>
203 <fontsize>10</fontsize>
204 <precision>3</precision>
205 <color>
206 <r>0</r>
207 <g>0</g>
208 <b>0</b>
209 </color>
210 <bgcolor mode="nobackground">
211 <r>255</r>
212 <g>255</g>
213 <b>255</b>
214 </bgcolor>
215 <bordermode>noborder</bordermode>
216 <borderradius>1</borderradius>
217 <borderwidth>1</borderwidth>
218 </bsbObject>
219 <bsbObject version="2" type="BSBHSlider">
220 <objectName>LoopBegin</objectName>
221 <x>8</x>
222 <y>140</y>
223 <width>500</width>
224 <height>27</height>
225 <uuid>{304e78d8-b320-453a-b28f-86b0ca872b86}</uuid>
226 <visible>true</visible>
227 <midichan>0</midichan>
228 <midicc>0</midicc>
229 <minimum>0.00000000</minimum>
230 <maximum>1.00000000</maximum>
231 <value>0.00000000</value>
232 <mode>lin</mode>
233 <mouseControl act="jump">continuous</mouseControl>
234 <resolution>-1.00000000</resolution>
235 <randomizable group="0">false</randomizable>
236 </bsbObject>
237 <bsbObject version="2" type="BSBDisplay">
238 <objectName>LoopBegin</objectName>
239 <x>448</x>
240 <y>157</y>
241 <width>60</width>
242 <height>30</height>
243 <uuid>{94c7e961-7981-4d21-942f-80bcc647daf5}</uuid>
244 <visible>true</visible>
245 <midichan>0</midichan>
246 <midicc>0</midicc>
247 <label>0.000</label>
248 <alignment>right</alignment>
249 <font>Liberation Sans</font>
250 <fontsize>9</fontsize>
251 <precision>3</precision>
252 <color>
253 <r>0</r>
254 <g>0</g>
255 <b>0</b>
256 </color>
257 <bgcolor mode="nobackground">
258 <r>255</r>
259 <g>255</g>
260 <b>255</b>
261 </bgcolor>
262 <bordermode>noborder</bordermode>
263 <borderradius>1</borderradius>
264 <borderwidth>1</borderwidth>
265 </bsbObject>
266 <bsbObject version="2" type="BSBLabel">
267 <objectName/>
268 <x>8</x>
269 <y>204</y>
270 <width>150</width>
271 <height>30</height>
272 <uuid>{0609a258-bba4-43bb-849c-b8709a47f1ba}</uuid>
273 <visible>true</visible>
274 <midichan>0</midichan>
275 <midicc>0</midicc>
276 <label>Loop End Point</label>
277 <alignment>left</alignment>
278 <font>Liberation Sans</font>
279 <fontsize>10</fontsize>
280 <precision>3</precision>
281 <color>
282 <r>0</r>
283 <g>0</g>
284 <b>0</b>
285 </color>
286 <bgcolor mode="nobackground">
287 <r>255</r>
288 <g>255</g>
289 <b>255</b>
290 </bgcolor>
291 <bordermode>noborder</bordermode>
292 <borderradius>1</borderradius>
293 <borderwidth>1</borderwidth>
294 </bsbObject>
295 <bsbObject version="2" type="BSBHSlider">
296 <objectName>LoopEnd</objectName>
297 <x>8</x>
298 <y>187</y>
299 <width>500</width>
300 <height>27</height>
301 <uuid>{49415594-5e61-46ce-b9f8-3adcf2b957c5}</uuid>
302 <visible>true</visible>
303 <midichan>0</midichan>
304 <midicc>0</midicc>
305 <minimum>0.00000000</minimum>
306 <maximum>1.00000000</maximum>
307 <value>1.00000000</value>
308 <mode>lin</mode>
309 <mouseControl act="jump">continuous</mouseControl>
310 <resolution>-1.00000000</resolution>
311 <randomizable group="0">false</randomizable>
312 </bsbObject>
313 <bsbObject version="2" type="BSBDisplay">
314 <objectName>LoopEnd</objectName>
315 <x>448</x>
316 <y>204</y>
317 <width>60</width>
318 <height>30</height>
319 <uuid>{6a4ff02e-3d5e-4143-855e-95b4c2614157}</uuid>
320 <visible>true</visible>
321 <midichan>0</midichan>
322 <midicc>0</midicc>
323 <label>1.000</label>
324 <alignment>right</alignment>
325 <font>Liberation Sans</font>
326 <fontsize>9</fontsize>
327 <precision>3</precision>
328 <color>
329 <r>0</r>
330 <g>0</g>
331 <b>0</b>
332 </color>
333 <bgcolor mode="nobackground">
334 <r>255</r>
335 <g>255</g>
336 <b>255</b>
337 </bgcolor>
338 <bordermode>noborder</bordermode>
339 <borderradius>1</borderradius>
340 <borderwidth>1</borderwidth>
341 </bsbObject>
342 <bsbObject version="2" type="BSBLabel">
343 <objectName/>
344 <x>8</x>
345 <y>63</y>
346 <width>150</width>
347 <height>30</height>
348 <uuid>{feb05e56-b1b1-4494-8c71-ce9e40994fb9}</uuid>
349 <visible>true</visible>
350 <midichan>0</midichan>
351 <midicc>0</midicc>
352 <label>Amplitude</label>
353 <alignment>left</alignment>
354 <font>Liberation Sans</font>
355 <fontsize>10</fontsize>
356 <precision>3</precision>
357 <color>
358 <r>0</r>
359 <g>0</g>
360 <b>0</b>
361 </color>
362 <bgcolor mode="nobackground">
363 <r>255</r>
364 <g>255</g>
365 <b>255</b>
366 </bgcolor>
367 <bordermode>noborder</bordermode>
368 <borderradius>1</borderradius>
369 <borderwidth>1</borderwidth>
370 </bsbObject>
371 <bsbObject version="2" type="BSBHSlider">
372 <objectName>Amplitude</objectName>
373 <x>8</x>
374 <y>46</y>
375 <width>500</width>
376 <height>27</height>
377 <uuid>{88f53f0d-44d4-4847-8885-c15e934a8109}</uuid>
378 <visible>true</visible>
379 <midichan>0</midichan>
380 <midicc>0</midicc>
381 <minimum>0.00000000</minimum>
382 <maximum>1.00000000</maximum>
383 <value>0.50000000</value>
384 <mode>lin</mode>
385 <mouseControl act="jump">continuous</mouseControl>
386 <resolution>-1.00000000</resolution>
387 <randomizable group="0">false</randomizable>
388 </bsbObject>
389 <bsbObject version="2" type="BSBDisplay">
390 <objectName>Amplitude</objectName>
391 <x>448</x>
392 <y>63</y>
393 <width>60</width>
394 <height>30</height>
395 <uuid>{dd0574f3-9876-4c0e-b747-f61dee837c94}</uuid>
396 <visible>true</visible>
397 <midichan>0</midichan>
398 <midicc>0</midicc>
399 <label>0.500</label>
400 <alignment>right</alignment>
401 <font>Liberation Sans</font>
402 <fontsize>9</fontsize>
403 <precision>3</precision>
404 <color>
405 <r>0</r>
406 <g>0</g>
407 <b>0</b>
408 </color>
409 <bgcolor mode="nobackground">
410 <r>255</r>
411 <g>255</g>
412 <b>255</b>
413 </bgcolor>
414 <bordermode>noborder</bordermode>
415 <borderradius>1</borderradius>
416 <borderwidth>1</borderwidth>
417 </bsbObject>
418 <bsbObject version="2" type="BSBLabel">
419 <objectName/>
420 <x>8</x>
421 <y>110</y>
422 <width>150</width>
423 <height>30</height>
424 <uuid>{bf3e8a57-4a8a-4a9d-b67d-9521542ae93d}</uuid>
425 <visible>true</visible>
426 <midichan>0</midichan>
427 <midicc>0</midicc>
428 <label>Frequency Ratio</label>
429 <alignment>left</alignment>
430 <font>Liberation Sans</font>
431 <fontsize>10</fontsize>
432 <precision>3</precision>
433 <color>
434 <r>0</r>
435 <g>0</g>
436 <b>0</b>
437 </color>
438 <bgcolor mode="nobackground">
439 <r>255</r>
440 <g>255</g>
441 <b>255</b>
442 </bgcolor>
443 <bordermode>noborder</bordermode>
444 <borderradius>1</borderradius>
445 <borderwidth>1</borderwidth>
446 </bsbObject>
447 <bsbObject version="2" type="BSBHSlider">
448 <objectName>FreqRatio</objectName>
449 <x>8</x>
450 <y>93</y>
451 <width>500</width>
452 <height>27</height>
453 <uuid>{8ff8f945-02c5-4ac9-a2e7-f20a8a28a2a5}</uuid>
454 <visible>true</visible>
455 <midichan>0</midichan>
456 <midicc>0</midicc>
457 <minimum>-2.00000000</minimum>
458 <maximum>2.00000000</maximum>
459 <value>1.00000000</value>
460 <mode>lin</mode>
461 <mouseControl act="jump">continuous</mouseControl>
462 <resolution>-1.00000000</resolution>
463 <randomizable group="0">false</randomizable>
464 </bsbObject>
465 <bsbObject version="2" type="BSBDisplay">
466 <objectName>FreqRatio</objectName>
467 <x>448</x>
468 <y>110</y>
469 <width>60</width>
470 <height>30</height>
471 <uuid>{4b684f89-629e-4f7a-974d-7dd7165f85a7}</uuid>
472 <visible>true</visible>
473 <midichan>0</midichan>
474 <midicc>0</midicc>
475 <label>1.000</label>
476 <alignment>right</alignment>
477 <font>Liberation Sans</font>
478 <fontsize>9</fontsize>
479 <precision>3</precision>
480 <color>
481 <r>0</r>
482 <g>0</g>
483 <b>0</b>
484 </color>
485 <bgcolor mode="nobackground">
486 <r>255</r>
487 <g>255</g>
488 <b>255</b>
489 </bgcolor>
490 <bordermode>noborder</bordermode>
491 <borderradius>1</borderradius>
492 <borderwidth>1</borderwidth>
493 </bsbObject>
494 <bsbObject version="2" type="BSBLineEdit">
495 <objectName>_Browse</objectName>
496 <x>180</x>
497 <y>302</y>
498 <width>326</width>
499 <height>28</height>
500 <uuid>{15a8ec14-710f-43e6-be9e-f5dc8c8786cb}</uuid>
501 <visible>true</visible>
502 <midichan>0</midichan>
503 <midicc>0</midicc>
504 <label>Songpan.wav</label>
505 <alignment>left</alignment>
506 <font>Liberation Sans</font>
507 <fontsize>10</fontsize>
508 <precision>3</precision>
509 <color>
510 <r>0</r>
511 <g>0</g>
512 <b>0</b>
513 </color>
514 <bgcolor mode="nobackground">
515 <r>229</r>
516 <g>229</g>
517 <b>229</b>
518 </bgcolor>
519 <background>nobackground</background>
520 </bsbObject>
521 <bsbObject version="2" type="BSBLabel">
522 <objectName/>
523 <x>8</x>
524 <y>251</y>
525 <width>150</width>
526 <height>30</height>
527 <uuid>{a842add9-35e8-4567-92ab-8061be1c10f7}</uuid>
528 <visible>true</visible>
529 <midichan>0</midichan>
530 <midicc>0</midicc>
531 <label>Initial Phase (i-rate)</label>
532 <alignment>left</alignment>
533 <font>Liberation Sans</font>
534 <fontsize>10</fontsize>
535 <precision>3</precision>
536 <color>
537 <r>0</r>
538 <g>0</g>
539 <b>0</b>
540 </color>
541 <bgcolor mode="nobackground">
542 <r>255</r>
543 <g>255</g>
544 <b>255</b>
545 </bgcolor>
546 <bordermode>noborder</bordermode>
547 <borderradius>1</borderradius>
548 <borderwidth>1</borderwidth>
549 </bsbObject>
550 <bsbObject version="2" type="BSBHSlider">
551 <objectName>InitPhase</objectName>
552 <x>8</x>
553 <y>234</y>
554 <width>500</width>
555 <height>27</height>
556 <uuid>{67d5f50b-6ff1-43e9-90bc-2a4968903ba7}</uuid>
557 <visible>true</visible>
558 <midichan>0</midichan>
559 <midicc>0</midicc>
560 <minimum>0.00000000</minimum>
561 <maximum>1.00000000</maximum>
562 <value>0.00000000</value>
563 <mode>lin</mode>
564 <mouseControl act="jump">continuous</mouseControl>
565 <resolution>-1.00000000</resolution>
566 <randomizable group="0">false</randomizable>
567 </bsbObject>
568 <bsbObject version="2" type="BSBDisplay">
569 <objectName>InitPhase</objectName>
570 <x>448</x>
571 <y>251</y>
572 <width>60</width>
573 <height>30</height>
574 <uuid>{8caaf76d-57ae-4684-8b3a-76e073bfd7d0}</uuid>
575 <visible>true</visible>
576 <midichan>0</midichan>
577 <midicc>0</midicc>
578 <label>0.000</label>
579 <alignment>right</alignment>
580 <font>Liberation Sans</font>
581 <fontsize>9</fontsize>
582 <precision>3</precision>
583 <color>
584 <r>0</r>
585 <g>0</g>
586 <b>0</b>
587 </color>
588 <bgcolor mode="nobackground">
589 <r>255</r>
590 <g>255</g>
591 <b>255</b>
592 </bgcolor>
593 <bordermode>noborder</bordermode>
594 <borderradius>1</borderradius>
595 <borderwidth>1</borderwidth>
596 </bsbObject>
597 <bsbObject version="2" type="BSBLabel">
598 <objectName/>
599 <x>8</x>
600 <y>281</y>
601 <width>100</width>
602 <height>30</height>
603 <uuid>{8de3ea13-9050-4b9d-8b34-9fec61fe4e48}</uuid>
604 <visible>true</visible>
605 <midichan>0</midichan>
606 <midicc>0</midicc>
607 <label>Input :</label>
608 <alignment>left</alignment>
609 <font>Liberation Sans</font>
610 <fontsize>10</fontsize>
611 <precision>3</precision>
612 <color>
613 <r>0</r>
614 <g>0</g>
615 <b>0</b>
616 </color>
617 <bgcolor mode="nobackground">
618 <r>255</r>
619 <g>255</g>
620 <b>255</b>
621 </bgcolor>
622 <bordermode>noborder</bordermode>
623 <borderradius>1</borderradius>
624 <borderwidth>1</borderwidth>
625 </bsbObject>
626 <bsbObject version="2" type="BSBButton">
627 <objectName>_Browse</objectName>
628 <x>8</x>
629 <y>302</y>
630 <width>170</width>
631 <height>30</height>
632 <uuid>{8c630a69-dc58-46a0-a696-60bc59cec1d6}</uuid>
633 <visible>true</visible>
634 <midichan>0</midichan>
635 <midicc>0</midicc>
636 <type>value</type>
637 <pressedValue>1.00000000</pressedValue>
638 <stringvalue>Songpan.wav</stringvalue>
639 <text>Browse Audio File</text>
640 <image>/</image>
641 <eventLine/>
642 <latch>false</latch>
643 <latched>false</latched>
644 </bsbObject>
645 </bsbPanel>
646 <bsbPresets>
647 </bsbPresets>