File: follower.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (37 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download
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;
}