title: Fastest way of resizing (rescaling) a 1D vector by an arbitrary factor
body: <p>I have the following code that does the resizing of a 1D vector with nearest neighbor interpolation in a similar fashion you'd also resize an image. Another term would be resampling, but there seems to be a lot of confusion around these terms (resampling is also a technique in statistics), so I prefer to be more descriptive.</p>
  <p>Currently the code looks like this and I need to optimize it:</p>
  <pre><code>inline void resizeNearestNeighbor(const int16_t* current, uint32_t currentSize, int16_t* out, uint32_t newSize, uint32_t offset = 0u)
  {
      if(currentSize == newSize)
      {
          return;
      }
  
      const float scaleFactor = static_cast&lt;float&gt;(currentSize) / static_cast&lt;float&gt;(newSize);
      for(uint32_t outIdx = 0; outIdx&lt;newSize; ++outIdx)
      {
          const int currentIdx = static_cast&lt;uint32_t&gt;(outIdx * scaleFactor);
          out[outIdx] = current[(currentIdx + offset)%currentSize];
      }
  }
  </code></pre>
  <p>This of course is not hugely efficient because the operation to take the integer part of a float by downcasting is expensive and I don't think it can take any benefit of vectorization in this case. The platform is Cortex M7, so if you're familiar with any vectorization techniques on this platform, it would be also very helpful.</p>
  <p>The use case of this code is a sound effect that allows for smoothly changing the length of a delay line (hence the additional offset parameter, since it's a ring buffer). Being able to smoothly change the length of a delay line sounds like slowing down or speeding up playback in a tape recorder, only it's in a loop. Without this scaling, there are lots of clicking noises and artifacts. Currently the hardware struggles with all the DSP and this code on top of that and it can't rescale long delay lines in real time.</p>