Juce Tutorial 10- Generating Audio Output

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everybody I'd like to welcome you to another juice tutorial and today is a very exciting tutorial in that this is going to be the first one where we're going to actually work to generate some audio output now the output that we're going to generate is just going to be some random white noise but there I think what we could do is we could focus on this tutorial about the ways that we need to the things that we need to think about in order to generate audio output within Jesus because there are a couple things that we need to be aware of and a couple things that we need to do now one thing that I'm going to emphasize here is that as I've said a couple times before I'm learning to juice myself and one thing that I've found through the past couple days looking through you know the tutorial and looking through the documentation was you know there are a lot of different aspects and I would think I would compare it to an onion you know that you get kind of your surface level knowledge base you know just to get things kind of working and then as you get more and more experience you can kind of peel back that onion and learn more and get more involved with some other aspects of you know that the the class in this case the audio app component class um you know because I found that there were some things that didn't quite understand couldn't quite get my head around but you know I think that those things will just kind of come with experience and practice and so you know I'm just going to try to dive in the best that I can explain things the best I can and I hope that you can as well okay so as always we're going to generate a new project okay and this is going to be a little bit different in that we're going to generate an audio application rather than a GUI application keiko so we're going to click on audio application and we'll just call this audio out one I'm just going through this in my development folder create great creates two files we've got our main component cpp and our main our main juice dot cpp which gives us our juice functionality as we've said before so just going to open that up the next code now and here we are so this main component dot cpp so this is very similar to the to the GUI application that we that we did in the past except it's going to have some additional things that we need to to go over okay first thing that's different is that if you look in the class here we can see that it is actually inheriting from audio app component class rather than just the regular component class where we were generating you know sliders and dials and whatnot okay and what this does is this allows us to to use some different functions for actually generating input and output within juice okay if we go to our constructor then we have set size we've gone through that then we have this function set audio channels is automatically set it for two and two so that's two inputs and two outputs and we can see that if we command click in there and just look at where where where Liz my this is my head here where our constructor is we got number of input channels number of output channels okay so we'll do tutorials a little bit later on input on inputting sound and processing that and in our destructor we have the shutdown audio function and so that's just when our application shuts down shuts down the audio okay pretty self-explanatory now these next three functions are um these are pure virtual functions that need to be called anytime that we're inheriting from the audio app component class ok pure virtual functions which means that we need we need to we need to actually call them the doesn't to actually put anything inside of them you know it's just that if we're inheriting from them then we need the they need to be called and they need to be declared okay so first one is prepare to play so this my understanding of this is that this happens once when the application is started okay samples per block expected is buffer I'm just I'm going to assume that you know what a buffer is so I'm not going to go into that then the sample break now I was getting these numbers from the sound card you know I think that if we wanted to we could change we can change those numbers we can change the buffer size and the sample rate within this block here if we needed to somebody tell me if I'm wrong about that okay so the next one is the most important one get next audio block okay now this is where we're going to do our audio processing today now we have this we have this object here called audio source channel info I'll come back to that in a minute then we have this final we have this final function release resources this is when the audio device stops okay then we have paint and resize functions which we've gone through before okay now going back to audio source channel info okay because this is this is kind of where the meat of everything happens and where you know what one thing that I'll say is that this I don't know if I said it before but the audio app component class I've spent the last couple days kind of going through it and reading through the documentation everything and it is kind of a winding kind of you know to me it's a little bit you know confusing but I think it's just because it's a new thing for me and we have so we have this audio source channel info object here so if we just go into our documentation here okay and then this will this will this will kind of help us you know figure out what we need to do okay so audio source channel info okay it doesn't really give us a description in here but the way that I understand it is that this is where we get all of our information about the buffer um you know where are where our right buffer is if we want to if we want to write values into our buffer if if we want to get you know how large our buffer is and we can then we can get that information from from this class okay also like the number of channels so we're in stereo today we have two outputs so we're in stereo so so this this audio source channel info the way that I understand it is this is where we get all of our information about the buffer channel you know number of channels that were running so on and so forth okay so now we're going to go in here I'm just going to erase all of this okay and I'm just going to follow I'm just going to follow along a keyboard dad hopefully it comes back here one second here we go yeah so what I'm going to so what I'm going to do is I'm going to generate some audio output and this is following along roughly with the juice tutorial on January audio output okay but what I want to do is rather than just as usual just kind of going through it and just kind of glossing through and saying ah here's you know here's this and here's this you know I want us to kind of think through the process think of think about what we're actually doing and then you know I think with repetition and with practice you know this is something that we can um you know that will just become kind of second hand nature as we do it more okay so when we're when we're looking to fill a buffer okay we have two channels now the way that I understand it is that when you're writing into a buffer you have one buffer between two channels so the first the first value of the buffer goes to the left channel or channel zero and then the second value goes to the right-hand channel or channel one okay and then it just goes back and forth filling the filling each speaker with sound okay so the way that I understand it is that the first thing that we need to do is actually go through and iterate over each channel okay so this is a little bit you know this is one of those things that's like well how would I know that if I wasn't following this tutorial and the answer is to be honest I don't know it's just something that you know I think we just have to learn with experience and just practice okay so we're gonna do for loop okay I'm sure that if you've done any of you've done anything with sound you know that you have to iterate through a for loop to fill this buffer so we're just going to pull this channel okay so so um we got to iterate through each each channel so we've got two channels and then we've so what we got to do is we got to find out okay well what you know how many channels do we have okay so we've got this audio source channel info okay so we're going to go with this object buffer to fill okay now let me get to the documentation okay and show you what we got here so we got if you look in here you've got a buffer pointer okay so we need to we need to access the buffer okay the the which is you know the values that are waiting for us to write our sound into okay so you can see that this is a pointer okay so we've got buffer to fill dot buffer okay now okay we need to get to the channels to iterate through the channels okay so this took a little bit of work to find out okay well where where are these things coming from okay so at the moment we are in audio source channel info right now you've got this audio sample buffer object right so let's just click into this class right now this is a little bit confusing because is there's a newly created audio buffer class alright so you click through there and then you got to click through here okay and now we're in now we're in the audio buffer class okay so what we need to do is get the number of channels right then here we go get num channels okay now this is a pointer okay it's not just like a regular object so here we need to use the arrow operator okay rather than just saying buffered dot get num channels okay it has to be the arrow operator because the buffer is a pointer okay get num channels okay and then we're going to go plus plus channel okay so just to go through what what to do Oh need to capitalize the T so we've got so we've just gotten the number of channels from our buffer okay so we went into our audio source channel info into the buffer okay and now we want to get we basically want to iterate between the two channels okay now if I I'm not going to do it but what did I do here let me just run it compile it see if it see if it runs undeclared identifier channel oh I forgot to put int here okay so if I were to if I were to console out here over what channel is it would just go back and forth between 0 & 1 okay so we don't need to do that let's just move on okay cool so now we need to create a pointer for two to base so now we have a buffer we have a we have a buffer pointer okay so now we need to point into the actual address of that to actually write our value into okay so we're going to create a pointer a float pointer and we're just going to call this buffer okay and so now we need to make this buffer so now we need to get to the actual location of the the actual first location of the buffer the first index of the buffer okay so we need buffer to fill dot so we need to go back into the buffer okay I'm glad I'm going through this with you okay so now we need to get to so so now we've gone into the buffer now we need to go and get into the actual first index of the buffer okay so so we're going to use this one get right pointer okay so what we're doing is we're just going to we're just going to go to the very first index in our buffer okay so get right pointer okay now the channel number is just the the channel that we're iterating over okay the sample index so we need to go to the first we need to go to the first index in our buffer right so we need buffer to fill dot okay now if we just look here we're lucky because what we need right here is this is what we need right here start sample okay that goes to the first the first index of of our buffer okay so bit like I said before a bit confusing a bit kind of you know windy but you know this is just something that I think we just have to practice over and just repeat over and over again and as we repeat it you know well you know we'll get the hang of it okay so we've gone through so so now we've gone through the channels we've created a buffer pointer okay that's pointing to the first the first index of our buffer so now we need to iterate through the buffer itself and be able to write our random values into it okay so we're going to do another for loop I'm going to call this up call it index equals zero our index has to be so so if we're thinking about our buffer size so it needs to be less so so what we need to iterate through is less than the size of our actual buffer okay so we got buffer to fill but here we go num samples okay so so we're going so so the first one we went through the channel we wrote a pointer that points to the first two to the first index and our buffer now we're iterating through the buffer itself and we're and we want to make sure that we don't go outside of the buffer size so that's why we have buffer to fill dot num samples okay maybe I should call this samples rather than I'll call this sample rather than index the key from confusing guys okay so we've got plus plus sample okay cool so now we have so now we get to the point where we have to actually write the the values into the buffer itself okay so we write it so we're writing it into the address of buffer right so so we're writing it into our right pointer okay so we got buffer and then we just this sample is going to be our index number of our buffer okay because it's iterating through the whole buffer so equals okay so now we just need to generate some random values okay there's an actual random class okay so if we go to random okay so this is a class that specializes in generating random numbers I think I lost my okay I lost my way here let me go back great so we're so we're here in the random class so that means that we need to create a random object okay we're just going to do it here in private just random random okay now what we need to do is we need to go we need to go between you know for if we're generating values that are going into the speaker's well the this the values can't go more than plus one or minus one so they need to go so they need to be values between plus one and minus one okay so we're talking about floating point values okay so what we need is this is this function here next float okay so we've got random okay a random object that we just created dot next float okay now there's a problem the problem is that if we look here into next float okay returns a random floating point number between 0 and 1 okay but we need it to be between minus 1 and plus 1 okay so we're going to do a little bit of math trickery to actually get it to do that okay so we got 0 to 1 we're going to multiply that by 2 okay so that's going to give us a that's going to give us a values between plus 2 0 and plus 2 ok and then what we're going to do is we're going to subtract 1 okay and that's going to give us values now between plus one and minus one okay now if I now if I do that now that's going to be very loud because you know we're obviously going to be going to the full extent of our you know of our speakers okay so what I'm going to do is I'm actually going to put these in parentheses and I'm going to multiply this by 0.25 okay so what that's going to do rather than go in between plus 1 and minus 1 which would you know which would be really loud it's going to go between plus 2 5 and minus I mean plus 0.25 and minus 0.25 okay ah looks like it didn't like something what have I done here ah the same thing again forgot to declare this isn't it okay so we should be cool now okay let's see what happens okay fingers crossed we did everything right and hopefully we should be cool come on one of these days okay is it doing it still thinking okay and there's our there's our random those are random white noise okay so um as I said you know that's that's a little bit that's a little bit when it's a little bit windy but you know I hope that the way that I described it was was effective if you have any questions or anything about it just um just drop me a line drop me a message or a comment okay and that's it for this tutorial so next next one I think we're going to do try to move into generating like an actual sine wave okay so hope you hope you learned something from this tutorial and I will see you next time
Info
Channel: The Audio Programmer
Views: 8,545
Rating: undefined out of 5
Keywords: audio programming, creative coding, audio coding, creative programming, digital signal processing, dsp, plugins, vst, software development, ableton, max msp, c++, sample rate, bit depth, nyquist theorem, juce framework, tutorial, beginner, easy, games development, games programming, basics, openFrameworks, open Frameworks, ofx, Maxim, Maximilian
Id: GjNeYI6-uNE
Channel Id: undefined
Length: 21min 41sec (1301 seconds)
Published: Sun Aug 20 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.