Latency in reading log from SD Card

I’m currently working on a project where I am attempting to read a CSV log from an SD card and interpret it into keyboard and mouse commands using the Keyboard and Mouse libraries for the Arduino Leonardo.

Currently, the sketch plays through all the commands, but the timing seems to drift. If I look at the playback from the serial monitor, I see pauses every so often. I’ve tried monitoring the RAM usage at the same time, and it doesnt appear to be filling, so that leads me to believe it’s some sort of bandwidth issue with the SPI interface on the Arduino.

Here’s the sketch I am using to play the logs back, and a sample log itself.

https://github.com/addisokw/ArduinoHIDPlayback/blob/master/keyboard_playback/keyboard_playback.ino

https://github.com/addisokw/ArduinoHIDPlayback/blob/master/bioshock/combined_log_bioshock.csv

A bit of context to the arbitrary log file format I’m using:

Column 1 is the time which the action occurs,
Column 2 is 0/1//2 to determine whether it is a keyboard command, a mouse movement command, or a mouse click
Column 3 is either mouse X / ascii for a keyboard command / or the mouse button to be pressed (depending on the second field),
Column 4 is either mouse y, key up or down (0,1), or mouse up/down (0,1)

I see pauses every so often

You are going to need to quantify this. How long are the pauses? How often do they occur?

Data is read from the file in 512 byte blocks, when the read buffer is empty. Most reads then read from the buffer. Since your records are small, I'd expect the first read to take some time, but then you should be able to read 25 or 30 times before the buffer is empty, and the card has to actually be accessed again.