mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 12:07:49 +02:00
new fixes
This commit is contained in:
@ -63,6 +63,7 @@ void ConfigManager::release(bool changed) {
|
||||
void ConfigManager::autoSaveWorker(ConfigManager* _this) {
|
||||
while (_this->autoSaveEnabled) {
|
||||
if (!_this->mtx.try_lock()) {
|
||||
spdlog::warn("ConfigManager locked, waiting...");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
continue;
|
||||
}
|
||||
|
@ -119,4 +119,61 @@ namespace dsp {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Squelch : public Block<Squelch, complex_t, complex_t, 1, 1> {
|
||||
public:
|
||||
Squelch() : Block({1}, {1}, this, worker) {}
|
||||
|
||||
void init(stream<complex_t>* input, int blockSize) {
|
||||
in[0] = input;
|
||||
inputBlockSize[0] = blockSize;
|
||||
out[0]->setMaxLatency(blockSize * 2);
|
||||
outputBlockSize[0] = blockSize;
|
||||
level = -50.0f;
|
||||
}
|
||||
|
||||
float level;
|
||||
int onCount;
|
||||
int offCount;
|
||||
|
||||
private:
|
||||
static void worker(Squelch* _this) {
|
||||
int blockSize = _this->inputBlockSize[0];
|
||||
stream<complex_t>* in = _this->in[0];
|
||||
stream<complex_t>* out = _this->out[0];
|
||||
complex_t* buf = new complex_t[blockSize];
|
||||
|
||||
int _on = 0, _off = 0;
|
||||
bool active = false;
|
||||
|
||||
while (true) {
|
||||
if (in->read(buf, blockSize) < 0) { break; };
|
||||
for (int i = 0; i < blockSize; i++) {
|
||||
if (log10(sqrt((buf[i].i*buf[i].i) + (buf[i].q*buf[i].q))) * 10.0f > _this->level) {
|
||||
_on++;
|
||||
_off = 0;
|
||||
}
|
||||
else {
|
||||
_on = 0;
|
||||
_off++;
|
||||
}
|
||||
if (_on >= _this->onCount && !active) {
|
||||
_on = _this->onCount;
|
||||
active = true;
|
||||
}
|
||||
if (_off >= _this->offCount && active) {
|
||||
_off = _this->offCount;
|
||||
active = false;
|
||||
}
|
||||
if (!active) {
|
||||
buf[i].i = 0.0f;
|
||||
buf[i].q = 0.0f;
|
||||
}
|
||||
}
|
||||
if (out->write(buf, blockSize) < 0) { break; };
|
||||
}
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
@ -63,26 +63,95 @@ namespace dsp {
|
||||
bool bypass;
|
||||
|
||||
private:
|
||||
// static void _worker(DCBiasRemover* _this) {
|
||||
// complex_t* buf = new complex_t[_this->_bufferSize];
|
||||
// float ibias = 0.0f;
|
||||
// float qbias = 0.0f;
|
||||
// while (true) {
|
||||
// if (_this->_in->read(buf, _this->_bufferSize) < 0) { break; };
|
||||
// if (_this->bypass) {
|
||||
// if (_this->output.write(buf, _this->_bufferSize) < 0) { break; };
|
||||
// continue;
|
||||
// }
|
||||
// for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
// ibias += buf[i].i;
|
||||
// qbias += buf[i].q;
|
||||
// }
|
||||
// ibias /= _this->_bufferSize;
|
||||
// qbias /= _this->_bufferSize;
|
||||
// for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
// buf[i].i -= ibias;
|
||||
// buf[i].q -= qbias;
|
||||
// }
|
||||
// if (_this->output.write(buf, _this->_bufferSize) < 0) { break; };
|
||||
// }
|
||||
// delete[] buf;
|
||||
// }
|
||||
|
||||
static void _worker(DCBiasRemover* _this) {
|
||||
complex_t* buf = new complex_t[_this->_bufferSize];
|
||||
float ibias = 0.0f;
|
||||
float qbias = 0.0f;
|
||||
complex_t* mixBuf = new complex_t[_this->_bufferSize];
|
||||
|
||||
float currentPhase = 0.0f;
|
||||
float lastPhase = 0.0f;
|
||||
double phase = 0.0f;
|
||||
|
||||
while (true) {
|
||||
float ibias = 0.0f;
|
||||
float qbias = 0.0f;
|
||||
if (_this->_in->read(buf, _this->_bufferSize) < 0) { break; };
|
||||
if (_this->bypass) {
|
||||
if (_this->output.write(buf, _this->_bufferSize) < 0) { break; };
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect the frequency of the signal
|
||||
double avgDiff = 0.0f;
|
||||
// for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
// currentPhase = fast_arctan2(buf[i].i, buf[i].q);
|
||||
// float diff = currentPhase - lastPhase;
|
||||
// if (diff > 3.1415926535f) { diff -= 2 * 3.1415926535f; }
|
||||
// else if (diff <= -3.1415926535f) { diff += 2 * 3.1415926535f; }
|
||||
// avgDiff += diff;
|
||||
// lastPhase = currentPhase;
|
||||
// }
|
||||
// avgDiff /= (double)_this->_bufferSize;
|
||||
// avgDiff /= (double)_this->_bufferSize;
|
||||
|
||||
// Average the samples to "filter" the signal to the block frequency
|
||||
for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
ibias += buf[i].i;
|
||||
qbias += buf[i].q;
|
||||
}
|
||||
ibias /= _this->_bufferSize;
|
||||
qbias /= _this->_bufferSize;
|
||||
|
||||
// Get the phase difference from the last block
|
||||
currentPhase = fast_arctan2(ibias, qbias);
|
||||
float diff = currentPhase - lastPhase;
|
||||
if (diff > 3.1415926535f) { diff -= 2 * 3.1415926535f; }
|
||||
else if (diff <= -3.1415926535f) { diff += 2 * 3.1415926535f; }
|
||||
avgDiff += diff;
|
||||
lastPhase = currentPhase;
|
||||
avgDiff /= (double)_this->_bufferSize;
|
||||
|
||||
// Generate a correction signal using the phase difference
|
||||
for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
buf[i].i -= ibias;
|
||||
buf[i].q -= qbias;
|
||||
mixBuf[i].i = sin(phase);
|
||||
mixBuf[i].q = cos(phase);
|
||||
phase -= avgDiff;
|
||||
phase = fmodl(phase, 2.0 * 3.1415926535);
|
||||
}
|
||||
|
||||
// Mix the correction signal with the original signal to shift the unwanted signal
|
||||
// to the center. Also, null out the real component so that symetric
|
||||
// frequencies are removed (at least I hope...)
|
||||
float tq;
|
||||
for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
buf[i].i = ((mixBuf[i].i * buf[i].q) + (mixBuf[i].q * buf[i].i)) * 1.4142;
|
||||
buf[i].q = 0;
|
||||
}
|
||||
|
||||
if (_this->output.write(buf, _this->_bufferSize) < 0) { break; };
|
||||
}
|
||||
delete[] buf;
|
||||
|
@ -92,6 +92,10 @@ void windowInit() {
|
||||
|
||||
credits::init();
|
||||
|
||||
core::configManager.aquire();
|
||||
gui::menu.order = core::configManager.conf["menuOrder"].get<std::vector<std::string>>();
|
||||
core::configManager.release();
|
||||
|
||||
gui::menu.registerEntry("Source", sourecmenu::draw, NULL);
|
||||
gui::menu.registerEntry("Audio", audiomenu::draw, NULL);
|
||||
gui::menu.registerEntry("Scripting", scriptingmenu::draw, NULL);
|
||||
@ -117,7 +121,6 @@ void windowInit() {
|
||||
displaymenu::init();
|
||||
|
||||
// Load last source configuration
|
||||
|
||||
// Also add a loading screen
|
||||
// Adjustable "snap to grid" for each VFO
|
||||
// Finish the recorder module
|
||||
@ -129,10 +132,9 @@ void windowInit() {
|
||||
// Do VFO in two steps: First sample rate conversion, then filtering
|
||||
|
||||
// And a module add/remove/change order menu
|
||||
// get rid of watchers and use if() instead
|
||||
// Switch to double for all frequecies and bandwidth
|
||||
|
||||
// Update UI settings
|
||||
core::configManager.aquire();
|
||||
fftMin = core::configManager.conf["min"];
|
||||
fftMax = core::configManager.conf["max"];
|
||||
gui::waterfall.setFFTMin(fftMin);
|
||||
@ -159,8 +161,6 @@ void windowInit() {
|
||||
fftHeight = core::configManager.conf["fftHeight"];
|
||||
gui::waterfall.setFFTHeight(fftHeight);
|
||||
|
||||
gui::menu.order = core::configManager.conf["menuOrder"].get<std::vector<std::string>>();
|
||||
|
||||
core::configManager.release();
|
||||
}
|
||||
|
||||
@ -297,10 +297,6 @@ void drawWindow() {
|
||||
core::configManager.release(true);
|
||||
}
|
||||
|
||||
if (dcbias.changed()) {
|
||||
sigpath::signalPath.setDCBiasCorrection(dcbias.val);
|
||||
}
|
||||
|
||||
int _fftHeight = gui::waterfall.getFFTHeight();
|
||||
if (fftHeight != _fftHeight) {
|
||||
fftHeight = _fftHeight;
|
||||
@ -418,6 +414,9 @@ void drawWindow() {
|
||||
ImGui::Text("Framerate: %.1f FPS", ImGui::GetIO().Framerate);
|
||||
ImGui::Text("Center Frequency: %.0 Hz", gui::waterfall.getCenterFrequency());
|
||||
ImGui::Text("Source name: %s", sourceName.c_str());
|
||||
if (ImGui::Checkbox("Test technique", &dcbias.val)) {
|
||||
sigpath::signalPath.setDCBiasCorrection(dcbias.val);
|
||||
}
|
||||
ImGui::Spacing();
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,8 @@ namespace ImGui {
|
||||
}
|
||||
int refCenter = mousePos.x - (widgetPos.x + 50);
|
||||
if (refCenter >= 0 && refCenter < dataWidth && mousePos.y > widgetPos.y && mousePos.y < (widgetPos.y + widgetSize.y)) {
|
||||
vfo->setOffset(((((double)refCenter / ((double)dataWidth / 2.0)) - 1.0) * (viewBandwidth / 2.0)) + viewOffset);
|
||||
double off = ((((double)refCenter / ((double)dataWidth / 2.0)) - 1.0) * (viewBandwidth / 2.0)) + viewOffset;
|
||||
vfo->setOffset(round(off / vfo->snapInterval) * vfo->snapInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user