MIDI Clock Generator, given Analog Audio Input

I'm looking to build a device, which would have the following capabilities:

  • Receive an analog audio input signal, over 1/4" TS connection, consisting of click track audio
  • Receive MIDI commands over 5 PIN Din Connection, just for pass through capability
  • Generate a MIDI clock signal, based on the BPM frequency of the incoming analog audio click track
  • Merge the generated MIDI clock signal into the incoming MIDI commands, and send them both out of a 5 pin MIDI DIN connector

So two 5-pin MIDI DIN connectors, and one 1/4" TS input connector.

For functionality, I'm thinking:

  • Send the MIDI "Start" command when a new BPM is detected
  • Send MIDI Clock while audio is being detected on the 1/4" input
  • Send MIDI "Stop" command when the audio input changes from "present" to "not present"

I'd like it to send a new "Start" command when the BPM changes, so external devices synchronizing to the MIDI clock, will re-sync to the downbeat when moving to the next song with a different BPM.

Since this would be based on click track audio, I don't need it to try and figure out the BPM of a complex musical track. The click track is on/off signals coming in.

I do need it to merge the generated MIDI clock signal into an existing MIDI stream though.

I've done some MIDI arduino work before, but never with MIDI clock generation. I've read some tutorials on generating MIDI clock, but nothing specifically like this.

So my 1st question is what hardware is best for this? An arduino UNO and a MIDI shield? Or is there a more finished product I can buy, which would provide the 3 connection points already assembled, and I just have to write the code for it?

Thanks for any assistance :slight_smile:

So it looks like a Sparkfun Redboard, with a Sparkfun MIDI shield, will give me 90% of the hardware to do this.

SparkFun Guide

If I use the "Forty Seven Effects" MIDI library, it has a "Soft Thru" mode, which merges incoming bytes with the outgoing. So this should enable me to merge the MIDI clock signal in with any MIDI commands coming in through the "MIDI In" jack.

The only piece I'm still unsure about is how to bring in an analog audio click signal. Can I just use an analog input pin for the audio directly? Or do I need an additional audio shield to determine when the clicks are happening?

I am hoping the arduino can sense when the audio click starts, and based on the time between the start of each click, can determine the BPM being sent. Since it's just a constant click, with silence between the clicks, would sensing voltage be enough to do this?

I think the basic approach is to use a state-machine to manage input samples from analogRead,
you need a threshold to detect a click starting, then a timeout before triggering again (to allow
for the click to subside).

Then the basic logic is a loop to check for incoming midi bytes and push them through,
and drive the analogRead state-machine.

When the next click is detected the appropriate packet should be immediately queued. This
queue should only be allowed to go out on serial if the through-midi is not in the middle of
a packet (so you have to parse the basic midi packet structure to know when that is).