 For audio, there are two primary components. There's what's called the audio listener and an audio source an Audio source is a component which actually emits sound and an audio listener is like the microphone in the world Which picks up the sound? So first off the audio listener is what we usually have attached to our camera Because that's usually where we want to perceive sound from is in the same position as our camera And so here in the scene we have an FPS controller from the standard asset library prefab And it's child object is really just a camera attached to the character controller And this game object is where we have our audio listener. It doesn't have any properties And in fact if you go look at the audio listener class, there's only two interesting things in here These two static properties pause and volume pause is a boolean Which if you set to true it effectively pauses all sound in the whole game and volume is a float value between zero to one Where one is full volume and zero is totally muted So it's it's basically the the master volume control of the whole game So that's really all there is to know about audio listener And in fact, you're really only supposed to have one enabled audio listener in your game at any time You can have multiple audio listeners in your scene Like say if you have multiple different cameras and you switch between those cameras Just make sure to disable and enable the audio listeners appropriately so that there's only one active at a time In fact, you'll get a warning in the Unity console if you have more than one enabled audio listener I don't think anything actually bad happens if you have multiple audio listeners active at the same time But it's it's not really a supported behavior of the engine. So you should avoid it So we have our audio listener attached to our camera. And then in the scene I have on these two cubes Both of them have an audio source And for this red cube the audio source audio clip property is set to Prokofiev and Playing Awake is checked. So this sound will start playing when the cube is loaded. So if I hit play here You will hear the music coming out of this cube And it gets louder to get closer because sound by default is Spatialized it's 3d position sound and so it matters where the audio listener is relative to the audio source the further away I get the audio listeners getting further and further away. And so it attenuates it gets Quieter and quieter and I get closer and it gets louder and louder and louder Also, if you have multi-channel output, you know stereo or 7.1 or something if I turn to the left It should only be coming out of your right channels if I turn to the left and should only be coming out of left channels And yeah, also, there's a Doppler effect you can kind of hear as I go back and forth Maybe maybe it's a little subtle at the yeah, actually not that subtle Yeah, you get some pretty nasty pitch wavering as I move back and forth because the default Doppler effect is actually pretty strong It's only on one, but in my experience, that's a pretty strong Doppler effect So something more realistic in my opinion would be something down like here Here I'll just actually exaggerate it so you can make sure you can hear it Yeah, that's pretty noticeable yeah, and so for the attenuation from by distance the default setting is logarithmic roll-off which is Pretty natural now this seems pretty sudden to me in my experience like Like it gets quite pretty damn fast in a way that's a little unrealistic to me, but you can also make it linear so now it's a Linear falloff from distance, which is probably not realistic But maybe that's what you want and then you can also just make it totally custom You can just set this curve to whatever the hell you want you can you can do some weird stuff Which I don't know why you would want to do that, but you could so actually just stop this so it stops playing. There we go You also have settings for Looping that's pretty obvious. It'll loop when it gets to the end You can tell it to bypass effects. We'll talk about adding effects later There's also concept of reverb zones there they're like collider areas Which you enter and then it applies reverb effects to when though that when the audio listener enters the reverb zone It applies effects to anything that reaches the audio listener Mute pretty damn obvious Output to to mixer groups will get to mixers in a minute priority That's a number which determines that if you have a lot of sounds going The the hardware at some point is limited in how many sounds it can play is there's some kind of upper limit for your system Of how many sounds can be playing at once Strangely the lower numbers are higher priorities. So zero is the highest priority 256 is the lowest priority And so you set priorities on your audio sources and then sounds emitting from those audio sources with the higher priority Will be privileged first if we have to pick and choose which sounds are gonna be playing That's what priorities about and then volume. That's of course self-explanatory and pitch That's also pretty self-explanatory. One is the normal pitch, but you can pitch stuff down You know lower the pitch to point seven seventy percent of normal and now if we play It's obviously lower and also slower as well. So it's not changing tempo to to compensate It actually slows it down and speeds it up when you change pitch Okay, and then we have stereo pan That's just biasing the sound between the two channels if it's a stereo sound So this is this was actually a stereo source. I believe when you look was it? Yeah, it's a stereo source so it should be controlling the balance between those two channels and Then spatial blend this one's very important This is determining whether the sound is positional or not They what they call 3d sound they really just mean positional sound and 2d they mean non-positional So if I set this all the way to 2d turn off the spatialization entirely Then it's as if the sound is not coming from anywhere in particular It's just it's like it's right on top of the audio listener no matter where the audio listener is positioned so now if I play and the sounds just Coming from everywhere no matter which way I've faced no matter how far away I am. It's the same volume Yeah, because it's not spatialized at all. Oh, I forgot to reset the pitch Anyway, so that's that's what spatial blend does and you can compromise you can kind of go in between where it's partially specialized So it's so the way to think of it is like 2d is actually really the default It's just the sound playing with no effects added with no attenuation or or channel balance added and the 3d is with the full Spatialization and then you can just great have gradations in between So let me set the pitch back to normal and That pretty much covers it. Yeah, that's that's the core stuff in the audio source And of course all of this is accessible in script You get a hold of the audio source component and then in code you have these properties Clip is the audio clip the the piece of audio data associated with the sound source is playing as a Boolean This is read only you can't set it, but you can just read is it playing volume and mutes those are just like This mute here and the volume slider here. That's what those are time and time samples These are not accessible in the inspector time is a float property Which gives you the playback position Determined in seconds and you can set this as well. So if you want to skip within the clip You can do so with this property and you do so by specifying the position in seconds There's also time samples which is specified the playback position in terms of the the PCM samples the pulse code modulation samples and This sometimes is useful because it's a more accurate way to to skip within your clip And then we have playing awake and loop those are just booleans. They're just these checkboxes loop and playing awake We have spatial blend roll-off mode spread max distance mid-distance Doppler level pan stereo pitch That's all these sliders what we talked about. They're all accessible here in the inspector But you can control them directly in code and Lastly output audio mixer group. That is this property here which concerns mixers So what are mixers? Well a mixer is a type of asset which we create inside unity here. I'll create an audio mixer We'll just call it mixer one and The way I edit this here double-click it brings up the audio mixer window This is a window you can open up here audio mixer. That's what it's showing you And If I had multiple mixers which I can have like in a multiple mixer assets They would all be listed here and I could just swap between them here I'll actually do that. I'll create another mixer I can just duplicate this one and hey, it's actually called mixer to just like I wanted Yeah, so I'm gonna swap back and forth between editing mixer one mixer two in this audio mixer window But the audio mixer contains is one or more groups These mixer groups and I create a group by hitting plus here create a bunch of groups. I'll just call this oops call this No, where's it? There we go group one And group two and group three doesn't really matter In a real project you give these more logical names, but this will do for now There we go They were arranged it as children of each other, but I didn't want them I just want them to be directly children of master So all the groups within a mixer are Ultimately children of master master is always the root of the mixer But then we can have like group to be a child of group one here There we go. Okay, so what these mixers are is that on our sound sources? You know, let me go back to the scene Ren I'm going to pick here Group one and we'll say this gray cube also as a sound source will pick group three Okay, oops don't want to bypass effects go back to the audio mixers. Okay, so now there are sounds being routed into these mixer groups and We can apply various effects to everything coming in so right now There's just the attenuation effect which everything has it's just a matter of controlling the volume So this actually is a way to boost volume above normal. So here actually let me do that I'm gonna raise this all the way up. And now if we play the scene should be considerably louder. I hope it's not too loud Yeah, that's pretty loud Okay, so yeah, so everything fed into group one is having the effects of group one applied And then the output of group one is fed into master Whereas anything fed into group two is fed through then group one which is then fed through master I should say routing sound sources are routed to the groups and then the groups are routed In this case group two is routed to group one and all the groups are ultimately routed to the master group of the mixer And then the output of the master group that is what is actually ultimately picked up by the audio listener Although actually what we can do is we're gonna have one mixer feed into another right now I'm editing mixer two and has these groups I'm gonna make mixer one a childhood mixer two and it's asking me to pick a group within mixer two I'm gonna say group two So now the output of the master of mixer one is being routed to group two of mixer two And I regret now not giving these clear names here. Let me actually rename it. I'll call these group B group A and Group C there we go. So that's the basic idea audio sources route to groups of mixers mixer groups route into each other or into the master group and the master group of a mixer can be routed into the group of Another mixer, but any mixer where the master group is not routed to another group of some other mixer The output of that master is picked up by audio listeners And there are quite a few interesting effects. We can apply to these groups like say for example high-pass which cuts off frequencies below certain Hertz. Let's see. I'm gonna cut off below To 120 130 whatever close enough and so if I go back to our scene, what's being routed to a was it? Yeah, the red cubes and now if we play I don't know how perceivable that is. Let me go back to the audio mixer. Oh Edit and play mode. Yeah, there we go You have to enable that otherwise your live changes won't take effect. I believe so let's turn this up Well, that's definitely noticeable Yeah, so this high-pass filter is being applied to everything routed into group A So that's one example of an effect applied through a mixer group. I won't go over these other things They're they're quite standard stuff if you've done audio editing, so I'll let you investigate that stuff on your own But I will note up here send and receive Which are not audio processing effects The idea of a send is that when our mixer group gets a certain level of decibel input It sends a signal to some receiver on another group and that group can do something in response like say Duck its volume, which is a common thing where if you have output of one kind in your game You want other stuff to get quieter or maybe increase usually one other stuff to get quieter like say When sound effects play you want like the music to duck down or when dialogue is playing you want the music to duck down So you can hook up these send and receive effects and I won't go into the details here But I'll just give you a heads up of what those things are about and Then over here you'll notice these views views are simply just an editing convenience If we had a really complicated mixer you wouldn't necessarily want to look at all the groups at the same time So if I create different views here, I'll just give it I'll just call it view to or whatever it doesn't matter What's this called? For the individual views I can toggle the visibility of the different groups And so if I switch back and forth between the views notice there's different selection of what's Visible and what's not so it's really just an editing thing Whereas snapshots is a little more significant the idea of a snapshot. Let me get rid of the views here And make them all visible The idea of a snapshot is if I have different snapshots again, I'll just call the snapshot to I Configure my groups in one snapshot and then do a different configuration in a different snapshot like say in this snapshot the attenuation is set to negative 24 whereas in this snapshot, it's Plus seven and so I have different snapshots which programmatically my code when I access the mixer in my code I can transition between the snapshots So I set up different snapshots and then trigger transitions between them in my code and the star here denotes So this is the start snapshot. I can make this one the start snapshot though If I right-click and set as start snapshot, so now this is the state which the mixer starts out with Last thing to cover about mixers is that when you access the mixer in code You don't automatically have access to all the properties of all the groups In fact, you have access to nothing by default If you want to programmatically control say the attenuation of group C here or the high pass of group A You need to expose parameters So here I click on group A and if I want to expose this cutoff frequency So I can programmatically read and modify in code I right-click and expose cutoff frequencies to script and now as you see there's a list of exposed parameters There's a name which by default is just my exposed param But I can edit that so it has some other name. We'll just call it a group a High pass. I don't know why it doesn't give it a better Default name that name was not very helpful But anyway, so now there's this parameter called group a high pass and now in my code when access the the mixer There's a property for setting and getting the values of these exposed parameters Let's see a very quick example of this in actual code I have this audio demo script and we want to access the audio mixer class Which is in the unity engine dot audio namespace which we have to import separate from the unity engine namespace And so now I have this field of type audio mixer, which we just called a mixer So in this game object where I have the instance of audio demo We need to hook up the audio mixer. So I hit the select button and we wanted I think mixer to yeah We want mixer to and so now when this audio demo script is instantiated This property will be set to that mixer and inside the start method. We can call get float and set float Specifying by string name the name of the exposed property will want to read and modify So here get float is getting the value the float value of that exposed property group a mixer We're logging it out and then we're setting it to the value of what we read plus 100 and oops I do not have that name here. What was the exposed parameter name? It was group a high pass. Yeah, right Okay, so let me fix that real quick High pass group a high pass There we go. That should work And so now if we come back and play the game, we should see printed on console 1837 and it should have modified our mixer I don't know if it shows up here, but it should have a different high pass value. Yeah, I think yeah It was 1837 now. It's 1937 So that's how you read and modify the exposed parameters of your mixer. I'm gonna get rid of all that We don't actually want that business Okay