Realtime self-tuning midi to cv (max/gen)

hello everyone, longtime lurker here… but i’ve done something that may be useful to someone so thought i’d do my first post:

it is a gen patch for doing midi to cv (eg with an expert sleepers IO). what (i think) is novel about it is that it works whilst playing sequences or undergoing deep or fast FM. so, if you’re very clumsy like me and scared of knocking the tuning knob mid-song I hope this can reduce your stage anxiety!

patch is here:

and a demo video here:

it works by running a virtual oscillator off the same note/fm as its sending to the real one (having compensated for output/input latency) then treating it like a race between the two - if the real one ‘laps’ the fake one then it adjusts the output voltage. that’s about it! it filters both so that it can use basic zero crossing detection to keep track of them (so as a result works best with simple waveforms, and will break with really wacky waves)

i think i’ve got this to the point where it’s sufficient for my own use, so i’m handing it over to the world now! if you want to adapt this to other platforms go ahead feel free (as long as it’s non commercial) there’s certainly room to make the code more efficient too (but it’s pretty light tbh)

there are some notes in the patch and i tried to document the gen code to explain what goes on as best i can, will follow this thread if people have questions. the most important thing is it needs an absolutely spot on round trip latency value for your particular driver/interface setup or it becomes chaotic.

if anyone with a better grasp of engineering than me can help: in terms of this being a PI closed loop control scheme, is the adjustment to ‘offset’ the integral term? could it be more stable if it did that bit slower? would smoothing the ‘errorvalue’ make it more stable? would that even allow introduction of a ‘D’ term?

thanks to leafcutter john for helpful chat and testing

(and since i’m writing, my sincere thanks to the people on this forum for creating such a pleasant and inspiring space to think about music making)



Just stumbled across this on Instagram, that’s marvelous and can be very useful indeed !

great to see you here, james – and thanks so much for sharing you work. i’ve always taken the knobs off my oscillators to reduce the odds of bumping them… this is a much better solution!


haha i wish i’d thought of that! million dollar space pen vs pencil…


Ooooh that’s really cool @jho!
A completely different approach from what I do with CV Toolkit (mostly because I use the calibration data to microtonal stuff etc) but it’s remarkable how cool it works.

I’ve had great success in terms of improvement of zero crossing detection by dynamically oversampling just the detector itself. Gen in poly~ can be frustrating at times but it’s definitely worth a shot imo.

this is so cool ! thank you for sharing. glad you are here ! i’ve definitely used this forum to inquire about your live setup before hah.

Now tell us about your Arc sequencer wizardry :grin: