Theory and Techniques of Electronic Music

download Theory and Techniques of Electronic Music

If you can't read please download the document

Transcript of Theory and Techniques of Electronic Music

TheoryandTechniquesofElectronicMusicDRAFT:March3,2006MillerPucketteCopyright c (2006MillerPucketteAllrightsreserved.Contents1 Sinusoids, amplitudeandfrequency 31.1 MeasuresofAmplitude . . . . . . . . . . . . . . . . . . . . . . . . 51.2 UnitsofAmplitude. . . . . . . . . . . . . . . . . . . . . . . . . . 61.3 ControllingAmplitude . . . . . . . . . . . . . . . . . . . . . . . . 71.4 Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.5 SynthesizingaSinusoid . . . . . . . . . . . . . . . . . . . . . . . 91.6 SuperposingSignals . . . . . . . . . . . . . . . . . . . . . . . . . 121.7 PeriodicSignals. . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.8 AbouttheSoftwareExamples. . . . . . . . . . . . . . . . . . . . 14QuickIntroductiontoPd . . . . . . . . . . . . . . . . . . . . . . 17Howtondandruntheexamples . . . . . . . . . . . . . . . . . 191.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Constantamplitudescaler . . . . . . . . . . . . . . . . . . . . . . 19Amplitudecontrolindecibels . . . . . . . . . . . . . . . . . . . . 21Smoothedamplitudecontrolwithanenvelopegenerator . . . . . 23Majortriad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Conversionbetweenfrequencyandpitch . . . . . . . . . . . . . . 24Moreadditivesynthesis . . . . . . . . . . . . . . . . . . . . . . . 25Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Wavetablesandsamplers 292.1 TheWavetableOscillator . . . . . . . . . . . . . . . . . . . . . . 312.2 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.3 Envelopingsamplers . . . . . . . . . . . . . . . . . . . . . . . . . 372.4 Timbrestretching . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.5 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452.6 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492.6.1 wavetableoscillator . . . . . . . . . . . . . . . . . . . . . 492.6.2 wavetablelookupingeneral . . . . . . . . . . . . . . . . . 502.6.3 usingawavetableasasampler . . . . . . . . . . . . . . . 522.6.4 loopingsamplers . . . . . . . . . . . . . . . . . . . . . . . 542.6.5 Overlappingsamplelooper . . . . . . . . . . . . . . . . . 562.6.6 Automaticreadpointprecession . . . . . . . . . . . . . . 58iiiiv CONTENTS3 Audioandcontrol computations 613.1 Thesamplingtheorem. . . . . . . . . . . . . . . . . . . . . . . . 613.2 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633.3 Controlstreams. . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.4 Convertingfromaudiosignalstonumericcontrolstreams . . . . 693.5 Controlstreamsinblockdiagrams . . . . . . . . . . . . . . . . . 703.6 Eventdetection. . . . . . . . . . . . . . . . . . . . . . . . . . . . 713.7 Controlcomputationusingaudiosignalsdirectly . . . . . . . . . 733.8 Operationsoncontrolstreams. . . . . . . . . . . . . . . . . . . . 753.9 ControloperationsinPd. . . . . . . . . . . . . . . . . . . . . . . 773.10 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793.10.1 Samplingandfoldover . . . . . . . . . . . . . . . . . . . . 793.10.2 Convertingcontrolstosignals . . . . . . . . . . . . . . . . 813.10.3 Non-loopingsampleplayer . . . . . . . . . . . . . . . . . . 823.10.4 Signalstocontrols . . . . . . . . . . . . . . . . . . . . . . 843.10.5 Analog-stylesequencer. . . . . . . . . . . . . . . . . . . . 843.10.6 MIDI-stylesynthesizer . . . . . . . . . . . . . . . . . . . . 864 Automationandvoicemanagement 894.1 EnvelopeGenerators . . . . . . . . . . . . . . . . . . . . . . . . . 894.2 LinearandCurvedAmplitudeShapes . . . . . . . . . . . . . . . 924.3 Continuousanddiscontinuouscontrolchanges. . . . . . . . . . . 944.3.1 Muting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954.3.2 Switch-and-ramp . . . . . . . . . . . . . . . . . . . . . . . 964.4 Polyphony. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984.5 Voiceallocation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 984.6 Voicetags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994.7 EncapsulationinPd . . . . . . . . . . . . . . . . . . . . . . . . . 1024.8 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034.8.1 ADSRenvelopegenerator . . . . . . . . . . . . . . . . . . 1034.8.2 Transferfunctionsforamplitudecontrol . . . . . . . . . . 1064.8.3 Additivesynthesis: Rissetsbell. . . . . . . . . . . . . . . 1074.8.4 Additivesynthesis: spectralenvelopecontrol . . . . . . . 1104.8.5 Polyphonicsynthesis: sampler . . . . . . . . . . . . . . . . 1135 Modulation 1195.1 Taxonomyofspectra . . . . . . . . . . . . . . . . . . . . . . . . . 1195.2 Multiplyingaudiosignals . . . . . . . . . . . . . . . . . . . . . . 1225.3 Waveshaping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1265.4 Frequencyandphasemodulation . . . . . . . . . . . . . . . . . . 1325.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1355.5.1 Ringmodulationandspectra . . . . . . . . . . . . . . . . 1355.5.2 Octavedividerandformantadder . . . . . . . . . . . . . 1375.5.3 Waveshapinganddierencetones . . . . . . . . . . . . . . 1385.5.4 WaveshapingusingChebychevpolynomials . . . . . . . . 1395.5.5 Waveshapingusinganexponentialfunction . . . . . . . . 140CONTENTS v5.5.6 Sinusoidalwaveshaping: evennessandoddness . . . . . . 1415.5.7 PhasemodulationandFM . . . . . . . . . . . . . . . . . 1436 Designerspectra 1476.1 Carrier/modulatormodel . . . . . . . . . . . . . . . . . . . . . . 1486.2 Pulsetrains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1516.2.1 Pulsetrainsviawaveshaping . . . . . . . . . . . . . . . . 1516.2.2 Pulsetrainsviawavetablestretching. . . . . . . . . . . . 1526.2.3 Resultingspectra. . . . . . . . . . . . . . . . . . . . . . . 1526.3 Movableringmodulation . . . . . . . . . . . . . . . . . . . . . . 1566.4 Phase-alignedformant(PAF)generator . . . . . . . . . . . . . . 1586.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1636.5.1 Wavetablepulsetrain . . . . . . . . . . . . . . . . . . . . 1636.5.2 Simpleformantgenerator . . . . . . . . . . . . . . . . . . 1666.5.3 Two-cosinecarriersignal . . . . . . . . . . . . . . . . . . . 1676.5.4 ThePAFgenerator . . . . . . . . . . . . . . . . . . . . . . 1686.5.5 Stretchedwavetables . . . . . . . . . . . . . . . . . . . . . 1727 Timeshifts 1737.1 Complexnumbers . . . . . . . . . . . . . . . . . . . . . . . . . . 1747.1.1 Sinusoidsasgeometricseries . . . . . . . . . . . . . . . . 1767.2 Timeshiftsandphasechanges . . . . . . . . . . . . . . . . . . . 1787.3 Delaynetworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1787.4 Recirculatingdelaynetworks . . . . . . . . . . . . . . . . . . . . 1837.5 Powerconservationandcomplexdelaynetworks . . . . . . . . . 1877.6 Articialreverberation. . . . . . . . . . . . . . . . . . . . . . . . 1927.6.1 Controllingreverberators . . . . . . . . . . . . . . . . . . 1947.7 Variableandfractionalshifts . . . . . . . . . . . . . . . . . . . . 1967.8 Accuracyandfrequencyresponseofinterpolatingdelaylines . . 1997.9 Pitchshifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2007.10 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2067.10.1 Fixed,noninterpolatingdelayline . . . . . . . . . . . . . 2067.10.2 Recirculatingcomblter. . . . . . . . . . . . . . . . . . . 2077.10.3 Variabledelayline . . . . . . . . . . . . . . . . . . . . . . 2087.10.4 Orderofexecutionandlowerlimitsondelaytimes . . . . 2097.10.5 Orderofexecutioninnon-recirculatingdelaylines . . . . 2117.10.6 Non-recirculatingcomblterasoctavedoubler . . . . . . 2137.10.7 Time-varyingcomplexcomblter: shakers . . . . . . . . 2147.10.8 Reverberator . . . . . . . . . . . . . . . . . . . . . . . . . 2167.10.9 Pitchshifter . . . . . . . . . . . . . . . . . . . . . . . . . . 2167.10.10Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 219vi CONTENTS8 Filters 2218.1 Taxonomyoflters. . . . . . . . . . . . . . . . . . . . . . . . . . 2228.1.1 Low-passandhigh-passlters. . . . . . . . . . . . . . . . 2228.1.2 Band-passandstop-bandlters. . . . . . . . . . . . . . . 2248.1.3 Equalizinglters . . . . . . . . . . . . . . . . . . . . . . . 2248.2 Designinglters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2278.2.1 Elementarynon-recirculatinglter . . . . . . . . . . . . . 2278.2.2 Non-recirculatinglter,secondform . . . . . . . . . . . . 2288.2.3 Elementaryrecirculatinglter . . . . . . . . . . . . . . . . 2318.2.4 Compoundlters . . . . . . . . . . . . . . . . . . . . . . . 2318.2.5 Realoutputsfromcomplexlters. . . . . . . . . . . . . . 2328.3 Designinglters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2348.3.1 One-polelow-passlter . . . . . . . . . . . . . . . . . . . 2348.3.2 One-pole,one-zerohigh-passlter . . . . . . . . . . . . . 2358.3.3 Shelvinglter. . . . . . . . . . . . . . . . . . . . . . . . . 2368.3.4 Band-passlter. . . . . . . . . . . . . . . . . . . . . . . . 2388.3.5 Peakingandband-stoplter . . . . . . . . . . . . . . . . 2388.3.6 Butterworthlters . . . . . . . . . . . . . . . . . . . . . . 2398.3.7 Stretchingtheunitcirclewithrationalfunctions . . . . . 2418.3.8 Butterworthband-passlter . . . . . . . . . . . . . . . . 2448.3.9 Time-varyingcoecients . . . . . . . . . . . . . . . . . . 2458.3.10 Impulseresponsesofrecirculatinglters . . . . . . . . . . 2478.3.11 All-passlters . . . . . . . . . . . . . . . . . . . . . . . . 2478.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2508.4.1 Subtractivesynthesis. . . . . . . . . . . . . . . . . . . . . 2508.4.2 Envelopefollowing . . . . . . . . . . . . . . . . . . . . . . 2508.4.3 SingleSidebandModulation. . . . . . . . . . . . . . . . . 2538.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2558.5.1 Prefabricatedlow-,high-,andband-passlters . . . . . . 2558.5.2 Prefabricatedtime-variableband-passlter . . . . . . . . 2568.5.3 Envelopefollowers . . . . . . . . . . . . . . . . . . . . . . 2588.5.4 Singlesidebandmodulation . . . . . . . . . . . . . . . . . 2588.5.5 Usingelementaryltersdirectly: shelvingandpeaking. . 2618.5.6 Makingandusingall-passlters . . . . . . . . . . . . . . 2619 Fourieranalysisandresynthesis 2659.1 Fourieranalysisofperiodicsignals . . . . . . . . . . . . . . . . . 2659.1.1 Fouriertransformasadditivesynthesis. . . . . . . . . . . 2679.1.2 PeriodicityoftheFouriertransform . . . . . . . . . . . . 2679.2 PropertiesofFouriertransforms . . . . . . . . . . . . . . . . . . 2679.2.1 FouriertransformofDC. . . . . . . . . . . . . . . . . . . 2689.2.2 Shiftsandphasechanges . . . . . . . . . . . . . . . . . . 2699.2.3 Fouriertransformofasinusoid . . . . . . . . . . . . . . . 2719.3 Fourieranalysisofnon-periodicsignals. . . . . . . . . . . . . . . 2729.4 Fourieranalysisandreconstructionofaudiosignals. . . . . . . . 2759.4.1 Narrow-bandcompanding . . . . . . . . . . . . . . . . . . 277CONTENTS vii9.4.2 Timbrestamping(classicalvocoder) . . . . . . . . . . . . 2799.5 Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2819.5.1 Phaserelationshipsbetweenchannels . . . . . . . . . . . . 2859.6 Phasebashing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2869.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28810Classical waveforms 29710.1 SymmetriesandFourierseries. . . . . . . . . . . . . . . . . . . . 29910.1.1 Sawtoothwavesandsymmetry . . . . . . . . . . . . . . . 30010.2 Decomposing the classical waveforms into sawtooth and parabolicwaves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30210.3 Fourierseriesoftheelementarywaveforms. . . . . . . . . . . . . 30410.4 Predictingandcontrollingfoldover . . . . . . . . . . . . . . . . . 30910.4.1 Oversampling. . . . . . . . . . . . . . . . . . . . . . . . . 30910.4.2 Sneakytrianglewaves . . . . . . . . . . . . . . . . . . . . 31010.4.3 Transitionsplicing . . . . . . . . . . . . . . . . . . . . . . 31110.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314viii CONTENTSIntroductionThisbookisaboutusingelectronictechniquestorecord, synthesize, process,andanalyzemusicalsounds,apracticewhichcameintoitsmodernformintheyears1948-1952, butwhosetechnological meansandartisticuseshaveunder-goneseveral revolutionssincethen. Nowadaysmostelectronicmusicismadeusing computers,and this book will focus exclusively on what used to be calledcomputer music, but which should really now be called electronic music usingacomputer.Most of the available computer music tools have antecedents in earlier gener-ations of equipment. The computer, however, is relatively cheap and the resultsof using one are much easier to document and re-create than those of earlier gen-erationsofequipment. Intheserespectsatleast,thecomputermakestheidealelectronic music instrumentuntil someone invents something even cheaper andmoreexiblethanacomputer.Thetechniques andpractices of electronicmusiccanbestudied(at leastintheory)withoutmakingexplicitreferencetothecurrentstateoftechnology.Still, its important to provide working examples of them. So each chapter startswiththeory(withoutanyreferencetoimplementation)andendswithaseriesofexamplesrealizedinacurrentlyavailablesoftwarepackage.The ideal reader of this book is anyone who knows and likes electronic musicof anygenre, hasplentyof facilitywithcomputersingeneral, andwhowantstolearnhowtomakeelectronicmusicfromthegroundup, startingwiththehumble oscillator and continuing through sampling, FM, ltering, waveshaping,delays,andsoon. Thiswilltakeplentyoftime.Thisbookdoesntconcernitself withtheeasierrouteof downloadingpre-cooked software to try out these techniques; instead, the emphasis is on learninghow to use a general-purpose computer music environment to realize them your-self. Of the several such packages are available, well use Pd, but that shouldntstopyoufromusingthesesametechniquesinsomeotherenvironmentsuchasCsound or Max/MSP. To facilitate this, each chapter is divided into a software-independent discussion of theory, followed by actual examples in Pd, which youcantransposeintoyourownfavoritepackage.Toreadthisbookyoumustalsounderstandmathematicsthroughinterme-diatealgebraandtrigonometry,whichmoststudentsshouldhavemasteredbyage17orso. Aquickglanceattherstfewpagesofchapteroneshouldshowyouifyourereadytotakeiton. ManyadultsintheU.S. andelsewheremay12 CONTENTShaveforgottenthismaterialandwillwanttogettheirAlgebra2textbooksoutasareference. ArefresherbyF.RichardMooreappearsin[Str85,pp. 1-68].YoudontneedmuchbackgroundinmusicasitistaughtintheWest; inparticular, Westernwrittenmusic notationis not needed. Some elementarybitsof Westernmusictheoryareused, suchasthetemperedscale, theA-B-Csystemof namingpitches, andterms like noteandchord. Alsoyoushouldbefamiliarwiththefundamentalterminologyofmusicalacousticssuchassinusoids,amplitude,frequency,andtheovertoneseries.Eachchapter starts withatheoretical discussionof some familyof tech-niquesortheoretical issues, followedbyaaseriesof examplesrealizedinPdtoillustratethem. TheexamplesareincludedinthePddistribution, soyoucanrunthemand/oreditthemintoyourownspinos. Inaddition,alltheg-ureswerecreatedusingPdpatches,whichappearinanelectronicsupplement.These arent carefully documented but in principle could be used as an exampleofPdsdrawingcapabilitiesforanyoneinterestedinlearningmoreaboutthat.Chapter1Sinusoids,amplitudeandfrequencyElectronic musicis madebysynthesizingor processingdigital audiosignals.Thesearesequencesofnumbers,..., x[n 1], x[n], x[n + 1], ...wheretheindexn, calledthesamplenumber, mayrangeoversomeorall theintegers. Asinglenumberinthesequenceiscalledasample. (Somewritersuse the word sample dierently, to mean recorded soundbut in this bookwell only use the word to mean a single number.)An example of a digital audiosignalistheSinusoid:Sinusoidx[n] = a cos(n +)whereaistheamplitude,istheangularfrequency,andistheinitialphase.Thephaseisafunctionofthesamplenumbern, equal to + n. Theinitialphaseisthephaseatthezerothsample(n = 0).Strictly speaking, this is the real Sinusoid, distinct from the complex Sinusoidintroducedlaterinchapter7;butwheretheresnochanceofconfusionwewillsimplysaySinusoidtospeakofthereal-valuedone.Figure1.1showsaSinusoidgraphically. Inpart(a)ofthegure, thehori-zontal axisshowssuccessivevaluesof nandthevertical axisshowsthecorre-sponsding values of x[n]. The graph is drawn in such a way as to emphasize thesamplednatureofthesignal. Alternatively,wecoulddrawitmoresimplyasacontinuouscurve(partb). Theupperdrawingisthemostfaithful representa-tionofthe(digitalaudio)Sinusoid,whereastheloweronecanbeconsideredasidealizationofit.34 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCY1-1 n0x[n]1-1 50 x(n)(a)(b)49 Figure1.1: Adigital audiosignal, showingits discrete-timenature(part a),andidealizedasacontinuousfunction(partb). Thissignal isa(real-valued)Sinusoid, fty points long, with amplitude 1, angular frequency 0.24, and initialphasezero.1.1. MEASURESOFAMPLITUDE 5Sinusoids playakeyroleinaudioprocessingbecause, if youshift oneofthemleftorrightbyanynumberofsamples,yougetanotherone. Thismakesiteasytocalculatetheeectof all sortsof operationsonsinusoids. Ourearsusethissamespecialpropertytohelpusparseincomingsounds,whichiswhysinusoids, andcombinationsof sinusoids, canbeusedforavarietyof musicaleects.Digital audio signals do not have any intrinsic relationship with time, but tolisten to them we must choose a sample rate, usually given the variable name R,which is the number of samples that t into a second. Time is related to samplenumberbyRt=n, ort=n/R. Asinusoidal signal withangularfrequencyhasareal-timefrequencyequaltof=R2incyclespersecond,becauseacycleis2radiansandasecondisRsamples.Areal-worldaudiosignalsamplitudemightbeexpressedasatime-varyingvoltageorairpressure, but thesamplesof adigital audiosignal areunitlessnumbers. Wellcasuallyassumeherethatthereisamplenumericalaccuracysothatwecanignoreround-o errors,and thatthenumericalformatis unlimitedinrange, sothatsamplesmaytakeanyvaluewewish. However, mostdigitalaudiohardwareworksonlyoveraxedrangeofinputandoutputvalues,mostoftenbetween-1and1. Moderndigitalaudioprocessingsoftwareusuallyusesaoating-pointrepresentationforsignals. Thisallowsustousewhateverunitsaremost convenient for anygiventask, as longas thenal audiooutput iswithinthehardwaresrange.1.1 MeasuresofAmplitudeStrictly speaking, all the samples in a digital audio signal are themselves ampli-tudes, andwealsospokeoftheamplitudeaoftheSinusoidabove. Indealingwith general digital audio signals,it is useful to have measures of amplitude forthem. Amplitudeandothermeasuresarebestthoughtofasapplyingtoawin-dow, axedrangeofsamplesofthesignal. Forinstance, thewindowstartingatsampleMoflengthNofanaudiosignalx[n]consistsofthesamples,x[M], x[M+ 1], . . . , x[M+N 1]Thetwomostfrequentlyusedmeasuresof amplitudearethepeakamplitude,whichissimplythegreatestsample(inabsolutevalue)overthewindow:Apeakx[n] = max [x[n][, n = M, . . . , M+N 1andtherootmeansquare(RMS)amplitude:ARMSx[n] =

Px[n]6 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYwherePx[n]isthemeanpower,denedas:Px[n] =1N

[x[M][2+ +[x[M+N 1][2

(Inthislastformula, theabsolutevaluesignsarentnecessaryatthemomentsince were working on real-valued signals, but they will become important laterwhenweconsidercomplex-valuedsignals.) NeitherthepeaknortheRMSam-plitudeofanysignalcan be negative,andeitheronecan be exactlyzero onlyifthesignalitselfiszeroforallninthewindow.TheRMSamplitudeof asignal mayequal thepeakamplitudebutneverexceeds it; and it may be as little as 1/Ntimes the peak amplitude, but neverlessthanthat.Under reasonable conditionsif the window contains at least several periodsandif theangular frequencyis well under oneradianper samplethepeakamplitudeof theSinusoidis approximatelyaandits RMSamplitudeabouta/2.1.2 UnitsofAmplitudeTwoamplitudes are oftenbest comparedusingtheir ratiorather thantheirdierence. For example, sayingthat one signals amplitude is greater thananothers byafactor of twois moreinformativethansayingit is greater by30millivolts. This is truefor anymeasureof amplitude(RMSor peak, forinstance). Tofacilitatethisweoftenexpressamplitudesinlogarithmicunitscalled decibels. If a is the amplitude of a signal (either peak or RMS, as denedabove),thenwecandenethedecibel(dB)leveldas:d = 20log10(a/a0)where a0 is a reference amplitude. This denition is set up so that, if we increasethesignalpowerbyafactoroften(sothattheamplitudeincreasesbyafactorof10), the logarithm will increase by 1/2, and so the value in decibels goes up(additively)byten. Anincreaseinamplitudebyafactoroftwocorrespondstoanincreaseofabout6.02decibels;doublingpowerisanincreaseof3.01dB.IndB, therefore, adding two uncorrelated signals of equal amplitude results in onethatisabout3dBhigher,whereasdoublingasignalincreasesitsamplitudeby6dB. TherelationshipbetweenlinearamplitudeandamplitudeindecibelsisgraphedinFigure1.2.Stillusinga0todenotethereferenceamplitude,asignalwithlinearampli-tude smaller than a0will have a negative amplitude in decibels: a0/10 gives -20dB, a0/100 gives -40, and so on. A linear amplitude of zero is smaller than thatofanyvalueindB,sowegiveitadBvalueof .In digital audio a convenient choice of reference, assuming the hardware hasamaximumamplitudeofone,isa0= 105= 0.000011.3. CONTROLLINGAMPLITUDE 70decibels1ampli-tude-20 -1000.1Figure1.2: TherelationshipbetweenDecibel andlinear scales of amplitude.Thelinearamplitude1isassignedto0dB.sothatthemaximumamplitudepossibleis100dB, and0dBislikelytobeinaudiblyquiet at anyreasonable listeninglevel. Convenientlyenough, thedynamicrangeofhumanhearingtheratiobetweenadamaginglyloudsoundandaninaudiblyquietoneisabout100dB.Amplitude is related in an inexact way to the perceived loudness of a sound.In general, two signals with the same peak or RMS amplitude wont necessarilyhavethesameloudnessatall. Butamplifyingasignalby3dB,say,willfairlyreliablymakeitsoundaboutonesteplouder. Muchhasbeenmadeof thesupposedly logarithmic nature of human hearing (and other senses), which maypartiallyexplainwhydecibelsaresuchausefulscaleofamplitude[RMW02,p.99].Amplitude is also related in an inexact way to musical dynamic. Dynamic isbetter thought of as a measure of eort than of loudness or power. It ranges overninevalues: rest,ppp,pp,p,mp,mf,f,,f. Thesecorrelateinan evenlooserwaywiththeamplitudeofasignalthandoesloudness[RMW02,pp. 110-111].1.3 ControllingAmplitudePerhapsthemostfrequentlyusedoperationonelectronicsoundsistochangetheiramplitudes. Forexample, asimplestrategyforsynthesizingsoundsisbycombining Sinusoids, which can be generated by evaluating the formula on page3, samplebysample. ButtheSinusoidhasaconstantnominal amplitudea,andwewouldliketobeabletovarythatintime.Ingeneral, tomultiplytheamplitudeof asignal x[n] byafactor y 0,8 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYyoucanjust multiplyeachsample byy, givinganewsignal y x[n]. Anymeasurementof theRMSorpeakamplitudeof x[n] will begreaterorlessbythefactory. Moregenerally,youcanchangetheamplitudebyanamounty[n]whichvariessamplebysample. If y[n] isnonnegativeandif it variesslowlyenough,theamplitudeoftheproducty[n]x[n](inaxedwindowfromMtoM+ N 1)will berelatedtothatofx[n] bythevalueofy[n] inthewindow(whichweassumedoesntchangemuchovertheNsamplesinthewindow).In the more general case where both x[n] and y[n] are allowed to take negativeand positive values and/or to change quickly, the eect of multiplying them cantbe described as simply changing the amplitude of one of them; this is consideredlaterinchapter5.1.4 FrequencyFrequencies, like amplitudes, are often described on a logarithmic scale, in orderto emphasize proportions between them, which usually provide a better descrip-tionoftherelationshipbetweenfrequenciesthandodierencesbetweenthem.Thefrequencyratiobetweentwomusicaltonesdeterminesthemusicalintervalbetweenthem.The Western musical scale divides the octave(the musical interval associatedwitharatioof 2:1) intotwelve equal sub-intervals, eachof whichthereforecorrespondstoaratioof21/12. Forhistoricalreasonsthissub-intervaliscalledahalf step. Aconvenient logarithmic scale for pitchis simplytocount thenumber of half-steps fromareferencepitchallowingfractions topermit ustospecifypitcheswhichdontfall onanoteof theWesternscale. ThemostcommonlyusedlogarithmicpitchscaleisMIDIpitch, inwhichthepitch69is assignedtoafrequencyof 440cycles per secondtheAabovemiddleC.ToconvertbetweenMIDIpitchandfrequencyincyclespersecond, applytheformulas:Pitch/FrequencyConversionm = 69 + 12log2(f/440)f= 4402(m69)/12Middle C, corresponding to MIDI pitch 60,comes to 261.626 cycles per second.MIDIitselfisanoldhardwareprotocolwhichhasunfortunatelyinsinuateditself into a great deal of software design. In hardware, MIDI allows only integerpitchesbetween0and127. However, theunderlyingscaleiswell denedforanyMIDInumber, evennegativeones; forexampleaMIDIpitchof -4isadecentrateofvibrato. Thepitchscalecannot,however,describefrequencieslessthanorequal tozerocyclespersecond. (ForacleardescriptionofMIDI,itscapabilitiesandlimitations,see[Bal03,ch.6-8]).Ahalf stepcomes toaratioof about 1.059to1, or about asixpercentincreaseinfrequency. Halfstepsarefurtherdividedintocents,eachcentbeing1.5. SYNTHESIZINGASINUSOID 9pitch440frequency4557 69 1102203300Figure1.3: TherelationshipbetweenMIDI pitchandfrequencyincyclespersecond(Hertz). Thespanof24MIDIvaluesonthehorixontal axisrepresentstwooctaves,overwhichtheoutputincreasesbyafactoroffour.onehundredthof ahalf step. Asaruleof thumb, itmighttakeaboutthreecentstomakeadiscernablechangeinthepitchofamusicaltone. AtmiddleCthiscomestoadierenceofabout1/2cyclepersecond. AgraphoffrequencyasafunctionofMIDIpitch,overatwo-octaverange,isshowninFigure1.3.1.5 SynthesizingaSinusoidIn most widely used audio synthesis and processing packages (Csound, Max/MSP,andPd, for instance), theaudiooperations arespeciedas networks of unitgenerators[Mat69]whichpassaudiosignalsamongthemselves. Theuserofthesoftwarepackagespeciesthenetwork, sometimescalledapatch, whichessen-tially corresponds to the synthesis algorithm to be used, and then worries abouthow to control the various unit generators in time. In this section,well use ab-stractblockdiagramstodescribepatches,butintheexamplessection(page19), well tochooseaspecicimplementationenvironmentandshowsomeofthesoftware-dependentdetails.ToshowhowtoproduceaSinusoidwithtime-varyingamplitudewellneedtointroducetwounitgenerators. FirstweneedapureSinusoidwhichismadewithanoscillator. Figure1.4(a)showstheiconforasinusoidaloscillator. Theinput is a frequency (in cycles per second), and the output is a Sinusoid of peakamplitudeone.Figure1.4(b) shows howtomultiplytheoutput of asinusoidal oscillatorbyanappropriate amplitude scaler y[n] tocontrol its amplitude. Since the10 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCY(a)OUTFREQUENCYOUTFREQUENCY(b)X y[n]Figure1.4: Blockdiagramsfor(a)asinusoidal oscillator; (b)controllingtheamplitudeusingamultiplierandanamplitudesignaly[n].oscillators peak amplitude is 1, the peak amplitude of the product is about y[n],assumingy[n]changesslowlyenoughanddoesntbecomenegativeinvalue.Figure1.5shows howtheSinusoidof Figure1.1is aectedbyamplitudechangebytwodierentcontrollingsignalsy[n]. Thecontrollingsignal showninpart(a)hasadiscontinuity, andsothereforedoestheresultingamplitude-controlledsinusoidshownin(b). Parts canddshowamoregently-varyingpossibilityfory[n] andtheresult. Intuitionsuggeststhattheresultshownin(b)wontsoundlikeanamplitude-varyingsinusoid,butinsteadlikeasinusoidinterruptedbyafairlyloudpopafter whichit continues morequietly. Ingeneral, forreasonsthatcantbeexplainedinthischapter, amplitudecontrolsignalsy[n] whichrampsmoothlyfromonevaluetoanotherarelesslikelytogiverisetoparasiticresults(suchasthatpop)thanareabruptlychangingones.Fornowwecanstatetwogeneralruleswithoutjustifyingthem. First,pureSinusoidsaretheclassofsignalsmostsensitivetotheparasiticeectsofquickamplitude change. So when you want to test an amplitude transition, if it worksforSinusoidsitwillprobablyworkforothersignalsaswell. Second,dependingonthe signal whose amplitude youare changing, the amplitude control willneed between 0 and 30 milliseconds of ramp timezero for the most forgivingsignals(suchaswhitenoise),and30fortheleast(suchasaSinusoid). Allthisalsodependsinacomplicatedwayonlisteninglevelsandtheacousticcontext.Suitable amplitude control functions y[n] may be obtained using an envelopegenerator. Figure1.6showsanetworkinwhichanenvelopegeneratorisusedtocontrol theamplitudeof anoscillator. Envelopegeneratorsvarywidelyin1.5. SYNTHESIZINGASINUSOID 11(a)(b)(c)(d)n-1 1-1 -1 -1 111y[n]x[n]y[n]x[n]y[n]y[n]050 Figure1.5: Twoamplitudefunctions(a, c), and, in(b)and(d), theresultofmultiplyingthembythepureSinusoidofFigure1.1.12 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYOUTFREQUENCYXFigure1.6: Usinganenvelopegeneratortocontrolamplitude.functionalityfromone designtoanother, but we will focus onthe simplestkind,whichgenerateslinesegmentsasshowning. 1.4(b). IfalinesegmentisspeciedtorampbetweentwooutputvaluesaandboverNsamplesstartingatsamplenumberM,theoutputis:y[n] = a + (b a)n MN, M n M+N 1.The output may have any number of segments such as this, laid end to end, overthe entire range of sample numbers n; at, horizontal segments can be made bysettinga = b.Inadditiontochangingamplitudes of sounds, amplitudecontrol is oftenused,expeciallyinreal-timeapplications,simplytoturnsoundsonando: toturnoneo, ramptheamplitudesmoothlytozero. Most softwaresynthesispackagesalsoprovidewaystoactuallystopmodulesfromcomputingsamplesatall,butherewelluseamplitudecontrolinstead.Envelopegeneratorsaredescribedinmoredetailinsection4.1.1.6 SuperposingSignalsIfasignal x[n] hasapeakorRMSamplitudeA(insomexedwindow), thenthescaledsignalka[n](wherek 0)hasamplitudekA. TheRMSpowerofthe scaled signal changes by a factor of k2. The situation gets more complicatedwhentwodierentsignalsareaddedtogether; justknowingtheamplitudesofthetwodoesnotsucetoknowtheamplitudeofthesum. Thetwoamplitudemeasures do at least obey triangle inequalities; for any two signals x[n] and y[n],Apeakx[n] +Apeaky[n] Apeakx[n] +y[n]1.7. PERIODICSIGNALS 13ARMSx[n] +ARMSy[n] ARMSx[n] +y[n]IfwexawindowfromMtoN+M 1asusual,wecanwriteoutthemeanpowerofthesumoftwosignals:Px[n] +y[n] = Px[n] +Py[n] + 2CORx[n], y[n]wherewehaveintroducedthecorrelationoftwosignals:CorrelationCORx[n], y[n] =x[M]y[M] + +x[M+N 1]y[M+N 1]NThecorrelationmaybepositive, zero, or negative. Over asucientlylargewindow,the correlation of two Sinusoids with dierent frequencies is negligible.Ingeneral,fortwouncorrelatedsignals,thepowerofthesumisthesumofthepowers:Px[n] +y[n] = Px[n] +Py[n], wheneverCORx[n], y[n] = 0Putintermsofamplitude,thisbecomes:(ARMSx[n] +y[n])2= (ARMSx[n])2+ (ARMSy[n])2.This is the familiar Pythagorean relation. So uncorrelated signals can be thoughtofasvectorsatrightanglestoeachother;positivelycorrelatedonesashavinganacuteanglebetweenthem, andnegativelycorrelatedashavinganobtuseanglebetweenthem.Forexample, if twouncorrelatedsignalsbothhaveRMSamplitudea, thesum will have RMS amplitude2a. On the other hand if the two signals happentobeequalthe most correlatedpossiblethe sumwill have amplitude 2a,whichisthemaximumallowedbythetriangleinequality.1.7 PeriodicSignalsAsignalx[n]issaidtorepeatataperiodifx[n +] = x[n]for all n. Such a signal would also repeat at periods 2and so on; the smallest if any at which a signal repeats is called the signals period. In discussing periodsof digital audiosignals, wequicklyrunintothedicultyof describingsignalswhose period isnt an integer, so that the equation above doesnt make sense.Throughout this section, well eectively ignore this diculty by supposing thatthesignal x[n] maysomehowbeinterpolatedbetweenthesamplessothatitswelldenedwhethernisanintegerornot.The Sinusoidhas aperiod(insamples) of 2/where is the angularfrequency. Moregenerally, anysumof Sinusoidswithfrequencies2k/, forintegersk,willhavethisperiod. SuchasumiscalledaFourierSeries:14 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYFourierSeriesx[n] = a0 +a1 cos (n +1) +a2 cos (2n +2) + +ap cos (pn +p)Moreover,ifwemakecertaintechnicalassumptions(ineectthatsignalsonlycontainfrequenciesuptoanitebound),wecanrepresentanyperiodicsignalassuchasum. Thisisthediscrete-timevariantofFourieranalysiswhichwillreappearinchapter9.Theangularfrequenciesof theSinusoidsaboveareall integermultiplesof. They are called the harmonicsof , which in turn is called the fundamental.Interms of pitch, theharmonics , 2, . . . areat intervals of 0, 1200, 1902,2400,2786,3102,3369,3600,...,centsabovethefundamental;thissequenceofpitchesissometimescalledtheharmonicseries. Therstsixof thesearealloddly close to multiples of 100; in other words, the rst six harmonics of a pitchin the Western scale land close to (but not always on) other pitches of the samescale;thethirdandsixthmissonlyby2centsandthefthmissesby14.Putanotherway,thefrequencyratio3:2isalmostexactlysevenhalf-tones,4:3isjustasneartovehalftones, andtheratios5:4and6:5arefairlyclosetointervalsof fourandthreehalf-tones, respectively. Thesefourintervalsarecalled the fth, the fourth, and the major and minor thirdsagain for historicalreasonswhichdontconcernushere.AFourierseries(withonlythreeterms)isshowninFigure1.7. Therstthreegraphsarethoseofsinusoids,whosefrequenciesareina1:2:3ratio. Thecommonperiodismarkedonthehorixontalaxis. Eachsinusoidhasadierentamplitude and initial phase. The sum of the three, at bottom, is not a sinusoid,butitstillmaintainstheperiodicitysharedbythethreecomponentsinusoids.Leavingquestionsofphaseaside,wecanusea bankofsinusoidaloscillatorstosynthesizeperiodictones, oreventomorphsmoothlythroughasuccessionof periodictones, byspecifyingthefundamental frequencyandthe(possiblytime-varying)amplitudesofthepartials. Figure1.8showsablockdiagramfordoingthis.Thisisanexampleof additivesynthesis; moregenerallythetermcanbeapplied to networks in which the frequencies of the oscillators are independentlycontrollable. The early days of computer music were full of the sound of additivesynthesis.1.8 AbouttheSoftwareExamplesTheexamplesforthisbookhavebeenrealizedusingPureData(Pd), andtouseandunderstandthemyouwill havetolearnatleastsomethingaboutPditself. Pd is an environment for quickly assembling computer music applications,primarily intended for live music performances involving computers. Pds utilityextendstographicalandothermedia, althoughherewellfocusonPdsaudiocapabilities.1.8. ABOUTTHESOFTWAREEXAMPLES 15++=Figure1.7: AFourierseries,showingthreesinusoidsandtheirsum. Thethreecomponentsinusoidshavefrequenciesintheratio1:2:3.16 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYOUTFREQUENCYX 2X 3+(more)X X XFigure1.8: Usingmanyoscillatorstosynthesizeawaveformwithdesiredhar-monicamplitudes.1.8. ABOUTTHESOFTWAREEXAMPLES 17Several other patchable audio DSP environments exist besides Pd. The mostwidelyusedoneiscertainlyBarryVercoesCsound, whichdiersfromPdinbeing text-basednot GUI basedwhich is an advantage in some respects and adisadvantageinothers. CsoundisbetteradaptedthanPdforbatchprocessingand it handles polyphony much better than Pd does. On the other hand, Pd hasabetterdevelopedreal-timecontrol structurethanCsound. MoreonCsoundcanbefoundin([Bou00]).Anotheralternativeinwideuse isJames McCartneysSuperCollider,whichisalsomoretextorientedthanPd, butlikePdisexplicitlydesignedforreal-timeuse. SuperColliderhaspowerfullinguisticconstructswhichmakeitmoreuseful thanCsoundasaprogramminglanguage. AnothermajoradvantageisthatSuperCollidersaudioprocessingprimitivesareheavilyoptimizedfortheprocessor family it runs on (MIPS), making it perhaps twice as ecient as Pd orCsound. AtthiswritingSuperColliderhasthedisadvantagethatitisavailableonlyforMacintoshcomputers(whereasPdandCsoundbothrunonavarietyofoperatingsystems.)Finally, Pd has a widely-used relative, Cycling74s commercial programMax/MSP(theothersnamedhereareall opensource). Bothbeginnersandsystemmanagers running multi-user, multi-purpose computer labs will ndMax/MSPbetter supportedanddocumentedthanPd. Its possibletotakeknowledge of Pdanduse it onMax/MSPandvice versa, andeventoportpatchesfromonetotheother,buttheyarenttrulycompatible.QuickIntroductiontoPdPddocumentsarecalledpatches.Theycorrespondroughlytotheboxesinthe abstract block diagrams shown earlier in this chapter, but in detail they arequitedierent, reectingthefact that Pdis animplementationenvironmentandnotaspecicationlanguage.APdpatch,suchastheoneshowninFigure1.9,consistsofacollectionofboxesconnectedinanetworkcalledapatch. Theborderofaboxtellsyouhowitstextisinterpretedandhowtheboxfunctions. Inpart(a)ofthegureweseethreetypesofboxes. Fromtoptobottomtheyare: amessagebox. Messageboxes, withaag-shapedborder, interpretthetextasamessagetosendwhenevertheboxisactivated(byanincomingmessageorwiththemouse.) Themessageinthiscaseconsistssimplyofthenumber34. anobjectbox. Objectboxeshavearectangularborder;theyusethetexttocreateobjects whenyouloadapatch. Object boxes mayrepresenthundreds of dierent classes of objectsincluding oscillators, envelopegenerators,andothersignalprocessingmodulestobeintroducedlaterdepending on the text inside. In this example,the box contains an adder.InmostPdpatches,themajorityofboxesareoftypeobject. Therstword typed into an objectbox species its class,whichin this case is just18 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCY34 + 1321 (a)dac~osc~440(b)frequencysinusoidal oscillatormultiplieroutput*~ 0.1 0message boxobject box(GUI) boxnumber(on/off)amplitudeFigure1.9: (a)threetypesof boxesinPd(message, object, andGUI); (b)asimplepatchtooutputaSinusoid.+. Anyadditional(blank-space-separated)wordsappearingintheboxarecalledcreationarguments,whichspecifytheinitialstateoftheobjectwhenitiscreated. a number box. number boxes are a particular case of a GUI box, which alsoincludepushbuttons, toggleswitches, sliders, andmore; thesewill comeuplater intheexamples. Thenumber boxhasapunched-card-shapedborder, withanickoutofitstoprightcorner. Whereastheappearanceofanobjectormessageboxisstaticwhenapatchisrunning, anumberboxscontents(thetext)changestoreectthecurrentvalueheldbythebox. You can also use a number box as a control by clicking and draggingupanddown,orbytypingvaluesinit.Ing. 1.9(a)themessagebox,whenclicked,sendsthemessage21toanobject box which adds 13 to it. The lines connecting the boxes carry data fromoneboxtothenext;outputsofboxesareonthebottomandinputsontop.Figure1.9(b)showsaPdpatchwhichmakesaSinusoidwithcontrollablefrequency and amplitude. The connecting patch lines are of two types here;thethinonesareforcarryingsporadicmessages,andthethickerones(connectingthe oscillator, the multiplier, and the output dac ) carry digital audio signals.SincePdisareal-timeprogram,theaudiosignalsowinacontinuousstream.Ontheotherhand, thesporadicmessagesappearatspecicbutpossiblyun-predictableinstantsintime.Whetheraconnectioncarriesmessagesorsignalsisafunctionof theboxtheconnectioncomesfrom; so, forinstance, +outputsmessages, but*outputs a signal. The inputs of objects may or may not accept signals (but theyalwaysacceptmessages,evenifonlytoconvertthemtosignals). Asanamingconvention, objectboxeswhichinputoroutputsignalsareall namedwithatrailingtilde()asin*andosc.1.9. EXAMPLES 19HowtondandruntheexamplesTorunthepatches,youmustrstdownload,install,andrunPd. Instructionsfor doing this appear in Pds on-line HTML documentation, which you can ndathttp:/crca/ucsd/edu/msp/software.htm.This book shouldappear at: http:/crca/ucsd/edu/msp/techniques.htm,possiblyinseveral revisions. Choosetherevisionthatcorrespondstothetextyourereading(gototheintroductiontondtherevisionnumber)anddown-loadthearchivecontainingtheassociatedrevisionof theexamples(youmayalsodownloadanarchiveof theHTMLversionforeasieraccessonyourma-chine.) Theexamplesshouldall stayinasingledirectory, sincesomeofthemdependonotherlesinthatdirectoryandmightnotndthemif youmovethingsaround.If youdowant tocopyoneof theexamples toanother directorysothatyoucanbuildonit (whichyourewelcometodo), youshouldeither includetheexamplesdirectoryinPdssearchpath(seethePddocumentation)orelsegureoutwhatotherlesareneededandcopythemtoo. AgoodwaytondthisoutisjusttorunPdontherelocatedleandseewhatPdcomplainsitcantnd.Thereshouldbedozensof lesintheexamplesfolder, includingtheex-amples themselves andthe support les. The lenames of the examples allbeginwitha letter (Afor chapter 1, Bfor 2, etc.) anda number, as inA01.sinewave.pd.The example patches are also distributed with Pd, but beware that you mayhaveadierentversionof theexampleswhichmightnotcorrespondwiththetextyourereading.1.9 ExamplesConstantamplitudescalerPatchA01.sinewave.pd, showningure1.10, containsessentiallythesimplestpossiblepatchthatmakesasound, withonlythreeobjectboxes. (Therearealsocomments,andtwomessageboxestoturnPdsDSP(audio)processingonando.) Thethreeobjectboxesare:osc : thesinusoidal oscillator. Theleft handsideinput andtheoutputtakedigital audiosignals. Theinputistakentobea(possiblytime-varying)frequency in Hz. The output is a Sinusoid at the specied frequency. If nothingis connected to the frequency inlet, the creation argument (440 in this example)isusedasthefrequency. Theoutputhaspeakamplitudeone. Youmaysetaninitialphasebysendingmessages(notaudiosignals)totherightinlet. Theleft(frequency)inletmayalsobesentmessagestosetthefrequency,sinceanyinletthattakesanaudiosignalmaybesentmessageswhichareautomaticallyconvertedtothedesiredaudiosignal. : themultiplier. This exists intwoforms. If acreationargument is20 CHAPTER1. SINUSOIDS,AMPLITUDEANDFREQUENCYosc~ 440dac~