pluck — Produces a naturally decaying plucked string or drum sound.
Audio output is a naturally decaying plucked string or drum sound based on the Karplus-Strong algorithms.
icps -- intended pitch value in Hz, used to set up a buffer of 1 cycle of audio samples which will be smoothed over time by a chosen decay method. icps normally anticipates the value of kcps, but may be set artificially high or low to influence the size of the sample buffer.
ifn -- table number of a stored function used to initialize the cyclic decay buffer. If ifn = 0, a random sequence will be used instead.
imeth -- method of natural decay. There are six, some of which use parameters values that follow.
simple averaging. A simple smoothing process, uninfluenced by parameter values.
stretched averaging. As above, with smoothing time stretched by a factor of iparm1 (>=1).
simple drum. The range from pitch to noise is controlled by a 'roughness factor' in iparm1 (0 to 1). Zero gives the plucked string effect, while 1 reverses the polarity of every sample (octave down, odd harmonics). The setting .5 gives an optimum snare drum.
stretched drum. Combines both roughness and stretch factors. iparm1 is roughness (0 to 1), and iparm2 the stretch factor (>=1).
weighted averaging. As method 1, with iparm1 weighting the current sample (the status quo) and iparm2 weighting the previous adjacent one. iparm1 + iparm2 must be <= 1.
1st order recursive filter, with coefs .5. Unaffected by parameter values.
iparm1, iparm2 (optional) -- parameter values for use by the smoothing algorithms (above). The default values are both 0.
kamp -- the output amplitude.
kcps -- the resampling frequency in cycles-per-second.
An internal audio buffer, filled at i-time according to ifn, is continually resampled with periodicity kcps and the resulting output is multiplied by kamp. Parallel with the sampling, the buffer is smoothed to simulate the effect of natural decay.
Plucked strings (1, 2, 5, 6) are best realized by starting with a random noise source, which is rich in initial harmonics. Drum sounds (methods 3, 4) work best with a flat source (wide pulse), which produces a deep noise attack and sharp decay.
The original Karplus-Strong algorithm used a fixed number of samples per cycle, which caused serious quantization of the pitches available and their intonation. This implementation resamples a buffer at the exact pitch given by kcps, which can be varied for vibrato and glissando effects. For low values of the orch sampling rate (e.g. sr = 10000), high frequencies will store only very few samples (sr / icps). Since this may cause noticeable noise in the resampling process, the internal buffer has a minimum size of 64 samples. This can be further enlarged by setting icps to some artificially lower pitch.
Here is an example of the pluck opcode. It uses the file pluck.csd.
Example 636. Example of the pluck opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if real audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o pluck.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 kcps = 220 icps = 220 ifn = 0 imeth = p4 asig pluck 0.7, 220, 220, ifn, imeth, .1, 10 outs asig, asig endin </CsInstruments> <CsScore> i 1 0 5 1 i 1 5 5 4 ;needs 2 extra parameters (iparm1, iparm2) i 1 10 5 6 e </CsScore> </CsoundSynthesizer>