Creating a Soundscape in Flash/AS3
Recently, I was tasked with creating a soundscape for a flash-based project we were producing for a client. I wanted to create something that would allow a user to navigate an image with their mouse and blend different audio files together—changing the pan and volume of sounds as they moved their mouse. Here’s the result:

http://www.sigmagroup.com/ftp/jschorn/preview/soundscape/The result seemed quite flexible and easy to implement. So I thought perhaps other Flash developers might find it useful. Here’s how it works.
I came up to two AS3 classes: SoundCell and Soundscape. A SoundCell is a circular representation of a sound in space. As you move closer to the center of the sound from any direction, it becomes louder. Move to the left of the sound, and it pans to your right. Move to the right, and it pans to your left. Move past the radius of the sound and it shuts off. The SoundCell also has a graphical representation that you can turn on or off so you can position cells. The Soundscape is an object that holds various SoundCells. It includes methods for adding cells, playing cells, and destroying them. Cells can overlap each other—creating some really nice blended sound effects.
Using the classes is easy and below is the step-by-step guide.
1. Import the Soundscape class.
- import com.sigma.sound.Soundscape;
2. Create a new instance of the Soundscape class and add it to the display list.
- var mySoundscape:Soundscape = new Soundscape();
- addChild(mySoundscape);
3. Add the cells you want using the addSoundCell() method. This method takes 6 parameters (filePath:String, xCoordinate:Number, yCoordinate:Number, radius:Number, visible:Boolean, color:Number).
- mySoundscape.addSoundCell(”audio/city.mp3″, 450, 200, 500, true, 0×990000);
4. When you’ve added all of your SoundCells, then call the start() method to initiate the Soundscape, and the Soundscape takes care of the rest.
- mySoundscape.start();
5. When you are done with your Soundscape you can destroy it with a call to the destroyCells() method.
- mySoundscape.destroyCells();
I’ve posted the source here. Feel free to use it and modify it to your heart’s content!
Tags: Flash, joe schorn, Sigma Group, Sound effect, Soundscape
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=db19c390-322c-4ab5-9c25-788c9720f9a1)

