From f7354554425e17757f31d81e26789ad20df852bf Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 21 Oct 2022 01:48:24 +0100 Subject: debugged, CPU usage reduced, progression formulated --- sonics/lagdetect.udo | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 sonics/lagdetect.udo (limited to 'sonics/lagdetect.udo') diff --git a/sonics/lagdetect.udo b/sonics/lagdetect.udo new file mode 100755 index 0000000..f4261b1 --- /dev/null +++ b/sonics/lagdetect.udo @@ -0,0 +1,59 @@ +#ifndef UDO_LAGDETECT +#define UDO_LAGDETECT ## +/* + Processing lag detection + + This file is part of the SONICS UDO collection by Richard Knight 2022 + License: GPL-2.0-or-later + http://1bpm.net +*/ + +#define LAG_DFLT_TTHRESH #0.05# + + +/* + Detect when the CPU cannot keep up with proessing: when the realtime clock differs from Csound's clock by a specified threshold time. + The trigger klagging is output periodically every iautotimethreshold*2 seconds rather than continuously + + klagging, ktimesincelastlag lagdetect [iautotimethreshold=LAG_DFLT_TTHRESH] + + klagging trigger indicating lag has been detected in this k-cycle + ktimesincelastlag time in seconds sine the last lag detected + iautotimethreshold if realtime clock and Csound clock differ more than this number of seconds, lag is assumed +*/ +opcode lagdetect, kk, j + iautotimethreshold xin + iautotimethreshold = (iautotimethreshold == -1) ? $LAG_DFLT_TTHRESH : iautotimethreshold + kstartrt init rtclock:i() + kclockrt rtclock + kstarts init times:i() + kclocks times + klag = abs:k((kclocks - kstarts) - (kclockrt - kstartrt)) + + klagging = 0 + ; if time difference is above threshold and last adjustment is double threshold, reduce parameters and reset times + if (klag > iautotimethreshold && kclockrt - kstartrt > iautotimethreshold * 2) then + kstartrt = kclockrt + kstarts = kclocks + klagging = 1 + endif + xout klagging, kclocks - kstarts +endop + + +/* + Detect when the CPU cannot keep up with proessing: when the realtime clock differs from Csound's clock by a specified threshold time + The trigger klagging is output periodically every iautotimethreshold*2 seconds rather than continuously + + klagging lagdetect [iautotimethreshold=LAG_DFLT_TTHRESH] + + klagging trigger indicating lag has been detected in this k-cycle + iautotimethreshold if realtime clock and Csound clock differ more than this number of seconds, lag is assumed +*/ +opcode lagdetect, k, j + iautotimethreshold xin + klagging, ktimesincelag lagdetect iautotimethreshold + xout klagging +endop + +#end -- cgit v1.2.3