[chuck-users] question about input detector from adc (MIC)

Ge Wang gewang at CS.Princeton.EDU
Tue Jan 3 02:19:40 EST 2006

Hi Lewis,

> I would like to detect "sound" input from MIC (adc).
> It means that if any sound occure, one event or anything should be 
> done.

> adc => gain g => blackhole;
> 1 => g.gain;
> g.last() => float x;
> while( true ) {
>   if ( std.fabs(x) == 1. )
>   <<<x>>>;
> }
> But the x is always 0.

It look like you are not advancing time in the loop, which means that 
the chuck time is frozen (and no audio is getting processed).  Also, 
you need to update x inside the loop.  Try this:

adc => gain g => blackhole;

float x;
while( true )
     g.last() => x;
     if( std.fabs(x) >= .95 )
         <<< x, "" >>>;
     1::samp => now;

The above code advances time in 1::samp (duration of 1 sample) 
increments - you might try different values to see the results.

Depending on what you want to do, this instantaneous polling approach 
is likely not robust.  An alternative is to take recent history into 
consideration - possibly by implement some sort of leaky integrator / 
envelope follower (as Perry mentioned).  It should be possible to do 
directly in chuck, though a specialized envelope follower unit 
generator might be more efficient (the latter is forthcoming).

Hope this helps.


More information about the chuck-users mailing list