Drum_KS uses a method designed by Kevin Karplus and Alex Strong to create a drum sound using very little computation. The algorithm is as follows: Start with wavetable X = of length p, X(t) = { + 1/2 (X(t-p) + X(t-p+1)) with probability b { - 1/2 (X(t-p) + X(t-p+1)) with probability 1-b for t > p. Since b introduces randomness into the sound, the initial wavetable can be anything from a completely random signal to a sine wave to a constant! The wavetable length p effects the decay rate of the sound (big p = long decay) as well as the pitch somewhat (big p = low pitch). p should be in a range from about 150 to 500. The probability b is called the blend factor and can range from 0 to 1, though values of exactly 0 and 1 only work with a random wavetable. b = 1/2 introduces the most randomness and produces the best "snare" sounds. b near 0 simply averages the samples, and produces string-like sounds where p controls the pitch. b = 0 doesn't work for constant or sine wavetables. b near 1 produces wierd electric crash cymbal-like sounds where most of the pitches die out quickly. b = 1 doesn't work for constant or sine wavetables. Snare sounds: (b = 0.5-0.6, p = 250-300, constant/random wavetables) drum_KS(1,0.5,250,'c'); drum_KS(1,0.5,300,'r'); drum_KS(1,0.6,300,'r'); Crash cymbal sounds: (b > 0.98, p = 200-800, random wavetable, decaying envelope) These have a long decay, so I had to add an envelope in order to fade out the end of the sound. The lower pitches seem to decay quicker. With b=1, the alogorithm works as a negative averaging function, so it doesn't work on constant or sine wavetables. drum_KS(1,.99,200,'r'); drum_KS(1,1,200,'r',[ones(1,8000),1:-0.0005:0]); drum_KS(1,1,400,'r',[ones(1,8000),1:-0.0005:0]); drum_KS(1,1,800,'r',[ones(1,8000),1:-0.0005:0]); Metallic plink sounds: (b > 0.98, p = 5-50, random wavetable) Envelope decay usually needed for b = 1. Odd p decay faster! drum_KS(1,.98,20,'r'); drum_KS(1,.98,50,'r'); drum_KS(1,1,5,'r'); drum_KS(1,1,25,'r',[ones(1,8000),1.01-logspace(-2,0,2000)]); drum_KS(1,1,9,'r'); String sounds: (b < 0.05, p = 20-400, random wavetable, decaying envelope) These can have a long decay time, so I added a logarithmic decay envelope to some. drum_KS(1,0,50,'r'); drum_KS(1,0.05,20,'r'); drum_KS(1,0,100,'r',[ones(1,8000),1.01-logspace(-2,0,2000)]); drum_KS(1,0,200,'r',[ones(1,16000),1.01-logspace(-2,0,2000)]); This algorithm is very hardware-efficient, as it only needs 1-bit of randomness, one addition/subtraction, and a 1-bit shift (to divide by 2) for each sample. Of course it is actually pretty slow on a modern 32-bit computer, where it uses several 32-bit instructions for every 1-bit operation! One neat feature of this algorithm is that it always because it produces a slightly different sound every time. Note that these function calls use Matlab's sample frequency of 8192 Hz.