String Simulator Synthesis Program

With Real Time Midi Control and Sound Output

by Theo Verelst

See also a page about the string physics and mathematics of the string simulator.


This document describes a physically modeled string simulator program, its algorithm and a windows compatible, downloadable implementation. It uses a mathematical / physical model where each string, like a guitar string, is divided in little segments, for which physical laws of inertia and local strain based acceleration hold. The mathematical update sweep solves the finite element like problem where the solver is  mathematically conditioned to make use of 'cheap' computer instructions, while maintaining an integer based average accuracy, to limit the amount of noise in the solution.

On a modern PC (say over 500 MHz) more than one string can be simultated to vibrate in parallel, and they can interact with eachother, like over the cam of a guitar. Also the string is not homogeneous, its end points exhibit progressive damping. The pickup point. like the element for an electrical guitar, can be set anywhere along the strings' length. Real time, midi controlled parameters include string length, by pitch bender, and feedback control, by the modulation wheel. A basic non-linear amplifier simulation feeds back a portion of the string sound mix to all strings, to simulate feedback.

The string 'pluck' initial state is based on a mathematical model which is key-velocity dependent, making the timbre of each string dependent on how hard it's corresponding key on the keyboard is struck. On a 2GHz pentium based machine, about 6 strings can be simulated in real time at CD quality, where the sound delay can be as short as one sample, but of course this point is never reached on the windows platform. The main state of the simulators string segments is stored in 32 bit integer form, the same holds for most computations.

This document describes the algoritms used, the results and directions of development. Hyperlinks are provided to the whole package sources, suitable for compilation under cygwin, available for non-commercial purposes, otherwise permission is needed from the author, .


Synthesis of sounds, reproduced electronically and of course reproduced electro-mechanically is about half a century old, and always there has been the idea of imitating existing instuments by synthesizers or organs on the one hand, and creating wild, weird and very beautyfull newly synthesized, comparable with no as yet existing  or known sounds.

Interestingly enough, a mechanical instument, electrically and very non-hifi amplified, has at least been as well known as all-electronics instruments, and still has uncomparable qualities compared to all widely spread synthesizers, which can only approach its sonic possibilities to a fairly large distance.

Sampling technology can make CD quality perfect recordings of also souring guitar solos, but after hitting the keys a few times become boring and uninspiring. Computers have been used for all kinds of synthesis, of which the better, more advanced ones from years ago can in principle run on later computers. Still, all or mostly electronics machines are popular, and the signal processing in modern synthesizers is more advanced than computers can handle from the same time, apart maybe from workstations or farms of parallel computers with working software.

This document describes an attempt to start simulating guitar strings in software, on a modern computer, so not the most advanced DSP's available, preferably under control of a MIDI keyboard, velocity sensitive and with pitch bend and modulation wheel.

So it attemps at exporing some of the basic sound palette of a electromagnetical instrument from the same era as the synthesizer, with the widely available resource of the personal computer. The approach is physical/mathematical, and not directly by measurements and existing guitar analysis. The resulting sound doesn't exactly qualify at the moment as either a typical acoustical or electrical guitar sound, but it is certainly strong enough and has 'string' qualities, and is at least interesting in its own respect, and good angle on further research.

Physical Model

                        Fig. 1 A string suspended by solid points

                  Fig. 2 Graph of string excursion e from rest, a few mass point examples,
                             and construction of the force vector based on neighbouring sampling points.

Mathematical Approximation


The mathematical model is of course the mathematical formulation of the above physical simulation model of the string, which is a very non-trivial problem. Solving a dicretized few hundred degree equation for the number of samples required for one second of sound in CD quality takes a lot of computations, even on modern computers, and arriving at a stable enough solution  by itself is not straighforward.

   Overview of the solution method

To solve the differential equation which comes natually from the physical finite-elemnt like method, or better put, the quantized difference equations, I use a full sweep approach where all segments are updated based nearest neighbour 'current state'

   Numerical stability considerations and solutions

The main solution to the huge error propagation problem using our 'full-out' simulation has been to not use more multiplications in the update sweep than divides by two, a simple nearest neighbour averaging filter per second order section. The integration step per such section

The software

The software downloadable below has a lot of options in the current algorithm fixed to pleasing but not by far the only possibilities. The string update algorithm has fixed end point medium changes, except there is a small change for release cycle (key up)  damping of the strings.

There is a single section non-linearity in the update sweep, and the overall feedback loop is gradually applied to a number of segments at an unadjustable point of the strings.

