From 95052c34ff83a1d713bfb20279befd85f5beb601 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Tue, 13 Feb 2024 03:11:37 +0100 Subject: [PATCH] more work on network source and syntax cleanup in iq exporter --- misc_modules/iq_exporter/src/main.cpp | 2 +- source_modules/network_source/src/main.cpp | 23 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/misc_modules/iq_exporter/src/main.cpp b/misc_modules/iq_exporter/src/main.cpp index 645e3057..9c9c5011 100644 --- a/misc_modules/iq_exporter/src/main.cpp +++ b/misc_modules/iq_exporter/src/main.cpp @@ -509,7 +509,7 @@ private: size = sizeof(int16_t)*2; break; case SAMPLE_TYPE_INT32: - volk_32f_s32f_convert_32i((int32_t*)_this->buffer, (float*)data, (float)2147483647.0f, count*2); + volk_32f_s32f_convert_32i((int32_t*)_this->buffer, (float*)data, 2147483647.0f, count*2); size = sizeof(int32_t)*2; break; case SAMPLE_TYPE_FLOAT32: diff --git a/source_modules/network_source/src/main.cpp b/source_modules/network_source/src/main.cpp index 90f6d8ae..08cd7c7d 100644 --- a/source_modules/network_source/src/main.cpp +++ b/source_modules/network_source/src/main.cpp @@ -244,31 +244,37 @@ private: } void worker() { + // Compute sizes int blockSize = samplerate / 200; - int frameSize = blockSize*SAMPLE_TYPE_SIZE[sampType]; + int sampleSize = SAMPLE_TYPE_SIZE[sampType]; + int frameSize = blockSize*sampleSize; + + // Allocate receive buffer uint8_t* buffer = dsp::buffer::alloc(frameSize); while (true) { // Read samples from socket + int bytes; { std::lock_guard lck(sockMtx); - int bytes = sock->recv(buffer, frameSize, true); + bytes = sock->recv(buffer, frameSize, true); + if (bytes <= 0) { break; } } - // Convert to CF32 - int count; + // Convert to CF32 (note: problem if partial sample) + int count = bytes / sampleSize; switch (sampType) { case SAMPLE_TYPE_INT8: - + volk_8i_s32f_convert_32f((float*)stream.writeBuf, (int8_t*)buffer, 128.0f, count*2); break; case SAMPLE_TYPE_INT16: - + volk_16i_s32f_convert_32f((float*)stream.writeBuf, (int16_t*)buffer, 32768.0f, count*2); break; case SAMPLE_TYPE_INT32: - + volk_32i_s32f_convert_32f((float*)stream.writeBuf, (int32_t*)buffer, 2147483647.0f, count*2); break; case SAMPLE_TYPE_FLOAT32: - //memcpy(stream.writeBuf, buffer, ) + memcpy(stream.writeBuf, buffer, bytes); break; default: break; @@ -278,6 +284,7 @@ private: if (!stream.swap(count)) { break; } } + // Free receive buffer dsp::buffer::free(buffer); }