How to set a Threshold for audio signal?

Mattia Zanzi's icon

Hi mates. I'd like to create a device which converts in real time specific audio events into MIDI triggers. This is how I was thinking to implement this.

I would exploit the send/receive objects. First, I'd use a max4live audio effect into an audio track which is receiving some audio signal from an external source (let's say, clicks produced by a guitar). I was thinking to set a threshold value to the audio signal, above which a trigger is sent. The way I'm sending the trigger is by using the if statement: if the value exceeds the threshold, then 1, else 0. Here's the example.

GATER DEFINITIVE.amxd
amxd 16.95 KB

I know is super rudimental. So how can I improve it? Because in the way I did it the thing doesn't detect all the events. Thanks!