IMPORTANT:  to prevent damage to your ears and possibly sound system, do not turn up the volume of your amplifier until you know what it sounds like when the update algorithms starts generating digital noise as a result of out of control overtones!

It is just a limitation of the current algorithm which causes dreadfull noise to be produced when stability of the string update is lost because of sound volume headroom overflow by pressing keys hard, excessive feedback by turning up the feedback control by the modulation wheel, or slowly building up feed-back sound.

Nothing is damaged in the software or you soundcard, ever, it is just a very load and penetrating and high frequency-rich sound, so be prepared to not blow up your tweeters if you are working at far more than normal room volume.

The way to get things under control is to press the number of keys equal to the number of strings you have (or just many), after you first released all keys, so to start fresh sounds for each string, and of course press the keys gently...

   The windows executable program 'pmsb.exe'

I put the program up for download here unless you've got cygwin installed, you probably will need this glut32.dll downloaded to the same directory as the program file, both files together are about 300 KB together for download.

To test the program, simply double click it on a windows 95, 98, 2000, NT or XP pentium machine, preferably over 600 MHz.

When the program pmsb.exe starts, it displays this text in a text window:

nocygwin version, doesn't need cygwin1.dll
it does need glut32.dll
click on one of the graphical window items for (reactivating) a string
or push one of the numberical keys (1- #strings, 0 silences strings)

author: M.T. Verelst,
PMS / PortAudio Test: output simulated guitar string wave.
Midi interface callback function: device opened
Midiopen: 0, midiInStart: 0.
The meaning of the last two lines is that the midi interface has been found and initialized correctly. When there is a problem opening the sound device, a message is generated. See below for command line invocation.

Also, a graphics window is opened:

shown here with the popup menu, brought up by the right mouse button, which can make the first string sound or the program quit.

Clearly, the interface has only testing meaning, the objects are linked to the first three strings (when the simulator is called to sound at least 3), and trigger those strings when clicked, so that real time 3D interaction is achieved.

   Midi Implementation

The program checks for the first midi port that is available on the system, and uses it, there is no configuration option. When the last two lines it prints at startup report 0 values, the midi interface should be active, and the program will start reading events from it.

The recognized midi messages are:

      Note on  with velocity and note number in principle over the whole theoretical range, but there is an upper not limit.

The string generator assignment is based on first free oscilator algorithm, in case of more notes than strings, the zeroth string takes all new notes, until another gets its corresponding key released.

The upper limit is when the number of string segments, which is used to influence the string frequency, becomes so small (say smaller than 30) that the relative frequency deviation per added or removed segment from the string length makes the tuning too inaccurate, and also the string dynamic behaviour based on too small a number of finite elements.

In other words, the high end detunes fundamentally.

Also, the pickup element is placed at a fixed count of string segments from the right side string suspension, counting to the left. When it threatens to 'fall off' on the left side, that is the element displacement is larger than the string length itself, the sound is gone, so notes corresponding to a string length larger than than the element offset (outnode) are completely muted. This happens already in the middle upper range of the keyboard.

     Note off  either by the actual midi message or by note on with zero velocity is recognized because synths with both systems exist. The repeated midi status protocol is not recognized, but is uncommon.

Note off triggers the release cycle of the string, which currently makes it resound without feedback,

Because all note offs are tracked and used, there is no chance of sounding the same note on two strings, except making use of the release cycle of one note, while pitch bending another to the same frequency.

      Modulation wheel   controls the feedback of the soundmix from the virtual elements, over the non-linear amplifier simulation back to each individual string in a smoothly coupled way. The range is adjusted so that usually considerable feedback can be generated, but it may easily enough set of simulator digital noise feedback error, which only stops after hitting enough keys light after releasing all keys first, pressing the 'donut' in the graphics picture (silences all strings), or quiting the program.

When applied right, can add a lot of strength and interest to the sound. A bit of feedback is often enough for more lively chords, and in-time change of the amount of feedback while notes resound (keys being held) works well, too.

The idea is no vibrato of course, as mostly the modulation wheel is used, but control of the mutual influencing of the strings, and feedback, to the point of oscillation. Because of the strings vibration simulation, influencing makes the phases of the harmonics change, even the overall frequency perception, and the character of chords. When oscillation is near, sustain changes.

      Pitch bend wheel  bends all strings corresponding to held down keys by the same relative amunt, resulting in a natural pitch bend, as is common on synthesizers. Because of gradual media change at the string ends, there can be an (small) error in relative frequency change from the mathematical scaling. This in fact happens on natural instruments, too, but when using high notes the number of segments for the string end becomes relatively larger, there is a relatively large deviation for high pitched notes.

      Midi active sensing is just noted, but completely ignored.

      Volume control  probably makes the output of the pmsb program's sound driver follow the volume slider on a controlling synth.

All midi messages are taken fixed from channel 1 (the first) only.

   Software source files

The source files are organized in a single directory and I've included two makefiles, one compiles with no-cygwin, so basically mingw, the other makes the program need cygwin.dll, but allows unix calls, as extension.

A zip file with the source files can be downloaded from here.

Download and reuse for non-commercial purposes is free, as long as the author and the source get clearly mentioned in any derived software or writing. Commercial rights are reserved: contant the author at .

   Load on the computer

Because of the not so light digital signal processing involved in making even one string simulated with some accuracy, the computer you run the program on, must have lets say 300 MegaHerz of clock speed, assuming a pentium machine, per string you want to simulate for normal use. If you use low frequencies, this need for clock speed goes up with 100% per octave...

So running on a ca. 2GHz pentium like machine should give you 6 strings without too much trouble when playing chords.

The graphics require nothing special, except probably some openGL possibility, I didn't test that, but no accelerated graphics is fine.


The resulting sounds vary by changing the sources, or the 'outnode' startup option. As is, the sound is string-like, not unlike a plucked acoustic (spanish) guitar with long sustain, or 'straight' electrical guitar in certain ranges.

When played (over a keyboard) right, the sound can be quite pleasing, and is uncomparable with most other synthesis forms. Chords can make use of the feedback, which makes the strings cross-resonate, that is they influence eachother, an effect which when used also on more than a few strings, possibly combined with pitch bends, is quite unique for a synthesizer, and immedeately sets this program apart from most other things in synthesis.

The sound evolves all the time. even though without changing the source you basically get one type of simulation, the sound doesn't suffer from synthesized sound deadness.

There is considerable space to play around with the parameters in the source, the end points (damping), the feedback characteristics and position, and the

In older versions, I tried resampling the results, which was very worth it, but of course the quality of the sound suffers, so I'd better let the time parameter in the simulation gain flexibility.

The modulation wheel feedback control is interesting, and can make for electrical guitar like sounds for sure, though one to one comparision isn't possible. Luckily for the author, comparisons in the one to one area can start to be made with amplified acoustical steel string guitars, which is not unwelcome.

Future directions

Evidently, the 'user interface' is almost non-exisitng, except some importnant prototyping basics, to see if the application can run with 3D graphics. I've made tcl-tk linked versions in the past, which allowed the strings to be shown graphically, and I prepared a version where such a link, over a socket connection, allows real-tie insteraction over a Tk interface with the simulator state.

Clearly, one would like to be able to set various parameters sch as the gradual end-point damping, the pickup and feedback points, the characteristics of amplifier, and maybe the initialisation patterns for the strings beign plucked.Also, the is interestng to pay attention to the mixing and stereo image of the strings.

A delay of preferably less than a millisecond, and constant would be a whole lot better than the delay of about 40 or 60 millseconds I now get on a windows XP system.

Also, at times it might be preferable to make a plugin for for instance the Qubase sequencer.

Algorithmically, the string 'pluck' could be well improved, possibly modelled after examples from 'real' guitars, maybe samples could be used for the initial string excursion development, both for string exitation as for the sequential strum pattern as in the exact timing the strings are plucked in, possibly with sub-sample accuracy.

The current model shows no longitudinal effects, and has no 2 dimensional excursion or rotation. Also, local stiffness isn't taken into account, as well as non-linear string tension characteristics or (non-linear) air resistance.

The 'pickup' isn;t modeled specidically, which is possibly preferable, but every electrical guitarist knows that the not so incredibly effective tone control can at times have to be used quite accurately for 'the right sound', subleties which aren't included here, just like microphone or magnetical pickup element characteristics.

For acoustical guitars, the soundboard (cam and connection to the board) and whole enclosure filter the sound and add resonances, to a lesser degree this holds also for an electrical guitar.

Clearly, for most famouns electrical guitar sounds, effect units and very non-linear amplifiers are essential, which is a field of its own, and not covered much here. As every musician knows, a good instrument over bad amplification is bad, but a lousy instrument over any sound reinforcement system is worse. Any musical sample player user knows what that means in the area of synthesis. The theory behind this simulator is such that it should be a more 'alive' instrument basis, which in practice thus far proves true.

 home page [2]       email: [2]