Changed the default NFM snap interval

This commit is contained in:
Ryzerth 2021-06-17 20:14:23 +02:00
parent b5d38c71ce
commit da2f4fcf3a
6 changed files with 160 additions and 33 deletions

View File

@ -214,4 +214,79 @@ namespace dsp {
std::condition_variable canReadVar;
std::condition_variable canWriteVar;
};
template <class T>
class BufferBlock : public generic_block<BufferBlock<T>> {
public:
BufferBlock() {}
BufferBlock(stream<T>* in, int bufferSize) { init(in, bufferSize); }
~BufferBlock(stream<T>* in, int bufferSize) {
generic_block<BufferBlock<T>>::stop();
delete[] buffer;
}
void init(stream<T>* in, int bufferSize) {
_in = in;
_bufferSize = bufferSize;
buffer = new T[_bufferSize];
generic_block<BufferBlock<T>>::registerInput(_in);
}
void setInput(stream<T>* in) {
std::lock_guard<std::mutex> lck(generic_block<BufferBlock<T>>::ctrlMtx);
generic_block<BufferBlock<T>>::tempStop();
generic_block<BufferBlock<T>>::unregisterInput(_in);
_in = in;
generic_block<BufferBlock<T>>::registerInput(_in);
generic_block<BufferBlock<T>>::tempStart();
}
int run() {
int count = _in->read();
if (count < 0) { return -1; }
// If there's enough space in the buffer, write data. Otherwise, discard
{
std::lock_guard<std::mutex> lck(bufferMtx);
if (dataInBuffer + count <= _bufferSize) {
memcpy(&buffer[dataInBuffer], _in->readBuf, count);
dataInBuffer += count;
}
}
// Notify reader that data is available
cnd.notify_all();
_in->flush();
return count;
}
void readWorker() {
}
private:
void doStart() {
}
void doStop() {
}
stream<T>* _in;
int _bufferSize;
T* buffer;
int dataInBuffer = 0;
std::mutex bufferMtx;
std::condition_variable cnd;
bool stopReaderThread = false;
std::thread readerThread;
};
};

View File

