Skip to content

Commit 95052c3

Browse files
more work on network source and syntax cleanup in iq exporter
1 parent 34171d4 commit 95052c3

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

misc_modules/iq_exporter/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class IQExporterModule : public ModuleManager::Instance {
509509
size = sizeof(int16_t)*2;
510510
break;
511511
case SAMPLE_TYPE_INT32:
512-
volk_32f_s32f_convert_32i((int32_t*)_this->buffer, (float*)data, (float)2147483647.0f, count*2);
512+
volk_32f_s32f_convert_32i((int32_t*)_this->buffer, (float*)data, 2147483647.0f, count*2);
513513
size = sizeof(int32_t)*2;
514514
break;
515515
case SAMPLE_TYPE_FLOAT32:

source_modules/network_source/src/main.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,31 +244,37 @@ class NetworkSourceModule : public ModuleManager::Instance {
244244
}
245245

246246
void worker() {
247+
// Compute sizes
247248
int blockSize = samplerate / 200;
248-
int frameSize = blockSize*SAMPLE_TYPE_SIZE[sampType];
249+
int sampleSize = SAMPLE_TYPE_SIZE[sampType];
250+
int frameSize = blockSize*sampleSize;
251+
252+
// Allocate receive buffer
249253
uint8_t* buffer = dsp::buffer::alloc<uint8_t>(frameSize);
250254

251255
while (true) {
252256
// Read samples from socket
257+
int bytes;
253258
{
254259
std::lock_guard lck(sockMtx);
255-
int bytes = sock->recv(buffer, frameSize, true);
260+
bytes = sock->recv(buffer, frameSize, true);
261+
if (bytes <= 0) { break; }
256262
}
257263

258-
// Convert to CF32
259-
int count;
264+
// Convert to CF32 (note: problem if partial sample)
265+
int count = bytes / sampleSize;
260266
switch (sampType) {
261267
case SAMPLE_TYPE_INT8:
262-
268+
volk_8i_s32f_convert_32f((float*)stream.writeBuf, (int8_t*)buffer, 128.0f, count*2);
263269
break;
264270
case SAMPLE_TYPE_INT16:
265-
271+
volk_16i_s32f_convert_32f((float*)stream.writeBuf, (int16_t*)buffer, 32768.0f, count*2);
266272
break;
267273
case SAMPLE_TYPE_INT32:
268-
274+
volk_32i_s32f_convert_32f((float*)stream.writeBuf, (int32_t*)buffer, 2147483647.0f, count*2);
269275
break;
270276
case SAMPLE_TYPE_FLOAT32:
271-
//memcpy(stream.writeBuf, buffer, )
277+
memcpy(stream.writeBuf, buffer, bytes);
272278
break;
273279
default:
274280
break;
@@ -278,6 +284,7 @@ class NetworkSourceModule : public ModuleManager::Instance {
278284
if (!stream.swap(count)) { break; }
279285
}
280286

287+
// Free receive buffer
281288
dsp::buffer::free(buffer);
282289
}
283290

0 commit comments

Comments
 (0)