Added baseband recording

This commit is contained in:
AlexandreRouma 2020-10-22 12:53:46 +02:00
parent fa1e647235
commit 0d45217dfd
5 changed files with 181 additions and 87 deletions

View File

@ -54,6 +54,10 @@ void SignalPath::setSampleRate(double sampleRate) {
dynSplit.start(); dynSplit.start();
} }
double SignalPath::getSampleRate() {
return sampleRate;
}
void SignalPath::start() { void SignalPath::start() {
dcBiasRemover.start(); dcBiasRemover.start();
split.start(); split.start();
@ -104,3 +108,15 @@ void SignalPath::setInput(dsp::stream<dsp::complex_t>* input) {
dcBiasRemover.setInput(input); dcBiasRemover.setInput(input);
dcBiasRemover.start(); dcBiasRemover.start();
} }
void SignalPath::bindIQStream(dsp::stream<dsp::complex_t>* stream) {
dynSplit.stop();
dynSplit.bind(stream);
dynSplit.start();
}
void SignalPath::unbindIQStream(dsp::stream<dsp::complex_t>* stream) {
dynSplit.stop();
dynSplit.unbind(stream);
dynSplit.start();
}

View File

@ -19,9 +19,12 @@ public:
void setSampleRate(double sampleRate); void setSampleRate(double sampleRate);
void setDCBiasCorrection(bool enabled); void setDCBiasCorrection(bool enabled);
void setFFTRate(double rate); void setFFTRate(double rate);
double getSampleRate();
dsp::VFO* addVFO(std::string name, double outSampleRate, double bandwidth, double offset); dsp::VFO* addVFO(std::string name, double outSampleRate, double bandwidth, double offset);
void removeVFO(std::string name); void removeVFO(std::string name);
void setInput(dsp::stream<dsp::complex_t>* input); void setInput(dsp::stream<dsp::complex_t>* input);
void bindIQStream(dsp::stream<dsp::complex_t>* stream);
void unbindIQStream(dsp::stream<dsp::complex_t>* stream);
private: private:
struct VFO_t { struct VFO_t {

View File

@ -8,6 +8,8 @@
#include <ctime> #include <ctime>
#include <signal_path/audio.h> #include <signal_path/audio.h>
#include <gui/gui.h> #include <gui/gui.h>
#include <signal_path/signal_path.h>
#include <config.h>
#define CONCAT(a, b) ((std::string(a) + b).c_str()) #define CONCAT(a, b) ((std::string(a) + b).c_str())
@ -75,6 +77,59 @@ private:
} }
} }
ImGui::BeginGroup();
// TODO: Change VFO ref in signal path
ImGui::Columns(3, CONCAT("RecordModeColumns##_", _this->name), false);
if (ImGui::RadioButton(CONCAT("Baseband##_", _this->name), _this->recMode == 0) && _this->recMode != 0) {
_this->recMode = 0;
}
ImGui::NextColumn();
if (ImGui::RadioButton(CONCAT("Audio##_", _this->name), _this->recMode == 1) && _this->recMode != 1) {
_this->recMode = 1;
}
ImGui::NextColumn();
if (ImGui::RadioButton(CONCAT("VFO##_", _this->name), _this->recMode == 2) && _this->recMode != 2) {
_this->recMode = 2;
}
ImGui::Columns(1, CONCAT("EndRecordModeColumns##_", _this->name), false);
ImGui::EndGroup();
if (_this->recMode == 0) {
ImGui::PushItemWidth(menuColumnWidth);
if (!_this->recording) {
if (ImGui::Button("Record", ImVec2(menuColumnWidth, 0))) {
_this->samplesWritten = 0;
_this->sampleRate = sigpath::signalPath.getSampleRate();
_this->writer = new WavWriter(ROOT_DIR "/recordings/" + genFileName("baseband_"), 16, 2, _this->sampleRate);
_this->iqStream = new dsp::stream<dsp::complex_t>();
_this->iqStream->init(_this->sampleRate / 200.0);
sigpath::signalPath.bindIQStream(_this->iqStream);
_this->workerThread = std::thread(_iqWriteWorker, _this);
_this->recording = true;
_this->startTime = time(0);
}
ImGui::TextColored(ImGui::GetStyleColorVec4(ImGuiCol_Text), "Idle --:--:--");
}
else {
if (ImGui::Button("Stop", ImVec2(menuColumnWidth, 0))) {
_this->iqStream->stopReader();
_this->workerThread.join();
_this->iqStream->clearReadStop();
sigpath::signalPath.unbindIQStream(_this->iqStream);
_this->writer->close();
delete _this->writer;
_this->recording = false;
}
uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate;
time_t diff = seconds;
tm *dtm = gmtime(&diff);
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec);
}
}
else if (_this->recMode == 1) {
ImGui::PushItemWidth(menuColumnWidth); ImGui::PushItemWidth(menuColumnWidth);
if (!_this->recording) { if (!_this->recording) {
if (ImGui::Combo(CONCAT("##_strea_select_", _this->name), &_this->selectedStreamId, nameList.c_str())) { if (ImGui::Combo(CONCAT("##_strea_select_", _this->name), &_this->selectedStreamId, nameList.c_str())) {
@ -90,14 +145,13 @@ private:
ImGui::PopItemFlag(); ImGui::PopItemFlag();
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
} }
if (!_this->recording) { if (!_this->recording) {
if (ImGui::Button("Record", ImVec2(menuColumnWidth, 0))) { if (ImGui::Button("Record", ImVec2(menuColumnWidth, 0))) {
_this->samplesWritten = 0; _this->samplesWritten = 0;
_this->sampleRate = 48000; _this->sampleRate = 48000;
_this->writer = new WavWriter("recordings/" + genFileName("audio_"), 16, 2, 48000); _this->writer = new WavWriter(ROOT_DIR "/recordings/" + genFileName("audio_"), 16, 2, 48000);
_this->stream = audio::bindToStreamStereo(_this->selectedStreamName, streamRemovedHandler, sampleRateChanged, _this); _this->audioStream = audio::bindToStreamStereo(_this->selectedStreamName, streamRemovedHandler, sampleRateChanged, _this);
_this->workerThread = std::thread(_writeWorker, _this); _this->workerThread = std::thread(_audioWriteWorker, _this);
_this->recording = true; _this->recording = true;
_this->startTime = time(0); _this->startTime = time(0);
} }
@ -105,10 +159,10 @@ private:
} }
else { else {
if (ImGui::Button("Stop", ImVec2(menuColumnWidth, 0))) { if (ImGui::Button("Stop", ImVec2(menuColumnWidth, 0))) {
_this->stream->stopReader(); _this->audioStream->stopReader();
_this->workerThread.join(); _this->workerThread.join();
_this->stream->clearReadStop(); _this->audioStream->clearReadStop();
audio::unbindFromStreamStereo(_this->selectedStreamName, _this->stream); audio::unbindFromStreamStereo(_this->selectedStreamName, _this->audioStream);
_this->writer->close(); _this->writer->close();
delete _this->writer; delete _this->writer;
_this->recording = false; _this->recording = false;
@ -119,12 +173,13 @@ private:
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec); ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec);
} }
} }
}
static void _writeWorker(RecorderModule* _this) { static void _audioWriteWorker(RecorderModule* _this) {
dsp::StereoFloat_t* floatBuf = new dsp::StereoFloat_t[1024]; dsp::StereoFloat_t* floatBuf = new dsp::StereoFloat_t[1024];
int16_t* sampleBuf = new int16_t[2048]; int16_t* sampleBuf = new int16_t[2048];
while (true) { while (true) {
if (_this->stream->read(floatBuf, 1024) < 0) { if (_this->audioStream->read(floatBuf, 1024) < 0) {
break; break;
} }
for (int i = 0; i < 1024; i++) { for (int i = 0; i < 1024; i++) {
@ -138,8 +193,27 @@ private:
delete[] sampleBuf; delete[] sampleBuf;
} }
static void _iqWriteWorker(RecorderModule* _this) {
dsp::complex_t* iqBuf = new dsp::complex_t[1024];
int16_t* sampleBuf = new int16_t[2048];
while (true) {
if (_this->iqStream->read(iqBuf, 1024) < 0) {
break;
}
for (int i = 0; i < 1024; i++) {
sampleBuf[(i * 2) + 0] = iqBuf[i].q * 0x7FFF;
sampleBuf[(i * 2) + 1] = iqBuf[i].i * 0x7FFF;
}
_this->samplesWritten += 1024;
_this->writer->writeSamples(sampleBuf, 2048 * sizeof(int16_t));
}
delete[] iqBuf;
delete[] sampleBuf;
}
std::string name; std::string name;
dsp::stream<dsp::StereoFloat_t>* stream; dsp::stream<dsp::StereoFloat_t>* audioStream;
dsp::stream<dsp::complex_t>* iqStream;
WavWriter* writer; WavWriter* writer;
std::thread workerThread; std::thread workerThread;
bool recording; bool recording;
@ -149,6 +223,7 @@ private:
int selectedStreamId; int selectedStreamId;
uint64_t samplesWritten; uint64_t samplesWritten;
float sampleRate; float sampleRate;
int recMode = 0;
}; };

View File

@ -1,6 +1,6 @@
{ {
"Radio": "./radio/Release/radio.dll", "Radio": "./radio/radio.so",
"Recorder": "./recorder/Release/recorder.dll", "Recorder": "./recorder/recorder.so",
"Soapy": "./soapy/Release/soapy.dll", "Soapy": "./soapy/soapy.so",
"RTLTCPSource": "./rtl_tcp_source/Release/rtl_tcp_source.dll" "RTLTCPSource": "./rtl_tcp_source/rtl_tcp_source.so"
} }