From 8f4942bbe969c4b058a3cbd1bf83dac9684f38f6 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 30 Jun 2021 02:48:36 +0200 Subject: [PATCH] Mooooore performance --- hackrf_source/src/main.cpp | 5 +---- plutosdr_source/src/main.cpp | 3 +++ recorder/src/main.cpp | 10 ++-------- sdrplay_source/src/main.cpp | 1 + 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/hackrf_source/src/main.cpp b/hackrf_source/src/main.cpp index 1cd792cb..f039aad4 100644 --- a/hackrf_source/src/main.cpp +++ b/hackrf_source/src/main.cpp @@ -361,10 +361,7 @@ private: HackRFSourceModule* _this = (HackRFSourceModule*)transfer->rx_ctx; int count = transfer->valid_length / 2; int8_t* buffer = (int8_t*)transfer->buffer; - for (int i = 0; i < count; i++) { - _this->stream.writeBuf[i].re = (float)buffer[i * 2] / 128.0f; - _this->stream.writeBuf[i].im = (float)buffer[(i * 2) + 1] / 128.0f; - } + volk_8i_s32f_convert_32f((float*)_this->stream.writeBuf, buffer, 128.0f, count*2); if (!_this->stream.swap(count)) { return -1; } return 0; } diff --git a/plutosdr_source/src/main.cpp b/plutosdr_source/src/main.cpp index 6186da38..8c8cfae5 100644 --- a/plutosdr_source/src/main.cpp +++ b/plutosdr_source/src/main.cpp @@ -235,6 +235,9 @@ private: _this->stream.writeBuf[i].re = (float)buf[i * 2] / 32768.0f; _this->stream.writeBuf[i].im = (float)buf[(i * 2) + 1] / 32768.0f; } + + volk_16i_s32f_convert_32f((float*)_this->stream.writeBuf, buf, 32768.0f, blockSize*2); + if (!_this->stream.swap(blockSize)) { break; }; } diff --git a/recorder/src/main.cpp b/recorder/src/main.cpp index 4cffebed..4e1ed70d 100644 --- a/recorder/src/main.cpp +++ b/recorder/src/main.cpp @@ -313,20 +313,14 @@ private: static void _audioHandler(dsp::stereo_t *data, int count, void *ctx) { RecorderModule* _this = (RecorderModule*)ctx; - for (int i = 0; i < count; i++) { - _this->wavSampleBuf[(2*i)] = std::clamp(data[i].l * 32767.0f, -32768, 32767); - _this->wavSampleBuf[(2*i) + 1] = std::clamp(data[i].r * 32767.0f, -32768, 32767); - } + volk_32f_s32f_convert_16i(_this->wavSampleBuf, (float*)data, 32767.0f, count*2); _this->audioWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t)); _this->samplesWritten += count; } static void _basebandHandler(dsp::complex_t *data, int count, void *ctx) { RecorderModule* _this = (RecorderModule*)ctx; - for (int i = 0; i < count; i++) { - _this->wavSampleBuf[(2*i)] = data[i].re * 32767.0f; - _this->wavSampleBuf[(2*i) + 1] = data[i].im * 32767.0f; - } + volk_32f_s32f_convert_16i(_this->wavSampleBuf, (float*)data, 32767.0f, count*2); _this->basebandWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t)); _this->samplesWritten += count; } diff --git a/sdrplay_source/src/main.cpp b/sdrplay_source/src/main.cpp index b8e9baa9..e066ed16 100644 --- a/sdrplay_source/src/main.cpp +++ b/sdrplay_source/src/main.cpp @@ -913,6 +913,7 @@ private: static void streamCB(short *xi, short *xq, sdrplay_api_StreamCbParamsT *params, unsigned int numSamples, unsigned int reset, void *cbContext) { SDRPlaySourceModule* _this = (SDRPlaySourceModule*)cbContext; + // TODO: Optimise using volk and math if (!_this->running) { return; } for (int i = 0; i < numSamples; i++) { int id = _this->bufferIndex++;