[SOUND]. [MUSIC]. Hello! Today in this lesson, I'm going to show you how to create some simple sound effects for, for a collision-based game that we're going to develop later in the lessons this week. And I'm then going to show you how to import those into your, your project quickly which, which is revision, you've already seen how to do that, but will just do it do the workflow again, just to show you that. I now want you to get really creative with these sound effects. You know collisions are great fun to make. I am just going to demonstrate some quick examples of how to do that but I want you to go for make your own sounds and once we got those collision sound effects into the application, what we going to do is figure out how to trigger them. But not just play them as they are, we want to play them with a bit more a bit of dynamic range on them. So what we'll do is, is parameterize the playback, so that depending on the number that comes in they might be played back in a different way. So let's make some sound effects. So I've already loaded up audacity which is a simple open-source. Audio editor and I'm just going to record straight into this, and my laptop mic. Of course you could record with much higher quality microphones if you like, and you'll get a better sound, but this will do just for demonstration purposes. So, I hit record, and then I'm going to make my sound effects. [MUSIC] Okay so I've now recorded a few sound effects lets just listen to those they're not quite healthy on the wave form display. [SOUND] Okay there fine. I quite like that. That's a good one. That's a quite nice one. And. [SOUND] There's one. So I'm going to take these uh, [SOUND] these three sounds and use these. Okay, so, first of all, I'll do, I'll convert to mono. So, it's track, stereo track to mono. Okay and then I will trim them down. So, it's good if you want to, if you want to, cause they're sound effects, you want them to trigger very accurately. So, it's best if you trim them right down. Okay, so, let's get the whole thing. That'll do. Copy that, paste it into a new one, then export and I'm going to put it into, I'm going to create a folder sound effects. And this one's going to be ping one dot wav. Okay. [SOUND] Close that. Then I've got the next ping. Zoom in. Make sure we've got a nice trim on it so that it's right up against the start the sound. And you can even duck into the sound a bit because they're sound effects, they're a little bit of a click. It's not too much of a problem. So, Edit, I can actually export directly from my selection. ping2.wav. [SOUND] Then I'm going to get [INAUDIBLE]. What have I got here? I'm just going to use this rumble sound here [NOISE]. Okay and export that file, export selection and rumble. Don't laugh. Okay. Get rid of that. Now I'm going to import these into my sketch. So my s-, I need to find the data folder for my sketch and it's called Android sound effects. There's the data folder. I've put all these into this folder called fx, so I'll copy those. Paste them into there. So I've got ping1, ping2 and rumble. you m-, yeah, remember that all the files that you put in the data folder will be included in your sketch. So you might want to just trim it down to just the ones that you need. so let's just get rid of The ones we don't need. Alright so we just got ping1, ping2 and rumble. So we've got all our files they're all ready to go just need to import, need to load them up so I'm going to have three players. play 1, you might because they're sound effects you might want to call them call the players something more sensible like, that relates to the sound they might make. So I've got ping one ping two and rumble, okay? That, that will make it easier to read the codes, know which one you're triggering. Okay? Now, so then I load them in. Ping one. Ping 2, then rumble. I wouldn't [UNKNOWN] here these sounds playing on my phone. That's why I'm talking so fast. So rumble, ping 1 Ping 2. So what I'll do quickly is I'll just test them So I'll do. let's just do a quick test to, to listen to the sounds. So, if the mouse, when the mouse is pressed. If mouseX [SOUND] is greater than uh, [SOUND] well, let's just trigger them, actually, one by one. So ping [SOUND] ping1.play, [SOUND] ping2.play, [SOUND] and rumble.play, just to make sure there's no problems there. Okay. So we've got all, we've loaded up the sounds, and we are playing like that. Now, because they're sound effects, I don't want them to loop. So I'm just going to tell them not to loop. Ping one set looping, so that's false. Okay. Now do that to the other two as well. Ping two set looping false. Rumble. Right. That's saved. Now I'm ready to run it on the device, so let's just tap the screen to wake it up and we hit play. If I don't have any syntax errors they'll build that app and push it onto the phone and hopefully when I tap the mouse button I should hear all three sounds playing at the same time. [SOUND] There they are. That's my sounds. Now. Now, as I said earlier, I'm going to parametrize these sounds. So I don't want them to be the same sound every time I play them. So I won't at, to, to set up, a perimeter I see. So I'll create a new function, could play sound. and, so, the, it's going to take an integer which is what sound I want to play and, it's going to take another integer, which is That's where I float, which is going to be the speed. When in fact I can just randomly generate the speed. so if sound equals 1, ping 1 dot play. Then I'll do a random number. Random between 0.1 and 2. So that will play sorry. Speed and then ping 1 dot play. Okay, so it sets the speed to a random number between 0.1 and 2. And it triggers play. And so I'm just going to copy that block and, and Activated for the other sound. So if they, if they pass it at number 2, then we play ping two. If we pass a number 3, we play rumble. Rumble. All right. So now, I'm going to just say h, if the mouse is pressed, play sound. And I pass in, Again I'm going to do it random, choose at random which sound I want to play. So, it's going to be in the range, one, two, three. Okay. And I'm going to. Cast that to an integer, because random normally gives you values which have floating points. Right, so, what have I done? I've got my three sounds. They're not, they're not looping. And when I, that's what we call one shot, as well as loop, or one shot is when it plays once. call play sound when they press the mouse and choose a random sound. And then actually I'm going to put that up to four, so that it can potentially go up to three, because it will round it down. And then finally I'm going to trigger the sound and depending which id comes in I'll choose which sound. To play. And I'm setting the speed on the sound up to random. So every time I tap it should show a different sound rather than parameters. OK. So now, I'm now ready to run my code on the phone. Now notice I had a little error there which I put an l instead of an i. So I'll just change that. So hopefully it should be ready to go. Okay, so again, we get the same error, run again. That's pushing onto the phone now. [SOUND] There's 1 more thing I might add to that, which is I'm going to cue the sound so that they go back to the start before playing. So, cue it back to 0, that rewind it. That's ready to play ping2.cue. [SOUND] To note and ping3.cue to p, sorry it's not called ping3, it's called rumble. Rumble cue to note. So that rewind the sound before I trigger it. So let's just run that on, on the phone and that's our last step. [BLANK_AUDIO] [SOUND] [MUSIC]. Okay, so that's a little bit of musique concrete for you at the end there. Have fun playing with this. You can obviously make all, all kinds of interesting sounds yourself. And you might think of other ways of maybe hooking, hooking interactivity into that function. So you might add another variable which controls the pitch so maybe it could be pitched in different ways depending on where the mouse is or the accelerometer data. And you can really make a fun little instrument which, you know, depending on what you're doing with the phone it can trigger all different samples with different Dynamics. So do play around with that one and we need to make a music [INAUDIBLE] instrument with that. What we're going to do based on that is, is develop a, set of dynamic sound effect for a game. [MUSIC]