Skip to main content

Display Detected Beats

Lesson 4 from: Audio Visualizer

Joseph Gray

Display Detected Beats

Lesson 4 from: Audio Visualizer

Joseph Gray

buy this class

$00

$00
Sale Ends Soon!

starting under

$13/month*

Unlock this classplus 2200+ more >

Lesson Info

4. Display Detected Beats

Lesson Info

Display Detected Beats

okay segment for we're going to display some detected beats. We're gonna create a function that the text beats in the audio. And then we're going to create functions that display a flash over the whole application window when it finds a B, and we'll do different colored flashes for different types of beats that it detects. So going back into processing, um, you go into the audio tab again and up at the top of it. Below are we declared our FFT stuff. We're going to just make a some one declaration to beat detect. And this is a really nice class in minimum, because it's really easy to work with and does really cool stuff. So beat detect who's gonna call it beat and then down inside of, um, are set up audio right below where we set up our FFT stuff. We're gonna dio we're going to set up beat stuff and instead she ate beat by signing at the new as a new beat, detect object and or object of class beat detect, and we're gonna again pass into it our buffer size and sample rate that we set up ...

the beginning of the program and then, right below that, we're gonna do another thing to set up our beat object. Um, we're going to call on it a method called set sensitivity. And we're gonna pass into this method. I'm just gonna pass 200 in there. This is something that you can set. You could even set it dynamically inside Draw if you wanted to, depending on what your application is, but sets into sensitivity. Um, this number will. This number represents milliseconds. And so this is 200 milliseconds, so it's gonna wait 200 milliseconds before it lets itself detect another beat. So if it finds a beat and then another, it finds another beat within 200 milliseconds, it ignores it on this allows you to dial in, like, you know, like I only want beats that happens so often, not like constantly all the time, because they could, depending on how noisy your audio data is. So this is just a way to kind of narrow that down by limiting how often it's it's able to detective beat, if that makes any sense at all. Um, then down inside of get audio, um, we're going to basically dio beat that detect and detectives, a method of the B object that just listens again, similar to kind of like forward, although it's a little more explicitly stated that is going to detect the most current data from the audio n dot mix. And that's what it's going to use Teoh find beats. Is that most current data? And, um, that's it, that's that's sending up the beat. Detect. So then going back into the main function here, or the main the tab, you know, all the way down to the bottom, we're gonna add three new functions to display this beat these beats as they're being detected, uh, void, Kick flash. And then I'm just gonna kind of caught. Well, I'm gonna do one of these and I'm going to copy Paste. Um, so if you do an if statement, if the beat thought is kick and his kick will give us back a, um, true or false like a Boolean, which is why we could just pass it directly into if here, a za parameter for if because I it's just listening to the frequency bands that are typically associated with a kick drum. So, like the lower frequency bands if it finds a beat like basically, if it finds a spike in the audio data in that frequency range, then it will say, OK, I've detected a kick drum and now this is all really approximate and and can be fine tuned in many ways, depending on your audio and put in the situation. You know how much noises and you know what? If you're doing a clever something of me a lot of noise, you maybe do some audio pre processing before even get to this stuff. Don't even worry about that right now, Um, so if B is kicked and we're just going to draw a rectangle to the screen and we're just going to start it up in the top left corner of the screen and we're gonna make it the entire width of the screen in the entire height of the screen So it's just going to draw a rectangle across the entire screen every time it detects the kick drum, and we're gonna do that for so we have kick you have snare, and then you have, um, hat. So like, high hat. So it's like snare drum, high hat on and a kick drum. So snare being kind of or mid tone on a high hat, being high tone. And so, if this is, as you might guess, is snare and then is hat and then those are, you know, this beat that is snare is hat is kicked, those air built in methods of minimum. And, you know, they have built into them the frequencies that are the common frequency ranges for those instruments again in the in the tip sheet. For this course, there's some discussion about how to use specific frequency ranges toe find beads. Um see, might want to look at that. Um Okay, so we've got those, and that's pretty much all there is to them. And now we're gonna actually implement them up here and draw you open the draw, and right above translate, because we don't want to translate our rectangles. We just want to translate that wave form. We're gonna put our beats above their recall. No stroke, because we don't want to have an outline around the whole screen. Um, and then we're gonna call Phil and again using hue saturation brightness. So zero is red in HSB mode for the 1st 1 and then just saturation is going to be all the way up to 2 55 and brightness is gonna be all the way up to 55. And so and then we're going to call our kick flash function we just created. And that way, every time a kick drums detected, it's going to draw a red square to the screen and or a sound that it approximate sa's being a kick drum, which you'll see that the trump it will make all of these go off because really, it's just looking at frequency ranges, and it's looking for dynamic changes in this frequency ranges. Eso is going to kind of do the same thing again here. So, um, we're gonna do this remake 77 which is green in HSB mode. You make that the sneer, and then we're gonna do this one more time for the high hat protection, which is going to be 1 44 which is blue and or a type of blue on. So that should be it. And one thing one thing before we get off into all this before we play it, which change background cause background right now is just gonna be constantly black. And these things when they get detected, it literally be a flash just for a frame. But the way our brain works with audio and matching it up visuals, it helps if there's, like, some kind of afterburn left over for us to feel like we really did see that beat. So what we're gonna do is again call no stroke. Onda reason I'm doing this is because later you might want to compartmentalize this in the functions. So, yes, we're calling this trip twice in a row, but, um, it's just for usability. Later on, if you wanted to turn this into a discreet function, re a pass into a film zero and then just I'm gonna put 32 in there. It's a nice Alfa value for a rectangle andan. We're just going to draw another rectangle starting in the top left and going across the whole screen and the whole height of the screen. Okay, so there we go. Uh, should we will play this And Gabe, Uh, nice thinking of this change. You've got to sneer flashes there instead of a snare flesh. Oh, yeah, you're right. That's what we should change that and try it again. OK, let's try that. You're right. Yep, closing. And you know, like I said, it's it's hard for us to you know, if you try playing this with some drum and bass type music or something, or some techno e thing where there's really good distinction between base and high range, this will actually look pretty much like you expect. But when you start getting into more complex tones with lots of harmonics, beats will get triggered in places you didn't expect that sort of thing. Which is why some people suggest pre processing your audio. In other words, running like a heavy e que on your audio before you even analyze it so you can really narrow things down. But that's a whole other top, right? But if you're already familiar with audio processing, then that would probably be a good route to go get a lot of accuracy. This wine people spend their lives learning about audio. There's a lot to know. Um, okay, so that's it for that section. Um, what we just did it set up the beat detection object and created some functions that draw those beats. His flashes and then implemented those functions into the draw method. Any questions that we have a couple of people who are saying that they're not getting a frequency map, it might just be an error. They're making a common error that you frequent theme. Oh, because we're passing mouse y in the frequency. You have to make sure you move your mouse far enough down into the windowpane, even though you can't see it turned on no curse, or you kind of have to move your mouse in there so you can give it some amplitude to draw it. Okay, So make sure your mouse is in the screen and down, so it needs to be further down in there or just instead of passing mouse y in their paths. Number like fight into there, OK? Yeah. All right. Cool. Well, then we had a question about Can we use any type of input microphone at all? That microphone doesn't matter, right? It's just right. It's. What's important is that in your system preferences on whatever operating system you're running that it is showing an audio because minimal automatically try to find that so you could run the audio input line from your stereo or something. Doesn't have to be in my crew. Okay, You could call. Okay,

RELATED ARTICLES

RELATED ARTICLES