The problem with your code is that it assumes that the frames are spaced exactly the same amount of time apart, it doesn't account for significant variance that can occur when capturing real data. Of course, if you're generating frames, there is some guarantee this might not be the case.
I assume the frame you want is the latest frame that is before the timestamp. If your times were held as struct timeval (an integral type) rather than float, you could use standard algorithms to do the search for you.