[SOUND]. [MUSIC]. Okay. So you've done some graphics. And now you're ready to do some sound. So I'm going to begin by showing you how to obtain some sounds. [INAUDIBLE] you get get sounds from pretty much anywhere. for example, you can record them yourself or you can obtain them from a website. Freesound.org is a really useful website for obtaining sounds. They have a wide selection of different sound effects, ambient sounds, and music. What I'm going to do is, I'm going to quickly make a sound myself by recording it. I'm going to use the open source audio editing software Audacity, which you can see here. So, I start with an empty page, I hit Record. [SOUND] I get my drumstick [NOISE] [SOUND]. So this is the bit of the sound that I'm interested in, so I copy that. Paste it into a new sound. Now because, because we're operating in mono here, we're, we're trying to keep the audio library as simple as possible. So we operate in mono. So I'm going to record my sound, like this, in stereo, but then bounce it to mono. So I go into the track menu, stereo track to mono. Now I'm ready to export. I'm going to store it into the data folder of the sketch. So you'll notice when you create a sketch like this one and save it that it puts data folder for you. So my sketch is called Android Start, and you can see I have a data folder in there. If it's not there, when you've just saved your sketch, you can just create it. The data folder is for additional files that you want to use in your sketch. In this case, audio files. So I'm going to save this audio file I just recorded into the data folder of the sketch. [SOUND] And I'm going to call it uh, [SOUND] ping.wav. [SOUND] Okay. So we've recorded our own sound. And now we're ready to see if we can get it to play on the mobile device. We're going to play a sound on the mobile device. In order to do this, we need to write in some, some lines of code to initialize the audio environment. The audio environment in this case is called Maxin/?. This is our custom audio library. [SOUND] So Maxim, so I created a variable called Maxim, which has the type Maxim. We'll worry more about the details of types later on in the course. Then, I need an audio player. Audio player, so that's the type, and I'll call it Player. So I've two variables ready to store these two object which I'm now going to create. So maxim equals new maxim, that creates a new, a new audio environment. You only ever need to create a single audio environment for your whole sketch, and everything operates within that single environment. Following that, I'm going to ask maxim to create my audio platform, player equals maxim .LoadFile, and I pass it the name of the file I just saved, ping.wav. Okay? And so, remember, ping.wav is the name of the file you just created, and it needs to be saved in the Data folder, so that the, so that Maxim can see it. because otherwise it, you can only access files in that Data folder. Okay, and finally, [SOUND] I'm going to set up an event, so that when they click on the screen or tap on the screen, they will be able to hear the sounds. So I'll just say player.play in there. So let's just try this out. So I've written my really simple sketch here. Let's just [UNKNOWN] go through that code again. We've got these two variables, one of which is the maxim, that's the audio environment that all of the, that deals with all of the audio processing. Audio player represents a single player which can play an audio file. [SOUND] Maxim is being created there in the setup function, and the player has been created, too. When they click the mouse, this function gets called, mouse pressed during the case of the touch screen device when they tap on the screen, and it will trigger play on the player object, which will cause the sound to play. I'm now going to run the sketch. Okay the sketch has launched on the device, so I tap the screen. [SOUND]. Okay, so you can now hear me hitting the table, playing from my Android device. So to exit the sketch, you need only press the Back button. Like that, and now it's stopped. Now, you noticed that it kept playing the sound. Because the default setting for the player is to loop the sound. So, for example, if you put a drum beat in there, it will loop it. And that's really useful for drum beats. But for for a sound effect like this you might not want it to loop. But before we look at that, let's just see what it sounds like when you play a drum beat in there. So I've already, I've already prepared a drum beat called mybeat.wav. Okay. So let's just see if we can play that on the, the device as well. So mybeat.wav. So I've just changed the, the file. Now remember that file. Oops, that, that file needs to be in the data folder. As you can see it's in the data folder of my sketch there. So I hit play again, and it will build the sketch again and send it over to the device. And then, when I hit the mouse button, you'll be able to hear the break beat. Okay, the device is ready. [MUSIC] So remember because it's looping, it's going to keep playing until you tell it to stop. So what've we done here? So we've created an audio file by recording it, but you can also obtain audio files from this FreeSound website. And I didn't exactly show you that. But if you don't want to freeze out, you can see, so you want it to find a break beat of your own. You can type break beat into there, into the search box, and you'll have to create an account before you can search and, and download files, but you can, it's pretty easy to do. You just do it by clicking on the account creation button at the top. Okay. So I've searched for Break Beat, and I've been given all of these files. And when you go into the file, you'll see that there's a download button. So if you want to get your own Break Beat into there, instead of using my one you can, you can download there. But you will need to load into Audacity, and exporters of monoware, as I showed you before, with my recorded sound. [SOUND]. So, we've, we've obtained some sounds, and we've learned about different types of sounds. And, we've set up the audio assistant to play a sound. And, we've had a little look of what, what looping is about. But you can actually control the looping properties of the, the audio player like this. So if I go into here, back again, I can tell it not to loop the files, so if I go back to my ping thing, which we didn't want to repeat, we just wanted it to play once, then I just do player.set looping, and set it to false, which says don't loop. Just play once. The thing is, I now need, you'll see that plays once, if I, if I do that. But if I wanted to play it again, I'll need to call Queue, because that will rewind it, back again. So once it's played, it's like a tape that's played to the end. You have to rewind it again to trigger it again. So what I'm going to do is I'm going to play it. And, in fact, I'm going to put it the other way around. So I'll queue it up to zero, then I'll play it. So I'm just going to run this sketch, and we'll see what it does. [SOUND] So it's ready. So we're going to hit the mouse button. [SOUND] You can hear it plays at once. If we hit it again. [SOUND] Can you hear it plays again? It's not looping because I told it not to. [SOUND]. Next week you're going to find out more about the details of how audio is represented in the computer's memory. But for now that gives you the basic tools that you need to create audio files and play them and control that playback. In your sketches. [MUSIC]