I programmed a gen looper with a master midi clock to sync devices (e.g. Digital Drumcomputer). I found that my clock is drifting a bit which means the time differences between the ticks vary a little bit. The way the looper works is that I record the initial loop. F.E: If I would record exactly one second of audio I would have 44100 samples recorded with 120 Beats Per minute. To midi sync that I would need a midi clock signal of 48 Ticks per second / 44100 samples.
Her is my code with some explanation:
The way I currently do it is like this but this is giving me drift as I assume WRAP is not appropriate to round to the nearest integer.
// MIDI CLOCK GENERATION
MidiCounter = wrap(Master_Counter,0,Midi_ClockInterval); => midi clock interval can be a float e.g 967.6777
beat_helper = delta (MidiCounter);
if (beat_helper < 0) mClock = 1;
else mClock = 0;
Any opinions are welcome how to solve this.
To sum it up: I am looking for a way to divide integers with floats and round the result to the nearest possible integer.