class:: SLOnset			
summary::experimental time domain onset detector
categories:: UGens>Analysis
//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://composerprogrammer.com/index.html
keyword:: SLUGens


Description::
Purely time domain onset detector

Works well for loud signals but fainter onsets are missed, and really loud onsets lead to multiple triggers. 

(my note: needs some sort of log amplitude correction?)


Examples::

code::
(
x = {arg threshold=10.0; 

var input, onsets; 

input = SoundIn.ar(0); 

onsets= SLOnset.kr(input,20,5,5,threshold); 

Out.ar(0, SinOsc.ar(440,0,0.1)*Decay2.ar(K2A.ar(onsets), 0.01, 0.1)); 

}.play;
)


x.set(\threshold, 10.0)


x.free;


b = Buffer.read(s,"sounds/a11wlk01.wav"); // remember to free the buffer later.
b = Buffer.read(s,"sounds/break2"); // remember to free the buffer later.


(
x = {arg threshold=10.0, hysteresis=20; 

var input, onsets; 

input = PlayBuf.ar(1, b, BufRateScale.kr(b), loop:1);

onsets= SLOnset.kr(input,20,5,5,threshold,hysteresis); 

Out.ar(0, input + (SinOsc.ar(440,0,0.1)*Decay2.ar(K2A.ar(onsets), 0.01, 0.05))); 

}.play;
)


//by setting these appropriately can get somewhere...
x.set(\threshold, 50.0)
x.set(\hysteresis, 10.0)

b.free;
::
