Replaced resample function with new algorithm.

This reduces compounding floating point errors, speeds up the function 1.5x, and ensures that there are no off-by-one errors leading to memory access problems.