It's themarblemachine I wenttogosynthesizedbythesoundsynthesizerthatmanyNotonlyisis a wonderfulmelody, butithighlightsthethreethingswe'regonnatalkabout.
Thisvideofirstislookingat a frequencymodulation, whichisveryimportantforgiving a realtexturetothesound.
Thisiseversosubtlychangingfrequency.
No, lostitsplayforthesecondpartwillbelookingatvoicesandinstruments.
Canwecomeupwith a nicedatastructurethatwrapsupeverythingwe'vedonesofar?
Sotheoscillatorsontheenvelopestorepresent a particularlyonfinally, atlonglastwillbelookingatpolyphonyforPaul, ifonlydependingonthisistheabilitytoplaymultiplenotesatthesametime.
Let's getstuff.
I'm startingwiththecodethatweusedattheendofthelastvideo, andifyouremember, thiscodereallyjustcontains a simpleoscillatoronanenvelopeon.
It's notreallythescopeofthisvideo, butwe'lltakeonethat's readymade, and I'lltryandexplainbitsofit.
Thepurposeoffrequencymodulation, though, istoadd a littlebitofvibratotothesound, andthiscanhave a lotofdepthandcharacterandtexturetothetonesthatwecanhear.
Whereas I wouldusuallytalkthroughthetheoryandthenwritethecode, I'm goingtodoittheotherwayaroundthistimesowecanlistentotheeffectfirst.
Thatmightmakeexplainingthemaths a littlesimpler, so I'm goingtomakesomemodificationstooscillatorfunction.
Wesee a clusteringofflowfrequencies, followedbyhighfrequenciesandlowfrequenciesandhighfrequencies.
Andsoif I verygentlychangedthelowfrequency, wecanseetheclustersgettighterandtighter.
Andif I changethehigherfrequency, whichwillbethenotewecansee, that's alsochangestheoutputwaveform.
Wecanchangetheeffectthatthelowfrequencyhasonthefighthighfrequencybyalteringitsamplitudeonthat, I callthis a fudgefactor, butthisisactuallyquite a complexphenomenoninthefrequencymodulationequation.
Soif I reducetheamplitude, wecanseewe'vejustleftwiththeoriginalnoteon.
As I increasethisvalue, weseethatthefrequencymodulationbecomesmoreprominentandhecoulddointerestingthingswiththis.
Infact, if I turnitrightup, westartgettingveryinterestingwayforms.
Indeed.
Nowdon't discountthestraightaway.
Theymightactuallysoundfantastic.
Let's gobacktoourveryfirstoscillatorequationonwhat's consideredthelowfrequencyoscillatorpartfirstsowewouldhavelowfrequencyoscillatorsamplitudesignoffthefrequencythatwewantTimes t.
Keenmathematiciansouttheremayhavespottedsomething a bitoddaboutleftintheuseoftea.
I don't wantthistobe a videoaboutmathematics.
Andifyou'rereallyinterested, therearemanyresourcesonlinethattalkabouthowfrequencymodulationisreally a combinationofftriggered a metricidentitiesoncalculus.
Sufficetosay, theequationwillendwiththeendis a bitof a bodyapproximation.
Whatisgoodenoughforthepurposesofthisvideo?
I'm nowgoingtomodifyouroscillatorfunctionsoitalwaysuses a lowfrequencyoscillator.
So I'veincludedherethefrequencyonDTH e amplitude, but I'm givingthemdefaultvaluesincasewedon't wanttouseiton.
I'm goingtocreate a basefrequencysowecanusethisfrequencyandtheothertypesofoscillators.
Thiswasouramplitude.
Andso a sinewavesimplybecomesthesign.
Thefrequencynowtheonlyonethat's trickytomodify.
Hereisthedigitalapproximationto a sorewavebecauseitdoesn't use D frequency, anditworksinrealtimeanddoesn't useangularvelocity.
I likethatNowthatwe'vegotenvelopesoscillators, lowfrequencyoscillatorsandfrequencymodulation, wecanhave a crackittryingtocreaterealisticsoundinginstruments.
I'm goingtotryandmake a harmonicatypesoundlikeyouheardatthestartofthisvideointheaudiotrackbyWinterGun.
I know a harmonicais a reedinstrument, andit's a breathethereedinstrument.
I'vecreated a name, space, coldsynth, andwhatyou'llseeinthisnamespaceisprettymuchexactlywhatwe'vegotalreadyinourprogram, wegot a W functionfordoingangularvelocity.
Thisis a basicnotesstructure.
Insteadofstoringthefrequency, I'm storingtheideaofthekeyonthekeyboardon I keeptrackofthetimes.
Whenitwasswitchedonenough, I alsostolesomethingcalledtheChannelAndi.
Thisiseffectivelythevoice.
Yousee.
Theoscillatorhasn't changedatall, and I'veincluded a functioncalledScale, whichtakesthenote I D ontranslatesitto a frequency, andthismaylooksilly, butit's exactlythesameaswehadbefore.
I'verefinedtheenvelopestructure a littlebitithasexactlythesamevariablesandoperatesinexactlythesamewayasbefore.
Buttherewere a fewglitches, forexample, releasingthekeywhilstitwasstillinthesackface.
Usingthislovelybitofcodehere, whichis a lambdafunction, you'llhavenoticedthatthestartofthisfunction I'm using, um, youtexthisistoprotectthevectorofnotesbecausethesoundmachine, thebackground, theOLCnoisemaker, that H filestartsitsownthreattoehandle.