add snap to nearest sample functionality