Skip to content

Commit 949fde0

Browse files
fix recorder options not disabled during recording, increase rfnm source dsp frame size and fix long pause when stopping rfnm
1 parent 123e34d commit 949fde0

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

misc_modules/recorder/src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ class RecorderModule : public ModuleManager::Instance {
249249
}
250250
ImGui::Columns(1, CONCAT("EndRecorderModeColumns##_", _this->name), false);
251251
ImGui::EndGroup();
252-
if (_this->recording) { style::endDisabled(); }
253252

254253
// Recording path
255254
if (_this->folderSelect.render("##_recorder_fold_" + _this->name)) {
@@ -284,8 +283,11 @@ class RecorderModule : public ModuleManager::Instance {
284283
config.release(true);
285284
}
286285

286+
if (_this->recording) { style::endDisabled(); }
287+
287288
// Show additional audio options
288289
if (_this->recMode == RECORDER_MODE_AUDIO) {
290+
if (_this->recording) { style::beginDisabled(); }
289291
ImGui::LeftLabel("Stream");
290292
ImGui::FillWidth();
291293
if (ImGui::Combo(CONCAT("##_recorder_stream_", _this->name), &_this->streamId, _this->audioStreams.txt)) {
@@ -294,6 +296,7 @@ class RecorderModule : public ModuleManager::Instance {
294296
config.conf[_this->name]["audioStream"] = _this->audioStreams.key(_this->streamId);
295297
config.release(true);
296298
}
299+
if (_this->recording) { style::endDisabled(); }
297300

298301
_this->updateAudioMeter(_this->audioLvl);
299302
ImGui::FillWidth();

source_modules/rfnm_source/src/main.cpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,6 @@ class RFNMSourceModule : public ModuleManager::Instance {
249249
// Open the device
250250
_this->openDev = new librfnm(librfnm_transport::LIBRFNM_TRANSPORT_USB, _this->selectedSerial);
251251

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-
265252
// Configure the stream
266253
_this->bufferSize = -1;
267254
_this->openDev->rx_stream(librfnm_stream_format::LIBRFNM_STREAM_FORMAT_CS16, &_this->bufferSize);
@@ -276,6 +263,22 @@ class RFNMSourceModule : public ModuleManager::Instance {
276263
_this->openDev->rx_qbuf(&_this->rxBuf[i]);
277264
}
278265

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+
279282
// Start worker
280283
_this->run = true;
281284
_this->workerThread = std::thread(&RFNMSourceModule::worker, _this);
@@ -295,12 +298,15 @@ class RFNMSourceModule : public ModuleManager::Instance {
295298
if (_this->workerThread.joinable()) { _this->workerThread.join(); }
296299
_this->stream.clearWriteStop();
297300

301+
// Stop the RX streaming
302+
_this->openDev->rx_stream_stop();
303+
298304
// Disable channel
299305
_this->openDev->s->rx.ch[_this->currentPath.chId].enable = RFNM_CH_OFF;
300306
_this->openDev->set(_this->currentPath.appliesCh);
301307

302-
// Stop the RX streaming
303-
_this->openDev->rx_stream_stop();
308+
// Flush buffers
309+
_this->openDev->rx_flush();
304310

305311
// Close device
306312
delete _this->openDev;
@@ -423,8 +429,13 @@ class RFNMSourceModule : public ModuleManager::Instance {
423429
int sampCount = bufferSize/4;
424430
uint8_t ch = (1 << currentPath.chId);
425431

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; }
427437

438+
int count = 0;
428439
while (run) {
429440
// Receive a buffer
430441
auto fail = openDev->rx_dqbuf(&lrxbuf, ch, 1000);
@@ -435,13 +446,17 @@ class RFNMSourceModule : public ModuleManager::Instance {
435446
else if (fail) { break; }
436447

437448
// 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);
439450

440451
// Reque buffer
441452
openDev->rx_qbuf(lrxbuf);
442453

443454
// Swap data
444-
if (!stream.swap(sampCount)) { break; }
455+
if (count >= bufCount) {
456+
if (!stream.swap(count*sampCount)) { break; }
457+
count = 0;
458+
}
459+
445460
}
446461

447462
flog::debug("Worker exiting");

0 commit comments

Comments
 (0)