Csound Granular Synthesis opcode Example

This text, copied from the Csound Manual[4] shows the various controls for one of the Csound's Granular Synthesis opcodes5.1 grain3 Accessed: March 14, 2011

grain3

grain3 Generate granular synthesis textures with more user control.

Description: Generate granular synthesis textures. grain2 is simpler to use but grain3 offers more control.

Syntax: ares grain3 kcps, kphs, kfmd, kpmd, kgdur, kdens, imaxovr, kfn, iwfn, kfrpow, kprpow [, iseed] [, imode]

Initialization:

imaxovr
maximum number of overlapping grains. The number of overlaps can be calculated by (kdens * kgdur); however, it can be overestimated at no cost in rendering time, and a single overlap uses (depending on system) 16 to 32 bytes of memory.
iwfn
function table containing window waveform (Use GEN20 to calculate iwfn).
iseed
(optional, default=0) seed value for random number generator (positive integer in the range 1 to 2147483646 (231 - 2)). Zero or negative value seeds from current time (this is also the default).
imode
(optional, default=0) sum of the following values:

Performance:

ares
output signal.
kcps
grain frequency in Hz.
kphs
grain phase. This is the location in the grain waveform table, expressed as a fraction (between 0 to 1) of the table length.
kfmd
random variation (bipolar) in grain frequency in Hz.
kpmd
random variation (bipolar) in start phase.
kgdur
grain duration in seconds. kgdur also controls the duration of already active grains (actually the speed at which the window function is read). This behavior does not depend on the imode flags.
kdens
number of grains per second.
kfrpow
this value controls the distribution of grain frequency variation. If kfrpow is positive, the random distribution (x is in the range -1 to 1) is 41#41 for negative kfrpow values, it is 42#42 Setting kfrpow to -1, 0, or 1 will result in uniform distribution (this is also faster to calculate). The image below shows some examples for kfrpow. The default value of kfrpow is 0.
kprpow
distribution of random phase variation (see kfrpow). Setting kphs and kpmd to 0.5, and kprpow to 0 will emulate grain2.
kfn
function table containing grain waveform. Table number can be changed at k-rate (this is useful to select from a set of band-limited tables generated by GEN30, to avoid aliasing).

Mehmet Okonsar 2011-03-14