| 1 | <refentry id="diskgrain"> |
| 2 | <indexterm id="Indexdiskgrain"><primary>diskgrain</primary></indexterm> |
| 3 | <refentryinfo><title>Signal Generators:Granular Synthesis</title></refentryinfo> |
| 4 | <refmeta> |
| 5 | <refentrytitle>diskgrain</refentrytitle> |
| 6 | </refmeta> |
| 7 | |
| 8 | <refnamediv> |
| 9 | <refname>diskgrain</refname> |
| 10 | <refpurpose> |
| 11 | Synchronous granular synthesis, using a soundfile as source. |
| 12 | </refpurpose> |
| 13 | </refnamediv> |
| 14 | |
| 15 | <refsect1> |
| 16 | <title>Description</title> |
| 17 | <para> |
| 18 | <emphasis>diskgrain</emphasis> implements synchronous granular synthesis. The source sound for the grains is obtained by reading a soundfile containing the samples of the source waveform. |
| 19 | </para> |
| 20 | </refsect1> |
| 21 | |
| 22 | <refsect1> |
| 23 | <title>Syntax</title> |
| 24 | <synopsis>asig <command>diskgrain</command> Sfname, kamp, kfreq, kpitch, kgrsize, kprate, \ |
| 25 | ifun, iolaps [,imaxgrsize , ioffset]</synopsis> |
| 26 | </refsect1> |
| 27 | |
| 28 | <refsect1> |
| 29 | <title>Initialization</title> |
| 30 | <para> |
| 31 | <emphasis>Sfilename</emphasis> -- source soundfile. |
| 32 | </para> |
| 33 | <para> |
| 34 | <emphasis>ifun</emphasis> -- grain envelope function table. |
| 35 | </para> |
| 36 | <para> |
| 37 | <emphasis>iolaps</emphasis> -- maximum number of overlaps, max(kfreq)*max(kgrsize). Estimating |
| 38 | a large value should not affect performance, but exceeding this value will probably have disastrous |
| 39 | consequences. |
| 40 | </para> |
| 41 | <para> |
| 42 | <emphasis>imaxgrsize</emphasis> -- max grain size in secs (default 1.0). |
| 43 | </para> |
| 44 | <para> |
| 45 | <emphasis>ioffset</emphasis> -- start offset in secs from beginning of file (default: 0). |
| 46 | </para> |
| 47 | |
| 48 | </refsect1> |
| 49 | |
| 50 | <refsect1> |
| 51 | <title>Performance</title> |
| 52 | <para> |
| 53 | <emphasis>kamp</emphasis> -- amplitude scaling |
| 54 | </para> |
| 55 | <para> |
| 56 | <emphasis>kfreq</emphasis> -- frequency of grain generation, or density, in grains/sec. |
| 57 | </para> |
| 58 | |
| 59 | <para> |
| 60 | <emphasis>kpitch</emphasis> -- grain pitch scaling (1=normal pitch, < 1 lower, > 1 higher; negative, backwards) |
| 61 | </para> |
| 62 | |
| 63 | <para> |
| 64 | <emphasis>kgrsize</emphasis> -- grain size in secs. |
| 65 | </para> |
| 66 | <para> |
| 67 | <emphasis>kprate</emphasis> -- readout pointer rate, in |
| 68 | grains. The value of 1 will advance the reading pointer 1 grain |
| 69 | ahead in the source table. Larger values will time-compress and |
| 70 | smaller values will time-expand the source signal. Negative |
| 71 | values will cause the pointer to run backwards and zero will |
| 72 | freeze it. |
| 73 | </para> |
| 74 | <para> |
| 75 | The grain generator has full control of frequency (grains/sec), |
| 76 | overall amplitude, grain pitch (a sampling increment) and grain |
| 77 | size (in secs), both as fixed or time-varying (signal) |
| 78 | parameters. An extra parameter is the grain pointer speed (or |
| 79 | rate), which controls which position the generator will start |
| 80 | reading samples in the file for each successive grain. It is |
| 81 | measured in fractions of grain size, so a value of 1 (the |
| 82 | default) will make each successive grain read from where the |
| 83 | previous grain should finish. A value of 0.5 will make the next |
| 84 | grain start at the midway position from the previous grain start |
| 85 | and finish, etc.. A value of 0 will make the generator read |
| 86 | always from a fixed position (wherever the pointer was last at). |
| 87 | A negative value will decrement pointer positions. This control |
| 88 | gives extra flexibility for creating timescale modifications in |
| 89 | the resynthesis. |
| 90 | </para> |
| 91 | <para> |
| 92 | <emphasis>Diskgrain</emphasis> will generate any number of |
| 93 | parallel grain streams (which will depend on grain |
| 94 | density/frequency), up to the olaps value (default 100). The |
| 95 | number of streams (overlapped grains) is determined by |
| 96 | grainsize*grain_freq. More grain overlaps will demand more |
| 97 | calculations and the synthesis might not run in realtime |
| 98 | (depending on processor power). |
| 99 | </para> |
| 100 | <para> |
| 101 | <emphasis>Diskgrain</emphasis> can simulate FOF-like formant |
| 102 | synthesis, provided that a suitable shape is used as grain |
| 103 | envelope and a sinewave as the grain wave. For this use, grain |
| 104 | sizes of around 0.04 secs can be used. The formant centre |
| 105 | frequency is determined by the grain pitch. Since this is a |
| 106 | sampling increment, in order to use a frequency in Hz, that |
| 107 | value has to be scaled by tablesize/sr. Grain frequency will |
| 108 | determine the fundamental. |
| 109 | </para> |
| 110 | <para> |
| 111 | This opcode is a variation on the <link |
| 112 | linkend="syncgrain"><citetitle>syncgrain</citetitle></link> |
| 113 | opcode. |
| 114 | </para> |
| 115 | <para> |
| 116 | <note>diskgrain does not do any resanmpling, so if the |
| 117 | sample rate of the source filename is not the same as csound's sr |
| 118 | value there will be pitch shifts |
| 119 | </note> |
| 120 | </para> |
| 121 | </refsect1> |
| 122 | <refsect1> |
| 123 | <title>Examples</title> |
| 124 | <para> |
| 125 | Here is an example of the diskgrain opcode. It uses the file <ulink url="examples/diskgrain.csd"><citetitle>diskgrain.csd</citetitle></ulink>. |
| 126 | <example> |
| 127 | <title>Example of the diskgrain opcode.</title> |
| 128 | <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> |
| 129 | <xi:include href="examples-xml/diskgrain.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 130 | </example> |
| 131 | </para> |
| 132 | </refsect1> |
| 133 | |
| 134 | <refsect1> |
| 135 | <title>See Also</title> |
| 136 | <para> |
| 137 | <link linkend="SiggenGranular"><citetitle>Granular Synthesis</citetitle></link> |
| 138 | </para> |
| 139 | </refsect1> |
| 140 | |
| 141 | <refsect1> |
| 142 | <title>Credits</title> |
| 143 | <para> |
| 144 | <simplelist> |
| 145 | <member>Author: &namevictor;</member> |
| 146 | <member>May 2007</member> |
| 147 | </simplelist> |
| 148 | New in Csound 5.06 |
| 149 | </para> |
| 150 | </refsect1> |
| 151 | </refentry> |