grain3
Generate granular synthesis textures with more user control.
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 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:
- 64: synchronize start phase of grains to kcps.
- 32: start all grains at integer sample location. This may be faster in some cases, however it also makes the timing of grain envelopes less accurate.
- 16: do not render grains with start time less than zero. (see the image below; this option turns off grains marked with red on the image).
- 8: interpolate window waveform (slower).
- 4: do not interpolate grain waveform (fast, but lower quality).
- 2: grain frequency is continuously modified by kcps and kfmd (by default, each grain keeps the frequency it was launched with). This may be slower at high control rates. It also controls phase modulation (kphs).
- 1: skip initialization.
![[A diagram showing grains with a start time less than zero in red.]](../../images/grain3_2.png)
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:
for negative kfrpow values, it is:
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.
![[A graph of distributions for different values of .]](../../images/grain2_rand-448x289.png)
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 Use GEN30, to avoid aliasing).
Note
grain3 internally uses the same random number generator as rnd31. So reading its documentation is also recommended.
Examples
Here is an example of the grain3 opcode. It uses the file grain3.csd.
Example of the grain3 opcode. | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
See Also
Credits
Author: Istvan Varga
New in version 4.15
Updated April 2002 by Istvan Varga