While we're in our town we want it to sound like a town that is in the middle of the forest. To accomplish this we should have some ambient sound that is low volume that just blends in to the environment. A good source of Creative Commons licensed sounds is The Freesound Project which can be found at http://www.freesound.org. There are a number of good candidates on the site and I have picked up one from user reinsamba for this test. You will find a copy of it in the assets folder of the project called evening in the forest.wav
.
Ambient Audio
folder in your project.evening in the forest.wav
file in this case, into the project and Unity will perform the necessary conversion:Now you have a usable AudioSource that can be added to other GameObjects in the scene. But remember, Unity will not distort the assets unless we tell it to by changing some properties of the original audio file. We brought in a fairly sizable AudioSource as a .wav
file.
If hardware isn't available, Unity will automatically fall back to software decoding. In our case here we are going from a 26.2MB Wav file to a 0.6MB compressed MP3 file. If you want a higher quality sample you can adjust the Compression slider to a higher value, but in our case this is simple ambient noise so we don't need an excessive amount of fidelity.
Now that we have created the AudioSource we need to attach it to a GameObject so that it will play. Since this is the sound of the environment, we can attach this to the ground that the player will walk around on.
We have told this AudioSource to loop its audio so we should hear this audio clip for the duration of the game while we're on this ground GameObject. One special note about compressed audio in iOS is that the compression process may tweak the beginning or end of your audio data, so you will want to listen to it after compressing it to make sure that it still loops properly.
We didn't necessarily have to attach the sound to the ground, we could have attached it to a different object. For example, if we wanted to give a marketplace the sounds of marketplace chatter we could attach that directly to the GameObject that represents the marketplace and when the player walks away from it, the sound would diminish.
We just created an ambient sound track for our world. By importing a
.wav
file and compressing it we have integrated an asset that is suitable for use on our mobile platform and can use the iOS device hardware to decompress the audio stream. Since we've attached this AudioSource to the ground of our world, we can be certain that it will be audible as we move through our environment. With this we have created some atmosphere for our world and given this area of the world a personality.
3.133.13.76