baud rate and latency

im using arduino uno to capture 5 piezo toggle values (table tennis balls&table) that are being forwarded over midi to ableton and i can tell an audible latency between the real and the augmented sound.
regarding baud rates and latency, i found out over testing that 57600, 9600 and 4800 react slower than 14400. how is the optimal baud rate being calculated ?
thanks

ggml:
i found out over testing that 57600, 9600 and 4800 react slower than 14400. how is the optimal baud rate being calculated ?

That's unintuitive and may indicate that there's a design flaw in the sensing or communication algorithm. Perhaps if you posted your code, and gave a bit more detail about the results you're getting (How much delay are you getting, in reality? How big a delay would be tolerable?), somebody might be able to suggest possible causes.

the code is standard firmata, the data gets passed over rs232 to a platform (vvvv) that is converting the impulses to midi.
differences in latency occur on the same setup, but at different baud rates, as described.

can you also test at 115200?

I know that 57600 is a "strange" baudrate as you check the libs how it is handled, but even then it should be faster than 14K.

Please post your code, maybe there is some fix?

In that case I suggest you need to determine whether the latency occurs within the Firmata sketch or the (ableton ?) application receiving the events from it, and then approach the corresponding user community for help.

sound and visual feedback are in sync
latency changes with baud rate of the arduino, on the same setup.

and indeed 115200 seems to work best, thank you

The signal passes so many buffers and code.
The resulting latency is hard to predict.

Did you know the Arduino can send midi codes itself ?

I think that most latency is in the firmata path. So I'm guessing that the latency could be easily half of what you have now by directly sending midi strings.

Detecting a knock is also something that often can be made a lot faster.
If you calculate the delta and test for a certain level, the knock will be detected on the rising slope. You can't get faster than that.

i need the sensor data inside my work platform (instead of sending midi directly from arduino), for a couple of reasons:

  • dynamic treshold
  • some boolean logic
  • signal used also for visual feedback, wich is not midi
  • cannot code

however,
could you please hint me at a resource about the minimal code that i would be needing for capturing 5 analog inputs (piezo),
so that i hopefully will reduce latency caused by standard firmata.

If you calculate the delta and test for a certain level, the knock will be detected on the rising slope

what do you mean by delta ?
what do you mean by test for a certain level? a treshold ?

With delta I mean the difference with the previous sample.
That is the first derivate.

If the value is above a certain level, the signal is rising with a steep slope.
Some filtering is needed to avoid detection of noise.

I think the best option is to let the Arduino do the detection and send the data to the midi and the work platform. So you have all the data and also a fast response.
But you have to know how to write code, since the code will always require some adjusting and finetuning.

i can implement something similar with 'framedifference'
before i implement logic in arduino, does it make sense from the latency pov to just to get rid of standard firmata and have some custom, minimal code that is only forwarding the analog inputs ?

I don't know the numbers for latency.
If I search for "firmata latency" there are many things to read about it, but I still don't know.

You could run a few tests, to see what happens, and to learn along the way.