[MUSIC] The most important think you need to know when trying to use audio in Unity is that you've got to load your audio files first. Now, audio files have to be in the right format in order for you to load them. Unity supports a number of common audio formats, these can be either compressed or uncompressed. For most sounds, when you're dealing with real time sound effects, I recommend uncompressed sounds. Uncompressed file format supported in unity include, commonly used AIFF auto interchange format, and wav Formats, these are what we call pulse code modulation formats, uncompressed. They are precisely the way that I described to you earlier, when I was discussing how audio data is stored on a computer. Other kind of files that you can import include compressed files, and there are two main compressed audio formats that Unity supports as standard. One of them is MP3. Now I'm just going to say it, MP3 is terrible. You don't just need to hear that from me. Anyone who's in any audio engineering would tell you, it's a really bad format. It's nasty, it's noisy, and it's going to make your stuff sound bad. And a better alternative, particularly because it's free, is the Ogg format. Ogg is an open source codec a lot like MP3, but actually it can sound a bit better. Now it's up to you what you do, but you should bear in mind that, Unity by default, inputs all your sounds and compresses them. You might not choose to do this. You might choose to do it differently. Bear in mind, the advice I've already given you when you're making these choices, because it can help you to make better decisions that make your end product much more interesting and better sounding. There is another form of audio file which Unity supports and that's the mod tracker audio file format. Mod trackers are really, really old ways of making sound of music particularly music tracks, and there's the XM format which is widely used by multi platforms like FastTracker. Now this is great, it's a great format because it uses tiny amounts of audio, and then people who write mods in mod trackers organize this audio in ways that are very efficient. You don't really need to do that anymore. Most of the time, if you're importing audio, you should just use stereo audio tracks for background music. However, if you know a composer who likes using the XM format, it can be really great. It has a particular kind of sound, particularly, it reminds people of beat up games. And it can be chip tune like, depending on how people put it together. So it's great that the XM format is supported. So what do we actually do if we want to use these audio files in Unity? The most important thing is to learn how to attach audio sources to objects. Here I've got a little Unity scene with an object in, which is this cube here. And I'm going to add an audio source by doing add component, selecting audio and audio source. And this is what's going to create the sound, and I need to add an audio clip, I'm just going to select, I've added in an audio clip to my scene. I got it from freesound.org which is a good environment. Now that's now added. I've clicked play on awake. So when the game starts, it will start playing. And I'll also click loop so it'll carry on looping. And if I play, you can hear that it's making a sound. [SOUND] So an audio source contains a reference to a file, we can actually select that file, or a clip which is related to it, and attach it to an audio source. This audio source can then be associated with an object. At this point, depending on the kind of interaction that we want to do, that source will start generating that sound. Let's say that it's a car or a virtual vehicle. The sound might be the engine sound effect, which will hopefully be a short loop. A short loop that we can vary the pitch of based on some other parameter. That audio source will automatically be positioned and it will use the head related transfer function in order to make sure that the listener perceives it, given it's actual measured distance in the virtual world. However, that will only work if you also configured something called an audio listener. In this scene, you can see we've got the main camera here, which I can select. And if you look at the main camera, there's an audio listener on that camera. All we need to know is that audio listener exists, and we can see it's down here on the inspector, it's there, it's all fine, so we will be able to hear audio. So the audio listener, is normally associated with your main camera. But it's a really important thing to be aware of. So your main camera is presumed to be the player. As a result, when the system in Unity is trying to calculate the volume and interaural time difference, and interaural amplitude difference, for the listener, is doing so based on the listeners position relative to the object, the audio source. So you need to make sure that your camera actually has an audio listener associated with it. Unity can then automatically calculate the audio mix, and use the relative position and speed to do so. Relative speed is used also to automatically calculate doppler effects. So you can switch on or off doppler effects and they will happen magically for you based on the speed of a particular audio source, how it moves and also its direction. [MUSIC]