@ -7,6 +7,7 @@
#include <volk/volk.h>
#include <GLFW/glfw3.h>
#include <spdlog/spdlog.h>
#include <gui/gui.h>
float DEFAULT_COLOR_MAP[][3] = {
{0x00, 0x00, 0x20},

View File

@ -154,7 +154,6 @@ namespace ImGui {
_BANDPLAN_POS_COUNT
};
private:
void drawWaterfall();
void drawFFT();

View File

@ -82,16 +82,58 @@ private:
}
}
bool bookmarkEditDialog(FrequencyBookmark& bm) {
bool bookmarkEditDialog() {
bool open = true;
std::string id = "Edit##freq_manager_edit_popup_" + name;
ImGui::OpenPopup(id.c_str());
FrequencyBookmark tmp = bm;
char nameBuf[1024];
strcpy(nameBuf, editedBookmarkName.c_str());
if (ImGui::BeginPopup(id.c_str(), ImGuiWindowFlags_NoResize)) {
if (ImGui::Button("Apply")) {
bm = tmp;
open = false;
ImGui::BeginTable(("freq_manager_edit_table"+name).c_str(), 2);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Name");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(200);
if (ImGui::InputText(("##freq_manager_edit_name"+name).c_str(), nameBuf, 1023)) {
editedBookmarkName = nameBuf;
}
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Frequency");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(200);
ImGui::InputDouble(("##freq_manager_edit_freq"+name).c_str(), &editedBookmark.frequency);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Bandwidth");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(200);
ImGui::InputDouble(("##freq_manager_edit_bw"+name).c_str(), &editedBookmark.bandwidth);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Mode");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(200);
char* testList = "WFM\0";
int testInt = 0;
ImGui::Combo(("##freq_manager_edit_mode"+name).c_str(), &testInt, testList);
ImGui::EndTable();
if (strlen(nameBuf) == 0) { style::beginDisabled(); }
if (ImGui::Button("Apply")) {
open = false;
bookmarks[nameBuf] = editedBookmark;
}
if (strlen(nameBuf) == 0) { style::endDisabled(); }
ImGui::SameLine();
if (ImGui::Button("Cancel")) {
open = false;
@ -109,6 +151,13 @@ private:
std::vector<std::string> selectedNames;
for (auto& [name, bm] : _this->bookmarks) { if (bm.selected) { selectedNames.push_back(name); } }
ImGui::Text("List");
ImGui::SameLine();
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
char* testList = "Bad music\0";
int testInt = 0;
ImGui::Combo(("##freq_manager_list_sel"+_this->name).c_str(), &testInt, testList);
//Draw buttons on top of the list
ImGui::BeginTable(("freq_manager_btn_table"+_this->name).c_str(), 3);
ImGui::TableNextRow();
@ -116,32 +165,39 @@ private:
ImGui::TableSetColumnIndex(0);
if (ImGui::Button(("Add##_freq_mgr_add_" + _this->name).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) {
// If there's no VFO selected, just save the center freq
FrequencyBookmark bm;
if (gui::waterfall.selectedVFO == "") {
bm.frequency = gui::waterfall.getCenterFrequency();
bm.bandwidth = 0;
bm.mode = -1;
_this->editedBookmark.frequency = gui::waterfall.getCenterFrequency();
_this->editedBookmark.bandwidth = 0;
_this->editedBookmark.mode = -1;
}
else {
bm.frequency = gui::waterfall.getCenterFrequency() + sigpath::vfoManager.getOffset(gui::waterfall.selectedVFO);
bm.bandwidth = sigpath::vfoManager.getBandwidth(gui::waterfall.selectedVFO);
bm.mode = -1;
_this->editedBookmark.frequency = gui::waterfall.getCenterFrequency() + sigpath::vfoManager.getOffset(gui::waterfall.selectedVFO);
_this->editedBookmark.bandwidth = sigpath::vfoManager.getBandwidth(gui::waterfall.selectedVFO);
_this->editedBookmark.mode = -1;
if (core::modComManager.getModuleName(gui::waterfall.selectedVFO) == "radio") {
int mode;
core::modComManager.callInterface(gui::waterfall.selectedVFO, RADIO_IFACE_CMD_GET_MODE, NULL, &mode);
bm.mode = mode;
_this->editedBookmark.mode = mode;
}
}
bm.selected = false;
char name[1024];
sprintf(name, "Test Bookmark (%d)", _this->testN);
_this->bookmarks[name] = bm;
_this->testN++;
_this->editedBookmark.selected = false;
_this->editOpen = true;
_this->editedBookmarkName = name;
// Find new unique default name
if (_this->bookmarks.find("New Bookmark") == _this->bookmarks.end()) {
_this->editedBookmarkName = "New Bookmark";
}
else {
char buf[64];
for (int i = 1; i < 1000; i++) {
sprintf(buf, "New Bookmark (%d)", i);
if (_this->bookmarks.find(buf) == _this->bookmarks.end()) { break; }
}
_this->editedBookmarkName = buf;
}
}
ImGui::TableSetColumnIndex(1);
@ -153,6 +209,7 @@ private:
if (selectedNames.size() != 1) { style::beginDisabled(); }
if (ImGui::Button(("Edit##_freq_mgr_edt_" + _this->name).c_str(), ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) {
_this->editOpen = true;
_this->editedBookmark = _this->bookmarks[selectedNames[0]];
_this->editedBookmarkName = selectedNames[0];
}
if (selectedNames.size() != 1) { style::endDisabled(); }
@ -193,23 +250,18 @@ private:
if (selectedNames.size() != 1) { style::endDisabled(); }
if (_this->editOpen) {
FrequencyBookmark& bm = _this->bookmarks[_this->editedBookmarkName];
_this->editOpen = _this->bookmarkEditDialog(bm);
}
if (_this->addOpen) {
FrequencyBookmark& bm = _this->bookmarks[_this->editedBookmarkName];
_this->addOpen = _this->bookmarkEditDialog(bm);
_this->editOpen = _this->bookmarkEditDialog();
}
}
std::string name;
bool enabled = true;
bool editOpen = false;
bool addOpen = false;
std::map<std::string, FrequencyBookmark> bookmarks;
std::string editedBookmarkName = "";
FrequencyBookmark editedBookmark;
int testN = 0;

View File

@ -172,7 +172,7 @@ private:
const float bbSampRate = 50000;
std::string uiPrefix;
float snapInterval = 10000;
float snapInterval = 2500;
float audioSampRate = 48000;
float bw = 50000;
bool running = false;

View File

@ -314,8 +314,8 @@ private:
static void _audioHandler(dsp::stereo_t *data, int count, void *ctx) {
RecorderModule* _this = (RecorderModule*)ctx;
for (int i = 0; i < count; i++) {
_this->wavSampleBuf[(2*i)] = data[i].l * 32768.0f;
_this->wavSampleBuf[(2*i) + 1] = data[i].r * 32768.0f;
_this->wavSampleBuf[(2*i)] = data[i].l * 32767.0f;
_this->wavSampleBuf[(2*i) + 1] = data[i].r * 32767.0f;
}
_this->audioWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t));
_this->samplesWritten += count;
@ -324,8 +324,8 @@ private:
static void _basebandHandler(dsp::complex_t *data, int count, void *ctx) {
RecorderModule* _this = (RecorderModule*)ctx;
for (int i = 0; i < count; i++) {
_this->wavSampleBuf[(2*i)] = data[i].re * 32768.0f;
_this->wavSampleBuf[(2*i) + 1] = data[i].im * 32768.0f;
_this->wavSampleBuf[(2*i)] = data[i].re * 32767.0f;
_this->wavSampleBuf[(2*i) + 1] = data[i].im * 32767.0f;
}
_this->basebandWriter->writeSamples(_this->wavSampleBuf, count * 2 * sizeof(int16_t));
_this->samplesWritten += count;