mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-26 02:48:31 +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>
|
||||
|
||||
namespace tuner {
|
||||
|
||||
void centerTuning(std::string vfoName, double freq) {
|
||||
if (vfoName != "") {
|
||||
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) {
|
||||
switch (mode) {
|
||||
case TUNER_MODE_CENTER:
|
||||
@ -124,6 +131,9 @@ namespace tuner {
|
||||
case TUNER_MODE_UPPER_HALF:
|
||||
normalTuning(vfoName, freq);
|
||||
break;
|
||||
case TUNER_MODE_IQ_ONLY:
|
||||
iqTuning(freq);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <module.h>
|
||||
|
||||
namespace tuner {
|
||||
void centerTuning(std::string vfoName, double freq);
|
||||
void normalTuning(std::string vfoName, double freq);
|
||||
void iqTuning(double freq);
|
||||
|
||||
enum {
|
||||
TUNER_MODE_CENTER,
|
||||
TUNER_MODE_NORMAL,
|
||||
TUNER_MODE_LOWER_HALF,
|
||||
TUNER_MODE_UPPER_HALF,
|
||||
TUNER_MODE_IQ_ONLY,
|
||||
_TUNER_MODE_COUNT
|
||||
};
|
||||
|
||||
|
@ -173,6 +173,7 @@ void FrequencySelect::draw() {
|
||||
for (int j = i; j < 12; j++) {
|
||||
digits[j] = 0;
|
||||
}
|
||||
|
||||
frequencyChanged = true;
|
||||
}
|
||||
if (ImGui::IsKeyPressed(GLFW_KEY_UP)) {
|
||||
@ -214,7 +215,15 @@ void FrequencySelect::draw() {
|
||||
for (int i = 0; i < 12; 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();
|
||||
|
||||
|
@ -14,6 +14,10 @@ public:
|
||||
bool frequencyChanged = false;
|
||||
bool digitHovered = false;
|
||||
|
||||
bool limitFreq;
|
||||
uint64_t minFreq;
|
||||
uint64_t maxFreq;
|
||||
|
||||
private:
|
||||
void onPosChange();
|
||||
void onResize();
|
||||
|
@ -336,15 +336,19 @@ namespace ImGui {
|
||||
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
|
||||
double freqOffset = (viewOffset + (viewBandwidth / 2.0)) - (wholeBandwidth / 2.0);
|
||||
viewOffset = (wholeBandwidth / 2.0) - (viewBandwidth / 2.0);
|
||||
if (!centerFrequencyLocked) {
|
||||
centerFreq += freqOffset;
|
||||
centerFreqMoved = true;
|
||||
}
|
||||
}
|
||||
if (viewOffset - (viewBandwidth / 2.0) < -(wholeBandwidth / 2.0)) {
|
||||
double freqOffset = (viewOffset - (viewBandwidth / 2.0)) + (wholeBandwidth / 2.0);
|
||||
viewOffset = (viewBandwidth / 2.0) - (wholeBandwidth / 2.0);
|
||||
if (!centerFrequencyLocked) {
|
||||
centerFreq += freqOffset;
|
||||
centerFreqMoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
lowerFreq = (centerFreq + viewOffset) - (viewBandwidth / 2.0);
|
||||
upperFreq = (centerFreq + viewOffset) + (viewBandwidth / 2.0);
|
||||
|
@ -141,6 +141,8 @@ namespace ImGui {
|
||||
|
||||
float selectedVFOSNR = NAN;
|
||||
|
||||
bool centerFrequencyLocked = false;
|
||||
|
||||
std::map<std::string, WaterfallVFO*> vfos;
|
||||
std::string selectedVFO = "";
|
||||
bool selectedVFOChanged = false;
|
||||
|
@ -7,6 +7,9 @@
|
||||
#include <core.h>
|
||||
#include <options.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())
|
||||
|
||||
@ -63,13 +66,19 @@ private:
|
||||
static void menuSelected(void* ctx) {
|
||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
tuner::tune(tuner::TUNER_MODE_IQ_ONLY, "", _this->centerFreq);
|
||||
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);
|
||||
}
|
||||
|
||||
static void menuDeselected(void* ctx) {
|
||||
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||
sigpath::signalPath.setBuffering(true);
|
||||
gui::waterfall.centerFrequencyLocked = false;
|
||||
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
||||
}
|
||||
|
||||
@ -112,8 +121,16 @@ private:
|
||||
_this->reader = new WavReader(_this->fileSelect.path);
|
||||
_this->sampleRate = _this->reader->getSampleRate();
|
||||
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.conf["path"] = _this->fileSelect.path;
|
||||
config.release(true);
|
||||
@ -152,6 +169,16 @@ private:
|
||||
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;
|
||||
std::string name;
|
||||
dsp::stream<dsp::complex_t> stream;
|
||||
@ -162,6 +189,8 @@ private:
|
||||
float sampleRate = 48000;
|
||||
std::thread workerThread;
|
||||
|
||||
double centerFreq = 0;
|
||||
|
||||
bool float32Mode = false;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user