Measuring Latency via Serial Port?

Hello,

I'm using Arduino Micro Pro in tandem with the MIDIUSB library. I have a very basic setup; when a push button is pushed, a MIDI note is sent via the USB to my softsynth via the serial port. I'd like to measure the time elapsed between the moment the button is triggered and when the sound is produced.

I am using using a fairly recent Macbook Pro and I have GarageBand listening to incoming MIDI messages.

Since the momentary button produces a click sound when pushed, I tried recording this with Audacity and once I captured the sound I could measure the time elapsed between when the click was produced and when the softsynth played the sound but this seems to be a very blunt method so I was wondering if someone could suggest something that'd yield a more granular result.

Thanks in advance.

And I think it is brilliant. I'm not sure you can do better, or what is wrong with what you are trying now. Other than it might be a bit fussy, and then there is looking at the evidence so yeah I guess I see why you look for something a step or two better.

Your code knows exactly and can remember, so to speak, when the note was initiated.

But the other end provides feedback that the same process can use to determine when the sound actually comes out of the speaker.

You have used a microphone, here the distance the sound travels might be significant, I'm too lazy not i a position just now to do the maths.

But.

You could attach a fairly simple,e circuit to the speaker to develop a digital input that would close the loop, giving the code that started the process the ability to know when it came to fruition.

Rectifying the speaker voltage and using it to run an optoisolator's input, and watching, however, the output of the optoisolator would work, I think.

a7

how much resolution?

just for my understanding, audacity is recording the both the sound of the "click" and tone produced by MIDI?

and you can look at the # of samples between the click and tone to determine the delay?

is the sample rate ~44kHz?

Yes, once you recorded the sample in Audacity, you can measure the distance between the peak produced by the click and the peak produced by the synth sound and this distance will correspond to the elapsed time. Resolution is not really that imprtant as long as you can see the two peaks in your waveform.

By more granular, what I had in mind was more like:

  • how much time it takes from the moment the click was detected to actually sending the MIDI message and
  • once the message is received on my laptop, how much time does it take for it to hit the softsynth

I can insert timers in my Arduino code but once it's sent, not sure how to trace it. I was thinking something similar to Wireshark although Wireshark is more for network communications so really not sure what tool to use. I am using a Mac.

Thanks