Skip to content

Commit

Permalink
more progress on the network source
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Feb 12, 2024
1 parent 2b752bb commit 01ab183
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions source_modules/network_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ enum SampleType {
SAMPLE_TYPE_FLOAT32
};

const size_t SAMPLE_TYPE_SIZE[] {
sizeof(int8_t)*2,
sizeof(int16_t)*2,
sizeof(int32_t)*2,
sizeof(float)*2,
};

class NetworkSourceModule : public ModuleManager::Instance {
public:
NetworkSourceModule(std::string name) {
Expand Down Expand Up @@ -237,40 +244,28 @@ class NetworkSourceModule : public ModuleManager::Instance {
}

void worker() {
int frameSize = samplerate / 200;
switch (sampType) {
case SAMPLE_TYPE_INT8:
frameSize *= 2*sizeof(int8_t);;
break;
case SAMPLE_TYPE_INT16:
frameSize *= 2*sizeof(int16_t);
break;
case SAMPLE_TYPE_INT32:
frameSize *= 2*sizeof(int32_t);
break;
case SAMPLE_TYPE_FLOAT32:
frameSize *= sizeof(dsp::complex_t);
break;
default:
return;
}
uint8_t* buffer = dsp::buffer::alloc<uint8_t>(STREAM_BUFFER_SIZE*sizeof(uint32_t));
int blockSize = samplerate / 200;
int frameSize = blockSize*SAMPLE_TYPE_SIZE[sampType];
uint8_t* buffer = dsp::buffer::alloc<uint8_t>(frameSize);

while (true) {
// Read samples from socket
int bytes = sock->recv(buffer, frameSize, true);
{
std::lock_guard lck(sockMtx);
int bytes = sock->recv(buffer, frameSize, true);
}

// Convert to CF32
int count;
switch (sampType) {
case SAMPLE_TYPE_INT8:
frameSize *= 2*sizeof(int8_t);;

break;
case SAMPLE_TYPE_INT16:
frameSize *= 2*sizeof(int16_t);

break;
case SAMPLE_TYPE_INT32:
frameSize *= 2*sizeof(int32_t);

break;
case SAMPLE_TYPE_FLOAT32:
//memcpy(stream.writeBuf, buffer, )
Expand All @@ -280,7 +275,7 @@ class NetworkSourceModule : public ModuleManager::Instance {
}

// Send out converted samples
//if (!stream.swap(bufferSize))
if (!stream.swap(count)) { break; }
}

dsp::buffer::free(buffer);
Expand Down

0 comments on commit 01ab183

Please sign in to comment.