views:

1082

answers:

6

Back in a freshman or software programming class we had to write a program that would simulate the sound of a guitar pluck.

I can make pure sin waves all day, but I am trying to remember how to do a sound like a guitar pluck. I remember it had something to with using random() and a falloff constant added to the sin wave, but I can not remember the details.

+7  A: 

I think I found just what you are looking for.

cdonner
+11  A: 

It is a really challenging problem to generate synthetic sounds that sound natural. There are many techniques - some simple, some really complex. To get good results you will have to use one of the more complex algorithms.

  • Subtractive synthesis
  • Additive synthesis
  • Granular synthesis
  • Wavetable synthesis
  • Frequency modulation synthesis
  • Phase distortion synthesis
  • Physical modeling synthesis
  • Sample-based synthesis
  • Subharmonic synthesis

This are some synthesis methods taken from Wikipedia. Physical modeling can produce really good sounds but this shows in the complexity of the method - the idea is simple, the implementation hard.

You should probably start with additive synthesis. For this just add sine waves of the fundamental frequency and integer multiplies. For example 440 Hz, 880Hz, 1320 Hz, ... The amplitude should drop exponentially with the frequency. Information about the structure of the components is best found in scientific papers about music instrument analysis. Finally you must modulate the amplitude of the signal with an timevarying envelope. The structure for a guitar can be found in mentioned papers, too.


The links from cdonner (Plucking a Guitar String - Karplus-Strong algorithm) and Dervin Thunk (Physical modeling) sound promising. A really simple approximation of full physical modeling with differential equations. Maybe quite limited to guitar strings and similar instruments, but exactly what you are looking for and surely simpler to do than tuning a additive model. I will try it myself if I find some time over the weekend; really exited what one can get out of the algorithm.

Daniel Brückner
+1  A: 

As a starting off point, you may want to look at some waveforms of guitar sounds. I would check out this posting by Bob Sturm on the MathWorks File Exchange. It looks like it contains a bunch of signal processing demos, and there are some .wav files included for many instruments, including a guitar. You can load them into MATLAB with WAVREAD, and then start figuring out how you might replicate the waveform (i.e. what sort of decay over time you will use, etc.).

gnovice
+2  A: 

Guitar synthesis is a particularly tricky problem because of the almost infinite number of ways of fingering the fretboard, and exciting the string.

Essentially the string will oscillate at its base frequency plus a number of harmonic with much much less energy. I'd recommend looking at the Fourier plot of a single un-fretted string pick.

You can get the steady state sound of the string pretty close by adding in the correct harmonics, but you also need to remember to simulate the attack, sustain and decay periods correctly: the amplitude will rise sharply (and probably peak) when the string is picked. It will drop off a little and sustain (hold mostly constant) for a short period and finally decay over a longer period. You need to get this right for it to sound like a guitar and not something else.

Adam Hawes
A: 

Considering it was a 1st-year (I had to look up "Freshman") programming class, my assumption would be that they were looking for a simple plucked-string filter, rather than an accurate physical simulation of a guitar (although that could probably get you extra credit). This is a common assignment when studying digital signal processing.

The filter consists of a delay loop which feeds through a low-pass filter and is mixed in with the input. To play a note, you send a short, broad-spectrum signal into the input (eg: a burst of white noise). This travels around the delay loop, losing some of its high-frequency components each time. The length of the delay loop defines the resonant frequency of the string.

geofftnz
A: 

On Windows, use Win32 MM apis (5 lines of code)