Rewrite main resampling loop (common and linear).