OSCFunc latency testing

That 44.3 kHz reading was pretty extreme – this is the only time I’ve ever seen such a far-out reading. It was on a built-in sound card (i.e. cheap hardware) and it did settle later back into a much closer value.

I’d say +/- 10 Hz is pretty typical for a ThinkPad built-in soundcard. I believe USB interfaces would be more stable.

I wouldn’t bother going down this road. You have no assurance that the transport time for OSC messages will be consistent.

I just thought to try a little bit simpler test – just differentiating the incoming time values. The earlier test assumed that 1.0 is a common standard between language and server, but we could forget about that and find 1/ the average time between OSC messages and 2/ the amount of fluctuation.

(
var lastTime = nil;

a = List.new;

OSCdef(\x, { |msg, time|
	if(lastTime.isNil) {
		lastTime = time
	} {
		a.add(time - lastTime);
		lastTime = time;
		if(a.size == 200) {
			z.free;
			OSCdef(\x).free;
			"done".postln;
		};
	};
}, '/time');

z = {
	var time = Sweep.ar;
	// '4' because it evenly divides 44100
	// integer number of samples between triggers
	SendReply.ar(Impulse.ar(4), '/time', time);
	Silent.ar(1)
}.play;
)

a = a.array;
a.plot;

On this machine, the plot shows a pattern of 3-4 values slightly longer than true, followed by one value that is much shorter than true. This might be different on other machines, or with different soundcards.

// some stats: start with the obvious = average
m = a.mean;
-> 0.249975831345  // quite close!

[a.maxItem - m, a.minItem - m]
-> [ 0.0068162446550105, -0.01864244534504 ]

// standard deviation
// (not using the '-1' correction bc this isn't a constructed random sample)
(a.sum { |y| (y - m).squared } / a.size).sqrt
-> 0.0098690657995142

So the maximum error in this test is (a.minItem absdif: m) / m = about 7.46%, which is kind of a lot. A 9 ms standard deviation also doesn’t inspire confidence.

I recall that you were trying to grab Onsets times in a buffer – just use the server’s time values. OSCFunc time will not be reliable for this, not at all.

I would expect jitter here too.

hjh