Master clock generator


#1

Witch of the classes to use from juce to get the most accurate midi clock generation.

I started with a Thread that is also a Timer with freq of 1ms. But i don’t know if that’s a good idea, also how to deal with timerCallback vs. run, what to call when to get the best results, perhaps an asyncUpdater ?

also is there any example online perhaps, on how to calculate all those MTC/Midi Clock messages ?


#2

None of the event based classes are suitable for this, because anything on the message thread can be delayed when other events are getting processed.

For a really precise timer, best thing would be a high priority thread that sits there using Time::waitForMillisecondCounter() to wait for the time that you need.


#3

how bad would this be:
http://code.google.com/p/xclock/source/browse/trunk/xsync.cpp

the gui get’s updated asynchronusly, and the thread just counts ticks.


#4

On Windows, you have the possibility to use the Multimedia Timer which allow a precision of up to 1ms. Ofcourse you have to have very fast code in there that is just used to update some counter or whatever. Check this out: http://msdn.microsoft.com/en-us/library/ms704986.aspx

On OS X, I think one could use native OS X’s Timers? I am not sure, but I think they are very exact, too.

On Linux I have no idea.

Anyway, it would be nice if JUCE had some kind of very exact Timers that are meant for just these kind of things.


#5

juce has a step of 1ms also, there are two ways HiRes and Normal i’m guiessing the HiRes is better for this.

i used the normal one for now, like Jules wrote, what i’m afraid the most is how GUI updates and cpu load will influence this type of code.

it’s really just 4 unsigned int’s beeing incremented and zeroed, so i’m guessing it’s kinda fast. maybe it can be faster, like inline or something, i dunno didn’t have time to go into performance optimizations on this level.


#6

What class/functions are you referring to?


#7
static double Time::getMillisecondCounterHiRes();
static uint32 	getMillisecondCounter ();
i use this one ->static void 	waitForMillisecondCounter (const uint32 targetTime) throw ();

generaly the Time class.

i use this in the code in the link it’s really just a couple of lines, really simple to be as fast as possible.