Debian Codegraph @

src/Examples/McCurdy Collection/FFT/pvstanal.csd

raw
1 ;Written by Iain McCurdy 2011
2
3 ;Modified for QuteCsound by René, May 2011
4 ;Tested on Ubuntu 10.04 with csound-float (git csound5-3c6d155, May 31 2011) and QuteCsound svn rev 848
5
6
7 ;Notes on modifications from original csd:
8 ; Add table(s) for exp slider
9 ; Add Browser for audio files, accept mono or stereo wav files
10 ; Instrument 1 is activated by MIDI and by the GUI, added pitchbend
11 ; Removed ifftsize, default to 2048
12
13
14 ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=alsa -Ma -m0 --midi-key-oct=4 --midi-velocity-amp=5
15 <CsoundSynthesizer>
16 <CsOptions>
17 --env:SSDIR+=../../SourceMaterials
18 </CsOptions>
19 <CsInstruments>
20 sr = 44100 ;SAMPLE RATE
21 ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
22 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
23 0dbfs = 1 ;MAXIMUM SOUND INTENSITY LEVEL REGARDLESS OF BIT DEPTH
24
25
26 giExp1 ftgen 0, 0, 129, -25, 0, 0.125, 128, 4.0 ;TABLE FOR EXP SLIDER
27
28
29 instr 10 ;GUI
30 ktrig metro 10
31 if (ktrig == 1) then
32 kfreeze invalue "Freeze"
33 gkfreeze = (kfreeze + 1)%2
34 gktimescal invalue "TimeScaling"
35 kpitch invalue "Pitch"
36 gkpitch tablei kpitch, giExp1, 1
37 outvalue "Pitch_Value", gkpitch
38 gkamp invalue "Amp"
39
40 ;AUDIO FILE CHANGE / LOAD IN POWER OF 2 TABLES **********************************************************************************************
41 Sfile_new strcpy "" ;INIT TO EMPTY STRING
42
43 Sfile invalue "_Browse"
44 Sfile_old strcpyk Sfile_new
45 Sfile_new strcpyk Sfile
46 kfile strcmpk Sfile_new, Sfile_old
47
48 gkfile_new init 0
49 if kfile != 0 then ;IF A BANG HAD BEEN GENERATED IN THE LINE ABOVE
50 gkfile_new = 1 ;Flag to inform instr 1 that a new file is loaded
51 reinit NEW_FILE ;REINITIALIZE FROM LABEL 'NEW_FILE'
52 endif
53 NEW_FILE:
54 ;FUNCTION TABLES NUMBERS OF THE SOUND FILE THAT WILL BE GRANULATED
55 ichn filenchnls Sfile
56 if ichn == 1 then
57 giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ MONO AUDIO FILE CHANNEL 1
58 giFileR = giFileL
59 else
60 giFileL ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 1 ;READ STEREO AUDIO FILE CHANNEL 1
61 giFileR ftgentmp 0, 0, 0, 1, Sfile, 0, 0, 2 ;READ STEREO AUDIO FILE CHANNEL 2
62 endif
63 ;*******************************************************************************************************************************************
64 endif
65 endin
66
67 instr 1
68 if p4!=0 then ;MIDI
69 ioct = p4 ;READ OCT VALUE FROM MIDI INPUT
70 ;PITCH BEND=============================================================================================
71 iSemitoneBendRange = 12 ;PITCH BEND RANGE IN SEMITONES
72 imin = 0 ;EQUILIBRIUM POSITION
73 imax = iSemitoneBendRange * .0833333 ;MAX PITCH DISPLACEMENT (IN oct FORMAT)
74 kbend pchbend imin, imax ;PITCH BEND VARIABLE (IN oct FORMAT)
75 kcps = cpsoct(ioct + kbend) ;SET FUNDAMENTAL
76 ;=======================================================================================================
77 endif
78
79 kporttime linseg 0, 0.001, 0.02 ;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
80
81 if p4!=0 then ;IF THIS IS A MIDI ACTIVATED NOTE...
82 kpitch = kcps/cpsoct(8) ;MAP TO MIDI NOTE VALUE TO PITCH (CONVERT TO RATIO: MIDDLE C IS POINT OF UNISON)
83 else ;OTHERWISE...
84 kpitch portk gkpitch, kporttime ;USE THE GUI SLIDER VALUE
85 endif ;END OF THIS CONDITIONAL BRANCH
86
87 kamp portk gkamp, kporttime ;APPLY PORTAMENTO SMOOTHING TO AMPLITUDE SLIDER VALUE
88
89 if gkfile_new = 1 then ;test if a new file is loaded by instr 10
90 gkfile_new = 0 ;flag to zero for next file change
91 reinit UPDATE2 ;REINITIALIZE FROM LABEL 'NEW_FILE1'
92 endif
93
94 UPDATE2: ;LABEL CALLED 'UPDATE2'
95 fsigL pvstanal gktimescal*gkfreeze,kamp,kpitch,giFileL
96 fsigR pvstanal gktimescal*gkfreeze,kamp,kpitch,giFileR
97
98 asigL pvsynth fsigL
99 asigR pvsynth fsigR
100
101 aenv linsegr 0, 0.05, 1, 0.05, 0 ;DE-CLICKING ENVELOPE
102 outs asigL*aenv, asigR*aenv ;SEND AUDIO TO OUTPUTS
103 endin
104
105 instr 2 ;SET TIME SCALING SLIDER TO P4 DETERMINED VALUES
106 outvalue "TimeScaling", p4
107 endin
108
109 instr 3 ;SET TIME SCALING SLIDER TO P4 DETERMINED VALUES
110 outvalue "Pitch", p4
111 endin
112
113 instr 11 ;INIT
114 outvalue "TimeScaling" , 1.0
115 outvalue "Pitch" , 0.6
116 outvalue "Amp" , 1.0
117 endin
118 </CsInstruments>
119 <CsScore>
120 ;INSTR | START | DURATION
121 i 10 0 3600 ;GUI
122 i 11 0 0 ;INIT
123 </CsScore>
124 </CsoundSynthesizer>
125
126
127 <bsbPanel>
128 <label>Widgets</label>
129 <objectName/>
130 <x>240</x>
131 <y>198</y>
132 <width>1107</width>
133 <height>282</height>
134 <visible>true</visible>
135 <uuid/>
136 <bgcolor mode="background">
137 <r>241</r>
138 <g>226</g>
139 <b>185</b>
140 </bgcolor>
141 <bsbObject version="2" type="BSBLabel">
142 <objectName/>
143 <x>2</x>
144 <y>2</y>
145 <width>512</width>
146 <height>280</height>
147 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
148 <visible>true</visible>
149 <midichan>0</midichan>
150 <midicc>0</midicc>
151 <label>pvstanal</label>
152 <alignment>center</alignment>
153 <font>Liberation Sans</font>
154 <fontsize>18</fontsize>
155 <precision>3</precision>
156 <color>
157 <r>0</r>
158 <g>0</g>
159 <b>0</b>
160 </color>
161 <bgcolor mode="background">
162 <r>181</r>
163 <g>199</g>
164 <b>255</b>
165 </bgcolor>
166 <bordermode>border</bordermode>
167 <borderradius>5</borderradius>
168 <borderwidth>2</borderwidth>
169 </bsbObject>
170 <bsbObject version="2" type="BSBLabel">
171 <objectName/>
172 <x>517</x>
173 <y>2</y>
174 <width>590</width>
175 <height>280</height>
176 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
177 <visible>true</visible>
178 <midichan>0</midichan>
179 <midicc>0</midicc>
180 <label>pvstanal</label>
181 <alignment>center</alignment>
182 <font>Liberation Sans</font>
183 <fontsize>18</fontsize>
184 <precision>3</precision>
185 <color>
186 <r>0</r>
187 <g>0</g>
188 <b>0</b>
189 </color>
190 <bgcolor mode="background">
191 <r>181</r>
192 <g>199</g>
193 <b>255</b>
194 </bgcolor>
195 <bordermode>border</bordermode>
196 <borderradius>5</borderradius>
197 <borderwidth>2</borderwidth>
198 </bsbObject>
199 <bsbObject version="2" type="BSBLabel">
200 <objectName/>
201 <x>520</x>
202 <y>21</y>
203 <width>583</width>
204 <height>258</height>
205 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
206 <visible>true</visible>
207 <midichan>0</midichan>
208 <midicc>0</midicc>
209 <label>-----------------------------------------------------------------------------------------------------------------------------------------------
210 'pvstanal' is very similar to the 'temposcal' opcode. Its priniciple difference is that it outputs an fsig as opposed to an audio signal as is the case with temposcal. An fsig might be a preferrable output if you are wanting to perform further processing using other pvs opcodes. pvstanal does not include the phase locking feature of temposcal. pvstanal uses phase vocoding to resynthesize a sound file stored in a GEN 1 function table. Movement through the sound file is controlled using a time scaling control. On screen switches allow the user to instantly freeze the sound or restore normal speed. Pitch can be controlled independently using a pitch ratio control. Unison can be restored using an on screen switch. The user can choose between four input sound file options. A variety of FFT sizes can be explored - smaller sizes will will result in less time smearing by more spectral distortion larger sizes will result in less spectral distortion but more time smearing. This example can also be activated from a MIDI keyboard in which case MIDI pitch is mapped to the the pitch ratio used by pvstanal. In this mode the GUI slider for pitch will be ignored. Middle C is the point of no transposition.</label>
211 <alignment>left</alignment>
212 <font>Liberation Sans</font>
213 <fontsize>14</fontsize>
214 <precision>3</precision>
215 <color>
216 <r>0</r>
217 <g>0</g>
218 <b>0</b>
219 </color>
220 <bgcolor mode="nobackground">
221 <r>255</r>
222 <g>255</g>
223 <b>255</b>
224 </bgcolor>
225 <bordermode>noborder</bordermode>
226 <borderradius>1</borderradius>
227 <borderwidth>1</borderwidth>
228 </bsbObject>
229 <bsbObject version="2" type="BSBButton">
230 <objectName/>
231 <x>8</x>
232 <y>8</y>
233 <width>120</width>
234 <height>30</height>
235 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
236 <visible>true</visible>
237 <midichan>0</midichan>
238 <midicc>0</midicc>
239 <type>event</type>
240 <pressedValue>1.00000000</pressedValue>
241 <stringvalue/>
242 <text> On / Off (MIDI)</text>
243 <image>/</image>
244 <eventLine>i 1 0 -1</eventLine>
245 <latch>true</latch>
246 <latched>false</latched>
247 </bsbObject>
248 <bsbObject version="2" type="BSBDisplay">
249 <objectName>TimeScaling</objectName>
250 <x>448</x>
251 <y>73</y>
252 <width>60</width>
253 <height>30</height>
254 <uuid>{745d6bee-b951-4a03-9fe8-9e10d5ae4556}</uuid>
255 <visible>true</visible>
256 <midichan>0</midichan>
257 <midicc>0</midicc>
258 <label>-0.720</label>
259 <alignment>right</alignment>
260 <font>Arial</font>
261 <fontsize>9</fontsize>
262 <precision>3</precision>
263 <color>
264 <r>0</r>
265 <g>0</g>
266 <b>0</b>
267 </color>
268 <bgcolor mode="nobackground">
269 <r>255</r>
270 <g>255</g>
271 <b>255</b>
272 </bgcolor>
273 <bordermode>noborder</bordermode>
274 <borderradius>1</borderradius>
275 <borderwidth>1</borderwidth>
276 </bsbObject>
277 <bsbObject version="2" type="BSBHSlider">
278 <objectName>TimeScaling</objectName>
279 <x>8</x>
280 <y>51</y>
281 <width>500</width>
282 <height>27</height>
283 <uuid>{06814721-6151-4baa-84e2-8f39843b07a4}</uuid>
284 <visible>true</visible>
285 <midichan>0</midichan>
286 <midicc>0</midicc>
287 <minimum>-2.00000000</minimum>
288 <maximum>2.00000000</maximum>
289 <value>-0.72000000</value>
290 <mode>lin</mode>
291 <mouseControl act="jump">continuous</mouseControl>
292 <resolution>-1.00000000</resolution>
293 <randomizable group="0">false</randomizable>
294 </bsbObject>
295 <bsbObject version="2" type="BSBLabel">
296 <objectName/>
297 <x>8</x>
298 <y>73</y>
299 <width>150</width>
300 <height>30</height>
301 <uuid>{c6d7165c-6730-426f-b293-52b411bc73cf}</uuid>
302 <visible>true</visible>
303 <midichan>0</midichan>
304 <midicc>0</midicc>
305 <label>Time Scaling</label>
306 <alignment>left</alignment>
307 <font>Arial</font>
308 <fontsize>10</fontsize>
309 <precision>3</precision>
310 <color>
311 <r>0</r>
312 <g>0</g>
313 <b>0</b>
314 </color>
315 <bgcolor mode="nobackground">
316 <r>255</r>
317 <g>255</g>
318 <b>255</b>
319 </bgcolor>
320 <bordermode>noborder</bordermode>
321 <borderradius>1</borderradius>
322 <borderwidth>1</borderwidth>
323 </bsbObject>
324 <bsbObject version="2" type="BSBButton">
325 <objectName>_Browse</objectName>
326 <x>7</x>
327 <y>205</y>
328 <width>170</width>
329 <height>30</height>
330 <uuid>{b9431a61-61f7-432b-bf6f-c47ddc7f9050}</uuid>
331 <visible>true</visible>
332 <midichan>0</midichan>
333 <midicc>0</midicc>
334 <type>value</type>
335 <pressedValue>1.00000000</pressedValue>
336 <stringvalue>AndItsAll.wav</stringvalue>
337 <text>Browse Audio File</text>
338 <image>/</image>
339 <eventLine/>
340 <latch>false</latch>
341 <latched>false</latched>
342 </bsbObject>
343 <bsbObject version="2" type="BSBLineEdit">
344 <objectName>_Browse</objectName>
345 <x>177</x>
346 <y>206</y>
347 <width>330</width>
348 <height>28</height>
349 <uuid>{68b5f90b-b78e-4581-b434-232db5f4c40f}</uuid>
350 <visible>true</visible>
351 <midichan>0</midichan>
352 <midicc>0</midicc>
353 <label>AndItsAll.wav</label>
354 <alignment>left</alignment>
355 <font>Arial</font>
356 <fontsize>10</fontsize>
357 <precision>3</precision>
358 <color>
359 <r>0</r>
360 <g>0</g>
361 <b>0</b>
362 </color>
363 <bgcolor mode="nobackground">
364 <r>229</r>
365 <g>229</g>
366 <b>229</b>
367 </bgcolor>
368 <background>nobackground</background>
369 </bsbObject>
370 <bsbObject version="2" type="BSBDisplay">
371 <objectName>Pitch_Value</objectName>
372 <x>448</x>
373 <y>121</y>
374 <width>60</width>
375 <height>30</height>
376 <uuid>{e18e15d6-c58d-4c38-a766-79602b72f947}</uuid>
377 <visible>true</visible>
378 <midichan>0</midichan>
379 <midicc>0</midicc>
380 <label>0.000</label>
381 <alignment>right</alignment>
382 <font>Arial</font>
383 <fontsize>9</fontsize>
384 <precision>3</precision>
385 <color>
386 <r>0</r>
387 <g>0</g>
388 <b>0</b>
389 </color>
390 <bgcolor mode="nobackground">
391 <r>255</r>
392 <g>255</g>
393 <b>255</b>
394 </bgcolor>
395 <bordermode>noborder</bordermode>
396 <borderradius>1</borderradius>
397 <borderwidth>1</borderwidth>
398 </bsbObject>
399 <bsbObject version="2" type="BSBHSlider">
400 <objectName>Pitch</objectName>
401 <x>8</x>
402 <y>99</y>
403 <width>500</width>
404 <height>27</height>
405 <uuid>{36779c76-0b42-4e18-819b-e02bf72d22dd}</uuid>
406 <visible>true</visible>
407 <midichan>0</midichan>
408 <midicc>0</midicc>
409 <minimum>0.00000000</minimum>
410 <maximum>1.00000000</maximum>
411 <value>0.60000002</value>
412 <mode>lin</mode>
413 <mouseControl act="jump">continuous</mouseControl>
414 <resolution>-1.00000000</resolution>
415 <randomizable group="0">false</randomizable>
416 </bsbObject>
417 <bsbObject version="2" type="BSBLabel">
418 <objectName/>
419 <x>8</x>
420 <y>121</y>
421 <width>150</width>
422 <height>30</height>
423 <uuid>{b74148fe-3ba3-4d62-b507-64eb27627e65}</uuid>
424 <visible>true</visible>
425 <midichan>0</midichan>
426 <midicc>0</midicc>
427 <label>Pitch</label>
428 <alignment>left</alignment>
429 <font>Arial</font>
430 <fontsize>10</fontsize>
431 <precision>3</precision>
432 <color>
433 <r>0</r>
434 <g>0</g>
435 <b>0</b>
436 </color>
437 <bgcolor mode="nobackground">
438 <r>255</r>
439 <g>255</g>
440 <b>255</b>
441 </bgcolor>
442 <bordermode>noborder</bordermode>
443 <borderradius>1</borderradius>
444 <borderwidth>1</borderwidth>
445 </bsbObject>
446 <bsbObject version="2" type="BSBDisplay">
447 <objectName>Amp</objectName>
448 <x>448</x>
449 <y>169</y>
450 <width>60</width>
451 <height>30</height>
452 <uuid>{3c299cf9-f5e6-4902-9f6c-4d3802f1beb8}</uuid>
453 <visible>true</visible>
454 <midichan>0</midichan>
455 <midicc>0</midicc>
456 <label>1.000</label>
457 <alignment>right</alignment>
458 <font>Arial</font>
459 <fontsize>9</fontsize>
460 <precision>3</precision>
461 <color>
462 <r>0</r>
463 <g>0</g>
464 <b>0</b>
465 </color>
466 <bgcolor mode="nobackground">
467 <r>255</r>
468 <g>255</g>
469 <b>255</b>
470 </bgcolor>
471 <bordermode>noborder</bordermode>
472 <borderradius>1</borderradius>
473 <borderwidth>1</borderwidth>
474 </bsbObject>
475 <bsbObject version="2" type="BSBHSlider">
476 <objectName>Amp</objectName>
477 <x>8</x>
478 <y>147</y>
479 <width>500</width>
480 <height>27</height>
481 <uuid>{b96a19b5-e2ff-4bc8-9d9c-e1878dc2c7ea}</uuid>
482 <visible>true</visible>
483 <midichan>0</midichan>
484 <midicc>0</midicc>
485 <minimum>0.00000000</minimum>
486 <maximum>5.00000000</maximum>
487 <value>1.00000000</value>
488 <mode>lin</mode>
489 <mouseControl act="jump">continuous</mouseControl>
490 <resolution>-1.00000000</resolution>
491 <randomizable group="0">false</randomizable>
492 </bsbObject>
493 <bsbObject version="2" type="BSBLabel">
494 <objectName/>
495 <x>8</x>
496 <y>169</y>
497 <width>150</width>
498 <height>30</height>
499 <uuid>{3f67483e-a5a5-4c55-8c4c-802b8cb45fcb}</uuid>
500 <visible>true</visible>
501 <midichan>0</midichan>
502 <midicc>0</midicc>
503 <label>Amp</label>
504 <alignment>left</alignment>
505 <font>Arial</font>
506 <fontsize>10</fontsize>
507 <precision>3</precision>
508 <color>
509 <r>0</r>
510 <g>0</g>
511 <b>0</b>
512 </color>
513 <bgcolor mode="nobackground">
514 <r>255</r>
515 <g>255</g>
516 <b>255</b>
517 </bgcolor>
518 <bordermode>noborder</bordermode>
519 <borderradius>1</borderradius>
520 <borderwidth>1</borderwidth>
521 </bsbObject>
522 <bsbObject version="2" type="BSBButton">
523 <objectName/>
524 <x>308</x>
525 <y>73</y>
526 <width>70</width>
527 <height>18</height>
528 <uuid>{eae817a3-8fa5-472e-86fa-a19ee5f5199d}</uuid>
529 <visible>true</visible>
530 <midichan>0</midichan>
531 <midicc>0</midicc>
532 <type>event</type>
533 <pressedValue>1.00000000</pressedValue>
534 <stringvalue/>
535 <text>Normal</text>
536 <image>/</image>
537 <eventLine>i 2 0 0.01 1</eventLine>
538 <latch>false</latch>
539 <latched>false</latched>
540 </bsbObject>
541 <bsbObject version="2" type="BSBButton">
542 <objectName/>
543 <x>378</x>
544 <y>121</y>
545 <width>70</width>
546 <height>18</height>
547 <uuid>{a671a876-7584-4a8c-9438-d9aa42ba31f8}</uuid>
548 <visible>true</visible>
549 <midichan>0</midichan>
550 <midicc>0</midicc>
551 <type>event</type>
552 <pressedValue>1.00000000</pressedValue>
553 <stringvalue/>
554 <text>Unisson</text>
555 <image>/</image>
556 <eventLine>i 3 0 0.01 0.6</eventLine>
557 <latch>false</latch>
558 <latched>false</latched>
559 </bsbObject>
560 <bsbObject version="2" type="BSBButton">
561 <objectName>Freeze</objectName>
562 <x>378</x>
563 <y>73</y>
564 <width>70</width>
565 <height>18</height>
566 <uuid>{5054e50c-733d-4f88-ae43-edf85e623ebe}</uuid>
567 <visible>true</visible>
568 <midichan>0</midichan>
569 <midicc>0</midicc>
570 <type>value</type>
571 <pressedValue>1.00000000</pressedValue>
572 <stringvalue/>
573 <text> Freeze</text>
574 <image>/</image>
575 <eventLine/>
576 <latch>true</latch>
577 <latched>false</latched>
578 </bsbObject>
579 </bsbPanel>
580 <bsbPresets>
581 </bsbPresets>
582 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>