[CM] Timing drift
Neil Baylis
neil.baylis at gmail.com
Wed Apr 8 00:07:54 PDT 2009
I'm seeing timing drift between two processes running cm3 on OSX/Leopard.
I'm also seeing the timing drift on Linux that another user reported, but I
think this case is unrelated to that one.
Here's the code:
(define (note-cycle endtime keys rate)
(process with pat = (make-cycle keys)
while (< (elapsed) endtime)
do
(send "mp:midi" key: (next pat) dur: rate)
(wait rate)))
(let* ((k1 (key '(c4 g4 a4 bf4)))
(k2 (key '(c2 e2 g2 a2 bf2 a2 g2 e2)))
(stop 8000))
(sprout
(list (note-cycle stop k1 .4)
(note-cycle stop k2 .2))))
If I define the two time delays to be equal, the processes seem to stay in
sync for at least a few minutes. But if I define them as above, they drift
apart fairly soon.
I think the reason for this is that there is some overhead in the process
that gets added on to the wait time for each iteration. So if the wait time
is shorter, the loop executes more often, and the overhead is incurred more
often. (The overhead would be everything in the loop apart from the wait
time).
What's the correct way to fix this? I can think of a way to do it that
involves sprouting only a single process, and sending multiple notes each
time through the loop, but it gets ugly fast if there are more than a couple
of parts/instruments.
I guess what I want is to wait an amount of time that would bring me to the
start of the next beat, but I'm not sure how to express that. I tried the
following, but it didn't help:
(define (note-cycle endtime keys rate)
(process with pat = (make-cycle keys)
for t = rate by rate
while (< (elapsed) endtime)
do
(send "mp:midi" key: (next pat) dur: rate)
(wait (- t (elapsed)))))
(I was attempting to pre-compute the value of "elapsed" at the start of the
next iteration.)
Basically I'm wanting to have one process run at an exact multiple of the
speed of another.
Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/cmdist/attachments/20090408/c59ad60a/attachment.html
More information about the Cmdist
mailing list