1;Written by Iain McCurdy, 2006
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;	Cannot display more than one space in Label, so can't display waveform 1 and 2 as bellow
8;		1. Transpose down:  /|  /|  /|  /|  /|  /|  /|  /|  /|  /|
9;	     	              / | / | / | / | / | / | / | / | / | / | /
10;    	     	        /  |/  |/  |/  |/  |/  |/  |/  |/  |/  |/
11
12;		2. Transpose up:   |\\  |\\  |\\  |\\  |\\  |\\  |\\  |\\  |\\
13;		                   | \\ | \\ | \\ | \\ | \\ | \\ | \\ | \\ | \
14;		                   |  \\|  \\|  \\|  \\|  \\|  \\|  \\|  \\|
15
16;	Add Browser for audio file and use of FilePlay2 udo, now accept mono or stereo wav files
17
18
19;my flags on Ubuntu: -iadc -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
20<CsoundSynthesizer>
21<CsOptions>
22--env:SSDIR+=../SourceMaterials
23</CsOptions>
24<CsInstruments>
25sr		= 44100		;SAMPLE RATE
26ksmps	= 10			;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
27nchnls	= 2			;NUMBER OF CHANNELS (2=STEREO)
280dbfs	= 1			;MAXIMUM SOUND INTENSITY LEVEL REGARDLESS OF BIT DEPTH
29
30
31opcode FilePlay2, aa, Skoo		; Credit to Joachim Heintz
32	;gives stereo output regardless your soundfile is mono or stereo
33	Sfil, kspeed, iskip, iloop	xin
34	ichn		filenchnls	Sfil
35	if ichn == 1 then
36		aL		diskin2	Sfil, kspeed, iskip, iloop
37		aR		=		aL
38	else
39		aL, aR	diskin2	Sfil, kspeed, iskip, iloop
40	endif
41		xout		aL, aR
42endop
43
44
45instr	10	;GUI
46	ktrig	metro	10
47	if (ktrig == 1)	then
48		gkGain	invalue	"Gain"			;init	.5
49		gktrans	invalue 	"Transposition"	;init	0
50		gkdlt	invalue 	"Delay_Time"		;init	.05
51		gkinput	invalue	"Input"
52	endif
53endin
54
55instr	1	;PLAYS FILE
56	if	gkinput=0	then
57		Sfile	invalue	"_Browse1"
58		;OUTPUT		OPCODE	FILE    | SPEED | INSKIP | LOOPING (0=OFF 1=ON)
59		asig, asigR	FilePlay2	Sfile,     1,       0,        1
60	else
61		asig	inch	1
62	endif
63	gasig	=	asig * gkGain							;RESCALE AUDIO SIGNAL WITH ON-SCREEN GAIN SLIDER
64endin
65
66instr 	2	;PITCH SHIFTER-DELAY INSTRUMENT
67	kporttime	linseg	0,0.001,0.005,1,0.005				;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
68	ktrans	portk	gktrans, kporttime					;SMOOTH CHANGES IN SLIDER VARIABLE
69	kdlt		portk	gkdlt, kporttime					;SMOOTH CHANGES IN SLIDER VARIABLE
70	koctfract	=		ktrans/12							;TRANSPOSITION AS FRACTION OF AN OCTAVE
71	kratio	=		cpsoct(8+koctfract)/cpsoct(8)			;RATIO OF NEW FREQ TO A DECLARED BASE FREQUENCY (MIDDLE C)
72	krate	=		(kratio-1)/kdlt					;SUBTRACT 1/1 SPEED
73
74	aphase	phasor	-krate							; MOVING PHASE 1-0
75
76	aignore	delayr	.2								; ALLOC DELAY LINE
77	adelsig	deltap3	aphase * kdlt						; VARIABLE TAP
78			delayw	gasig							; WRITE AUDIO TO THE BEGINNING OF THE DELAY BUFFER
79
80			outs		adelsig, adelsig
81	gasig	=		0								;CLEAR THE GLOBAL AUDIO SEND VARIABLES
82endin
83</CsInstruments>
84<CsScore>
85;INSTR | START | DURATION
86i 10		0		-1		;GUI
87i  2      0         -1		;INSTRUMENT 2 PLAYS A HELD NOTE
88
89f 0	  3600				;DUMMY SCORE EVENT KEEPS REALTIME PERFORMANCE GOING FOR 1 HOUR
90</CsScore>
91</CsoundSynthesizer>
92<bsbPanel>
93 <label>Widgets</label>
94 <objectName/>
95 <x>72</x>
96 <y>179</y>
97 <width>400</width>
98 <height>200</height>
99 <visible>true</visible>
100 <uuid/>
101 <bgcolor mode="background">
102  <r>241</r>
103  <g>226</g>
104  <b>185</b>
105 </bgcolor>
106 <bsbObject version="2" type="BSBLabel">
107  <objectName/>
108  <x>2</x>
109  <y>2</y>
110  <width>515</width>
111  <height>300</height>
112  <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
113  <visible>true</visible>
114  <midichan>0</midichan>
115  <midicc>0</midicc>
116  <label>Simple Pitch Shifter</label>
117  <alignment>center</alignment>
118  <font>Liberation Sans</font>
119  <fontsize>18</fontsize>
120  <precision>3</precision>
121  <color>
122   <r>0</r>
123   <g>0</g>
124   <b>0</b>
125  </color>
126  <bgcolor mode="background">
127   <r>158</r>
128   <g>220</g>
129   <b>217</b>
130  </bgcolor>
131  <bordermode>border</bordermode>
132  <borderradius>5</borderradius>
133  <borderwidth>2</borderwidth>
134 </bsbObject>
135 <bsbObject version="2" type="BSBButton">
136  <objectName/>
137  <x>5</x>
138  <y>5</y>
139  <width>112</width>
140  <height>32</height>
141  <uuid>{487d5181-d838-4cce-9628-317fefc350cb}</uuid>
142  <visible>true</visible>
143  <midichan>0</midichan>
144  <midicc>0</midicc>
145  <type>event</type>
146  <pressedValue>1.00000000</pressedValue>
147  <stringvalue/>
148  <text>   ON / OFF</text>
149  <image>/</image>
150  <eventLine>i 1 0 -1</eventLine>
151  <latch>true</latch>
152  <latched>false</latched>
153 </bsbObject>
154 <bsbObject version="2" type="BSBHSlider">
155  <objectName>Gain</objectName>
156  <x>9</x>
157  <y>60</y>
158  <width>500</width>
159  <height>27</height>
160  <uuid>{de47f47d-bcea-4c1c-ab4b-a323452b1f7e}</uuid>
161  <visible>true</visible>
162  <midichan>0</midichan>
163  <midicc>0</midicc>
164  <minimum>0.00000000</minimum>
165  <maximum>1.00000000</maximum>
166  <value>0.50200000</value>
167  <mode>lin</mode>
168  <mouseControl act="jump">continuous</mouseControl>
169  <resolution>-1.00000000</resolution>
170  <randomizable group="0">false</randomizable>
171 </bsbObject>
172 <bsbObject version="2" type="BSBLabel">
173  <objectName/>
174  <x>9</x>
175  <y>78</y>
176  <width>100</width>
177  <height>30</height>
178  <uuid>{0200a063-5db8-4668-bc2d-2d989a083f6e}</uuid>
179  <visible>true</visible>
180  <midichan>0</midichan>
181  <midicc>0</midicc>
182  <label>Gain</label>
183  <alignment>left</alignment>
184  <font>Arial</font>
185  <fontsize>10</fontsize>
186  <precision>3</precision>
187  <color>
188   <r>0</r>
189   <g>0</g>
190   <b>0</b>
191  </color>
192  <bgcolor mode="nobackground">
193   <r>255</r>
194   <g>255</g>
195   <b>255</b>
196  </bgcolor>
197  <bordermode>noborder</bordermode>
198  <borderradius>1</borderradius>
199  <borderwidth>1</borderwidth>
200 </bsbObject>
201 <bsbObject version="2" type="BSBDisplay">
202  <objectName>Gain</objectName>
203  <x>449</x>
204  <y>77</y>
205  <width>60</width>
206  <height>30</height>
207  <uuid>{ab191e3a-430d-4f1d-88aa-9840342cd2d3}</uuid>
208  <visible>true</visible>
209  <midichan>0</midichan>
210  <midicc>0</midicc>
211  <label>0.502</label>
212  <alignment>right</alignment>
213  <font>Arial</font>
214  <fontsize>9</fontsize>
215  <precision>3</precision>
216  <color>
217   <r>0</r>
218   <g>0</g>
219   <b>0</b>
220  </color>
221  <bgcolor mode="nobackground">
222   <r>255</r>
223   <g>255</g>
224   <b>255</b>
225  </bgcolor>
226  <bordermode>noborder</bordermode>
227  <borderradius>1</borderradius>
228  <borderwidth>1</borderwidth>
229 </bsbObject>
230 <bsbObject version="2" type="BSBLabel">
231  <objectName/>
232  <x>518</x>
233  <y>2</y>
234  <width>433</width>
235  <height>300</height>
236  <uuid>{74928ed2-b701-4668-9a11-74763d317e9b}</uuid>
237  <visible>true</visible>
238  <midichan>0</midichan>
239  <midicc>0</midicc>
240  <label>Simple Pitch Shifter</label>
241  <alignment>center</alignment>
242  <font>Liberation Sans</font>
243  <fontsize>18</fontsize>
244  <precision>3</precision>
245  <color>
246   <r>0</r>
247   <g>0</g>
248   <b>0</b>
249  </color>
250  <bgcolor mode="background">
251   <r>158</r>
252   <g>220</g>
253   <b>217</b>
254  </bgcolor>
255  <bordermode>border</bordermode>
256  <borderradius>5</borderradius>
257  <borderwidth>2</borderwidth>
258 </bsbObject>
259 <bsbObject version="2" type="BSBLabel">
260  <objectName/>
261  <x>520</x>
262  <y>20</y>
263  <width>429</width>
264  <height>268</height>
265  <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
266  <visible>true</visible>
267  <midichan>0</midichan>
268  <midicc>0</midicc>
269  <label>--------------------------------------------------------------------------------------------------------
270If the delay time is moved in a continuous cycle using a sawtooth waveform then a steady pitch shifting effect can be achieved. By using a sawtooth up waveform (1.) downward transpositions are achieved. By using a sawtooth down waveform (2.) upward transpoisitions are achieved. The 'Delay Time' slider controls the amplitude of the sawtooth waveform that modulates the delay time.
271Very short settings of this parameter can lead to harmonic distortions of the input signal but whilst longer 'Delay Time' settings give smoother pitch shifing effects, the temporal distortion of the source material becomes more marked. This is an extremely basic demonstration of this technique and glitches in the audio stream are heard each time the waveform jumps back to the beginning of its cycle. In real pitch shifters (and in the next example) each cycle of the delay time oscillation is amplitude enveloped to mute these glitches.</label>
272  <alignment>left</alignment>
273  <font>Arial</font>
274  <fontsize>14</fontsize>
275  <precision>3</precision>
276  <color>
277   <r>0</r>
278   <g>0</g>
279   <b>0</b>
280  </color>
281  <bgcolor mode="nobackground">
282   <r>255</r>
283   <g>255</g>
284   <b>255</b>
285  </bgcolor>
286  <bordermode>noborder</bordermode>
287  <borderradius>1</borderradius>
288  <borderwidth>1</borderwidth>
289 </bsbObject>
290 <bsbObject version="2" type="BSBDisplay">
291  <objectName>Transposition</objectName>
292  <x>449</x>
293  <y>117</y>
294  <width>60</width>
295  <height>30</height>
296  <uuid>{732b2008-7445-4893-a260-e68561cf8e71}</uuid>
297  <visible>true</visible>
298  <midichan>0</midichan>
299  <midicc>0</midicc>
300  <label>3.264</label>
301  <alignment>right</alignment>
302  <font>Arial</font>
303  <fontsize>9</fontsize>
304  <precision>3</precision>
305  <color>
306   <r>0</r>
307   <g>0</g>
308   <b>0</b>
309  </color>
310  <bgcolor mode="nobackground">
311   <r>255</r>
312   <g>255</g>
313   <b>255</b>
314  </bgcolor>
315  <bordermode>noborder</bordermode>
316  <borderradius>1</borderradius>
317  <borderwidth>1</borderwidth>
318 </bsbObject>
319 <bsbObject version="2" type="BSBLabel">
320  <objectName/>
321  <x>9</x>
322  <y>159</y>
323  <width>120</width>
324  <height>30</height>
325  <uuid>{b57ba536-8f28-4986-9bf7-8eb84262d8ca}</uuid>
326  <visible>true</visible>
327  <midichan>0</midichan>
328  <midicc>0</midicc>
329  <label>Delay Time</label>
330  <alignment>left</alignment>
331  <font>Arial</font>
332  <fontsize>10</fontsize>
333  <precision>3</precision>
334  <color>
335   <r>0</r>
336   <g>0</g>
337   <b>0</b>
338  </color>
339  <bgcolor mode="nobackground">
340   <r>255</r>
341   <g>255</g>
342   <b>255</b>
343  </bgcolor>
344  <bordermode>noborder</bordermode>
345  <borderradius>1</borderradius>
346  <borderwidth>1</borderwidth>
347 </bsbObject>
348 <bsbObject version="2" type="BSBHSlider">
349  <objectName>Transposition</objectName>
350  <x>9</x>
351  <y>100</y>
352  <width>500</width>
353  <height>27</height>
354  <uuid>{b8fa76b9-3d04-4156-a2f2-a413d3864da3}</uuid>
355  <visible>true</visible>
356  <midichan>0</midichan>
357  <midicc>0</midicc>
358  <minimum>-24.00000000</minimum>
359  <maximum>24.00000000</maximum>
360  <value>3.26400000</value>
361  <mode>lin</mode>
362  <mouseControl act="jump">continuous</mouseControl>
363  <resolution>-1.00000000</resolution>
364  <randomizable group="0">false</randomizable>
365 </bsbObject>
366 <bsbObject version="2" type="BSBDisplay">
367  <objectName>Delay_Time</objectName>
368  <x>449</x>
369  <y>157</y>
370  <width>60</width>
371  <height>30</height>
372  <uuid>{5f670bb1-e411-4f17-94a3-2321fdf5742b}</uuid>
373  <visible>true</visible>
374  <midichan>0</midichan>
375  <midicc>0</midicc>
376  <label>0.063</label>
377  <alignment>right</alignment>
378  <font>Arial</font>
379  <fontsize>9</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 <bsbObject version="2" type="BSBHSlider">
396  <objectName>Delay_Time</objectName>
397  <x>9</x>
398  <y>140</y>
399  <width>500</width>
400  <height>27</height>
401  <uuid>{1920efdc-fe11-4010-a22c-50efec0c27d3}</uuid>
402  <visible>true</visible>
403  <midichan>0</midichan>
404  <midicc>0</midicc>
405  <minimum>0.00100000</minimum>
406  <maximum>0.20000000</maximum>
407  <value>0.06269000</value>
408  <mode>lin</mode>
409  <mouseControl act="jump">continuous</mouseControl>
410  <resolution>-1.00000000</resolution>
411  <randomizable group="0">false</randomizable>
412 </bsbObject>
413 <bsbObject version="2" type="BSBLabel">
414  <objectName/>
415  <x>9</x>
416  <y>118</y>
417  <width>160</width>
418  <height>30</height>
419  <uuid>{aea841b2-29e6-42d6-ac23-02439b1cc47f}</uuid>
420  <visible>true</visible>
421  <midichan>0</midichan>
422  <midicc>0</midicc>
423  <label>Transposition (semitones)</label>
424  <alignment>left</alignment>
425  <font>Arial</font>
426  <fontsize>10</fontsize>
427  <precision>3</precision>
428  <color>
429   <r>0</r>
430   <g>0</g>
431   <b>0</b>
432  </color>
433  <bgcolor mode="nobackground">
434   <r>255</r>
435   <g>255</g>
436   <b>255</b>
437  </bgcolor>
438  <bordermode>noborder</bordermode>
439  <borderradius>1</borderradius>
440  <borderwidth>1</borderwidth>
441 </bsbObject>
442 <bsbObject version="2" type="BSBLabel">
443  <objectName/>
444  <x>94</x>
445  <y>200</y>
446  <width>80</width>
447  <height>30</height>
448  <uuid>{429fca04-6933-4c2e-9e1a-301edbfcdc10}</uuid>
449  <visible>true</visible>
450  <midichan>0</midichan>
451  <midicc>0</midicc>
452  <label>Source</label>
453  <alignment>right</alignment>
454  <font>Arial</font>
455  <fontsize>10</fontsize>
456  <precision>3</precision>
457  <color>
458   <r>0</r>
459   <g>0</g>
460   <b>0</b>
461  </color>
462  <bgcolor mode="nobackground">
463   <r>255</r>
464   <g>255</g>
465   <b>255</b>
466  </bgcolor>
467  <bordermode>noborder</bordermode>
468  <borderradius>1</borderradius>
469  <borderwidth>1</borderwidth>
470 </bsbObject>
471 <bsbObject version="2" type="BSBDropdown">
472  <objectName>Input</objectName>
473  <x>175</x>
474  <y>200</y>
475  <width>120</width>
476  <height>30</height>
477  <uuid>{45d19438-752c-4ed6-a700-3a764c5ab185}</uuid>
478  <visible>true</visible>
479  <midichan>0</midichan>
480  <midicc>0</midicc>
481  <bsbDropdownItemList>
482   <bsbDropdownItem>
483    <name>Audio File</name>
484    <value>0</value>
485    <stringvalue/>
486   </bsbDropdownItem>
487   <bsbDropdownItem>
488    <name>Live</name>
489    <value>1</value>
490    <stringvalue/>
491   </bsbDropdownItem>
492  </bsbDropdownItemList>
493  <selectedIndex>0</selectedIndex>
494  <randomizable group="0">false</randomizable>
495 </bsbObject>
496 <bsbObject version="2" type="BSBButton">
497  <objectName>_Browse1</objectName>
498  <x>6</x>
499  <y>242</y>
500  <width>170</width>
501  <height>30</height>
502  <uuid>{35203826-d49d-486b-bc9b-cfb6b31ad54f}</uuid>
503  <visible>true</visible>
504  <midichan>0</midichan>
505  <midicc>0</midicc>
506  <type>value</type>
507  <pressedValue>1.00000000</pressedValue>
508  <stringvalue>AndItsAll.wav</stringvalue>
509  <text>Browse Audio File</text>
510  <image>/</image>
511  <eventLine/>
512  <latch>false</latch>
513  <latched>false</latched>
514 </bsbObject>
515 <bsbObject version="2" type="BSBLineEdit">
516  <objectName>_Browse1</objectName>
517  <x>178</x>
518  <y>243</y>
519  <width>330</width>
520  <height>28</height>
521  <uuid>{9778dc6c-e6f4-446f-a6f8-b3fd0916fd59}</uuid>
522  <visible>true</visible>
523  <midichan>0</midichan>
524  <midicc>0</midicc>
525  <label>AndItsAll.wav</label>
526  <alignment>left</alignment>
527  <font>Arial</font>
528  <fontsize>10</fontsize>
529  <precision>3</precision>
530  <color>
531   <r>0</r>
532   <g>0</g>
533   <b>0</b>
534  </color>
535  <bgcolor mode="nobackground">
536   <r>229</r>
537   <g>229</g>
538   <b>229</b>
539  </bgcolor>
540  <background>nobackground</background>
541 </bsbObject>
542 <bsbObject version="2" type="BSBLabel">
543  <objectName/>
544  <x>178</x>
545  <y>270</y>
546  <width>330</width>
547  <height>30</height>
548  <uuid>{cc4ee995-e25a-4871-bb14-477ea340315b}</uuid>
549  <visible>true</visible>
550  <midichan>0</midichan>
551  <midicc>0</midicc>
552  <label>Restart the instrument after changing the audio file.</label>
553  <alignment>left</alignment>
554  <font>Liberation Sans</font>
555  <fontsize>12</fontsize>
556  <precision>3</precision>
557  <color>
558   <r>0</r>
559   <g>0</g>
560   <b>0</b>
561  </color>
562  <bgcolor mode="nobackground">
563   <r>255</r>
564   <g>255</g>
565   <b>255</b>
566  </bgcolor>
567  <bordermode>noborder</bordermode>
568  <borderradius>1</borderradius>
569  <borderwidth>1</borderwidth>
570 </bsbObject>
571</bsbPanel>
572<bsbPresets>
573</bsbPresets>
574