1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
//-----------------------------------------------------------------------------
// name: follower.ck
// desc: a simple envelope follower
//
// author: Perry R. Cook
/*-----------------------------------------------------------------------------
Hi all. I keep meaning to post to this list about the under-exploited
feature that all unit generators have, in that you can cause their inputs
to multiply rather than add. As an example, here's a simple power
envelope follower that doesn't require sample-level chuck intervention. A
gain UG is used to square the incoming A/D signal (try it on your built-in
mic), then a OnePole UG is used as a "leaky integrator" to keep a running
estimate of the signal power. The main loop wakes up each 100 ms and
checks the power, and prints out a message if it's over a certain level.
You might need to change the threshold, but you get the idea.
-----------------------------------------------------------------------------*/
// patch
adc => Gain g => OnePole p => blackhole;
// square the input
adc => g;
// multiply
3 => g.op;
// set pole position
0.99 => p.pole;
// loop on
while( true )
{
if( p.last() > 0.01 )
{
<<< "BANG!!" >>>;
80::ms => now;
}
20::ms => now;
}
|