1
$\begingroup$

I have a packetized binary data file that can be referenced in one of two ways:

  1. By an arbitrary time tick counter, and
  2. By a file offset in bytes.

In my example file, I have the following packet locations:

ticks           file offset 729047097              3214   <-- Location of first packet 739047132          37492760   <-- Location of last packet ---------          --------  10000035          37494046   <-- Differences 

I need a function that I can present start and end ticks, start and end offsets, and a candidate number of ticks between the start and end ticks, and have it return the corresponding file offset.

I already know that I can compute a Bytes per Tick value, and then multiply that by (candidate ticks minus start ticks), but what I would like to know is:

  1. What is the general form of this function, and
  2. Is there a name for this general form?

1 Answers 1

4

If I understand correctly what you're trying to do, it's called linear interpolation, and the formula for it is

$o(t)=o_0+(t-t_0)\frac{o_1-o_0}{t_1-t_0}\;,$

where $o_0$, $o_1$ and $t_0$, $t_1$ are the file offsets and ticks at start and end, respectively, and $o(t)$ is the file offset corresponding to tick $t$. The "bytes per tick" value is the fraction on the right. How to arrive at this is explained in the Wikipedia article.

  • 0
    Yes! I knew there was a name for it, I just couldn't remember.2011-08-09