It's been a while since my last post, but much real life stuff has been going on in the last year, and I haven't had the opportunity to do much programming.
Anyway onto todays topic .. after having spent a bit of time working on my sequencer / sampling / composing program, I thought it would be fun to have a go at little programs for synthesizing instrument sounds, either to import the results as samples into the composer program, or to develop a plugin architecture for instruments, similar to the steinberg VST instrument approach (but on a more basic level).
So it occurred to me that by using some simple physics models, it might be possible to get some interesting sounds from the complexity that often occurs in physics simulations. Obvious candidates seem to be a string (such as a guitar or piano) and a drum skin, the drum skin being a 2 dimensional version of the 1d string simulation.
I have a very vague idea of how the string system works, depending on the length of the string you can get a base oscillation with the wavelength of the string, then various overtones where multiple oscillations can fit into the length of the string.
After a quick google it (not surprisingly) seems several people have used the same approach, I found an interesting thesis on the subject by Balazs Bank, with some very impressive piano simulations, which got me interested!
Anyway I have had a quick go at doing a very simple simulation of a 1d string, then exporting the results as a wav file.
Each element of the string has a 1d position (amplitude) and 1d velocity, with the velocity altered according to the distance to each of the neighbouring elements (i.e. a lower neighbour pulls the element down, and vice versa). This velocity is used to determine changes to the position, and finally damping is applied to the velocity each iteration. Each end element of the string is clamped to 0.0 position and 0.0 velocity. A very simple model really, but enough to get some waveforms happening!
I really want to get things happening with a decent length string (hundreds of elements) but for now I've just been trying small numbers .. presumably the results depend on the parameters used for applying velocity, damping etc.
So here's some results:
3 elements (1 active element, as the ends of the string are clamped to 0.0)
5 elements
7 elements
21 elements
So far for 'listening' to the result I had just been outputting the amplitude of the middle element of the string. Instead I decided to take a slightly more realistic approach and sum the amplitudes of each element of the string:
21 elements (summed amplitudes)
This muffled off a lot of the higher frequencies and made a bit more of a realistic sound. Presumably in a real instrument the way different frequencies are muffled off or amplified can depend on things such as the shape and resonant frequencies of the box around the string (the wood around a violin for example).
Not really any super usable sounds yet, but quite promising for an hour or so's coding.