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, only in 1D rather than 2D. 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.
Currently the code looks like this and I need to optimize it:
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<float>(currentSize) / static_cast<float>(newSize);
for(uint32_t outIdx = 0; outIdx<newSize; ++outIdx)
{
const int currentIdx = static_cast<uint32_t>(outIdx * scaleFactor);
out[outIdx] = current[(currentIdx + offset)%currentSize];
}
}
You can ignore the offset in the function above - it's there because the item being resized is a ring buffer which can vary its length (by shortening head or tail).
I saw there's a group of functions designated for linear interpolation in CMSIS DSP library by Keil and perhaps there's also something that would fulfill this example as well and speed it up in the library. Unfortunately I'm unable to understand the provided example with the sine...
Do you know what would be the most efficient way of realizing the above function on this platform (can also use any form of interpolation and not just nearest neighbor)?