[chuck-users] Chuck Latency

Kyle Hipke kwhipke1 at gmail.com
Wed Aug 24 15:30:11 EDT 2011

I'm working on a project that requires low latency peak detection. But I'm
struggling with the low-latency part. I'm not sure if there's just a problem
with chuck, my code, or if my computer is slow. I'm on an Intel Core 2 Duo
2.13 GHz processor.
The following code illustrates the problem:

time chrono;

Impulse i => dac;

adc => Gain g => OnePole p => blackhole;
adc => g;
3 => g.op;
.9999 => p.pole;

now => time start;

10::samp => dur peakPollRate;

.001 => float threshold;

spork ~makeImpulses();
while (1) {
    if (p.last() > threshold) {
       <<< "peak at", (now - chrono) /ms >>>;
        .2::second => now;

    peakPollRate => now;

fun void makeImpulses() {
while (true) {
1 => i.next;
.8::second => now;
<<< "Impulse at ", (now - start) / ms >>>;

This code uses an impulse as a metronome and listens to the adc through a
OnePole filter for peaks above a threshold.

Here's two ways to demonstrate the problem (you'll need speakers and a mic):
1. With headphones in, adjust the threshold as low as possible without
picking up room noise (under //ADJUST THIS) then run the code. Make a
percussive sound into your mic that coincides with one of the impulses, then
kill chuck and look at the output. On my machine, it detects the peak ~200ms
after the metronome, even though I made the sound immediately when I heard
the metronome.
2. With speakers on, adjust the threshold and your speaker volume so that
the Impulses are detected as peaks, but no room noise is. Run the program
for a few clicks and kill it, then look at the output. On my machine, again,
I get a ~200ms delay.

Do other people have this same problem? Why is this happening?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20110824/432aed07/attachment.html>

More information about the chuck-users mailing list