Skip to content

Commit

Permalink
Merge pull request #1 from anathn/feature/RecorderModuleSplitFiles
Browse files Browse the repository at this point in the history
Recorder Module Creates New File on silence
  • Loading branch information
anathn committed Mar 7, 2024
2 parents 3a50960 + b89de04 commit db4372d
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions misc_modules/recorder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class RecorderModule : public ModuleManager::Instance {
if (config.conf[name].contains("ignoreSilence")) {
ignoreSilence = config.conf[name]["ignoreSilence"];
}
if (config.conf[name].contains("splitFile")) {
splitFile = config.conf[name]["splitFile"];
}
if (config.conf[name].contains("nameTemplate")) {
std::string _nameTemplate = config.conf[name]["nameTemplate"];
if (_nameTemplate.length() > sizeof(nameTemplate)-1) {
Expand Down Expand Up @@ -150,10 +153,7 @@ class RecorderModule : public ModuleManager::Instance {
return enabled;
}

void start() {
std::lock_guard<std::recursive_mutex> lck(recMtx);
if (recording) { return; }

void setupWriter() {
// Configure the wav writer
if (recMode == RECORDER_MODE_AUDIO) {
if (selectedStreamName.empty()) { return; }
Expand All @@ -177,7 +177,13 @@ class RecorderModule : public ModuleManager::Instance {
return;
}

// Open audio stream or baseband
}

void start() {
std::lock_guard<std::recursive_mutex> lck(recMtx);
if (recording) { return; }
// Open audio stream or baseband

if (recMode == RECORDER_MODE_AUDIO) {
// Start correct path depending on
if (stereo) {
Expand All @@ -196,32 +202,29 @@ class RecorderModule : public ModuleManager::Instance {
basebandSink.start();
sigpath::iqFrontEnd.bindIQStream(basebandStream);
}

recording = true;
}

void stop() {
std::lock_guard<std::recursive_mutex> lck(recMtx);
if (!recording) { return; }

writer.close();
// Close audio stream or baseband
if (recMode == RECORDER_MODE_AUDIO) {
splitter.unbindStream(&stereoStream);
monoSink.stop();
stereoSink.stop();
s2m.stop();


}
else {
// Unbind and destroy IQ stream
sigpath::iqFrontEnd.unbindIQStream(basebandStream);
basebandSink.stop();
delete basebandStream;

}

// Close file
writer.close();

recording = false;
}

Expand Down Expand Up @@ -322,6 +325,12 @@ class RecorderModule : public ModuleManager::Instance {
config.conf[_this->name]["ignoreSilence"] = _this->ignoreSilence;
config.release(true);
}

if (ImGui::Checkbox(CONCAT("Split File##_recorder_split_file_", _this->name), &_this->splitFile)) {
config.acquire();
config.conf[_this->name]["splitFile"] = _this->splitFile;
config.release(true);
}
}

// Record button
Expand Down Expand Up @@ -501,6 +510,7 @@ class RecorderModule : public ModuleManager::Instance {

static void complexHandler(dsp::complex_t* data, int count, void* ctx) {
RecorderModule* _this = (RecorderModule*)ctx;
if (!_this->writer.isOpen()){ _this->setupWriter(); }
_this->writer.write((float*)data, count);
}

Expand All @@ -515,8 +525,13 @@ class RecorderModule : public ModuleManager::Instance {
if (val > absMax) { absMax = val; }
}
_this->ignoringSilence = (absMax < SILENCE_LVL);
if (_this->ignoringSilence) { return; }
if (_this->ignoringSilence) {
if (_this->splitFile) { _this->writer.close(); }
return;
}
}

if (!_this->writer.isOpen()){ _this->setupWriter(); }
_this->writer.write((float*)data, count);
}

Expand All @@ -529,8 +544,13 @@ class RecorderModule : public ModuleManager::Instance {
if (val > absMax) { absMax = val; }
}
_this->ignoringSilence = (absMax < SILENCE_LVL);
if (_this->ignoringSilence) { return; }
if (_this->ignoringSilence) {
if (_this->splitFile) { _this->writer.close(); }
return;
}
}

if (!_this->writer.isOpen()){ _this->setupWriter(); }
_this->writer.write(data, count);
}

Expand Down Expand Up @@ -570,6 +590,7 @@ class RecorderModule : public ModuleManager::Instance {
std::string selectedStreamName = "";
float audioVolume = 1.0f;
bool ignoreSilence = false;
bool splitFile = false;
dsp::stereo_t audioLvl = { -100.0f, -100.0f };

bool recording = false;
Expand Down

0 comments on commit db4372d

Please sign in to comment.