mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-26 10:58:29 +01:00
Made the file source set the frequency of the waterfall
This commit is contained in:
parent
5f1a94c267
commit
fb32b4d55a
@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace tuner {
|
namespace tuner {
|
||||||
|
|
||||||
void centerTuning(std::string vfoName, double freq) {
|
void centerTuning(std::string vfoName, double freq) {
|
||||||
if (vfoName != "") {
|
if (vfoName != "") {
|
||||||
if (gui::waterfall.vfos.find(vfoName) == gui::waterfall.vfos.end()) { return; }
|
if (gui::waterfall.vfos.find(vfoName) == gui::waterfall.vfos.end()) { return; }
|
||||||
@ -110,6 +111,12 @@ namespace tuner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void iqTuning(double freq) {
|
||||||
|
gui::waterfall.setCenterFrequency(freq);
|
||||||
|
gui::waterfall.centerFreqMoved = true;
|
||||||
|
sigpath::sourceManager.tune(freq);
|
||||||
|
}
|
||||||
|
|
||||||
void tune(int mode, std::string vfoName, double freq) {
|
void tune(int mode, std::string vfoName, double freq) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case TUNER_MODE_CENTER:
|
case TUNER_MODE_CENTER:
|
||||||
@ -124,6 +131,9 @@ namespace tuner {
|
|||||||
case TUNER_MODE_UPPER_HALF:
|
case TUNER_MODE_UPPER_HALF:
|
||||||
normalTuning(vfoName, freq);
|
normalTuning(vfoName, freq);
|
||||||
break;
|
break;
|
||||||
|
case TUNER_MODE_IQ_ONLY:
|
||||||
|
iqTuning(freq);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <module.h>
|
||||||
|
|
||||||
namespace tuner {
|
namespace tuner {
|
||||||
void centerTuning(std::string vfoName, double freq);
|
void centerTuning(std::string vfoName, double freq);
|
||||||
void normalTuning(std::string vfoName, double freq);
|
void normalTuning(std::string vfoName, double freq);
|
||||||
|
void iqTuning(double freq);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TUNER_MODE_CENTER,
|
TUNER_MODE_CENTER,
|
||||||
TUNER_MODE_NORMAL,
|
TUNER_MODE_NORMAL,
|
||||||
TUNER_MODE_LOWER_HALF,
|
TUNER_MODE_LOWER_HALF,
|
||||||
TUNER_MODE_UPPER_HALF,
|
TUNER_MODE_UPPER_HALF,
|
||||||
|
TUNER_MODE_IQ_ONLY,
|
||||||
_TUNER_MODE_COUNT
|
_TUNER_MODE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,6 +173,7 @@ void FrequencySelect::draw() {
|
|||||||
for (int j = i; j < 12; j++) {
|
for (int j = i; j < 12; j++) {
|
||||||
digits[j] = 0;
|
digits[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
frequencyChanged = true;
|
frequencyChanged = true;
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_UP)) {
|
if (ImGui::IsKeyPressed(GLFW_KEY_UP)) {
|
||||||
@ -214,7 +215,15 @@ void FrequencySelect::draw() {
|
|||||||
for (int i = 0; i < 12; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
freq += digits[i] * pow(10, 11 - i);
|
freq += digits[i] * pow(10, 11 - i);
|
||||||
}
|
}
|
||||||
frequency = freq;
|
|
||||||
|
uint64_t orig = freq;
|
||||||
|
freq = std::clamp<uint64_t>(freq, minFreq, maxFreq);
|
||||||
|
if (freq != orig && limitFreq) {
|
||||||
|
setFrequency(freq);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frequency = orig;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@ public:
|
|||||||
bool frequencyChanged = false;
|
bool frequencyChanged = false;
|
||||||
bool digitHovered = false;
|
bool digitHovered = false;
|
||||||
|
|
||||||
|
bool limitFreq;
|
||||||
|
uint64_t minFreq;
|
||||||
|
uint64_t maxFreq;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onPosChange();
|
void onPosChange();
|
||||||
void onResize();
|
void onResize();
|
||||||
|
@ -336,15 +336,19 @@ namespace ImGui {
|
|||||||
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
|
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
|
||||||
double freqOffset = (viewOffset + (viewBandwidth / 2.0)) - (wholeBandwidth / 2.0);
|
double freqOffset = (viewOffset + (viewBandwidth / 2.0)) - (wholeBandwidth / 2.0);
|
||||||
viewOffset = (wholeBandwidth / 2.0) - (viewBandwidth / 2.0);
|
viewOffset = (wholeBandwidth / 2.0) - (viewBandwidth / 2.0);
|
||||||
|
if (!centerFrequencyLocked) {
|
||||||
centerFreq += freqOffset;
|
centerFreq += freqOffset;
|
||||||
centerFreqMoved = true;
|
centerFreqMoved = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (viewOffset - (viewBandwidth / 2.0) < -(wholeBandwidth / 2.0)) {
|
if (viewOffset - (viewBandwidth / 2.0) < -(wholeBandwidth / 2.0)) {
|
||||||
double freqOffset = (viewOffset - (viewBandwidth / 2.0)) + (wholeBandwidth / 2.0);
|
double freqOffset = (viewOffset - (viewBandwidth / 2.0)) + (wholeBandwidth / 2.0);
|
||||||
viewOffset = (viewBandwidth / 2.0) - (wholeBandwidth / 2.0);
|
viewOffset = (viewBandwidth / 2.0) - (wholeBandwidth / 2.0);
|
||||||
|
if (!centerFrequencyLocked) {
|
||||||
centerFreq += freqOffset;
|
centerFreq += freqOffset;
|
||||||
centerFreqMoved = true;
|
centerFreqMoved = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lowerFreq = (centerFreq + viewOffset) - (viewBandwidth / 2.0);
|
lowerFreq = (centerFreq + viewOffset) - (viewBandwidth / 2.0);
|
||||||
upperFreq = (centerFreq + viewOffset) + (viewBandwidth / 2.0);
|
upperFreq = (centerFreq + viewOffset) + (viewBandwidth / 2.0);
|
||||||
|
@ -141,6 +141,8 @@ namespace ImGui {
|
|||||||
|
|
||||||
float selectedVFOSNR = NAN;
|
float selectedVFOSNR = NAN;
|
||||||
|
|
||||||
|
bool centerFrequencyLocked = false;
|
||||||
|
|
||||||
std::map<std::string, WaterfallVFO*> vfos;
|
std::map<std::string, WaterfallVFO*> vfos;
|
||||||
std::string selectedVFO = "";
|
std::string selectedVFO = "";
|
||||||
bool selectedVFOChanged = false;
|
bool selectedVFOChanged = false;
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
#include <core.h>
|
#include <core.h>
|
||||||
#include <options.h>
|
#include <options.h>
|
||||||
#include <gui/widgets/file_select.h>
|
#include <gui/widgets/file_select.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <regex>
|
||||||
|
#include <gui/tuner.h>
|
||||||
|
|
||||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
@ -63,13 +66,19 @@ private:
|
|||||||
static void menuSelected(void* ctx) {
|
static void menuSelected(void* ctx) {
|
||||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||||
core::setInputSampleRate(_this->sampleRate);
|
core::setInputSampleRate(_this->sampleRate);
|
||||||
|
tuner::tune(tuner::TUNER_MODE_IQ_ONLY, "", _this->centerFreq);
|
||||||
sigpath::signalPath.setBuffering(false);
|
sigpath::signalPath.setBuffering(false);
|
||||||
|
gui::waterfall.centerFrequencyLocked = true;
|
||||||
|
gui::freqSelect.minFreq = _this->centerFreq - (_this->sampleRate/2);
|
||||||
|
gui::freqSelect.maxFreq = _this->centerFreq + (_this->sampleRate/2);
|
||||||
|
gui::freqSelect.limitFreq = true;
|
||||||
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
|
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menuDeselected(void* ctx) {
|
static void menuDeselected(void* ctx) {
|
||||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||||
sigpath::signalPath.setBuffering(true);
|
sigpath::signalPath.setBuffering(true);
|
||||||
|
gui::waterfall.centerFrequencyLocked = false;
|
||||||
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,8 +121,16 @@ private:
|
|||||||
_this->reader = new WavReader(_this->fileSelect.path);
|
_this->reader = new WavReader(_this->fileSelect.path);
|
||||||
_this->sampleRate = _this->reader->getSampleRate();
|
_this->sampleRate = _this->reader->getSampleRate();
|
||||||
core::setInputSampleRate(_this->sampleRate);
|
core::setInputSampleRate(_this->sampleRate);
|
||||||
|
std::string filename = std::filesystem::path(_this->fileSelect.path).filename().string();
|
||||||
|
_this->centerFreq = _this->getFrequency(filename);
|
||||||
|
tuner::tune(tuner::TUNER_MODE_IQ_ONLY, "", _this->centerFreq);
|
||||||
|
gui::freqSelect.minFreq = _this->centerFreq - (_this->sampleRate/2);
|
||||||
|
gui::freqSelect.maxFreq = _this->centerFreq + (_this->sampleRate/2);
|
||||||
|
gui::freqSelect.limitFreq = true;
|
||||||
|
}
|
||||||
|
catch (std::exception e) {
|
||||||
|
spdlog::error("Error: {0}", e.what());
|
||||||
}
|
}
|
||||||
catch (std::exception e) {}
|
|
||||||
config.acquire();
|
config.acquire();
|
||||||
config.conf["path"] = _this->fileSelect.path;
|
config.conf["path"] = _this->fileSelect.path;
|
||||||
config.release(true);
|
config.release(true);
|
||||||
@ -152,6 +169,16 @@ private:
|
|||||||
delete[] inBuf;
|
delete[] inBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double getFrequency(std::string filename) {
|
||||||
|
std::regex expr("[0-9]+Hz");
|
||||||
|
std::smatch matches;
|
||||||
|
std::regex_search(filename, matches, expr);
|
||||||
|
spdlog::warn("{0} {1}", filename, matches.size());
|
||||||
|
if (matches.empty()) { return 0; }
|
||||||
|
std::string freqStr = matches[0].str();
|
||||||
|
return std::atof(freqStr.substr(0, freqStr.size() - 2).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
FileSelect fileSelect;
|
FileSelect fileSelect;
|
||||||
std::string name;
|
std::string name;
|
||||||
dsp::stream<dsp::complex_t> stream;
|
dsp::stream<dsp::complex_t> stream;
|
||||||
@ -162,6 +189,8 @@ private:
|
|||||||
float sampleRate = 48000;
|
float sampleRate = 48000;
|
||||||
std::thread workerThread;
|
std::thread workerThread;
|
||||||
|
|
||||||
|
double centerFreq = 0;
|
||||||
|
|
||||||
bool float32Mode = false;
|
bool float32Mode = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user