[CM] Timing drift

Heinrich Taube taube at uiuc.edu
Wed Apr 8 03:09:12 PDT 2009


it would be useful to know if you get the same drift using chicken  
3.0.0 or 3.4.0
(im soory  have very little time to work over the next week -- )
if you can hack C you might try taking the time just before and after  
the process node calls into scheme and then subtracting the difference  
between these time stamps from the amount you increment the node by  
for its next run time. in other words to subtract out the time spent  
in scheme.



On Apr 8, 2009, at 2:07 AM, Neil Baylis wrote:

> 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
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist



More information about the Cmdist mailing list