billthefarmer / mididriver

Android midi driver using Sonivox EAS library
176 stars 52 forks source link

Add functions to modify latency #36

Closed thgcode closed 4 years ago

thgcode commented 4 years ago

I'm trying to reduce the latency of mididriver on my application. I'm using the Java wrapper. It would be nice if you could add functions to modify the buffer size and the other parameters before the driver initializes.

billthefarmer commented 4 years ago

There is only one parameter that is adjustable, the number of buffers. I have made it 4, the same as in MidiFile.cpp, the code that plays midi files in android...

// The midi engine buffers are a bit small (128 frames), so we batch them up
static const int NUM_BUFFERS = 4;

I measured the latency a while ago – https://github.com/billthefarmer/mididriver/issues/12#issuecomment-142563372. It's about 23ms. I thought that was good enough.

thgcode commented 4 years ago

Thank you very much for your reply. I'll try recompiling it with a smaller number of buffers to see if it helps. My problem is that I'm developing an app that needs to play the notes live got from a keyboard, so the faster it outputs audio the better.

thgcode commented 4 years ago

Update: I reduced the number of buffers from 4 to 1 and recompiled the app again. Some of the delay remains, but now it is enough to get the notes almost instantly from the keyboard. Thank you again.

billthefarmer commented 4 years ago

I originally built this driver for my Accordion and Melodeon apps which work in the same way. I would expect more latency from the keyboard than from this driver.