Sound programming

Sound manipulation

In the previous module you used Sound methods – play and stop. However sound may be manipulated in more advanced way. Let's modify the code from the previous exercise

on(release) {
	s1 = new Sound();
	s1.attachSound("sound3");
	s1.setVolume(50);
	s1.setPan(-100);
	s1.start(30);
	s1.onSoundComplete = function() {
		s1.setPan(100);
		s1.start(30);
		
	}
		
}

First part of the code is familiar to you. See another version of start()method of the sound – it has an argument "offset" and sound is started from the second 30. Also we used setVolumemethod to make sound 50% loud from the original.

setPanmethod create a pseudo-stereo effect shutting down at first to the right and then to the left channel.

Note onSoundComplete event handler – by using it it's not necessary to count how long sound is – when it finished playing this event is risen.

Next