16 May 2007

tap

tap

This block outputs a bpm value when triggered by a bang that can come from a MIDI message (eg a drum pad). When it loses track because the trigger is not periodic enough, it restarts and for a moment (2 taps) holds the previous tempo.

version

v1.0: built 14/05/2007 with Pd v0.40-2 [pd][pdf]
based on http://www.parasitaere-kapazitaeten.net/Pd/pdpatches

interface

Input 1: the inlet that receives triggers, anything counts: a bang, a value,...
Input 2: a reset knob: resets the counting when tempo is lost. Also happens automatically.

Output 1: the tempo in beats per minute (bpm)
Output 2: a bang when tempo is lost. It's not necessary to connect this with the reset input. It's taken care of inside

implementation


To calculate the tempo, this algorithm uses three steps: it calculates the interval between the previous click and the current click, it calculates the mean inter-click interval time and it computes the bpm value of this. Then as an extra step the last value before losing the tempo and dropping to 0bpm is remembered by only updating the outlet if it's not 0 (0 can never be a tempo of a song, therefor it's allowed)
The time between the current and previous tap, beat or click is calculated by a timer object, which does just that. A simple counter is used to start this process only after two taps, each time the reset restarts the counter.

Then the mean is calculated by adding the new value to the sum of the previous values (this last sum is made by multiplying the last mean value by the last counter index, so a small backward recalculation is done). This is each time divided by the current counter value (indicating the number of terms of the sum).

Another step decides if the tempo is between the right values, that it doesn't deviate too much. If it does, the whole thing is reset.

1 comment:

Anonymous said...

Hi,

I see you use some "fanning" connections here from the [bang( to the [timer]. Fanning connections can be the source of subtle bugs as the order, they get activated, is basically undefined (they depend on the creation order which is something that can change easily and it cannot be seen in a screenshot).

It's much better to use explict triggers as in:

[t b b]
|     |
[timer]

Ciao
-- Frank