| 1 | |
| 2 | <refentry id="GENfarey"> |
| 3 | <indexterm id="IndexGENfarey"><primary>GENfarey</primary></indexterm> |
| 4 | <refmeta> |
| 5 | <refentrytitle>GENfarey</refentrytitle> |
| 6 | </refmeta> |
| 7 | |
| 8 | <refnamediv> |
| 9 | <refname>"farey"</refname> |
| 10 | <refpurpose> |
| 11 | Fills a table with the Farey Sequence F<subscript>n</subscript> of the integer n. |
| 12 | </refpurpose> |
| 13 | </refnamediv> |
| 14 | |
| 15 | <refsect1> |
| 16 | <title>Description</title> |
| 17 | <para>Plugin gen in fareygen.</para> |
| 18 | <para> |
| 19 | A Farey Sequence F<subscript>n</subscript> of order n is a list of fractions in their lowest terms between 0 and 1 and in ascending order. Their denominators do not exceed n. |
| 20 | This means a fraction a/b belongs to F<subscript>n</subscript> if 0 ≤ a ≤ b ≤ n. |
| 21 | The numerator and denominator of each fraction are always coprime. |
| 22 | 0 and 1 are included in F<subscript>n</subscript> as the fractions 0/1 and 1/1. |
| 23 | For example F<subscript>5</subscript> = {0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1} |
| 24 | Some properties of the Farey Sequence: |
| 25 | <itemizedlist> |
| 26 | <listitem> |
| 27 | If a/b and c/d are two successive terms of F<subscript>n</subscript>, then bc - ad = 1. |
| 28 | </listitem> |
| 29 | <listitem> |
| 30 | If a/b, c/d, e/f are three successive terms of F<subscript>n</subscript>, then: |
| 31 | c/d = (a+e) / (b+f). |
| 32 | In this case c/d is called the mediant fraction between a/b and e/f. |
| 33 | </listitem> |
| 34 | <listitem> |
| 35 | If n > 1, then no two successive terms ofF<subscript>n</subscript> have the same denominator. |
| 36 | </listitem> |
| 37 | </itemizedlist> |
| 38 | </para> |
| 39 | <para> |
| 40 | The length of any Farey Sequence F<subscript>n</subscript> is determined by |
| 41 | |F<subscript>n</subscript>| = 1 + SUM over n (phi(m)) |
| 42 | where phi(m) is Euler's totient function, which gives the number of integers ≤ m that are coprime to m. |
| 43 | </para> |
| 44 | <para> |
| 45 | Some values for the length of F<subscript>n</subscript> given n: |
| 46 | <informaltable> |
| 47 | <tgroup cols="2"> |
| 48 | <thead> |
| 49 | <row> |
| 50 | <entry>n</entry> |
| 51 | <entry>F<subscript>n</subscript></entry> |
| 52 | </row> |
| 53 | </thead> |
| 54 | <tbody> |
| 55 | <row> |
| 56 | <entry>1</entry> |
| 57 | <entry>2</entry> |
| 58 | </row> |
| 59 | <row> |
| 60 | <entry>2</entry> |
| 61 | <entry>3</entry> |
| 62 | </row> |
| 63 | <row> |
| 64 | <entry>3</entry> |
| 65 | <entry>5</entry> |
| 66 | </row> |
| 67 | <row> |
| 68 | <entry>4</entry> |
| 69 | <entry>7</entry> |
| 70 | </row> |
| 71 | <row> |
| 72 | <entry>5</entry> |
| 73 | <entry>11</entry> |
| 74 | </row> |
| 75 | <row> |
| 76 | <entry>6</entry> |
| 77 | <entry>13</entry> |
| 78 | </row> |
| 79 | <row> |
| 80 | <entry>7</entry> |
| 81 | <entry>19</entry> |
| 82 | </row> |
| 83 | <row> |
| 84 | <entry>8</entry> |
| 85 | <entry>23</entry> |
| 86 | </row> |
| 87 | <row> |
| 88 | <entry>9</entry> |
| 89 | <entry>29</entry> |
| 90 | </row> |
| 91 | <row> |
| 92 | <entry>10</entry> |
| 93 | <entry>33</entry> |
| 94 | </row> |
| 95 | <row> |
| 96 | <entry>11</entry> |
| 97 | <entry>43</entry> |
| 98 | </row> |
| 99 | <row> |
| 100 | <entry>12</entry> |
| 101 | <entry>47</entry> |
| 102 | </row> |
| 103 | <row> |
| 104 | <entry>13</entry> |
| 105 | <entry>59</entry> |
| 106 | </row> |
| 107 | <row> |
| 108 | <entry>14</entry> |
| 109 | <entry>65</entry> |
| 110 | </row> |
| 111 | <row> |
| 112 | <entry>15</entry> |
| 113 | <entry>73</entry> |
| 114 | </row> |
| 115 | <row> |
| 116 | <entry>16</entry> |
| 117 | <entry>81</entry> |
| 118 | </row> |
| 119 | <row> |
| 120 | <entry>17</entry> |
| 121 | <entry>97</entry> |
| 122 | </row> |
| 123 | <row> |
| 124 | <entry>18</entry> |
| 125 | <entry>103</entry> |
| 126 | </row> |
| 127 | <row> |
| 128 | <entry>19</entry> |
| 129 | <entry>121</entry> |
| 130 | </row> |
| 131 | <row> |
| 132 | <entry>20</entry> |
| 133 | <entry>129</entry> |
| 134 | </row> |
| 135 | </tbody> |
| 136 | </tgroup> |
| 137 | </informaltable> |
| 138 | </para> |
| 139 | </refsect1> |
| 140 | <refsect1> |
| 141 | <title>Syntax</title> |
| 142 | <synopsis><command>f</command> # time size "farey" fareynum mode</synopsis> |
| 143 | </refsect1> |
| 144 | <refsect1> |
| 145 | <title>Initialization</title> |
| 146 | <para> |
| 147 | <emphasis>size</emphasis> -- number of points in the table. Must |
| 148 | be a power of 2 or power-of-2 plus 1 (see <link |
| 149 | linkend="f"><citetitle>f statement</citetitle></link>). |
| 150 | </para> |
| 151 | |
| 152 | <para> |
| 153 | <emphasis>fareynum</emphasis> -- the integer n for generating Farey Sequence F<subscript>n</subscript> |
| 154 | </para> |
| 155 | <para> |
| 156 | <emphasis>mode</emphasis> -- integer to trigger a specific |
| 157 | output to be written into the table: |
| 158 | <itemizedlist> |
| 159 | <listitem> |
| 160 | <para>0 -- outputs floating point numbers representing the |
| 161 | elements of F<subscript>n</subscript>.</para> |
| 162 | </listitem> |
| 163 | <listitem> |
| 164 | <para> 1 -- outputs delta values of successive elements of |
| 165 | F<subscript>n</subscript>, useful for generating note durations for |
| 166 | example.</para> |
| 167 | </listitem> |
| 168 | <listitem> |
| 169 | <para> 2 -- outputs only the denominators of the integer |
| 170 | ratios, useful for indexing other tables or instruments for |
| 171 | example.</para> |
| 172 | </listitem> |
| 173 | <listitem> |
| 174 | <para> 3 -- same as mode 2 but with normalised |
| 175 | output.</para> |
| 176 | </listitem> |
| 177 | <listitem> |
| 178 | <para> 4 -- same as mode 0 but with 1 added to each number, |
| 179 | useful for generating tables for tuning opcodes, for example |
| 180 | <emphasis>cps2pch</emphasis>. |
| 181 | </para> |
| 182 | </listitem> |
| 183 | </itemizedlist> |
| 184 | </para> |
| 185 | </refsect1> |
| 186 | |
| 187 | <refsect1> |
| 188 | <title>Examples</title> |
| 189 | <para> |
| 190 | <informalexample> |
| 191 | <programlisting> |
| 192 | <emphasis role="stamnt">f</emphasis>1 0 -23 "farey" 8 0</programlisting> |
| 193 | Generates generates Farey Sequence F<subscript>8</subscript>. The table contains all |
| 194 | 23 elements of F<subscript>8</subscript> as floating point numbers. |
| 195 | |
| 196 | <programlisting> |
| 197 | <emphasis role="stamnt">f</emphasis>1 0 -18 "farey" 7 1</programlisting> |
| 198 | This generates Farey Sequence F<subscript>7</subscript>. The table contains 18 delta values of F<subscript>7</subscript>, |
| 199 | i.e. the difference between r<subscript>i+1</subscript> - r<subscript>i</subscript>, where r is the ith element of F<subscript>n</subscript>. |
| 200 | |
| 201 | <programlisting> |
| 202 | <emphasis role="stamnt">f</emphasis>1 0 -43 "farey" 11 2</programlisting> |
| 203 | This generates Farey Sequence F<subscript>11</subscript>. The table contains the denominators of all |
| 204 | 43 fractions in F<subscript>11</subscript>. |
| 205 | |
| 206 | <programlisting> |
| 207 | <emphasis role="stamnt">f</emphasis>1 0 -43 "farey" 11 3</programlisting> |
| 208 | This generates Farey Sequence F<subscript>11</subscript>. The table contains the denominators of all |
| 209 | 43 fractions in F<subscript>11</subscript>, each of those divided by 11, i.e. normalised. |
| 210 | |
| 211 | <programlisting> |
| 212 | <emphasis role="stamnt">f</emphasis>1 0 -18 "farey" 7 4</programlisting> |
| 213 | This generates Farey Sequence F<subscript>7</subscript>. The table contains all fractions of F<subscript>7</subscript>, |
| 214 | same as mode 0, but this time '1' is added to each table element. |
| 215 | </informalexample> |
| 216 | </para> |
| 217 | <para> |
| 218 | <example> |
| 219 | <title>A simple example of the GENfarey routine.</title> |
| 220 | <para> |
| 221 | 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. |
| 222 | </para> |
| 223 | <xi:include href="examples-xml/genfarey.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 224 | </example> |
| 225 | </para> |
| 226 | |
| 227 | <para> |
| 228 | Here is a complete example of the GENfarey routine. It uses the files <ulink url="examples/genfarey-2.csd"><citetitle>genfarey-2.csd</citetitle></ulink>. |
| 229 | <example> |
| 230 | <title>Another example of the GENfarey routine.</title> |
| 231 | <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> |
| 232 | <xi:include href="examples-xml/genfarey-2.csd.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> |
| 233 | </example> |
| 234 | |
| 235 | <textobject> |
| 236 | <phrase>These are the diagrams of the waveforms of the GENfarey routines, as used in the example:</phrase> |
| 237 | </textobject> |
| 238 | |
| 239 | <mediaobject> |
| 240 | <imageobject> |
| 241 | <imagedata fileref="images/genfarey-2_1.png" format="PNG"/> |
| 242 | </imageobject> |
| 243 | |
| 244 | <textobject> |
| 245 | <phrase>gidelta ftgen 100,0,-18,"farey",7,1 - delta values of Farey Sequence 7</phrase> |
| 246 | </textobject> |
| 247 | |
| 248 | <caption> |
| 249 | <para>gidelta ftgen 100,0,-18,"farey",7,1 - delta values of Farey Sequence 7</para> |
| 250 | </caption> |
| 251 | </mediaobject> |
| 252 | |
| 253 | <mediaobject> |
| 254 | <imageobject> |
| 255 | <imagedata fileref="images/genfarey-2_2.png" format="PNG"/> |
| 256 | </imageobject> |
| 257 | |
| 258 | <textobject> |
| 259 | <phrase>gimult ftgen 101,0,-18,"farey",7,2 - generate the denominators of fractions of F_7 </phrase> |
| 260 | </textobject> |
| 261 | |
| 262 | <caption> |
| 263 | <para>gimult ftgen 101,0,-18,"farey",7,2 - generate the denominators of fractions of F_7 </para> |
| 264 | </caption> |
| 265 | </mediaobject> |
| 266 | |
| 267 | </para> |
| 268 | </refsect1> |
| 269 | |
| 270 | <refsect1> |
| 271 | <title>See Also</title> |
| 272 | <para> |
| 273 | <link linkend="SiggenModels"><citetitle>Models and Emulations</citetitle></link> |
| 274 | </para> |
| 275 | </refsect1> |
| 276 | |
| 277 | <refsect1> |
| 278 | <title>Credits</title> |
| 279 | <para> |
| 280 | <simplelist> |
| 281 | <member>Author: Georg Boenn</member> |
| 282 | <member>University of Glamorgan</member> |
| 283 | <member>2010</member> |
| 284 | </simplelist> |
| 285 | </para> |
| 286 | |
| 287 | <para>New in Csound version 5.13</para> |
| 288 | </refsect1> |
| 289 | </refentry> |
| 290 |