Timing repeating events

Hi!

I’m trying to evaluate the frequency at which an OSC IN chop is receiving new messages. I have a custom circuit sending OSC messages and I’d like to make sure it is sending as close as possible to 60 updates per second.

My first approach was to use a chop EXEC’s on value change handler in this manner:

import time

def onValueChange(channel, sampleIndex, val, prev):
	current_time = time.process_time()
	print("Freq = " + str(1 / (current_time - op('oscin1').fetch('last_time'))))
	op('oscin1').store('last_time', current_time)
	return

This sort of works but when the messages come in quick succession current_time and last_time are equal which results in division by zero. It appears that time.process_time() isn’t a very reliable way of timing stuff from within a CHOP whose internal sample rate is already very close to the rate I wish to evaluate… Also, I’d like to get an idea of how fast messages are coming in even when the actual values haven’t changed so this approach won’t work.

I also tried attaching an INFO chop to the OSC IN chop to see what information was available but again I seem to be constrained by the CHOP’s sampling frequency so I’ve now switched to a OSC IN dat instead thinking it wouldn’t have the same sample rate characteristics as the CHOP but I still face the same division by zero issues as with the CHOP. I’ve also tried starting a timer chop every time a new message comes in and using the timer fraction to calculate the frequency but this also seems to saturate at 60fps.

What is the best approach to accomplish my goal?

Thanks!

Perhaps use an OSC In DAT and count number of messages over some length of time. With the OSC In DAT you will not lose messages, even if multiple messages get bunched up in the one frame.