Close

Latency goes below 10ms!

A project log for RaspiDrums

Electronic drums using a Raspberry Pi and ±200g accelerometers.

jeremyJeremy 09/13/2015 at 13:550 Comments

Latency has always been an issue since I started this project. The main reason was that the sound card I use a minimum buffer size of 1024 samples, which corresponds to a latency of 21.3 ms at 48kHz sample rate.

The obvious choice is to use another sound card. I now use a Startech ICUSBAUDIO2D, for which I can set a 44.1, 48, or even 96kHz sample rate. But that's not it, the minimum buffer size is 96 samples, which corresponds to 2 ms latency at 48kHz.

Using this configuration, I was able to compare the delay between the piezo, that is already in one of my Roland's drum pads, and the output of the RaspiDrums.

The following figure shows how this delay changes.

The average delay is 12.8 ± 0.7 ms. But that's without setting a high priority to the process. So, using nice, and setting the highest priority, I was able to get 9.2 ± 0.8 ms. That's below 10 ms!

Those tests were performed with a scan time of 4 ms, which means that RaspiDrums scans the signal for 4 ms, looking for the maximum value, before it sends the sound to the mixer. Lowering this value leads to a lower latency. So finally, using a 1 ms scan time instead of 4 should lead to 6.2 ± 0.8 ms (not tested, but I recommend you use a 4 ms scan time).

In conclusion, that definitely proves that RaspiDrums latency is below 10 ms. Note that even without using nice (12.8 ms latency), I don't really notice any latency while playing.

Cheers.

Discussions