1 Primer uporabe Env za fade in in fade out, ter Pan2 za stereo signal. (drafting/testing Computer Music & SuperCollider curriculum)
Luka Prinčič edited this page 2020-09-16 12:38:22 +02:00

Primer uporabe Env za fade-in in fade-out, ter Pan2 za stereo signal.

/*

An example of:
- use of variables
- use of Pan2.ar to have stereo
- use of Env().kr() to create start and
  end fades of sound stream 

*/
( 
{
	// define variables' names we will need
	var fadein, duration, fadeout, pan;
	
	// assign values (or synths!) to variables
	fadein = 4; // fade-in in seconds
	duration = 50; // duration in seconds
	fadeout = 5; // fade-out in, you guessed it, seconds!
	
	// panning left-right: from "-1" to "1". 0 is center.
	// do you dare to put an UGen instead of floating point number?
	pan = LFNoise1.kr(0.5).range(-1,1); 
	         
	// a mono signal "inside" the Pan2 UGen will become stereo with a pan
	Pan2.ar( 
		in:
		//...... your code ..........
		// for example:
		(Saw.ar(LFNoise0.kr(0.4).range(50,90)) 
			* LFPulse.kr(0.4, width: 0.2))
		+ 
		(Saw.ar(LFNoise0.kr(0.5).range(100,200)) 
			* LFPulse.kr(0.5, width: 0.4))
		+ 
		(Saw.ar(LFNoise0.kr(0.6).range(100,400)) 
			* LFPulse.kr(0.6, width: 0.1))
		+ 
		(Saw.ar(LFNoise0.kr(0.7).range(40,150)) 
			* LFPulse.kr(0.7, width: 0.3))
		* 0.2
		//
		// .... end of your code.
		, // this comma separates arguments inside Pan2.ar: (in, pos, level)
		// define position in the stereo
		pos: pan, 
		
		// define level. 
		// we use a simple basic envelope definition to create
		// fade-in and fade-out 
		level: Env([0,1,1,0], [fadein, duration, fadeout]).kr(2);
		
		// check the shape with .plot:
		// Env([0,1,1,0], [4,50,5]).plot 
		// just select above code and evaluate with ctrl+enter)
		
	)	
}.play
)