开发者

Generate musical instrument sounds algorithmically

Is it possible to generate a musi开发者_开发问答cal instrument's sounds using only algorithms? or can it only be done via pre-recorded sound samples?


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.


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.


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.


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.


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.


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?


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.


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.


I've had a lot of success and fun with FM synthesis. It is a computationally light method, and is the source of a huge number of pop synth sounds from the 1980's (being the basis of the ubiquitous Yamaha DX-7).

I do use it for generating sound on the fly rather than using recordings. A simple example of a string synth sound generated on the fly can be had (free download, Win64) from http://philfrei.itch.io/referencenotekeyboard. The organ synth on that same program is a simple additive synthesis algo.

I would have to dig around for some good tutorials on this. I know we discussed it a bunch at java-gaming.org, when I was trying to figure it out, and then when helping nsigma work out a kink in his FM algo. The main thing is to use phase rather than frequency modulation if you want to chain more than a single modulator to a carrier.

Which reminds me! A kind of amazing java-based sound generator to check out, allows the generation of a number of different forms of synthesis, with real time control: PraxisLIVE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