1CLASS:: MedianTriggered
2summary:: Median of recent values, triggered
3categories:: UGens>Filters
4related:: Classes/MeanTriggered
5
6DESCRIPTION::
7Calculates the median of the most recent length values, but only paying attention to values input while the trigger is greater than zero. One application of this is to calculate a running median of values coming from FFT analysis.
8
9While trig<=0, the last-measured median is held constant.
10
11The length argument is set at initialisation, and cannot be modulated. The length is directly reflected in the amount of real-time memory taken by this UGen, so please think carefully before using large values of length. Values in the low single- or double-figures are expected.
12
13The median is implemented using a simple "selection sort", which is another argument against using large values for length since the performance is not tailored for large collections.
14
15EXAMPLES::
16code::
17s.boot;
18// Simple polling of median values - you could do this without a UGen!
19x = {|val=1, t_trig=0| MedianTriggered.kr(val, t_trig, 3).poll(t_trig, "Median of recent 3 values"); }.play;
20x.set(\val, 10.rand.postln, \t_trig, 1); // Execute this repeatedly
21
22x.free;
23
24// Same but with 4 values - note the way medians behave with even-sized sets
25x = {|val=1, t_trig=0| MedianTriggered.kr(val, t_trig, 4).poll(t_trig, "Median of recent 4 values"); }.play;
26x.set(\val, 10.rand.postln, \t_trig, 1); // Execute this repeatedly
27
28x.free;
29
30// Using it as an audio filter - compare the sounds of these:
31x = {WhiteNoise.ar(0.1)}.play;
32x.free;
33x = {MedianTriggered.ar(WhiteNoise.ar(0.1), 1, 3)}.play; // Note that Median.ar is more efficient for this kind of thing
34x.free;
35x = {MedianTriggered.ar(WhiteNoise.ar(0.1), 1, 11)}.play; // Note that Median.ar is more efficient for this kind of thing
36x.free;
37::
38
39