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.<br>
The following code illustrates the problem:<br><br><div><div>time chrono;</div><div><br></div><div>Impulse i => dac;</div><div><br></div><div>adc => Gain g => OnePole p => blackhole;</div><div>adc => g;</div>
<div>3 => g.op;</div><div>.9999 => p.pole;</div><div><br></div><div>now => time start;</div><div><br></div><div>10::samp => dur peakPollRate;</div><div><br></div><div>//ADJUST THIS</div><div>.001 => float threshold;</div>
<div><br></div><div>spork ~makeImpulses();</div><div>while (1) {  </div><div>    if (p.last() > threshold) {</div><div>       <<< "peak at", (now - chrono) /ms >>>;</div><div>        .2::second => now;</div>
<div>    }</div><div>    </div><div>    peakPollRate => now;</div><div>}</div><div><br></div><div>fun void makeImpulses() {</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>while (true) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">         </span>1 => i.next;</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>.8::second => now;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span><<< "Impulse at ", (now - start) / ms >>>;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>}</div></div><div><br></div><div>This code uses an impulse as a metronome and listens to the adc through a OnePole filter for peaks above a threshold.<br>
<br>Here's two ways to demonstrate the problem (you'll need speakers and a mic):<br>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.</div>
<div>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.<br>
<br>Do other people have this same problem? Why is this happening?</div>