2 summary:: Gaussian function oscillator
3 categories:: UGens>Generators>Deterministic
6 A non-band-limited gaussian function oscillator. Output ranges from strong::minval:: to 1.
8 LFGauss implements the formula:
10 f(x) = exp(squared(x - iphase) / (-2.0 * squared(width)))
12 where x is to vary in the range -1 to 1 over the period dur. strong::minval:: is the initial value at -1.
18 duration of one full cycle ( for strong::freq:: input: strong::dur = 1 / freq:: )
20 relative width of the bell. Best to keep below 0.25 when used as envelope. (default: 0.1)
22 initial offset (default: 0)
24 if loop is > 0, UGen oscillates. Otherwise it calls doneAction after one cycle (default: 1)
26 doneAction, which is evaluated after cycle completes (2 frees the synth, default: 0).
27 See link::Reference/UGen-doneActions:: for more detail.
31 subsection:: Some plots
37 { LFGauss.ar(0.1, 0.12) }.plot(0.1);
40 { LFGauss.ar(0.1, 0.12, -1, loop: 0) }.plot(0.1);
42 // moving further away from the center
43 { LFGauss.ar(0.1, 0.12, 2) }.plot(0.2);
46 { LFGauss.ar(0.065, 0.12, 0, loop: 1) }.plot(0.3);
49 subsection:: Some calculations
53 strong::minval:: for a given width:
54 code::minval = exp(-1.0 / (2.0 * squared(width)))::
56 strong::width:: for a given minval:
57 code::width = sqrt(-1.0 / log(minval))::
59 strong::width at half maximum (0.5):::
60 code::(2 * sqrt(2 * log(2)) * width) = ca. 2.355 * width::
63 // minval for a width of 0.1:
64 (exp(1 / (-2.0 * squared(0.1)))) // 2e-22
66 // maximum width for a beginning at -60dB:
67 // we want the beginning small enough to avoid clicks
68 sqrt(-1 / ( 2 * log(-60.dbamp))) // 0.269
70 // minval for width of 0.25
71 (exp(1 / (-2.0 * squared(0.25)))).ampdb // -70dB
73 // maximum is always 1:
74 { LFGauss.ar(0.1, XLine.kr(1, 0.03, 1), 0, loop: 1) }.plot(1);
76 // a gauss curve in sclang:
77 (0..1000).normalize(-1, 1).collect(_.gaussCurve(1, 0, 0.1)).plot;
80 // rescale the function to the range 0..1
83 var width = XLine.kr(0.04, 1.0, 1);
84 var min = (exp(1.0 / (-2.0 * squared(width))));
85 var gauss = LFGauss.ar(0.1, width, loop: 1);
86 gauss.linlin(min, 1, 0, 1);
90 // range does the same implicitly
93 var width = XLine.kr(0.04, 1.0, 1);
94 LFGauss.ar(0.1, width, loop: 1).range(0, 1);
99 subsection:: Sound examples
101 // modulating duration
102 { LFGauss.ar(XLine.kr(0.1, 0.001, 10), 0.03) * 0.2 }.play;
104 // modulating width, freq 60 Hz
105 { LFGauss.ar(1/60, XLine.kr(0.1, 0.001, 10)) * 0.2 }.play;
107 // modulating both: x position is frequency, y is width factor.
108 // note the artefacts due to alisasing at high frequencies
109 { LFGauss.ar(MouseX.kr(1/8000, 0.1, 1), MouseY.kr(0.001, 0.1, 1)) * 0.1 }.play;
111 // LFGauss as amplitude modulator
112 { LFGauss.ar(MouseX.kr(1, 0.001, 1), 0.1) * SinOsc.ar(1000) * 0.1 }.play;
115 { LFGauss.ar(0.001, 0.2, [0, MouseX.kr(-1, 1)]).sum * 0.2 }.scope;
117 // for very small width we are "approaching" a dirac function
118 { LFGauss.ar(0.01, SampleDur.ir * MouseX.kr(10, 3000, 1)) * 0.2 }.play;
120 // dur and width can be modulated at audio rate
122 { var dur = SinOsc.ar(MouseX.kr(2, 1000, 1) * [1, 1.1]).range(0.0006, 0.01);
123 var width = SinOsc.ar(0.5 * [1, 1.1]).range(0.01, 0.3);
124 LFGauss.ar(dur, width) * 0.2
129 // several frequecies and widths combined
132 var mod = LFGauss.ar(MouseX.kr(1, 0.07, 1), 1 * (MouseY.kr(1, 3) ** (-1..-6)));
133 var carr = SinOsc.ar(200 * (1.3 ** (0..5)));
134 (carr * mod).sum * 0.1
141 var son = LeakDC.ar(LFGauss.ar(0.005, 0.2));
142 BPF.ar(son * 3, MouseX.kr(60, 2000, 1), 0.05)
147 subsection:: Gabor Grain
153 var dur = ncycles / freq;
156 var env = LFGauss.ar(dur, width, loop: 0, doneAction: 2);
157 var son = FSinOsc.ar(freq, 0.5pi, env);
164 SynthDef(\gabor, { |out, i_freq = 440, i_sustain = 1, i_pan = 1, i_amp = 0.1, i_width = 0.25 |
165 var env = LFGauss.ar(i_sustain, i_width, loop: 0, doneAction: 2);
166 var son = FSinOsc.ar(i_freq, 0.5pi, env);
167 OffsetOut.ar(out, Pan2.ar(son, i_pan, i_amp));
172 // modulating various parameters
177 \freq, Pbrown(step:0.01).linexp(0, 1, 100, 14000),
178 \dur, Pbrown().linexp(0, 1, 0.004, 0.02),
179 \legato, Pbrown(1, 3, 0.1, inf),
180 \pan, Pwhite() * Pbrown()
185 // modulating width only
192 \width, Pseg(Pseq([0.25, 0.002], inf), 10, \exp),
198 // compare with sine grain.
200 SynthDef(\gabor, { |out, i_freq = 440, i_sustain = 1, i_pan = 1, i_amp = 0.1, i_width=0.25 |
201 var env = EnvGen.ar(Env.sine(i_sustain * i_width), doneAction: 2);
202 var son = FSinOsc.ar(i_freq, 0.5pi, env);
203 OffsetOut.ar(out, Pan2.ar(son, i_pan, i_amp));