167 lines
2.8 KiB
Text
167 lines
2.8 KiB
Text
|
#lang scribble/manual
|
||
|
@(require (for-label racket))
|
||
|
|
||
|
@title{RandSeed}
|
||
|
Sets the synth's random generator seed.@section{related}
|
||
|
Classes/RandID
|
||
|
@section{categories}
|
||
|
UGens>Generators>Stochastic, UGens>Random
|
||
|
|
||
|
|
||
|
@section{description}
|
||
|
|
||
|
|
||
|
When the trigger signal changes from nonpositive to positive, the synth's
|
||
|
random generator seed is reset to the given value. All synths that use
|
||
|
the same random number generator reproduce the same sequence of numbers
|
||
|
again.
|
||
|
|
||
|
|
||
|
See link::Classes/RandID:: UGen for setting the randgen id and
|
||
|
link::Reference/randomSeed:: for the client side equivalent.
|
||
|
|
||
|
|
||
|
@section{classmethods}
|
||
|
|
||
|
|
||
|
@section{method}
|
||
|
kr, ir
|
||
|
|
||
|
@section{argument}
|
||
|
trig
|
||
|
|
||
|
The trigger. Trigger can be any signal. A trigger happens when
|
||
|
the signal changes from non-positive to positive.
|
||
|
|
||
|
|
||
|
@section{argument}
|
||
|
seed
|
||
|
The random seed.
|
||
|
|
||
|
@section{Examples}
|
||
|
|
||
|
|
||
|
|
||
|
@racketblock[
|
||
|
|
||
|
// start a noise patch
|
||
|
|
||
|
(
|
||
|
{
|
||
|
var noise, filterfreq;
|
||
|
noise = WhiteNoise.ar(0.05 ! 2) + Dust2.ar(70 ! 2);
|
||
|
filterfreq = LFNoise1.kr(3, 5500, 6000);
|
||
|
Resonz.ar(noise * 5, filterfreq, 0.5) + (noise * 0.5)
|
||
|
}.play;
|
||
|
)
|
||
|
|
||
|
// reset the seed at a variable rate
|
||
|
(
|
||
|
x = { arg seed=1956;
|
||
|
RandSeed.kr(Impulse.kr(MouseX.kr(0.1, 100)), seed);
|
||
|
}.play;
|
||
|
)
|
||
|
|
||
|
|
||
|
|
||
|
x.set(\seed, 2001);
|
||
|
x.set(\seed, 1798);
|
||
|
x.set(\seed, 1902);
|
||
|
|
||
|
|
||
|
// above you can see that the sound of the LFNoise1 is not exactly reproduced (filter frequency)
|
||
|
// this is due to interference between the internal phase of the noise ugen and the
|
||
|
// seed setting rate.
|
||
|
|
||
|
// a solution is to start a new synth:
|
||
|
|
||
|
(
|
||
|
SynthDef("pseudorandom", { arg out, sustain=1, seed=1967, id=0;
|
||
|
var noise, filterfreq;
|
||
|
RandID.ir(id);
|
||
|
RandSeed.ir(1, seed);
|
||
|
|
||
|
|
||
|
noise = WhiteNoise.ar(0.05 ! 2) + Dust2.ar(70 ! 2);
|
||
|
filterfreq = LFNoise1.kr(3, 5500, 6000);
|
||
|
|
||
|
Out.ar(out,
|
||
|
Resonz.ar(noise * 5, filterfreq, 0.5) + (noise * 0.5)
|
||
|
*
|
||
|
Line.kr(1, 0, sustain, doneAction: Done.freeSelf)
|
||
|
)
|
||
|
|
||
|
}).add;
|
||
|
)
|
||
|
|
||
|
// the exact same sound is reproduced
|
||
|
(
|
||
|
fork {
|
||
|
loop {
|
||
|
Synth("pseudorandom");
|
||
|
1.1.wait; // wait a bit longer than sustain, so sounds don't overlap
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// changing the rand seed changes the sound:
|
||
|
|
||
|
(
|
||
|
fork {
|
||
|
(1902..2005).do { |seed|
|
||
|
seed.postln;
|
||
|
3.do {
|
||
|
Synth("pseudorandom", [\seed, seed]);
|
||
|
1.1.wait;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// cd skipper
|
||
|
(
|
||
|
fork {
|
||
|
(1902..2005).do { |seed|
|
||
|
seed.postln;
|
||
|
rrand(4,10).do {
|
||
|
Synth("pseudorandom", [\seed, seed, \sustain, 0.05]);
|
||
|
0.06.wait;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// if the sounds overlap, this does not work as expected anymore
|
||
|
// sounds vary.
|
||
|
|
||
|
(
|
||
|
fork {
|
||
|
loop {
|
||
|
Synth("pseudorandom");
|
||
|
0.8.wait; // instead of 1.1
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
// rand id can be used to restrict the resetting of the seed to each voice:
|
||
|
|
||
|
(
|
||
|
fork {
|
||
|
var id=0;
|
||
|
(1902..2005).do { |seed|
|
||
|
seed.postln;
|
||
|
3.do {
|
||
|
Synth("pseudorandom", [\seed, seed, \id, id]);
|
||
|
id = id + 1 % 16; // there is 16 different random generators
|
||
|
0.8.wait;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
::
|
||
|
|
||
|
]
|
||
|
|
||
|
|