diff --git a/misc_modules/iq_exporter/src/main.cpp b/misc_modules/iq_exporter/src/main.cpp index 645e30578..9c9c50113 100644 --- a/misc_modules/iq_exporter/src/main.cpp +++ b/misc_modules/iq_exporter/src/main.cpp @@ -509,7 +509,7 @@ class IQExporterModule : public ModuleManager::Instance { 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 90f6d8ae5..08cd7c7da 100644 --- a/source_modules/network_source/src/main.cpp +++ b/source_modules/network_source/src/main.cpp @@ -244,31 +244,37 @@ class NetworkSourceModule : public ModuleManager::Instance { } 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 @@ class NetworkSourceModule : public ModuleManager::Instance { if (!stream.swap(count)) { break; } } + // Free receive buffer dsp::buffer::free(buffer); }