views:

239

answers:

8

Is it possible to generate a musical instrument's sounds using only algorithms? or can it only be done via pre-recorded sound samples?

+5  A: 

It is completely possible - that is one of the things synthesizers do.

It being possible doesn't mean it is simple. Synthesizers are usually expensive, and the amount of algorithms used are complex - the wikipedia page I linked before has links to some of them.

Pre-recorded sounds are simpler and cheaper to use, but they also have their limitations - they sound more "repetitive" for example.

egarcia
+6  A: 

Wavetable synthesis (PDF) is the most realistic method of real-instrument synthesis, as it takes samples and alters them slightly (for example adding vibrato, expression etc).

The waveforms generated by most musical instruments (especially wind and brass instruments) are so complex that pure algorithmic synthesis is not yet optimised enough to run on current hardware - even if it were, the technical complexities of writing such an algorithm are huge.

Interesting site here.

Andy
Is there a tutorial on the net that shows how to generate the sound of a specific note of a specific instrument? eg. A4 on the piano (440Hz)A step by step guide with all equations and variables...
LaSha
@LaSha: from the page @Andy links to: "Ultimately, using additive synthesis is not efficient. In practice, you have to add a great many frequencies to make the sound realistic. I have come close to reproducing the note of an acoustic piano after adding nearly a hundred frequency components. Instruments that have sharp attack envelopes, like the hammer impact on a piano, require many frequencies just to get the sharp beginning to sound right."
egrunin
@ergrunin: It is true that many frequency components need to be added, but there are synthesis techniques such as FM (frequency modulation) that allow the addition of many frequency components with just a few sinusoids used to generate them. So its not necessarily true that additive synthesis is inefficient.
fsmc
+3  A: 

It certainly is, and there are many approaches. Wolfram recently released WolframTones, which (unsurprisingly, if you know Wolfram) uses cellular automata. A detailed description of how it functions is here.

Nick Johnson
+4  A: 

Several years back, Sound on Sound magazine ran an excellent series called "Synth Secrets" which can now be viewed online for free. They give a good introduction to the types of techniques used in hardware synthesizers (both analogue and digital), and includes some articles discussing the difficulties of replicating certain real-world instrument sounds such as plucked and bowed strings, brass, snare drums, acoustic pianos etc.

Mark Heath
+1  A: 

In addition to the answers provided here, there are also analysis synthesis frameworks that construct mathematical models (often based on capturing the trajectories of sinusoidal or noise components) of an input sound, allowing transformation and resynthesis. A few well-known frameworks are: SMS (available through the CLAM C++ project,) and Loris.

Physical models of instruments also are an option - they model the physical properties of an instrument such as reed stiffness, blowhole aperture, key clicking, and often produce realistic effects by incorporating non-linear effects such as overblowing. STK is one of these frameworks in C++.

These frameworks are generally more heavy then the wavetable synthesis option, but can provide more parameters for manipulation.

fsmc
+1  A: 

Karplus Strong Algorithm gives a very good synthesis of a plucked string. It can also be coded in a few lines of C. You create a circular buffer of floats (length proportional to the wavelength ie 1/f), and fill it full of random noise between -1 and 1.

Then you cycle through: each cycle, you replace the value at your current index with the average of the previous two values, and emit this new value.

index = (index+1) % bufSize; 
outVal = buf[index] = decay * 0.5 * ( buf[index-1] + buf[index-2] );

The resultant byte stream gives you your sound. Of course, this can be heavily optimised.

To make your soundwave damp to 0.15 of its original strength after one second, you could set decay thus:

#define DECAY_1S =.15
Float32 decay = pow(DECAY_1S, 1.0f / freq);

Note: you need to size the original buffer so that it contains one complete waveform. so if you wish to generate a 441Hz sound, and your sampling rate is 44.1KHz, then you will need to allocate 100 elements in your buffer.

You can think of this as a resonance chamber, whose fundamental frequency is 441Hz, initially energised, with energy dissipating outwards from every point in the ring simultaneously. Magically it seems to organise itself into overtones of a fundamental frequency.

Could anyone post more algorithms? How about an algorithm for a continuous tone?

Ohmu
+1  A: 

After several days of hunting, this the best resource I have found: https://ccrma.stanford.edu/~jos/

This is a treasure trove for the subject of synthesising sounds.

STK For example, this page links to a C example of synthesising a string, also a sound toolkit STK written in C++ for assisting this work.

This is going to keep me quiet for a few weeks while I dig through it.

Ohmu
A: 

Chuck

This PDF details how SMule created Ocarina for the iPhone (I'm sure everyone has seen the advert). they did it by porting Chuck - Strongly-timed, Concurrent, and On-the-fly Audio Programming Language

This is available for MacOS X, Windows, and Linux.

Ohmu