Skip to content

Commit

Permalink
fix recorder options not disabled during recording, increase rfnm sou…
Browse files Browse the repository at this point in the history
…rce dsp frame size and fix long pause when stopping rfnm
  • Loading branch information
AlexandreRouma committed Jul 18, 2024
1 parent 123e34d commit 949fde0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
5 changes: 4 additions & 1 deletion misc_modules/recorder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ class RecorderModule : public ModuleManager::Instance {
}
ImGui::Columns(1, CONCAT("EndRecorderModeColumns##_", _this->name), false);
ImGui::EndGroup();
if (_this->recording) { style::endDisabled(); }

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

if (_this->recording) { style::endDisabled(); }

// Show additional audio options
if (_this->recMode == RECORDER_MODE_AUDIO) {
if (_this->recording) { style::beginDisabled(); }
ImGui::LeftLabel("Stream");
ImGui::FillWidth();
if (ImGui::Combo(CONCAT("##_recorder_stream_", _this->name), &_this->streamId, _this->audioStreams.txt)) {
Expand All @@ -294,6 +296,7 @@ class RecorderModule : public ModuleManager::Instance {
config.conf[_this->name]["audioStream"] = _this->audioStreams.key(_this->streamId);
config.release(true);
}
if (_this->recording) { style::endDisabled(); }

_this->updateAudioMeter(_this->audioLvl);
ImGui::FillWidth();
Expand Down
51 changes: 33 additions & 18 deletions source_modules/rfnm_source/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,6 @@ class RFNMSourceModule : public ModuleManager::Instance {
// Open the device
_this->openDev = new librfnm(librfnm_transport::LIBRFNM_TRANSPORT_USB, _this->selectedSerial);

// Configure the device
_this->openDev->s->rx.ch[_this->currentPath.chId].enable = RFNM_CH_ON;
_this->openDev->s->rx.ch[_this->currentPath.chId].samp_freq_div_n = _this->samplerates[_this->srId];
_this->openDev->s->rx.ch[_this->currentPath.chId].freq = _this->freq;
_this->openDev->s->rx.ch[_this->currentPath.chId].gain = _this->gain;
_this->openDev->s->rx.ch[_this->currentPath.chId].rfic_lpf_bw = 100;
_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;
_this->openDev->s->rx.ch[_this->currentPath.chId].path = _this->currentPath.path;
rfnm_api_failcode fail = _this->openDev->set(_this->currentPath.appliesCh);
if (fail != rfnm_api_failcode::RFNM_API_OK) {
flog::error("Failed to configure device: {}", (int)fail);
}

// Configure the stream
_this->bufferSize = -1;
_this->openDev->rx_stream(librfnm_stream_format::LIBRFNM_STREAM_FORMAT_CS16, &_this->bufferSize);
Expand All @@ -276,6 +263,22 @@ class RFNMSourceModule : public ModuleManager::Instance {
_this->openDev->rx_qbuf(&_this->rxBuf[i]);
}

// Flush buffers
_this->openDev->rx_flush();

// Configure the device
_this->openDev->s->rx.ch[_this->currentPath.chId].enable = RFNM_CH_ON;
_this->openDev->s->rx.ch[_this->currentPath.chId].samp_freq_div_n = _this->samplerates[_this->srId];
_this->openDev->s->rx.ch[_this->currentPath.chId].freq = _this->freq;
_this->openDev->s->rx.ch[_this->currentPath.chId].gain = _this->gain;
_this->openDev->s->rx.ch[_this->currentPath.chId].rfic_lpf_bw = 100;
_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;
_this->openDev->s->rx.ch[_this->currentPath.chId].path = _this->currentPath.path;
rfnm_api_failcode fail = _this->openDev->set(_this->currentPath.appliesCh);
if (fail != rfnm_api_failcode::RFNM_API_OK) {
flog::error("Failed to configure device: {}", (int)fail);
}

// Start worker
_this->run = true;
_this->workerThread = std::thread(&RFNMSourceModule::worker, _this);
Expand All @@ -295,12 +298,15 @@ class RFNMSourceModule : public ModuleManager::Instance {
if (_this->workerThread.joinable()) { _this->workerThread.join(); }
_this->stream.clearWriteStop();

// Stop the RX streaming
_this->openDev->rx_stream_stop();

// Disable channel
_this->openDev->s->rx.ch[_this->currentPath.chId].enable = RFNM_CH_OFF;
_this->openDev->set(_this->currentPath.appliesCh);

// Stop the RX streaming
_this->openDev->rx_stream_stop();
// Flush buffers
_this->openDev->rx_flush();

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

// TODO: Define number of buffers per swap to maintain 200 fps
// Define number of buffers per swap to maintain 200 fps
int maxBufCount = STREAM_BUFFER_SIZE / sampCount;
int bufCount = (sampleRate / sampCount) / 200;
if (bufCount <= 0) { bufCount = 1; }
if (bufCount > maxBufCount) { bufCount = maxBufCount; }

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

// Convert buffer to CF32
volk_16i_s32f_convert_32f((float*)stream.writeBuf, (int16_t*)lrxbuf->buf, 32768.0f, sampCount * 2);
volk_16i_s32f_convert_32f((float*)&stream.writeBuf[(count++)*sampCount], (int16_t*)lrxbuf->buf, 32768.0f, sampCount * 2);

// Reque buffer
openDev->rx_qbuf(lrxbuf);

// Swap data
if (!stream.swap(sampCount)) { break; }
if (count >= bufCount) {
if (!stream.swap(count*sampCount)) { break; }
count = 0;
}

}

flog::debug("Worker exiting");
Expand Down

0 comments on commit 949fde0

Please sign in to comment.