Using gen to measure to time between impulses

Robin Price's icon

I'm trying to make a gen patch that will report the time delay between two impulses arriving (I'm using piezo's on a table and in theory when bonked the mic closest to the physical source of the impulse should receive it soonest). I found this on making a latch function which is useful

Any advice on how to use gen to measure the time between when two signals go high?

Graham Wakefield's icon

A sample counter can be created with [accum 1]. This will output a signal that increases by one for each sample passed. The trick is to reset this counter when the first impulse occurs, and read the output when the second impulse occurs. The [accum] operator resets when it receives a nonzero value to the right-most inlet, so that part is pretty easy. Capturing (and holding) the count at the second impulse can be done with a [sah], or a combination of [history] and [?].