Fine tune onset detection


( This question follows a previous one about multichannel onset detection here Multichannel onset detection? )

I need to detect collision between pieces of wood. I am using contact mics in both the colliding pieces and then onset detection. In theory for every hit I should get two onsets fired (one for each piece of wood that collides) but sometimes one of the pieces fires the onset but the other does not. This seems pretty random, sometimes very quick hits are detected and then a single clear hit it is not.

for instance I get [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] instead of [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] when I can clearly see in the s.meter that both 0 and 7 channels are getting input signal when I hit.

The input audio signal is low and the meter reports around -60 for both pieces of wood. I am just boosting the signal multiplying it by a gain value and this seems to be ok.

I have been plying around with different parameters of the onset detection but I fail to understand how to finetune further the detection, there are so many parameters involved that it is difficult to make sense of changes. I noticed that longer LocalBuf in the FFT are not good and I get good results with 512 and 1024. I also noticed that odftype of \mk1 or \wphase work better.

The code is here, the synthdef is in line 56 and the onset detection parameters are in the variables at the top as well. I dont think the problem is related to any code error because I am checking the raw onset data coming from the synth and ithe problem is already there before any code I do to deal with the data.

I hope I am being clear, any suggestions?

Realtime onset detection is tricky in my experience. One thing to be aware of us it that Onsets is kr. only so rapid, percussive onsets might be hard to catch as they can fall in between control cycles. I would try the FluidOnsetSlice (part of the Flucoma tool kit) which seems to perform a little better than If there is silence in between hits you might have more luck using an ar trigger based on Amplitude possibly using SetResetFF so that you get a trigger when the amplitude passes a threshold and then no triggers till the amplitude drops under a ‘silence’ threshold.

1 Like

ok, thanks for the tips!