almostEric / FrozenWasteland

Plugins for VCV Rack
Other
91 stars 18 forks source link

Quad Alg Rhythm: rounding error drift #38

Closed midiguru closed 4 years ago

midiguru commented 5 years ago

I set up a simple pattern in which line 1 is 8 steps long while line 2 is 16 steps. Each of them is set so that the Divs create an alternating on/off pattern. I'm using Impromptu Clocked, and I've patched in a Count Modula Boolean module so that the Quad will stop when Clocked stops. Time Sync is set to 1.

When I hit the Run button in Clocked, the two lines play a quarter-note rhythm and an eighth-note rhythm, as expected. Getting them to line up so that the quarter-notes hit at the same time as every other eighth-note is hit-or-miss. I have to click the Clocked Run button a few times to get them lined up rhythmically. This is not a desirable state of affairs, but it's not why I'm filing an issue.

The problem is that with a Time Sync of 1, the two lines gradually drift apart. This is presumably because you're calculating the timing on the fly rather than relying on the Clock input to step through the patterns. There's a rounding error between line 1 and line 2. It will take a couple of minutes for the rounding error to become obvious -- and it's possible that it won't happen at some tempos. Clocked is currently set to 158 bpm.

I really like what you're doing with this module ... and I'd like to offer to help with testing it. But there seem to be some under-the-hood design issues. I'm not a programmer, but I have many years of experience testing digital music systems. (Oh, I did write a whole book on Csound once. I guess that counts as programming experience.)

Anyway, if you'd like me to take a more active role, let me know. I'm not trying to be arrogant here, I hope that's obvious. I'd like to be helpful.

midiguru commented 5 years ago

Here's a patch that demonstrates the cumulative rounding error. rounding_error.zip

almostEric commented 5 years ago

HI, I ran the patch for about 20 minutes and did not get the error you experienced. That said, I switched to using double precision variables for the clock calculation so hopefully that will improve things. I also reworked the logic on startup/reset so that things should fire off more smoothly.

1.2.1 has been pushed, waiting for the vcv build system to do its thing