cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / Random / RandSeed.html
blob65a43e34b9f0d227abe72ad2cf3411632c599d6e
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.35">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #000000; min-height: 16.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
21 span.s1 {font: 18.0px Helvetica}
22 span.s2 {color: #0000bf}
23 span.s3 {color: #102ac3}
24 span.s4 {color: #007300}
25 span.s5 {color: #000000}
26 span.Apple-tab-span {white-space:pre}
27 </style>
28 </head>
29 <body>
30 <p class="p1"><span class="s1"><b>RandSeed<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>set the synth's random generator seed</b></p>
31 <p class="p2"><br></p>
32 <p class="p1"><b>RandSeed.kr(trig, seed)</b></p>
33 <p class="p1"><b>RandSeed.ar(trig, seed)</b></p>
34 <p class="p3"><br></p>
35 <p class="p1">When the trigger signal changes from nonpositive to positve, the synth's random generator <b>seed</b> is reset to the given value. All synths that use the same random number generator reproduce the same sequence of numbers again. The seed may be a demand rate ugen.</p>
36 <p class="p3"><br></p>
37 <p class="p1">see <a href="RandID.html"><span class="s2">RandID</span></a> ugen for setting the randgen id,<span class="Apple-converted-space"> </span></p>
38 <p class="p1">also <a href="../../Core/Kernel/randomSeed.html"><span class="s2">randomSeed</span></a> for the client side equivalent</p>
39 <p class="p3"><br></p>
40 <p class="p1"><b>Note: </b>An audio rate version is not available, because other ugens look up random seeds<span class="Apple-converted-space">  </span>at control rate only.</p>
41 <p class="p4"><br></p>
42 <p class="p4"><br></p>
43 <p class="p5"><br></p>
44 <p class="p6">{ <span class="s3">RandSeed</span>.ar(<span class="s3">Impulse</span>.ar(3 ** <span class="s3">MouseX</span>.kr(1, 8)), 1871); <span class="s3">WhiteNoise</span>.ar * 0.1 }.play</p>
45 <p class="p7"><br></p>
46 <p class="p7"><br></p>
47 <p class="p6">{ <span class="s3">RandSeed</span>.ar(<span class="s3">Impulse</span>.ar(3 ** <span class="s3">MouseX</span>.kr(1, 8)), <span class="s3">Dstutter</span>(<span class="s3">Dwhite</span>().exprange(2, 400), <span class="s3">Dwhite</span>().range(0, 1000))); <span class="s3">WhiteNoise</span>.ar * 0.1 }.play</p>
48 <p class="p4"><br></p>
49 <p class="p4"><br></p>
50 <p class="p8">// start a noise patch</p>
51 <p class="p9"><br></p>
52 <p class="p10">(</p>
53 <p class="p10">{</p>
54 <p class="p10"><span class="s2">var</span> noise, filterfreq;</p>
55 <p class="p10">noise = <span class="s2">WhiteNoise</span>.ar(0.05 ! 2) + <span class="s2">Dust2</span>.ar(70 ! 2);</p>
56 <p class="p10">filterfreq = <span class="s2">LFNoise1</span>.kr(3, 5500, 6000);</p>
57 <p class="p10"><span class="s2">Resonz</span>.ar(noise * 5, filterfreq, 0.5) + (noise * 0.5) <span class="Apple-converted-space"> </span></p>
58 <p class="p10">}.play;</p>
59 <p class="p10">)</p>
60 <p class="p4"><br></p>
61 <p class="p8">// reset the seed at a variable rate</p>
62 <p class="p10">(</p>
63 <p class="p10">x = { <span class="s2">arg</span> seed=1956;</p>
64 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">RandSeed</span>.kr(<span class="s2">Impulse</span>.kr(<span class="s2">MouseX.kr(</span>0.1, 100)), seed);</p>
65 <p class="p10">}.play;</p>
66 <p class="p10">)<span class="Apple-tab-span"> </span></p>
67 <p class="p9"><br></p>
68 <p class="p9"><br></p>
69 <p class="p9"><br></p>
70 <p class="p10">x.set(<span class="s4">\seed</span>, 2001);</p>
71 <p class="p10">x.set(<span class="s4">\seed</span>, 1798);</p>
72 <p class="p10">x.set(<span class="s4">\seed</span>, 1902);</p>
73 <p class="p9"><br></p>
74 <p class="p9"><br></p>
75 <p class="p8">// above you can see that the sound of the LFNoise1 is not exactly reproduced (filter frequency)</p>
76 <p class="p8">// this is due to interference between the internal phase of the noise ugen and the<span class="Apple-converted-space"> </span></p>
77 <p class="p8">// seed setting rate.</p>
78 <p class="p9"><br></p>
79 <p class="p8">// a solution is to start a new synth:</p>
80 <p class="p9"><br></p>
81 <p class="p10">(</p>
82 <p class="p10"><span class="s2">SynthDef</span>(<span class="s4">\pseudorandom</span>, { <span class="s2">arg</span> out, sustain=1, seed=1967, id=0;</p>
83 <p class="p10"><span class="Apple-tab-span"> </span><span class="s2">var</span> noise, filterfreq;</p>
84 <p class="p10"><span class="Apple-tab-span"> </span><span class="s2">RandID</span>.ir(id);</p>
85 <p class="p10"><span class="Apple-tab-span"> </span><span class="s2">RandSeed</span>.ir(1, seed);</p>
86 <p class="p9"><span class="Apple-tab-span"> </span></p>
87 <p class="p9"><span class="Apple-tab-span"> </span></p>
88 <p class="p10"><span class="Apple-tab-span"> </span>noise = <span class="s2">WhiteNoise</span>.ar(0.05 ! 2) + <span class="s2">Dust2</span>.ar(70 ! 2);</p>
89 <p class="p10"><span class="Apple-tab-span"> </span>filterfreq = <span class="s2">LFNoise1</span>.kr(3, 5500, 6000);</p>
90 <p class="p9"><span class="Apple-tab-span"> </span></p>
91 <p class="p10"><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out,</p>
92 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Resonz</span>.ar(noise * 5, filterfreq, 0.5) + (noise * 0.5)<span class="Apple-converted-space"> </span></p>
93 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>*</p>
94 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Line</span>.kr(1, 0, sustain, doneAction:2)</p>
95 <p class="p10"><span class="Apple-tab-span"> </span>)</p>
96 <p class="p9"><br></p>
97 <p class="p10">}).send(s);</p>
98 <p class="p10">)</p>
99 <p class="p9"><br></p>
100 <p class="p8">// the exact same sound is reproduced</p>
101 <p class="p10">(</p>
102 <p class="p10">fork {</p>
103 <p class="p10"><span class="Apple-tab-span"> </span>loop {</p>
104 <p class="p11"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\pseudorandom<span class="s5">);</span></p>
105 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>1.1.wait; </span>// wait a bit longer than sustain, so sounds don't overlap</p>
106 <p class="p10"><span class="Apple-tab-span"> </span>}</p>
107 <p class="p10">}</p>
108 <p class="p10">)</p>
109 <p class="p9"><br></p>
110 <p class="p8">// changing the rand seed changes the sound:</p>
111 <p class="p9"><br></p>
112 <p class="p10">(</p>
113 <p class="p10">fork {</p>
114 <p class="p10"><span class="Apple-tab-span"> </span>(1902..2005).do { <span class="s2">|seed|</span></p>
115 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>seed.postln;</p>
116 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>3.do {</p>
117 <p class="p11"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\pseudorandom<span class="s5">, [</span>\seed<span class="s5">, seed]);</span></p>
118 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>1.1.wait;</p>
119 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}</p>
120 <p class="p10"><span class="Apple-tab-span"> </span>}</p>
121 <p class="p10">}</p>
122 <p class="p10">)</p>
123 <p class="p9"><br></p>
124 <p class="p8">// cd skipper</p>
125 <p class="p10">(</p>
126 <p class="p10">fork {</p>
127 <p class="p10"><span class="Apple-tab-span"> </span>(1902..2005).do { <span class="s2">|seed|</span></p>
128 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>seed.postln;</p>
129 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>rrand(4,10).do {</p>
130 <p class="p11"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\pseudorandom<span class="s5">, [</span>\seed<span class="s5">, seed, </span>\sustain<span class="s5">, 0.05]);</span></p>
131 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.06.wait;</p>
132 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}</p>
133 <p class="p10"><span class="Apple-tab-span"> </span>}</p>
134 <p class="p10">}</p>
135 <p class="p10">)</p>
136 <p class="p9"><br></p>
137 <p class="p8">// if the sounds overlap, this does not work as expected anymore</p>
138 <p class="p8">// sounds vary.</p>
139 <p class="p9"><br></p>
140 <p class="p10">(</p>
141 <p class="p10">fork {</p>
142 <p class="p10"><span class="Apple-tab-span"> </span>loop {</p>
143 <p class="p11"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s2">Synth</span><span class="s5">(</span>\pseudorandom<span class="s5">);</span></p>
144 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.8.wait; </span>// instead of 1.1</p>
145 <p class="p10"><span class="Apple-tab-span"> </span>}</p>
146 <p class="p10">}</p>
147 <p class="p10">)</p>
148 <p class="p9"><br></p>
149 <p class="p8">// rand id can be used to restrict the resetting of the seed to each voice:</p>
150 <p class="p9"><br></p>
151 <p class="p10">(</p>
152 <p class="p10">fork {</p>
153 <p class="p10"><span class="Apple-tab-span"> </span><span class="s2">var</span> id=0;</p>
154 <p class="p10"><span class="Apple-tab-span"> </span>(1902..2005).do { <span class="s2">|seed|</span></p>
155 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>seed.postln;</p>
156 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>3.do {</p>
157 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Synth</span>(<span class="s4">\pseudorandom</span>, [<span class="s4">\seed</span>, seed, <span class="s4">\id</span>, id]);</p>
158 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>id = id + 1 % 16; </span>// there is 16 different random generators</p>
159 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.8.wait;</p>
160 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}</p>
161 <p class="p10"><span class="Apple-tab-span"> </span>}</p>
162 <p class="p10">}</p>
163 <p class="p10">)</p>
164 <p class="p9"><br></p>
165 <p class="p9"><br></p>
166 </body>
167 </html>