Umm… on that UDO… I realised after posting that my formula was a bit off.
This does better.
;reduces amplitude of an audio signal based on the number of currently active instruments.
;reduction is 3db every doubling of current instances.
;ktime smooths the changes to avoid clicks (defaults to 0.08 seconds)
;iinsnum is the instrument number to monitor (defaults to calling instrument p1. 0 monitors all instruments.)
opcode activedamp, a,aOj
asig, ktime, iinsnum xin
iinsnum = (iinsnum == -1 ? p1 : iinsnum)
kinsnums active iinsnum, 0, 0
klognum = max(1,kinsnums) * -3
kampfac2 = ampdbfs(log2(max(1,kinsnums)) * -3); drop 3db every doubling.
asig *= lineto(kampfac2, limit:k(ktime, 0.008, 5))