Audio Processing Tutorial: How To Create an AWESOME Distortion VST/AU Plugin In C++ (JUCE Framework)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right everybody welcome to this another tutorial and this time we're gonna create a VST plug-in or an au plug-in for your audio production software so if you're on Mac and you're using Xcode or something or on Windows you can use like FL studio or Cubase or you know any of those kind of software you know you've got all these you know VST plugins and stuff today I'm gonna show how to create a distortion plugin for your guitar and before we dive right into the code i want to demo what this plugin actually does so i'm gonna open it for studio year and the current setup let's go got going on is i've got my guitar plugged into my sound god with an audio jack you know your normal guitar jack and then i've got the output of my sound cord plugged into my little Marshall amp that I've got right next to me on my desk here I'm surprised that it actually fits on the desk I mean it's got a neat little amp so I'm gonna be demonstrating this in FL Studio I mean this will work in Cubase or any other software you and it doesn't matter on what platform you are you can still follow along this is a cross-platform solution so if you're on Windows Mac or Linux you can use any audio production software on any of those platforms and this will actually work so you're not limited by its platform or anything like that this should work pretty much everywhere so okay I've got a house studio open I'm going to add a VST ax I'm gonna add the plug-in so it's a VST test plug-in so there we go this is this is what the distortion plug-in actually looks like so it's very simple we've only got four knobs on this thing it's a drive knob arranged not a blend knob and a volume knob it's now down controls or anything on this thing yet so I'm gonna add the guitar over there and I'm gonna play this through my amp so if I grab the guitar all right so I guess I'm just gonna take it through the different sort of controls on this thing so the first knob is obviously the drive along this is the amount of distortion that we want right and this rough goes together with the range knob so they sort of act together so if you put a low drive on you will throw off your a very quiet there's just a little bit of distortion and we can put even less distortion on by decreasing the range so you can hear that they sort of just a little bit of distortion so it's like a crunchy kind of sound so just as a little bit of crunch to the distortion okay anyway the second not the third nope on this thing it's the blend knob this blends in the clean sound of your guitar so you can sort of blend between the distorted sound and the clean sound so you can for example add a lot of distortion like a V Distortion but then you can blend the clean sound into it a little bit so you can put a lonely little distortion only come through a little bit and then put a lot of clean sound on day on the mix it sounds like you can hear a lot of clean sound coming through there which is the idea of this control so okay at the moment this distortion plugin doesn't have any any time controls or anything like that it's very simple it's only got your basic you know just a distortion stuff so there are no high-pass filters or low-pass filters or anything like that on you so what I'm gonna do to make this sound a little bit better is I'm going to add the distortion over there then I'm gonna just add a little bit of filtering and this I'm gonna add a filter today and after distortion I'm gonna add another filter over there so before we distort the sound we usually want to you know cut the lows a little bit like that you know something like this you know and just to get rid of and then we want to boost the mids something like that that you do and then right here we want to cut the very highest frequencies boost the mids sort of a bit something like that that should give much nicer Distortion so if we actually so yeah that's obviously a lot better adding some filtering to this we may actually implement this in the distortion plug-in itself later but chlidren we won't do that in this tutorial and that will come in a future video anyway I'm yeah I hope you guys like this Distortion we got up anyway let's alright so that's basically it guys that's the distortion so now let's dive into the code into others actually work so that we can create this thing right so I'm gonna just this you know just off for now all right so maybe this guitar down comes in the way alright so do you if it isn't for V anyway let's dive into the code now so what we're gonna do is okay so there are a couple of things that you're gonna install first let's see we're already saving minuting goodness I've taken a bit longer there so there are a couple of things you're gonna need for this so the first thing you're gonna need is we're gonna be using well the first thing you should know is we're gonna be using the juice framework to create this distortion and while we could just do it from scratch I mean completely without any template code or anything done for us but that's really unnecessary I mean it's that means we have to create the GOI stuff ourselves and it's just a pain in the butt to go through all of that so I thought you know let's use a framework like juice or something you know so this is the thing you're gonna want to do is go to juice and juice let's say source right because we want the source code so you'll see this Jetta page so just you know click on that and then here we are so this is the juice 5 library so you want to download the source code so just go there clone or download and then download the zip file right after you've done it at that default you will have this juice master zip so you're just gonna want to you know extract the somewhere on a desktop or anywhere where it's we can access it then you will see this juice master fold there that's what we want right so that's the first thing you're gonna need the second if you're under Windows or Windows 10 your gonna need the Windows 10 SDK so when 10 SDK so you'll be able to download it from Microsoft website I believe so yeah there we go we understand SDK development up Windows app development thing so yeah you're gonna want to download this right this is absolutely required like it's not optional if you're under Windows 8 or something you're gonna need doing this I taste guy I believe you're gonna need a stick at if you're under Mac you're not gonna need to download any SDKs exit for the Steinberg is ticket so that's the other thing we need to know that we need to download the Steinberg or VST SDK you know so so this is this is just an SDK so you're gonna want to download this guy over there the VHD three point six point eight audio plug-in SDKs right so this isn't just for only for vsts this is for IU plugins if you're under Mac or using Logic Pro X or something then you're gonna take the IU is the guy of course if you're under Windows we use the VST SDK so just go ahead and download this this should include pretty much everything you're gonna need and once you've downloaded that you want that extract it's some way we can you know sowing a seed drive it will look something like this VST is decay and there it is right so just an extract that some way probably on your C Drive I guess is the best place to put it wherever you want really it doesn't matter and that's really all you're gonna need apart from that you're just gonna need a compiler or while a an IDE I'm gonna be using Visual Studio for this I've got the latest version 2017 so yeah let's get started so the first thing I want to do is go into the juice folder the juice master they may want to go to extras then producer and in worlds and then you want to select your IDE so if you're under Linux you want to build this mic file if you're under Mac you want to build this you know Xcode project in Xcode if you're under Visual Studio on Windows you want a selector version of Visual Studio and open up the project file that's what I'm gonna do so let's open up there it's all in Foley for under visual studio if you're on Mac or whatever just open the Xcode project and build it on Mac I'm gonna explain how to do this on Windows Mac and Linux while I'm doing this but I'm gonna be demonstrating this under windows so if you're on any other platform just follow along you'll be able to follow along without any issues on Linux you're just gonna need GCC or something to compile the Reggie's app so let's open this visual studio project so you will basically just have this producer app the only thing you need to do is Ian to go and go to build and build the solution that's it just build it right you don't need to do anything and at this point you can pause the video because it's gonna take a while to bolt mine's already bolt so as you can see it's already finished so once it's bolts you want to go to the x86 folder or whatever yours is school then go to debug app and then you'll see this reduce executable there then you need to open that up because that's what we're gonna be using then close close project okay so if you don't already have an account you're gonna want to create an account with cheese and just create a student account or wait you know there's not count to something which is completely for free so you're gonna want to sign in and create an account before I can actually use Jesus so just do that it's not a big deal or anything anyway if you already have an account then you can just create a new project and this is what you will see you can see that Jesus is quite powerful you can do a whole bunch of things so that your applications and the matters duplications OpenGL stuff even typing libraries and audio applications and audio plugins what we're looking for is an OD plugin and you can see this creates a VST au or tests or anything like that when we're doing or any kind of plugin so it's cross-platform completely so let's click on audio plug-in then you want to select your IDE that you're gonna be using in my case I'm gonna be using visual studio so visually 2017 is selected for me to select your vision of Visual Studio so I'm gonna call this distortion VST you know something then you're gonna want to uncheck this checkbox if it's selected and you're gonna wanna select the modules folder so just click on that and then you're gonna wanna browse to your juice master the G's folder that you extract it for the G source code then you just want to click on modules and hit OK just to select the modules folder for this and then just create it create a great project that's really it alright so the only thing we need to you'll see that the project basically exists of 4 files right for code files it's a plug-in processor and the plug-in editor this so the edit is mainly older he uses interface stuff the GUI stuff in the processor is where we do the actual art called audio processing things to create a distortion blogging so let's go to project settings there couple of things you need to set up here so you can give yourself a company name just don't put anything like you know apostrophes and things in there because if you have things like this or this you know in the company name then it's gonna put that in the source code and in C++ whenever you have this you're indicating in your character and whenever of this you're indicating a string right so don't put anything like that in the company name just put normal characters otherwise you're gonna get compiled compiling errors in your source code which is gonna be nasty just give yourself company name if you want to like we it's these I'll see now I just almost did that so just that should be good enough so let's scroll down see what other things they are so we're gonna do both the VST right that's checked um we don't need to order unit so just uncheck that you can build a VST three if you want to I'm just going to do the normal you see it works perfectly fine 53 is not necessary it's really not and then standalone plug-in I couldn't get that to work so I'm just gonna disable that anyways if you can you can do that if you want to I'm not going to let's see what else six plus eleven yeah I tried then plugin channel configuration so we're gonna need to do that so you can see that this is just a monastery of stuff yeah we basically just all the thing that you have one input waveform output to impeach stitch an or outputs things like that this is the general configuration so let's do that we started with two curly brackets 1 comma 1 and then we have a comma and then whenever we have two channels there's our pick two channels so just do that no big deal and that's it now go ahead and save the project hit file save yes it's is saving then open this up in Visual Studio so click on your IDE button right there to open this up in your IDE there we go we're not going to actually edit the code in produce we're gonna edit the code in Visual Studio because I don't know I'm just more familiar with Visual Studio I've been using and were anyway gonna need your IDE to compile this producer doesn't include a compiler so you can only edit the code thing no point in doing that really so it's loading all this includes and things so now what we want to do is we want to link the project to either Steinberg it's the guy so go to project properties project properties and we're going to do this for both the products thing so then go to C++ Visual C++ directories include erector ease and let's add the include birthday so we're going to add the Steinberg SDKs let's see VST h2k vs T - SDK like public dot SDK sauce VST 2 dot X select that folder and also select VST SDK visit to sdk just that then it apply and let's do this for both the project so other one as well properties visual c++ directories include our rectory is edit let's let's see dr VST ack-ack no public that sdk sauce you see two point x that one and then the other one is it to rot a sticker that's it your apply all right so the products are now set up at the cut that we can edit is in the shared code project so that distortion VST sauce right there's a for source code files right so let's open these boys up so now we're gonna coat the plugin so we've already got basic template code already done for us which is part of the juice framework which i'm really grateful for cuz it's really tedious doing all the low level you know it's decays stuff from scratch it's a pain in the ass so I'm very grateful for Jesus really it works it just works I don't know how it works but works so I'm really grateful for Jesus for providing us with this amazing framework really this is it's amazing anyway let's go to the plug-in editor and let's start working on that GUI so going to the header file of the plug-in editor so they dot H file let's create our knobs so long so we're gonna go ahead and create these little knobs so the drive range plane and following up as you can see these action of knobs are just sliders their sliders which looks which you know getting like rotation so they're called rotary sliders very cool anyway let's create these guys okay so anyway let's create this sliders so the part of the the plugin editor so okay let these sliders or just called sliders you know there's a slider clause which is part of juice the juice framework which we're gonna use and we're gonna create these as pointers to objects and these pointers are called scoped pointers so Jesus this nice scope pointer class which we're gonna use and we're gonna clear the pointer to the slider so this is a template class and really the first one is a drive knob drive which other knobs drive range plaint and volume so drive range and blend in the volume so let me first explain this whole script point I think goes on I are probably wondering what the heck is the skyPoint thing like it doesn't make sense right and these are just normal pointers like if we go to the definition of this right so go to definition you will see that it basically says this Clause holds a pointer which is automatically deleted deleted when this object goes out of scope so it's exactly what it says it's a scoped pointer I pointed to the object which is Skyped so whenever the object goes out of scope the point is destroyed and it frees up the memory so it's just a nice way of doing memory management inside of juice many memory management is also very important and performance is very important we need the audio processing cause the audio your sound card create what's called an audio callback and this order callback is called every you know forty four point one kilohertz right and if your code fails to provide an audio buffer for the sound card in time for the auto call back your son god is not gonna receive an audio buffer in time and what's gonna happen then is you're gonna hear a weird buzzing noise in your audio which is really nasty and terrible so yeah performance is really important in audio processing it's super important so anyway we've created some knobs the next thing we need to do is we need to create attachment for the slide attachment for these so that you can sort of slide the values and things so this also Skyped pointers scatter pointer and these are called an audio process so value 3 States I'm gonna explain this a little bit later and slider attachment right so and we're gonna call this a drive and for the drive knob and then we're going to do this for every single other knob drive range land volume volume okay so this provides us with a soul you know valley tree stating it's an XML thing it works with XML I'm not exactly sure it's exactly 100% how it works but I believe it creates an XML file which basically stores all your you know parameter values and things for parameters it allows you to create things like presets and stuff like that like if you have if you've got any like presets and things that allows you to create presets and save them and manage them in a very nice and a2i so it works as XML I'm not exactly sure but how it works but we're going to be using this whole valley tree State thing because it allows you to you know shape parameters between classes and things like that very easily and it's very neat it's a real nice way of doing things so that's why we use this value tree State things anyway next thing to do is well already done with the ADA file so let's get to the plugin editor c++ file the implementation for all of this and in the constructor right here okay so this is the size of our window right so this I believe is five hundred by two hundred so let's do that five hundred five hundred by two hundred and we're gonna add all our knobs and things in yes so let's create them so we want to add and make visible our lobs right so we're gonna do that drive knob drive knob and we're gonna install is not instant with an initial I anyway we're just gonna say equals in here slider and just call this driver I guess doesn't matter then we can say drive knob now it dot all right we have to remember that we created a pointer so we need to dereference this like this then we just sit slider style because we want the rotary slider so it looks like a rotational thing this slider there we go then like by default that come with a text box in a full label thing we don't want that we're gonna do the takes many relators I Drive nope the reference it takes a text box style so what we want is the slider no text box because we don't want it takes the thanks jeez for that option false what is the other thing the width and the height jeez hundred five hundred she day right so let's do this for every single knob so this is for the drive knob the range knob the other knobs rain Jesus this is a drive the range land and volume let's you know let's copy this all right so that is that an excellent addition to the attachment the valley tree settings that you can attach to neither the parameter values and things like that so yeah let's do that so the drive attachment it's equal to an ear or the air process so very tree we staked the slider attachment but so now we're actually gonna create the attachment so let's see what parameters this got anyone control it so the first thing is a body process of edit restate audio processor valley tree state state to control I'll say this text in the state from the audio processor which is this process of P the right there but we haven't created to state it so we actually need to go to the plug-in processor the processor that say which is reference this is P and you get this plug-in processor so that it a file let's get there the far let's create that state that is looking for the valley tree State thing so let's get to the air file let's go to you know let's create this in private then we're just gonna create a getter for this in the public side of things so again scoped pointer and this we want to order process of a decreased state or the EO processor so value very tree state and we're just gonna call it in a state right then we want to create a getter for this in the public and the public public when it is a getter so it's gonna return or deal processor Valley three states reference always pass by reference for performance so to avoid copying gets tight painting yeah that's it now let's implement this in the C++ file so go to the CPP let's see so here's a constructor other things where's the process block where do we do the processing all right so yeah and the process block this is where we're gonna do all the odd core depressants and stuff in this process block method so let's do the gate state method below this alright cuz why not so let's copy this gate state it stage two this is the distortion audio processor because this method belongs to that class and then we return a point the dereference state alright because it take some reference it returns a reference so we dereference it and put it in there right now we can go back to the plug-in editor and we can continue this drive attachment the attachment thing so now what we've done you can see that this conch this method taxing parameters you know there let's start to control and the state comes from the audio processor which is the spirited that peers audio processor the state is part of the state that we've just put in there so we can say P dot gets tied over sketch state gets type method that we just created there we go gets that it works then it takes in the parameter ID which I believe is just drive yeah I've called the drive small caps and then it takes in the slider to control the slider to control and this is the drive and knob that we created so but it takes in a reference it doesn't take in a pointer and remember it's a Scot pointer that we corrected something to dereference it drive just like that so then we can just do this for each knob so drive range linked volume volume I know this like this you know user interface stuff is not exciting but it has to be done right I know it's we're not going into the auto audio processing stuff yet that's a little bit later but we'll get there just you know hang on drive range blend volume that's it now we're almost finished guys seriously we're almost there now we just need to align this so it says yeah this is January generally where you'll want to light out the positions of any sub components in your editor so let's do our tails let's lay them out in yeah all right it says this will lay out the positions and things so let's the positions and stuff of these knobs and things over there so the way we do that is we call the you know the drive for every knob we just go that you know sit down stting arrive set bounds this will set the light and sizes and things so this looks like this right we have an exposition the wire position the width and the height of that knob and all just kinda make the width and height 100 so and we want them nicely and light out in the center of the thing right like like this so the way I did this was you know let us take the I did it with a broad face so we're gonna say get with get with and then what I do is what am i doing good good get to it and then I divide this by 5 because we have 4 knobs so if at the 5 / 5 then I can just multiply by the position that the thing is that so multiplied by 1 and let's round this in more brackets well one because it's a face knob on the thing then we subtract from it the side its size / - you're right so the size is under so we just they say under / to you now we did our height the Y position so again get right developer to because we wanted in the center surrounded by brackets then we subtract again the well the lights the water back to from it and then the width and the height is 100 and 100 right that's it so we do this for each knob it's a drive range blend volume now this is the first one second the fourth so just do that should work fine now let's taste this art so go it and hope this bold solution please work right I hope I don't get any compiled everybody so I always do so I won't be surprised if there are errors in the code so far so good but it is only started so let's compile let's go to the VST openly of VST folders alone where you store all your VST plugins' so I'm gonna open that the VST these two plugins right this is where I put all my VST plugins for if you're stealing a key Basin whatever some of them are stored on other places but you know the ones I make are oh yeah so that's that let's see whatever we got see how long is this oh we're ready for a minute een jeez guys this is gonna be a long video sorry about that but yeah we are making a distortion plugin I mean what's not hard about it alright and we haven't even got to the audio processing jeez okay this is gonna be a long video but I'll pull through you know okay okay right successful so now let's open this open the solution folder get x86 the bug VHT and right there this dll file that's our VST plugin if you're on Mac 11 a new plugin right so it's like that put it in a vsts folder right the distortion vestido dll now let's go back to FL studio more plugins add more plugins manage plugins we did between the starts can they go it found a distortion VST the dll stirring press it what the hell is it doing okay anyway let's scroll down oh there we got distortion VST let's check that now we'll be able to add us let's say distortion VST right a critical error let's retry this okay so okay yeah I know what this is happening cuz it the knobs isn't being constructed yet right in the audio processor right so now let's get to the audio processes C++ file this was a waste of time anyway okay let's get the constructor and let's actually construct these things you know so this is a constructor you can see it's all the exclu genus you know over here which we don't care about so this is where we actually implement the constructor what maze is this anyway just things for the compiler I guess we haven't even created the state yet geez the toilets in actually greater status state is equal to me audio processor Valley Tree State this takes in I don't even know audio processor to connect you were inside of the audio processor so let's just dereference this then with gods let's see undo manager i don't ever until manages so no pointer let's see if this will work now i think we actually have to add the parameters to the knobs as well i don't think it'll work yet what did see maybe it does maybe so let's copy this VST plugin over to our VST folder again see if it works replies continue open the audio software please work please work and it works people it works you can see we've got a phone knobs and the salah' world at the back way so yeah it works this time around so yeah okay so let's go to the plugin editor cuz I felt this elavil takes late just comment that out because we don't want that right now let's get the plugin processor let's let's other parameters in the constructor right below where we created this state so once the state's let's call the add parameter create an actor and the time we need to create them as well let's see so the label text this is this drive as well and the range okay so this is where we actually add the range so let's Texan and normalizable arrange objects so let's create that thing normalizable range and this basically just you know it takes in the range that we can be is having to specify the type so this is also a template class I'd specify that this is a flight and then there are different constructors for this list there are nine of the MIT start and end I guess we can use that but this one is even better so we can specify the starting range the end of the range of the values and interval value so Bywater increments so we can make it really accurate or really inaccurate if you want to so we're always gonna make it accurate so the start value will always be zero point zero or zero point if you prefer for floating-point you know efficiency or another other one just one point zero or one point if it doesn't matter really then the accuracy value let's make this accurate so let's say 0.001 for very accurate values this is insane accurate but it will it'll work so that's fine the end the default value right default value we can just make this one and then this function and honking and laughing so just no pointers BTR that's it and this of course has to be done for every single knob for every parameter that we want to add there are four of them so okay so that works now we can do the xml valley tree thing for the xml valley trees die so that you can get student things in memory somewhere so with a state the state of the state is equal to value tree value 3 and then we'll just add the primary name in there so now we do this for every single thing so the state of the state is basically the value tree and volume so this might look weird what I'm doing here like what he said equal to villager then your Sun City equal to something else I mean this doesn't make sense does it but I think in the constructor or some or in the equals operator I think it actually overloads this operator probably possibly too you know yeah it does overload it operator equal yeah it does so it's it's got some way of indexing these in a weird way by overloading the operator I'm not sure exactly how that works I haven't taken a look at the class yet so you can get to the close definition and look at how that works I'm not going to it's it's not interesting now we just want to set the state information and stuff and we did that a little bit more down in the code like we said state information let's look for that gate state no get the state information and sits that yeah this is what I want that so it says yeah you should use this messages to it parameters in the block you could use other raw data is the XML or valid three courses as intermediaries to make it easy to save and like complex data and that's exactly what we're doing we're using the intermediate stages that Jesus provides with the valley tree state and X and I'll stuff it really makes things a lot easier so this October googling I found out this tags in my memory it's actually in the demo as well they could have actually done this for you because you know this cut is gonna be similar for pretty much all the plugins in the world good string memory output stream stream good a stream and this will be there just takes in the the destination buffer which is this memory block thing that this data and then it takes in the buffer size oh I don't know what that is boolean you know false yeah let's just do that one then state state dot write the string stream like I said this is G's that kind of really the scurry has part of the framework I'd say but anyway they didn't say value tree tree tree straight a valley tree equals read from dot on like this read from daughter looks actually exactly it's a method in the value P class never mind so this is the daughter and the size and vice like I said I mean if I've got this / - these parameters as inputs they anyways I could have just added this line for you I mean I don't see the point anyway if if tree dot is valid so here we just check if the thing is valid if it's valid we just you know add the tree to this site if it's not we don't otherwise we're gonna get some weird exception if it's not valid so state state right there we go and that's it that's now we're actually done now I can just do yous guys now it's sounded odd called audio processing stuff so now let's go to the process block method in the plug-in processor so this is where we're gonna do all the heavy hardcore things the terrible audio processing stuff so yeah it is this is a place where you'd normally do the cut of your block into audio processing and that's exactly what you're gonna do we're gonna do the cuts of the plugins audio processing so you can just ignore this little fold above here this is what really matter so we're gonna clear this so basically how this works is for every channel right now the channels or your left and your right channels like so if you're using no no audio you only have one channel if you're using stereo audio you've two channels and you can also have more channels in some cases but that's sort of irrelevant in this guy's right in this case we're only gonna have two channels if you're still if you're using more loading only you know you can basically choose the amount of generals what you want anyway for every channel it gets a point a flight pointer to the channel to the buffer now this buffer is above a bottle buffer which is basically like an array of float values it's an array of flight values now those flag values in the array or the audio samples so you're gonna get a buffer which is an array of floating point values and all those floating point values are basically the audio data in the buffer those all your audio samples right so those are the different frequencies sampled by our digital to analog or analog to digital converter in a sound card so those are the valleys that we're going to tamper with and you can see it already created this flight point for us a flight pointer to the channel daughter so this is basically an array of floating point values so we can say channel daughter 0 or 1 or whatever is equal to some value right then we suddenly put a value into there that you know the first what do you sample in the buffer we don't want to do that of course that will corrupt that audio data and cause noises and things so now let's do the audio processing so well the first thing we're gonna do is we want the parameters for all the knobs so we don't want to get the parameters in this loop because that's gonna slow down the loop which is not going so we're gonna have a floating point value like the drive value that drive so that's gonna be the value of the drive knob right and this is a we Canady the state is a pointer so on the dereferences state get raw parameter value and we want to get the driver value right now we're just gonna get all the parameter valleys so that we can process these drive range blend and volume all right so now I've got all the parameter values that we need and now we can just do the plain audio processing stuff so what we're gonna do is for every sample we're gonna distort the audio sound that's what we want to do so we've got an array to all these samples but we want to do this for every sample solution where the for loops are for every integer song or sample is equal to zero sample smaller than buffer dot get some samples no this is a method so then some pulse was passed we just incremental samples integer some oh I mean right so now we can do this thing for every single sample but what we can also do instead of we can just say channel dot or you know channel now dot put the sample in there so that we can modify the current sample but what we can also do is we can increment say channel dr. plus plus then we increment the pointer so that it points to the next bit of channel daughter you can do it any way you want really so let's do the distortion so let let's first talk about what distortion actually is how it actually works so a distortion plug in your life probably you know if you've ever played around with your amp or something if you crank up the volume extremely high you will sometimes your slight better distortion coming through right so you might probably think well it's easy to create distortion just crank up the volume crazy I put a lot of gain on something and that creates Distortion well that's not really entirely true distortion does mean applying a lot of gain to gain to an audio signal but it's not just that it's a lot more than that distortion is a result of clapping audio sound let me demonstrate this so let me go in to open up geogebra so for this if you don't have geogebra go ahead and download geogebra it's useful really really useful it allows you to visualize graphs and functions on things and manipulate them and do all sorts of fancy maths with graphs and things which really is usually in audio processing if you want to visualize an audio function it can come in real handy so typically you'd have your audio song right so we can for example say sine of X right there's our sine wave right now a lot of people would say well distortion you just amplify this thing a lot you just put a lot of gain to this to create Distortion well that's not true and here's why that's not true let's say multiply this by two right now it's just extremely loud it's just you know the amplitude has gone up it just louder it's not distorted it is louder sometimes it will distort because there's a bit of clipping going on but on its own if you just make something loud it won't distort and yes I make things harder as you can see I just multiplied the sine wave by two so in the plug-in we can also we can just easily do that you know we can crank up the volume so we can just you know take the signal so the channel dotter so we did reference a channel daughter so that we have a floating-point and we can just say multiply this by let's say the drive value for instance right then we amplify that signal a lot but that just you know makes it louder it doesn't great distortion at all it just make things very loud it won't distort it so the way we distort things is we clip the value but the way we do that is we say the maximum value it can go to is for instance one so what we do is it for example create a line right there you know I want to create a line please there we go something like that right so it'll go up then it will suddenly see this and then it will go there and then this so it won't actually reach this boat geez that was a terrible explanation so let's say we want to clip the audio at one so it can't go louder than one right that's what we want to do right now we can clip it by just you know making sure the maximum value it can go to is one so everywhere will be zero one we clip the audio so basically what will happen is the sound wave will go it'll go up it'll go up it will see this is one this is maximum we can't go either then once that losses go along with a straight line we'll go down again it'll reach negative one see okay we're ready at negative one we can't go higher than that so let's just go straight across the line that will create that will create a distortion effect that will make it sound distorted and the way we do that is we can just simply use an if statement say if the channel daughter so if the channel daughter is bigger than one the in channel daughter is equal to one right that will clip the value at one make me shape can't go either we always goes on 2d references but that's not what we're actually gonna do to create this Distortion as you can see this scratch is very all that sudden change sudden in a Mesa kind of distortion that's not what we want we want a beautiful smooth nice distortion and the way we do that let me show you how we do that to do that we use a nice function so this function is two divided by PI times arc tan so 810 of X now look at this beauty so as you can see this function is very smooth but also the maximum value is 1 as you can see this is 1 it'll never quite reach one you can go on it'll get closer and closer to one but it will never reach one and it's very smooth it's a very smooth way of clipping things there's no sudden hard line cut off anyway so we just apply this formula to this so did the barber pi times the octane of X that's the distortion function we can ease the clipping algorithm so the first thing we do is we amplify the signal so that it will actually clip the more we amplify the flight the closer the value will the leaves will go to one in other words the more it will be clipped and the distortion will be heavier so here's how we do that so we say channel data is equal to two we of course on ad two divided by PI so it's a float PI 2 divided by 5 times a 10 of the channel daughter right and that's it we're done that creates the distortion but right now all we've done is the drive knob right only the drive is multiplied in there we haven't done the blend or the range or the volume it so let's do the range quickly and we simply just multiply the range in there with the drive knob because I told it well they kind of like go together this is bass change the range by which the drive knob is allowed to go so the more you increase the range the more you increase the maximum drive value you can go to so the more you know you change the range into a chicken just a drive knob the maximum value basically so now I've done that now I need to do the blend but the blend blends in the clean signal right now we've already distort the signal right there we can't get any clean signal anyway so what we need to do is before we applied any gain or anything to the channel data we need to save it as a clean value right of flight let's call the screen signal like cig is equal to channel data so this is a clean signal before it has been distorted then we apply gain to it and then we clip the gain to create the distortion effect now we want a blend this distorted value in with a clean signal value right this clean signal let's go in and do that so let's around this in brackets because this is a distorted signal now we want to do this if you want to multiply this by the Blaine value right so the blend is low it multiplies by level a so then only a little bit distortion is gonna come through right if the blend is I a lot of it is gonna go through so let's throw this ball brackets again so we're gonna add what we're gonna do is we're gonna add the clean signal to this and then divide by two to create the average value between the clean signal and distort the signal that will give you the plaint between the two so let's add the clean signal to this so clean sig now we want to multiply this by the Blaine value as well but we want to multiply this by 1 divided by the blend they will want to take all of this and divide it by 2 now we're gonna multiply the volume in this wall so let's add another bracket there for the volume so now I multiply this by the volume and guys that is basically it that's how you create a distortion plugin but I'm not quite finished yet alright I just want to surround this in brackets as well what was it just add a bracket there as well for safety reasons you know you never know so we're ready an hour in this has been taking long so long so that's it that is the distortion now let's go back to the plug-in editor because no plugin processor let's go to the constructor of the plugin processor where we created these things so for the drive knob the minimum value is zero maximum is one default value on that's fine for the range we wanted to go up to at least like three thousand you know so looking great a very heavy distortion then for the planed yeah that's between zero and one that's perfectly fine for the volume let's make the volume here and go up to like three like that now let's go in and build this and let's test out this distortion plug-in because in theory were basically done so let's test it out and see if it works it's building building and it's the bolt succeeded so let's get to the VST folder your project folder copy the VST plug-in DLL file or I you whatever you're using then go to your VST plugins folder replace it in there then open up your audio production software or whatever you're using let's open up let's go distortion VST there we go guys that's our distortion plugin so now let me grab my guitar let's crank up the volume a bit all right so works it works the only thing we didn't do was you will notice that there is no there's no labels on these knobs so let's just quickly add those labels so go to the plug-in editor C++ file you will see somewhere we saw this little bit of ticks the subtle world takes there we go the salad world takes right we're gonna use that as a template to strophe now add text to this thing so so let's add the text to this so we're gonna say g dot and draw text you know draw text drive let's cool this yeah let's make the text drive what other parent is taking the area okay so this is basically the it's basically this write the area their X&Y positions and the things let's add this we're gonna keep it the same as other things cuz it is basically the same then that's a lip you know the height so we can do that I think so that's this bit over there this as well then instead of you know this - under / - you think we're just gonna set plus five and then I think that should do it and then the width and the heart 100 by 100 we want to make it sentence I just location justification same turd false right that's the text now we just do this for every knob one two three four Drive range playing volume both this replaces Suton on because the plugin has to be disabled and sort of exited before you can actually replace the dll file okay so let's replace that replace and continue and what I notice all the labels and everything and this is a distortion plugin guys done so this was really fun to do actually okay I see I've done the blend knob incorrectly so this is embarrassing really how did I go wrong anyway let's see we multiplied this all right two point if let's see maybe that is that can't be it clean sigil times one other sort of it's not wonderful especially one minus the plane okay so just rebuilt that that's the first one - the plane not one divided by the blend it's not the inverted it's just one - the blender okay so just do that then it should work absolutely fine so now let's you know talk about that's it guys thank you all for you know pitching it for this this is really cool it was really fun I'm planning to do a whole like series on this the next one we can probably go a it and do some low-pass filters and I best focusing anything to some tongue controls for the distortion we can do some reverbs delays and you know harmonic freeze plugins and I was also thinking about doing a series but you know doing things like reverse engineering actual analog electronics for guitar effects and pedals and things and then actually simulating that because if you reverse engineer electronics you can actually write a derivative from formula out for the circuit and then it can implement that in C++ and then just you know create an exact identical simulation of what italics electronics to do to your audio signal you would simulate that and you would you know create a plug-in some planning on doing tear downs of whole bunch of you know effects pedals and things analog ones of course and then simulating them in C++ and I'll be recording that I think that's can be quite fun and yeah if there's any suggestions in your requests anything's you guys wanna know any questions please but if that means the description of this video also another thing if you go to my youtube channel you might notice there's no channel out there like if I go to youtube like my channel is dead well not dead hopefully not dead but if I get to my channel you'll see absolutely no channel art that's a problem I need channel art and you know I'm not an artist or Photoshop you know Pierce and say even if you guys you know we'd like to make some channel art for my channel please do so and post it in the description of the video or some way or you can send me an email or anything like that I would really love to check it out and if you guys have channel odd submissions for me real that'll be great so I want something sort of in the style of unis and programming things electronic stuff you know things like that because those are the kind of videos that I make so yeah anyway if they're anything like that and please both that any white guys and good day I'll see you all in the next one the next video will probably be a voxel engine tutorial one because I want to do another voxel anyone I sense if initial terrain generation thing and stuff like that which is gonna be really fun so pitching for that as well thank you all for watching and I'll see you all in the next one
Info
Channel: Reon Fourie
Views: 78,159
Rating: undefined out of 5
Keywords: How to create a VST plugin, VST plugin tutorial, AU, VST, Audio Processing, Creating a Distortion effect, Distortion, Guitar Distortion, How to make a guitar distortion, DSP distortion tutorial, DSP Programming C++
Id: iNCR5flSuDs
Channel Id: undefined
Length: 77min 29sec (4649 seconds)
Published: Fri Dec 08 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.