/*--------------------------------------------------------------------------- S.M.E.L.T. : Small Musically Expressive Laptop Toolkit Copyright (c) 2007 Rebecca Fiebrink and Ge Wang. All rights reserved. http://smelt.cs.princeton.edu/ http://soundlab.cs.princeton.edu/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U.S.A. -----------------------------------------------------------------------------*/ //----------------------------------------------------------------------------- // name: follower-trigger.ck // desc: simple (but effective) envelope follower // // author: Rebecca Fiebrink and Ge Wang // // to run (in command line chuck): // %> chuck follower-trigger.ck // // to run (in miniAudicle): // (make sure VM is started, add the thing) //----------------------------------------------------------------------------- // patch adc => Gain g => OnePole p => blackhole; // square the input, by chucking adc to g a second time adc => g; // set g to multiply its inputs 3 => g.op; // sound output SinOsc s => ADSR e => JCRev r => dac; // set params e.set( 10::ms, 5::ms, .5, 20::ms ); .1 => r.mix; e.keyOff(); 600 => s.freq; // set pole position, influences how closely the envelope follows the input // : pole = 0 -> output == input; // : as pole position approaches 1, follower will respond more slowly to input 0.99 => p.pole; // threshold .3 => float threshold; // duration between successive polling 20::ms => dur pollDur; // duration to pause when onset detected 100::ms => dur pauseDur; // infinite time loop while( true ) { // detect onset if( p.last() > threshold ) { // do something e.keyOn(); // pause pauseDur => now; // close e.keyOff(); } // determines poll rate pollDur => now; }