@@ -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