I have situation where each 1ms is coming new buffer of 2*200 samples of int16_t. (multiplied by 2 is because complex data)
Those data should be added into Armadillo Complex Double Matrix, in the fastest way possible (less than 1 ms), to specific slot.
Does anyone know better approach?
Current test code takes longer than 1ms (tested with both cases)
nb_of_samples = 200;
void write(uint32_t rawId, uint32_t slotId, int16_t *samples)
{
size_t currentBlock = slotId * nb_of_samples; // slot identification
auto const memPtr = matrix.colptr(currentBlock) + rawId; // pointer to position from where to start write new received samples
std::for_each(std::execution::par_unseq, m_index.begin(), m_index.end(), [&memPtr, &samples](size_t index)
{
new (memPtr + index) std::complex<double>(samples[index], samples[index+1]);
});
// second idea, simple for
// for(size_t i = 0; i < NB_OF_SAMPLES; ++i)
// {
// new (memPtr + i) std::complex<double>(samples[i], samples[i+1]);
// }
}
C++ makes a special exception to aliasing and UB rules for std::complex
. This is done for compatibility of widely used C subroutines.
https://en.cppreference.com/w/cpp/numeric/complex
So you can just use something simple like this:
void convert(std::complex<double> *pout, const uint16_t* pin)
{
for (size_t i = 0; i < nb_of_samples*2 ; i++)
reinterpret_cast<double*>(pout)[i] = pin[i];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.