Skip to content

Commit

Permalink
more work on network source and syntax cleanup in iq exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Feb 13, 2024
1 parent 34171d4 commit 95052c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion misc_modules/iq_exporter/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 15 additions & 8 deletions source_modules/network_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(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;
Expand All @@ -278,6 +284,7 @@ class NetworkSourceModule : public ModuleManager::Instance {
if (!stream.swap(count)) { break; }
}

// Free receive buffer
dsp::buffer::free(buffer);
}

Expand Down

0 comments on commit 95052c3

Please sign in to comment.