@@ -249,19 +249,6 @@ class RFNMSourceModule : public ModuleManager::Instance {
249
249
// Open the device
250
250
_this->openDev = new librfnm (librfnm_transport::LIBRFNM_TRANSPORT_USB, _this->selectedSerial );
251
251
252
- // Configure the device
253
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].enable = RFNM_CH_ON;
254
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].samp_freq_div_n = _this->samplerates [_this->srId ];
255
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].freq = _this->freq ;
256
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].gain = _this->gain ;
257
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].rfic_lpf_bw = 100 ;
258
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].fm_notch = _this->fmNotch ? rfnm_fm_notch::RFNM_FM_NOTCH_ON : rfnm_fm_notch::RFNM_FM_NOTCH_OFF;
259
- _this->openDev ->s ->rx .ch [_this->currentPath .chId ].path = _this->currentPath .path ;
260
- rfnm_api_failcode fail = _this->openDev ->set (_this->currentPath .appliesCh );
261
- if (fail != rfnm_api_failcode::RFNM_API_OK) {
262
- flog::error (" Failed to configure device: {}" , (int )fail);
263
- }
264
-
265
252
// Configure the stream
266
253
_this->bufferSize = -1 ;
267
254
_this->openDev ->rx_stream (librfnm_stream_format::LIBRFNM_STREAM_FORMAT_CS16, &_this->bufferSize );
@@ -276,6 +263,22 @@ class RFNMSourceModule : public ModuleManager::Instance {
276
263
_this->openDev ->rx_qbuf (&_this->rxBuf [i]);
277
264
}
278
265
266
+ // Flush buffers
267
+ _this->openDev ->rx_flush ();
268
+
269
+ // Configure the device
270
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].enable = RFNM_CH_ON;
271
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].samp_freq_div_n = _this->samplerates [_this->srId ];
272
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].freq = _this->freq ;
273
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].gain = _this->gain ;
274
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].rfic_lpf_bw = 100 ;
275
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].fm_notch = _this->fmNotch ? rfnm_fm_notch::RFNM_FM_NOTCH_ON : rfnm_fm_notch::RFNM_FM_NOTCH_OFF;
276
+ _this->openDev ->s ->rx .ch [_this->currentPath .chId ].path = _this->currentPath .path ;
277
+ rfnm_api_failcode fail = _this->openDev ->set (_this->currentPath .appliesCh );
278
+ if (fail != rfnm_api_failcode::RFNM_API_OK) {
279
+ flog::error (" Failed to configure device: {}" , (int )fail);
280
+ }
281
+
279
282
// Start worker
280
283
_this->run = true ;
281
284
_this->workerThread = std::thread (&RFNMSourceModule::worker, _this);
@@ -295,12 +298,15 @@ class RFNMSourceModule : public ModuleManager::Instance {
295
298
if (_this->workerThread .joinable ()) { _this->workerThread .join (); }
296
299
_this->stream .clearWriteStop ();
297
300
301
+ // Stop the RX streaming
302
+ _this->openDev ->rx_stream_stop ();
303
+
298
304
// Disable channel
299
305
_this->openDev ->s ->rx .ch [_this->currentPath .chId ].enable = RFNM_CH_OFF;
300
306
_this->openDev ->set (_this->currentPath .appliesCh );
301
307
302
- // Stop the RX streaming
303
- _this->openDev ->rx_stream_stop ();
308
+ // Flush buffers
309
+ _this->openDev ->rx_flush ();
304
310
305
311
// Close device
306
312
delete _this->openDev ;
@@ -423,8 +429,13 @@ class RFNMSourceModule : public ModuleManager::Instance {
423
429
int sampCount = bufferSize/4 ;
424
430
uint8_t ch = (1 << currentPath.chId );
425
431
426
- // TODO: Define number of buffers per swap to maintain 200 fps
432
+ // Define number of buffers per swap to maintain 200 fps
433
+ int maxBufCount = STREAM_BUFFER_SIZE / sampCount;
434
+ int bufCount = (sampleRate / sampCount) / 200 ;
435
+ if (bufCount <= 0 ) { bufCount = 1 ; }
436
+ if (bufCount > maxBufCount) { bufCount = maxBufCount; }
427
437
438
+ int count = 0 ;
428
439
while (run) {
429
440
// Receive a buffer
430
441
auto fail = openDev->rx_dqbuf (&lrxbuf, ch, 1000 );
@@ -435,13 +446,17 @@ class RFNMSourceModule : public ModuleManager::Instance {
435
446
else if (fail) { break ; }
436
447
437
448
// Convert buffer to CF32
438
- volk_16i_s32f_convert_32f ((float *)stream.writeBuf , (int16_t *)lrxbuf->buf , 32768 .0f , sampCount * 2 );
449
+ volk_16i_s32f_convert_32f ((float *)& stream.writeBuf [(count++)*sampCount] , (int16_t *)lrxbuf->buf , 32768 .0f , sampCount * 2 );
439
450
440
451
// Reque buffer
441
452
openDev->rx_qbuf (lrxbuf);
442
453
443
454
// Swap data
444
- if (!stream.swap (sampCount)) { break ; }
455
+ if (count >= bufCount) {
456
+ if (!stream.swap (count*sampCount)) { break ; }
457
+ count = 0 ;
458
+ }
459
+
445
460
}
446
461
447
462
flog::debug (" Worker exiting" );
0 commit comments