detomon / BlipKit

C library for creating the beautiful sound of old sound chips
https://blipkit.audio
Other
34 stars 5 forks source link

Running Separate Tracks at Different Speeds #3

Closed AuzFox closed 1 year ago

AuzFox commented 1 year ago

Hello! Had a quick question regarding attaching multiple clocks to a context. I hope it's not too much trouble! I'm trying to write a tracker similar to LSDJ in that each track can set its own play speed based on the tempo of the song. (For example, track A might run at 4 rows per beat while track B runs at 5 rows per beat) I don't believe this is possible when only using the master clock, but I see that it's possible to attach multiple clocks to a context, so my thinking is to create one clock per track and use that to drive the divider callbacks. Would this be the correct approach? If so, how would I set this up? If not, what would be the preferred method to accomplish this?

detomon commented 1 year ago

Hello @AuzFox

I think using multiple clocks for this situation is the right approach. You can use the clocks's callback directly without attaching dividers (it's still possible if needed with BKDividerAttachToClock). I made a new example which shows this: https://github.com/detomon/BlipKit/blob/master/examples/clocks.c (I hope it's clear). This uses three clocks running with different periods which sync up every second. Technically, there is a drift between the clocks because of rounding errors, but it's minuscule and shouldn't be relevant.

AuzFox commented 1 year ago

Ah, this is just what I was looking for, and the example seems pretty clear to me on how it's working. Thanks a bunch! :) By the way, sorry for not responding in the last issue I opened, but I appreciate the help for both issues!

detomon commented 1 year ago

No problem at all. Glad it helped!