Debian Codegraph @

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

raw
1 ;Written by Iain McCurdy, 2007
2
3 ;Modified for QuteCsound by René, September 2010, updated Feb 2011
4 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6 ;Notes on modifications from original csd:
7 ; Add Browser for audio file and use of FilePlay2 udo, now accept mono or stereo wav files
8
9
10 ;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
11 <CsoundSynthesizer>
12 <CsOptions>
13 --env:SSDIR+=../../SourceMaterials
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100 ;SAMPLE RATE
17 ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
18 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
19 0dbfs = 1 ;MAXIMUM SOUND INTENSITY LEVEL REGARDLESS OF BIT DEPTH
20
21
22 opcode FilePlay2, aa, Skoo ; Credit to Joachim Heintz
23 ;gives stereo output regardless your soundfile is mono or stereo
24 Sfil, kspeed, iskip, iloop xin
25 ichn filenchnls Sfil
26 if ichn == 1 then
27 aL diskin2 Sfil, kspeed, iskip, iloop
28 aR = aL
29 else
30 aL, aR diskin2 Sfil, kspeed, iskip, iloop
31 endif
32 xout aL, aR
33 endop
34
35
36 instr 1 ;GUI
37 ktrig metro 10
38 if (ktrig == 1) then
39 gkGain invalue "Gain"
40 gkinput invalue "Input"
41 endif
42 endin
43
44 instr 2
45 if gkinput==1 then ;IF 'INPUT' SWITCH IS SET TO 'AUDIO FILE' THEN IMPLEMENT THE NEXT LINE OF CODE
46 Sfile invalue "_Browse1"
47 ;OUTPUT OPCODE FILE_PATH| SPEED | INSKIP | WRAPAROUND (1=ON)
48 asig, asigR FilePlay2 Sfile, 1, 0, 1 ;READ A STORED AUDIO FILE FROM THE HARD DRIVE
49 else ;IF 'INPUT' SWITCH IS NOT SET TO 'AUDIO FILE' THEN IMPLEMENT THE NEXT LINE OF CODE
50 asig inch 1 ;READ AUDIO FROM THE COMPUTER'S LIVE INPUT CHANNEL 1 (LEFT)
51 endif
52
53 ;OUTPUT OPCODE INPUT | IFFTSIZE | IOVERLAP | IWINSIZE | IWINTYPE
54 fsig pvsanal asig, 1024, 256, 1024, 1 ;ANALYSE THE AUDIO SIGNAL AND CREATE AN 'F' SIGNAL (OPTIONAL INPUT ARGUMENTS ARE OMITTED)
55 ;OUTPUT OPCODE INPUT
56 aresyn pvsynth fsig ;RESYNTHESIZE THE f-SIGNAL AS AN AUDIO SIGNAL
57 outs aresyn * gkGain, aresyn * gkGain ;SEND THE RESYNTHESIZED SIGNAL TO THE AUDIO OUTPUTS AND RESCALE GAIN USING ON-SCREEN SLIDER
58 endin
59 </CsInstruments>
60 <CsScore>
61 ;INSTR | START | DURATION
62 i 1 0 3600 ;GUI
63 </CsScore>
64 </CsoundSynthesizer>
65
66
67 <bsbPanel>
68 <label>Widgets</label>
69 <objectName/>
70 <x>73</x>
71 <y>206</y>
72 <width>1103</width>
73 <height>344</height>
74 <visible>true</visible>
75 <uuid/>
76 <bgcolor mode="background">
77 <r>241</r>
78 <g>226</g>
79 <b>185</b>
80 </bgcolor>
81 <bsbObject version="2" type="BSBLabel">
82 <objectName/>
83 <x>2</x>
84 <y>2</y>
85 <width>516</width>
86 <height>280</height>
87 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
88 <visible>true</visible>
89 <midichan>0</midichan>
90 <midicc>0</midicc>
91 <label>pvsanal and pvsynth</label>
92 <alignment>center</alignment>
93 <font>Liberation Sans</font>
94 <fontsize>18</fontsize>
95 <precision>3</precision>
96 <color>
97 <r>0</r>
98 <g>0</g>
99 <b>0</b>
100 </color>
101 <bgcolor mode="background">
102 <r>181</r>
103 <g>199</g>
104 <b>255</b>
105 </bgcolor>
106 <bordermode>border</bordermode>
107 <borderradius>5</borderradius>
108 <borderwidth>2</borderwidth>
109 </bsbObject>
110 <bsbObject version="2" type="BSBLabel">
111 <objectName/>
112 <x>519</x>
113 <y>2</y>
114 <width>584</width>
115 <height>280</height>
116 <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
117 <visible>true</visible>
118 <midichan>0</midichan>
119 <midicc>0</midicc>
120 <label>pvsanal and pvsynth</label>
121 <alignment>center</alignment>
122 <font>Liberation Sans</font>
123 <fontsize>18</fontsize>
124 <precision>3</precision>
125 <color>
126 <r>0</r>
127 <g>0</g>
128 <b>0</b>
129 </color>
130 <bgcolor mode="background">
131 <r>181</r>
132 <g>199</g>
133 <b>255</b>
134 </bgcolor>
135 <bordermode>border</bordermode>
136 <borderradius>5</borderradius>
137 <borderwidth>2</borderwidth>
138 </bsbObject>
139 <bsbObject version="2" type="BSBLabel">
140 <objectName/>
141 <x>522</x>
142 <y>22</y>
143 <width>574</width>
144 <height>252</height>
145 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
146 <visible>true</visible>
147 <midichan>0</midichan>
148 <midicc>0</midicc>
149 <label>---------------------------------------------------------------------------------------------------------------------------------------------
150 Pvsanal and pvsynth are two of the core opcodes used when when working with streaming phase vocoding analysis in Csound.
151 Pvsanal is used to create a streaming FFT analysis signal of an audio signal input. It outputs an 'fsig' signal which can be read and modified by Csound's streaming FFT opcodes.
152 Pvsynth is the compliment to pvsanal in that it takes an fsig signal and reynthesises it into an audio signal. This example is rather undramatic in that it merely takes an audio signal (either the live input or a stored sound file), converts it into an fsig, and then resynthesises it back into its initial state as an audio signal. Normally, as demonstrated in subsequent examples, further processing of the fsig would be applied before the resynthesis. Pvsanal also allows the user to make settings for aspects of the analysis such as window size, window type, FFT size and overlap but these setting should normally hard set into the code and left unchanged. The settings used in this example represent a good default setting. For further information regarding these parameters refer to the Csound Reference Manual.</label>
153 <alignment>left</alignment>
154 <font>Liberation Sans</font>
155 <fontsize>14</fontsize>
156 <precision>3</precision>
157 <color>
158 <r>0</r>
159 <g>0</g>
160 <b>0</b>
161 </color>
162 <bgcolor mode="nobackground">
163 <r>255</r>
164 <g>255</g>
165 <b>255</b>
166 </bgcolor>
167 <bordermode>noborder</bordermode>
168 <borderradius>1</borderradius>
169 <borderwidth>1</borderwidth>
170 </bsbObject>
171 <bsbObject version="2" type="BSBLabel">
172 <objectName/>
173 <x>10</x>
174 <y>90</y>
175 <width>100</width>
176 <height>30</height>
177 <uuid>{6d8d92f5-813d-4e91-867e-f3384b0baf9d}</uuid>
178 <visible>true</visible>
179 <midichan>0</midichan>
180 <midicc>0</midicc>
181 <label>Gain</label>
182 <alignment>left</alignment>
183 <font>Arial</font>
184 <fontsize>10</fontsize>
185 <precision>3</precision>
186 <color>
187 <r>0</r>
188 <g>0</g>
189 <b>0</b>
190 </color>
191 <bgcolor mode="nobackground">
192 <r>255</r>
193 <g>255</g>
194 <b>255</b>
195 </bgcolor>
196 <bordermode>noborder</bordermode>
197 <borderradius>1</borderradius>
198 <borderwidth>1</borderwidth>
199 </bsbObject>
200 <bsbObject version="2" type="BSBHSlider">
201 <objectName>Gain</objectName>
202 <x>10</x>
203 <y>73</y>
204 <width>500</width>
205 <height>27</height>
206 <uuid>{8fbaf396-5ad3-4de9-b5fe-cf9991b23868}</uuid>
207 <visible>true</visible>
208 <midichan>0</midichan>
209 <midicc>0</midicc>
210 <minimum>0.00000000</minimum>
211 <maximum>1.00000000</maximum>
212 <value>0.27000000</value>
213 <mode>lin</mode>
214 <mouseControl act="jump">continuous</mouseControl>
215 <resolution>-1.00000000</resolution>
216 <randomizable group="0">false</randomizable>
217 </bsbObject>
218 <bsbObject version="2" type="BSBDisplay">
219 <objectName>Gain</objectName>
220 <x>450</x>
221 <y>90</y>
222 <width>60</width>
223 <height>30</height>
224 <uuid>{0a5ba1c3-3448-4200-9a48-c116a64fc284}</uuid>
225 <visible>true</visible>
226 <midichan>0</midichan>
227 <midicc>0</midicc>
228 <label>0.270</label>
229 <alignment>right</alignment>
230 <font>Arial</font>
231 <fontsize>9</fontsize>
232 <precision>3</precision>
233 <color>
234 <r>0</r>
235 <g>0</g>
236 <b>0</b>
237 </color>
238 <bgcolor mode="nobackground">
239 <r>255</r>
240 <g>255</g>
241 <b>255</b>
242 </bgcolor>
243 <bordermode>noborder</bordermode>
244 <borderradius>1</borderradius>
245 <borderwidth>1</borderwidth>
246 </bsbObject>
247 <bsbObject version="2" type="BSBButton">
248 <objectName/>
249 <x>8</x>
250 <y>8</y>
251 <width>100</width>
252 <height>29</height>
253 <uuid>{24979132-c53f-4414-ac6b-6b4f503ecfe8}</uuid>
254 <visible>true</visible>
255 <midichan>0</midichan>
256 <midicc>0</midicc>
257 <type>event</type>
258 <pressedValue>1.00000000</pressedValue>
259 <stringvalue/>
260 <text> On / Off</text>
261 <image>/</image>
262 <eventLine>i 2 0 -1</eventLine>
263 <latch>true</latch>
264 <latched>false</latched>
265 </bsbObject>
266 <bsbObject version="2" type="BSBDropdown">
267 <objectName>Input</objectName>
268 <x>178</x>
269 <y>146</y>
270 <width>100</width>
271 <height>30</height>
272 <uuid>{65bb9cc6-078d-45fd-99aa-dd17a8d2d144}</uuid>
273 <visible>true</visible>
274 <midichan>0</midichan>
275 <midicc>0</midicc>
276 <bsbDropdownItemList>
277 <bsbDropdownItem>
278 <name>Live Input</name>
279 <value>0</value>
280 <stringvalue/>
281 </bsbDropdownItem>
282 <bsbDropdownItem>
283 <name>Audio File</name>
284 <value>1</value>
285 <stringvalue/>
286 </bsbDropdownItem>
287 </bsbDropdownItemList>
288 <selectedIndex>1</selectedIndex>
289 <randomizable group="0">false</randomizable>
290 </bsbObject>
291 <bsbObject version="2" type="BSBLabel">
292 <objectName/>
293 <x>116</x>
294 <y>146</y>
295 <width>60</width>
296 <height>30</height>
297 <uuid>{b3560c14-84be-4876-9100-5807ffe16e97}</uuid>
298 <visible>true</visible>
299 <midichan>0</midichan>
300 <midicc>0</midicc>
301 <label>Input</label>
302 <alignment>right</alignment>
303 <font>Arial</font>
304 <fontsize>10</fontsize>
305 <precision>3</precision>
306 <color>
307 <r>0</r>
308 <g>0</g>
309 <b>0</b>
310 </color>
311 <bgcolor mode="nobackground">
312 <r>255</r>
313 <g>255</g>
314 <b>255</b>
315 </bgcolor>
316 <bordermode>noborder</bordermode>
317 <borderradius>1</borderradius>
318 <borderwidth>1</borderwidth>
319 </bsbObject>
320 <bsbObject version="2" type="BSBButton">
321 <objectName>_Browse1</objectName>
322 <x>7</x>
323 <y>204</y>
324 <width>170</width>
325 <height>30</height>
326 <uuid>{5e2eb661-fbd0-428c-a273-5074fe20afd0}</uuid>
327 <visible>true</visible>
328 <midichan>0</midichan>
329 <midicc>0</midicc>
330 <type>value</type>
331 <pressedValue>1.00000000</pressedValue>
332 <stringvalue>AndItsAll.wav</stringvalue>
333 <text>Browse Audio File</text>
334 <image>/</image>
335 <eventLine/>
336 <latch>false</latch>
337 <latched>false</latched>
338 </bsbObject>
339 <bsbObject version="2" type="BSBLineEdit">
340 <objectName>_Browse1</objectName>
341 <x>178</x>
342 <y>205</y>
343 <width>330</width>
344 <height>28</height>
345 <uuid>{b9c6f525-5aaa-4e05-a133-073738bc02bb}</uuid>
346 <visible>true</visible>
347 <midichan>0</midichan>
348 <midicc>0</midicc>
349 <label>AndItsAll.wav</label>
350 <alignment>left</alignment>
351 <font>Arial</font>
352 <fontsize>10</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>206</r>
361 <g>206</g>
362 <b>206</b>
363 </bgcolor>
364 <background>nobackground</background>
365 </bsbObject>
366 <bsbObject version="2" type="BSBLabel">
367 <objectName/>
368 <x>178</x>
369 <y>233</y>
370 <width>330</width>
371 <height>30</height>
372 <uuid>{a63909ac-6fa4-41c8-a84b-ba08e76132ab}</uuid>
373 <visible>true</visible>
374 <midichan>0</midichan>
375 <midicc>0</midicc>
376 <label>Restart the instrument after changing the audio file.</label>
377 <alignment>left</alignment>
378 <font>Liberation Sans</font>
379 <fontsize>12</fontsize>
380 <precision>3</precision>
381 <color>
382 <r>0</r>
383 <g>0</g>
384 <b>0</b>
385 </color>
386 <bgcolor mode="nobackground">
387 <r>255</r>
388 <g>255</g>
389 <b>255</b>
390 </bgcolor>
391 <bordermode>noborder</bordermode>
392 <borderradius>1</borderradius>
393 <borderwidth>1</borderwidth>
394 </bsbObject>
395 </bsbPanel>
396 <bsbPresets>
397 </bsbPresets>
398 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>