Gen Midi Clock - gets messed up in max due to jitter and EDGE

    Mar 08 2020 | 8:33 pm
    Dear all,
    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.

    • Mar 08 2020 | 9:52 pm
      I found the problem which leads me to another questions. I am accurately producing simulation of a midi clock in gen. To get that clock Out I am using a EDGE object. This edge object is producing jitter which means my 100% timing of my midi clock that has been produced in the gen world gets messed up. This means the accurate timed impules get delayed variously when crossing over from GEN to MAX.
      I understand that this is normal behaviour but how can I then get an accurate clock signal in the max world when it is generated in the gen world????
      Thanks for your advice.
    • Mar 09 2020 | 2:47 pm
      go into AudioOptions, try reducing your signal vector size to 32(because you mentioned you need at least a 48ticks/44100samples..., you won't be able to get this unless your scheduler is polling at that rate or faster...), set your Scheduler to "Overdrive" and "In Audio Interrupt" too. Try these settings first, it will cause the CPU to be a bit intensive, so if it works, then you can try without "In Audio Interrupt", if that works, try without "Overdrive", eventually finding just the right balance between CPU-intensive and accurate as you need. here's a bit more info:
    • Mar 09 2020 | 7:29 pm
      Thanks Raja, will try out :-)
    • Mar 13 2020 | 11:44 am
      Worked out well. My GEN Midi clock is very stable now :-)