Numerical Sound Synthesis N ume ric al Sound Sy nthe sis: Finite Diffe re nc e Sc he m e s and Simulation in M usic al Ac oustic s Stefan Bilbao © 2009 John Wiley & Sons, Ltd. ISBN: 978-0-470-51046-9 Numerical Sound Synthesis Finite Difference Schemes and Simulation in Musical Acoustics Stefan Bilbao Acoustics and Fluid Dynamics Group/Music, University of Edinburgh, UK A John Wiley and Sons, Ltd., Publication Thiseditionfirstpublished2009 ©2009,JohnWiley&Sons,Ltd Registeredoffice JohnWiley&SonsLtd,TheAtrium,SouthernGate,Chichester,WestSussex,PO198SQ,UnitedKingdom Fordetailsofourglobaleditorialoffices,forcustomerservicesandforinformationabouthowtoapplyforpermission toreusethecopyrightmaterialinthisbookpleaseseeourwebsiteatwww.wiley.com. TherightoftheauthortobeidentifiedastheauthorofthisworkhasbeenassertedinaccordancewiththeCopyright, DesignsandPatentsAct1988. Allrightsreserved. Nopartofthispublicationmaybereproduced, storedinaretrievalsystem,ortransmitted,inany form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright,DesignsandPatentsAct1988,withoutthepriorpermissionofthepublisher. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmaynotbeavailable inelectronicbooks. Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and productnamesusedinthisbookaretradenames,servicemarks,trademarksorregisteredtrademarksoftheirrespective owners.Thepublisherisnotassociatedwithanyproductorvendormentionedinthisbook.Thispublicationisdesigned toprovideaccurateandauthoritativeinformationinregardtothesubjectmattercovered.Itissoldontheunderstanding thatthepublisherisnotengagedinrenderingprofessional services.Ifprofessionaladviceorotherexpertassistanceis required,theservicesofacompetentprofessionalshouldbesought. ® MATLAB MATLABandanyassociatedtrademarksusedinthisbookaretheregisteredtrademarksofTheMathWorks, Inc. ® ForMATLAB productinformation,pleasecontact: TheMathWorks,Inc. 3AppleHillDrive Natick,MA,01760-2098USA Tel:508-647-7000 Fax:508-647-7001 E-mail:[email protected] Web:www.mathworks.com LibraryofCongressCataloguing-in-PublicationData Bilbao,StefanD. Numericalsoundsynthesis:finitedifferenceschemesandsimulationinmusicalacoustics/StefanBilbao. p.cm. Includesbibliographicalreferencesandindex. ISBN978-0-470-51046-9(cloth) 1.Musicalinstruments—Mathematicalmodels.2.Musicalinstruments—Computersimulation.3.Finitedifferences.I. Title. ML3817.B552009 781.2(cid:2)3015118—dc22 2009015955 AcataloguerecordforthisbookisavailablefromtheBritishLibrary. ISBN:978-0-470-51046-9(Hbk) Typesetin9/11ptTimesbyLaserwordsPrivateLimited,Chennai,India. PrintedandboundinSingaporebyMarkonoPrintMediaPteLtd Contents Preface ix 1 Sound synthesisand physical modeling 1 1.1 Abstract digital sound synthesis 2 1.2 Physical modeling 8 1.3 Physical modeling: a larger view 18 2 Time series and difference operators 25 2.1 Time series 26 2.2 Shift, difference, and averaging operators 27 2.3 Frequency domain analysis 31 2.4 Energeticmanipulations and identities 38 2.5 Problems 42 3 The oscillator 45 3.1 The simpleharmonic oscillator 46 3.2 A finite difference scheme 49 3.3 Otherschemes 55 3.4 Lumped mass–springnetworks 61 3.5 Loss 63 3.6 Sources 67 3.7 Problems 68 3.8 Programming exercises 71 4 The oscillatorin musical acoustics 73 4.1 Nonlinearoscillators 74 4.2 Losslessoscillators 74 4.3 Lossy oscillators 82 4.4 Problems 87 4.5 Programming exercises 90 vi CONTENTS 5 Grid functions and finite difference operators in 1D 93 5.1 Partial differential operators and PDEs 93 5.2 Grid functions and difference operators 98 5.3 Coordinate changes 112 5.4 Problems 113 5.5 Programming exercises 115 6 The 1D wave equation 117 6.1 Definition and properties 118 6.2 A simple finite difference scheme 131 6.3 Other schemes 148 6.4 Modal synthesis 152 6.5 Loss 153 6.6 Comparative study I 155 6.7 Problems 157 6.8 Programming exercises 161 7 Linear bar and string vibration 163 7.1 The ideal uniform bar 163 7.2 Stiff strings 174 7.3 Frequency-dependent loss 177 7.4 Coupling with bow models 180 7.5 Coupling with hammer and mallet models 183 7.6 Multiplestrings 185 7.7 Prepared strings 187 7.8 Coupled bars 194 7.9 Helical springs 199 7.10 Spatial variation and stretched coordinates 206 7.11 Problems 213 7.12 Programming exercises 218 8 Nonlinearstring vibration 221 8.1 The Kirchhoff–Carrier string model 221 8.2 General planar nonlinear string motion 232 8.3 Non-planar string motion 242 8.4 Problems 244 8.5 Programming exercises 247 9 Acoustictubes 249 9.1 Webster’s equation 249 9.2 The vocal tract and speech synthesis 258 9.3 Reed wind instruments 265 9.4 Other wind instruments 278 9.5 Problems 278 9.6 Programming exercises 283 CONTENTS vii 10 Grid functions and finite difference operators in 2D 287 10.1 Partial differential operators and PDEs in two space variables 288 10.2 Grid functions and difference operators: Cartesian coordinates 291 10.3 Grid functions and difference operators: radial coordinates 299 10.4 Problems 301 10.5 Programming exercises 303 11 The 2D wave equation 305 11.1 Definition and properties 305 11.2 A simplefinite difference scheme 310 11.3 Otherfinite difference schemes 312 11.4 Digitalwaveguide meshes 315 11.5 Lumped mass–springnetworks 316 11.6 Modal synthesis 317 11.7 Finitedifference schemes in radial coordinates 318 11.8 Comparative study II 321 11.9 Problems 322 11.10 Programming exercises 327 12 Linear plate vibration 331 12.1 The Kirchhoff thin plate model 331 12.2 Loss and tension 341 12.3 Plate excitation 341 12.4 Plate–stringconnections 346 12.5 Anisotropicplates 349 12.6 The thin platein radial coordinates 352 12.7 Problems 355 12.8 Programming exercises 357 13 Nonlinearplate vibration 361 13.1 The Berger plate model 361 13.2 The von Ka´rma´n plate model 363 13.3 Spherical shell vibration 371 13.4 Problems 376 13.5 Programming exercises 378 14 Conclusion and perspectives 379 14.1 A family of musical systems 379 14.2 Comparative study III 382 14.3 Beyond finitedifference methods 386 A Matlab code examples 391 A.1 The simpleharmonic oscillator 391 A.2 Hammer collisionwith mass–springsystem 392 A.3 Bowed mass–spring system 393 viii CONTENTS A.4 The 1D wave equation: finite difference scheme 394 A.5 The 1D wave equation: digital waveguidesynthesis 395 A.6 The 1D wave equation: modal synthesis 397 A.7 The ideal bar 398 A.8 The stiff string 399 A.9 The Kirchhoff–Carrier equation 401 A.10 Vocal synthesis 402 A.11 The 2D wave equation 403 A.12 Thin plate 405 B List of symbols 407 Bibliography 411 Index 427 Preface Whilethisbookwasbeingwritten,digitalsoundsynthesisreachedsomethingofamilestone—its 50thbirthday.Setagainsttheleisurelypaceofthedevelopmentandevolutionofacousticmusical instruments in previous years, a half century is not a long time. But given the rate at which computational power has increased in the past decades, it is fair to say that digital sound is, if not old, at least enjoying a robust middle age. Many of the techniques that developed early on, duringa15-yearburstofcreativitybeginninginthelate1950s,havebecomeclassics:wavetables, sinusoids,andFMoscillatorsarenowthecornerstonesofmodernsynthesis.Allofthesemethods appeared at a time when operation counts and algorithmic simplicity were of critical importance. In the early days, these algorithms stretched the bounds of computing power, only to produce soundwhen shoehornedinto thebusy scheduleofa universitymainframe by a devoted and often sleep-deprived composer. Now, however, sounds of this nature may be produced quickly and easily, and are used routinely by musicians in all walks of life. Beyond allowing musicians to do faster what was once grindingly slow, increased computa- tional power has opened the door to research into newer, more demanding techniques. Certainly, inthelast20years,themostsignificantefforthasgoneintoasetofmethodsknown,collectively, as “physical modeling.” The hope is that by sticking to physical descriptions of musical objects, better synthetic sound quality may be achieved. There are many such methods available—all, however, may ultimately be viewed as numerical simulation techniques, applied to generate an approximate solution to the equations which describe an acoustic entity, such as a string, drum head,orxylophonebar.Theinterestingthingisthat,inoneway,thisisastepbackward;afterall, modern numerical solution techniques are at least 80 years old, and predate the existence of not only the first digital sound synthesis methods, but in fact digital computers themselves! It is also a step backward in another sense—physical modeling techniques are far more computationally intensivethan the classicmethods, and, again, likethe old days, algorithm efficiency has become a concern. Is physical modeling a step forward? This is a question that may only be answered subjectively—by listening to the sounds which may be produced in this way. As mentioned above, physical modeling sound synthesis is an application of numerical sim- ulation techniques. Regardless of the application, when one is faced with solving a problem numerically, many questions arise before any algebraic manipulations or computer coding are attempted. Or, rather, after one has made oneor many such attempts, thesequestionsare begged. There are many, but the most important are: • How faithfully is the solutionto be rendered? (Accuracy) • Howlongshouldonereasonablyexpecttowaitforthesolutiontobecomputed?(Efficiency) • How bad is it if, for some unexpected reason, the simulationfails? (Stability) x PREFACE Thoughtheidealanswersare,ofcourse,“very,notlong,andbad,”onemightguessthatrarely will one be able to design a method which behaves accordingly. Compromises are necessary, and the types of compromises to be made will depend on the application at hand. Regarding the first question above, one might require different levels of accuracy in, for instance, a routine weather prediction problem, as compared to the design of a nuclear reactor component. As for the second, though in all cases speedier computation is desirable, in most mainstream simulation applications the premium is placed rather on accuracy (as per the first question), though in some, such as for instance control systems built to reduce panel flutter, efficient on-line performance is essential. Finally, because many mainstream simulation applications are indeed intended to run off-line, many techniques have developed over the years in order to control the usual problems in simulation, such as oscillatory behavior and instability. In some applications, typically in an off-line scenario, such as in the design of an airfoil, if one encounters numerical results which suffer from these problems, one can adjust a parameter or two, and run the simulation again. But in an on-line situation,or if theapplication is to beused by a non-expert (such as might occur in the case of 3D graphics rendering), the simulation algorithm needs to produce acceptable results with littleor no intervention from the user. In other words, it must be robust. Whataboutsoundsynthesisthen?Numericalsimulationmethodshaveindeed,forsometime, playedaroleinpurestudiesoftheacousticsofmusicalinstruments,divorcedfromsoundsynthesis applications, which are the subject of this book. For this reason, one might assume that such methods could be applied directly to synthesis. But in fact, the constraints and goals of synthesis aresomewhatdifferentfromthoseofscientificresearchinmusicalacoustics.Synthesisisarather special case of an application of numerical methods, in that the result is judged subjectively. Sometimes there is a target sound from a real-world instrument to be reproduced, but another, perhaps longer-term goal is to produce sounds from instruments which are wholly imaginary, yet stillbasedon physicalprinciples.Furthermore, thesemethodsaredestined,eventually,tobeused by composers and musicians, who surely will have little interest in the technical side of sound synthesis,andwhoare becomingincreasinglyaccustomed toworkinginareal-timeenvironment. For this reason, it seems sensibleto put more emphasis on efficiency and stability,rather than on computing extremely accurate solutions. Suchconsiderations,aswellastheauxiliaryconcernofprogrammingease,naturallyleadone toemploythesimplestsimulationmethodsavailable,namelyfinitedifferenceschemes.Thesehave beenaroundforquitealongtime,and,inmanymainstreamapplications,havebeensupersededby newer techniques which are better suited to the complexities of real-world simulation problems. Ontheotherhand,therearemanyadvantagestostickingwitharelativelysimpleframework:these methodsareefficient,quiteeasytoprogram,and,bestofall,onecanusequitebasicmathematical tools in order to arrive quickly at conclusions regarding their behavior. The trick in synthesis, however, is to understand this behavior in an audio setting, and, unfortunately, the way in which simulationtechniquessuchasfinitedifferenceschemes arepresentedinmanystandardtextsdoes not address the peculiarities of sound production. This has been one of the main motivations for writing this book. Every book has a latent agenda. Frequency domain analysis techniques play a central role in both musical acoustics and numerical analysis, and such techniques are not neglected here. The reason for this is, of course, that many important features of real-world systems (such as musical instruments) may be deduced through linearization. But frequency domain techniques constitute onlyasinglepointofview—thereareothers.Adynamicalsystemsviewpoint,inparticularwhen energyconceptsareemployed,canalsobeinformative.Theuseofenergeticprinciplesamountsto morethanjustadifferentslantontheanalysisofnumericalmethodsthanthatprovidedbyfrequency domainmethods;itisinfactmuchmoregeneral,andatthesametimelessrevealing—thedynamics of a system are compressed into the time evolution of a single scalar function. The information it does yield, however, is usually exactly what one needs in order to answer thorny questions PREFACE xi about,say,thestabilityofnonlinearnumerical methods,as wellas howtoproperlysetnumerical boundary conditions.It is the key to solid design of numerical methods and ofimmense practical utility,andforthesereasonsisgivenanelaboratetreatmentinthisbook.Besides—it’sinteresting! Thisworkisnotreallyintendeddirectlyformusiciansorpractisingacousticians,butratherfor workingengineersand(especially)doctoralstudentsandresearchersworkingonthemoretechnical side of digital audio and sound synthesis. Nor is it meant as a collection of recipes, despite the inclusion of a body of code examples. I realize that the audience for this book will be narrowed somewhat (and maybe a little disappointed) because of this. The reason for this is that physical modeling synthesis is really numerical simulation, a disciplinewhich is somewhat more removed fromaudioprocessingthanmanymightliketobelieve.Thereisaneed,Ithink,tostepbackfrom the usual techniques which have been employed for this purpose, generally those which evolved outofthelanguageandtoolsofelectricalengineers,namelydigitalsignalprocessing,andtotakea lookatthingsinthewayasimulationspecialistmight.Thebodyoftechniquesisdifferentenough torequireagooddealofmathematicswhichmaybeunfamiliartotheaudioengineer.Atthesame time, the audio-informed point of view taken here may seem foreign to the simulation specialist. It is my greatest hope that this book will serve to engender curiosity in both of these groups of people—in the ultimate interest, of course, of producing new and beautiful sounds. Book summary Chapter1isahistoricaloverviewofdigitalsoundsynthesistechniques—thoughfarfromcomplete, it highlights the (sometimes overlooked) links between abstract sound synthesis methods, based essentiallyonsignalprocessingmanipulations,andmoremodernphysicalmodelingsoundsynthesis methods, as well as the connections among the various physical modeling methodologies. InChapter2,timeseriesanddifferenceoperatorsareintroduced,andsometimeisspentonthe frequencydomaininterpretationofsuchoperators,aswellasoncertainmanipulationswhichareof useinenergyanalysisoffinitedifferenceschemes.Specialattentionispaidtothecorrespondence between finite difference operations and simple digitalfilter designs. The simple harmonic oscillator is introduced in Chapter 3, and serves as a model for many of the systems which appear throughout the rest of the book. Various difference schemes are analyzed,especiallywithrespecttonumericalstabilityandaccuracy,usingbothfrequencydomain and energetic principles; the linear loss mechanism is also introduced. Chapter 4 introduces various nonlinear excitation mechanisms in musical acoustics, many of which reduce to nonlinear generalizations of the harmonic oscillator, as well as associated finite difference schemes. Chapter 5 is designed as a reference chapter for the remainder of the book, with a complete introduction to the tools for the construction of finite difference schemes for partial differential equationsintimeandonespatialdimension,includinggridfunctions,differenceoperators,aswell asadescriptionoffrequencydomaintechniquesandinnerproductformulations,whichareuseful for nonlinearproblems and the determination of numerical boundary conditions. Asatestproblem,the1Dwaveequationandavarietyofnumericalmethodsarepresentedin Chapter6.Variousfeaturesofinterestinmusicalsimulations,includingpropersettingsforboundary conditions, readout, and interpolation, numerical dispersion and its perceptual significance, and numerical stability conditions, are discussed. In addition, finite difference schemes are related to modal methods, digital waveguides, and lumped networks, and relative strengths and weaknesses are evaluated. Chapter 7 deals with more musical extensions of the 1D wave equation and finite difference schemestothecaseoftransversevibrationofbarsandstiffstrings,andconsiderabletimeisspent on loss modeling as well as the coupling with hammer, mallet, and bow models, and coupling withlumpedelementsandbetweenbars.Thechapterendswithanextensiontohelicalspringsand spatially varying string and bar systems.
Description: