This is some code for finding the centroid of a transient. A click in the right inlet will trigger the analysis. Playing around with it has convinced me it’s super useful however I’m not super confident in my C coding so I won’t be publishing this as part of any packages. I’m really nervous about memory leaks etc. If someone wants to look it over and possibly alter it, go for it.
It computes an FFT, finds a bark(ish) scale and then gives the centroid of that scale. It’s probably great at analyzing table drumming.
I gave a quick glance at your code and it has has some issues.
It is not a good idea to make outlet calls from the perform routine.
Read the chapter "Anatomy of a MSP Object" from the Max/MSP SDK.
You want to create and use a clock to schedule outlet calls from the high priority thread.
Since a clock_delay() function will be called from the perform routine, you also need to pay attention not to clog the scheduler by calling the function too often, especially at small vector sizes.
Going from the audio thread to the scheduler thread is not trivial in complex scenarios.
Your scenario is not very complex but you need to take care of a few important things.
I am sorry for being so general, but I don’t have time to go into specifics right now…
Maybe someone else may be able to go more in depth…