| 1 | |
| 2 | <refentry id="grain2"> |
| 3 | <indexterm id="IndexGrain2"><primary>grain2</primary></indexterm> |
| 4 | <refentryinfo><title>Signal Generators:Granular Synthesis</title></refentryinfo> |
| 5 | <refmeta> |
| 6 | <refentrytitle>grain2</refentrytitle> |
| 7 | </refmeta> |
| 8 | |
| 9 | |
| 10 | |
| 11 | <refnamediv> |
| 12 | <refname>grain2</refname> |
| 13 | <refpurpose> |
| 14 | Easy-to-use granular synthesis texture generator. |
| 15 | </refpurpose> |
| 16 | </refnamediv> |
| 17 | |
| 18 | <refsect1> |
| 19 | <title>Description</title> |
| 20 | <para> |
| 21 | Generate granular synthesis textures. <emphasis>grain2</emphasis> is simpler to use, but <link linkend="grain3"><citetitle>grain3</citetitle></link> offers more control. |
| 22 | </para> |
| 23 | </refsect1> |
| 24 | |
| 25 | <refsect1> |
| 26 | <title>Syntax</title> |
| 27 | <synopsis>ares <command>grain2</command> kcps, kfmd, kgdur, iovrlp, kfn, iwfn [, irpow] \ |
| 28 | [, iseed] [, imode]</synopsis> |
| 29 | </refsect1> |
| 30 | |
| 31 | <refsect1> |
| 32 | <title>Initialization</title> |
| 33 | <para> |
| 34 | <emphasis>iovrlp</emphasis> -- (fixed) number of overlapping grains. |
| 35 | </para> |
| 36 | |
| 37 | <para> |
| 38 | <emphasis>iwfn</emphasis> -- function table containing window waveform (Use <link linkend="GEN20">GEN20</link> to calculate <emphasis>iwfn</emphasis>). |
| 39 | </para> |
| 40 | |
| 41 | <para> |
| 42 | <emphasis>irpow</emphasis> (optional, default=0) -- this value controls the distribution of grain frequency variation. If <emphasis>irpow</emphasis> is positive, the random distribution (<emphasis>x</emphasis> is in the range -1 to 1) is <literallayout>abs(x) ˆ ((1 / irpow) - 1);</literallayout> for negative <emphasis>irpow</emphasis> values, it is <literallayout>(1 - abs(x)) ˆ ((-1 / irpow) - 1)</literallayout>Setting <emphasis>irpow</emphasis> to -1, 0, or 1 will result in uniform distribution (this is also faster to calculate). The image below shows some examples for <emphasis>irpow</emphasis>. The default value of <emphasis>irpow</emphasis> is 0. |
| 43 | </para> |
| 44 | |
| 45 | <para> |
| 46 | <mediaobject> |
| 47 | <imageobject> |
| 48 | <imagedata fileref="images/grain2_rand-448x289.png" format="PNG"/> |
| 49 | </imageobject> |
| 50 | |
| 51 | <textobject> |
| 52 | <phrase>[A graph of distributions for different values of <emphasis>irpow</emphasis>.]</phrase> |
| 53 | </textobject> |
| 54 | |
| 55 | <caption> |
| 56 | <para>A graph of distributions for different values of <emphasis>irpow</emphasis>.</para> |
| 57 | </caption> |
| 58 | </mediaobject> |
| 59 | </para> |
| 60 | |
| 61 | <para> |
| 62 | <emphasis>iseed</emphasis> (optional, default=0) -- seed value for random number generator (positive integer in the range 1 to 2147483646 (2<superscript>31</superscript> - 2)). Zero or negative value seeds from current time (this is also the default). |
| 63 | </para> |
| 64 | |
| 65 | <para> |
| 66 | <emphasis>imode</emphasis> (optional default=0) -- sum of the following values: |
| 67 | <itemizedlist> |
| 68 | <listitem><para><emphasis>8:</emphasis> interpolate window waveform (slower).</para></listitem> |
| 69 | <listitem><para><emphasis>4:</emphasis> do not interpolate grain waveform (fast, but lower quality).</para></listitem> |
| 70 | <listitem><para><emphasis>2:</emphasis> grain frequency is continuously modified by <emphasis>kcps</emphasis> and <emphasis>kfmd</emphasis> (by default, each grain keeps the frequency it was launched with). This may be slower at high control rates.</para></listitem> |
| 71 | <listitem><para><emphasis>1:</emphasis> skip initialization.</para></listitem> |
| 72 | </itemizedlist> |
| 73 | </para> |
| 74 | |
| 75 | </refsect1> |
| 76 | |
| 77 | <refsect1> |
| 78 | <title>Performance</title> |
| 79 | <para> |
| 80 | <emphasis>ares</emphasis> -- output signal. |
| 81 | </para> |
| 82 | |
| 83 | <para> |
| 84 | <emphasis>kcps</emphasis> -- grain frequency in Hz. |
| 85 | </para> |
| 86 | |
| 87 | <para> |
| 88 | <emphasis>kfmd</emphasis> -- random variation (bipolar) in grain frequency in Hz. |
| 89 | </para> |
| 90 | |
| 91 | <para> |
| 92 | <emphasis>kgdur</emphasis> -- grain duration in seconds. <emphasis>kgdur</emphasis> 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 <emphasis>imode</emphasis> flags. |
| 93 | </para> |
| 94 | |
| 95 | <para> |
| 96 | <emphasis>kfn</emphasis> -- 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 <link linkend="GEN30">GEN30</link>, to avoid aliasing). |
| 97 | </para> |
| 98 | |
| 99 | <note> |
| 100 | <title>Note</title> |
| 101 | <para> |
| 102 | <emphasis>grain2</emphasis> internally uses the same random number generator as <emphasis>rnd31</emphasis>. So reading <link linkend="rnd31"><citetitle>its documentation</citetitle></link> is also recommended. |
| 103 | </para> |
| 104 | </note> |
| 105 | </refsect1> |
| 106 | |
| 107 | <refsect1> |
| 108 | <title>Examples</title> |
| 109 | <para> |
| 110 | Here is an example of the grain2 opcode. It uses the file <ulink url="examples/grain2.csd"><citetitle>grain2.csd</citetitle></ulink>. |
| 111 | |
| 112 | <example> |
| 113 | <title>Example of the grain2 opcode.</title> |
| 114 | |
| 115 | <para>See the sections <link linkend="UsingRealTime"><citetitle>Real-time Audio</citetitle></link> and <link linkend="CommandFlags"><citetitle>Command Line Flags</citetitle></link> for more information on using command line flags.</para> |
| 116 | <xi:include href="examples-xml/grain2.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 117 | </example> |
| 118 | </para> |
| 119 | </refsect1> |
| 120 | |
| 121 | <refsect1> |
| 122 | <title>See Also</title> |
| 123 | <para> |
| 124 | <link linkend="SiggenGranular"><citetitle>Granular Synthesis</citetitle></link> |
| 125 | </para> |
| 126 | </refsect1> |
| 127 | |
| 128 | <refsect1> |
| 129 | <title>Credits</title> |
| 130 | <para> |
| 131 | <simplelist> |
| 132 | <member>Author: &nameistvan;</member> |
| 133 | </simplelist> |
| 134 | </para> |
| 135 | |
| 136 | <para>New in version 4.15</para> |
| 137 | <para>Updated April 2002 by &nameistvan;</para> |
| 138 | </refsect1> |
| 139 | </refentry> |