// This uses built-in ChucK Unit Generators to // compute Zero Crossings, lots of monkey business :-) // by Perry R. Cook, updated January 2014 adc => ZeroX z => HalfRect f => OnePole p => blackhole; // basic patch 0.0 => float myZeroes; // This holds the last zero crossing count spork ~ ZC(1.000); while (1) { 100.0 :: second => now; // do other stuff here } fun void ZC(float howoften) { (howoften*44100) - 1 => float wait; while (1) { wait :: samp => now; p.last() => myZeroes; <<< "Zero Crossings = ", myZeroes >>>; 0.0 => p.a1; 0.0 => p.b0; 1 :: samp => now; -1.0 => p.a1; // this is dangerous, but we 1.0 => p.b0; // know what we're doing } }