pull/29/head
Ryzerth 2020-09-18 00:23:03 +02:00
rodzic c1052b1b28
commit 1ef31f0f8b
16 zmienionych plików z 873 dodań i 402 usunięć

Wyświetl plik

@ -95,7 +95,14 @@ MOD_EXPORT void _DRAW_MENU_(RadioContext_t* ctx) {
ctx->sigPath.setDemodulator(SigPath::DEMOD_LSB, ctx->bandWidth);
API->setVFOReference(ctx->name, mod::API_t::REF_UPPER);
}
if (ImGui::RadioButton(CONCAT("RAW##_", ctx->name), ctx->demod == 7) && ctx->demod != 7) { ctx->demod = 7; };
if (ImGui::RadioButton(CONCAT("RAW##_", ctx->name), ctx->demod == 7) && ctx->demod != 7) {
ctx->demod = 7;
ctx->bandWidth = 10000;
ctx->bandWidthMin = 3000;
ctx->bandWidthMax = 10000;
ctx->sigPath.setDemodulator(SigPath::DEMOD_RAW, ctx->bandWidth);
API->setVFOReference(ctx->name, mod::API_t::REF_CENTER);
};
ImGui::Columns(1, CONCAT("EndRadioModeColumns##_", ctx->name), false);
ImGui::EndGroup();

Wyświetl plik

@ -28,10 +28,13 @@ void SigPath::init(std::string vfoName, uint64_t sampleRate, int blockSize, dsp:
bandwidth = 200000;
// TODO: Set default VFO options
// TODO: ajust deemphasis for different output sample rates
// TODO: Add a mono to stereo for different modes
demod.init(input, 100000, 200000, 800);
amDemod.init(input, 50);
ssbDemod.init(input, 6000, 3000, 22);
cpx2stereo.init(input, 22);
audioResamp.init(&demod.output, 200000, 48000, 800);
deemp.init(&audioResamp.output, 800, 50e-6, 48000);
@ -77,6 +80,9 @@ void SigPath::setDemodulator(int demId, float bandWidth) {
else if (_demod == DEMOD_DSB) {
ssbDemod.stop();
}
else if (_demod == DEMOD_RAW) {
cpx2stereo.stop();
}
else {
spdlog::error("UNIMPLEMENTED DEMODULATOR IN SigPath::setDemodulator (stop)");
}
@ -145,6 +151,14 @@ void SigPath::setDemodulator(int demId, float bandWidth) {
deemp.bypass = true;
ssbDemod.start();
}
else if (demId == DEMOD_RAW) {
API->setVFOSampleRate(vfoName, 10000, bandwidth);
cpx2stereo.setBlockSize(API->getVFOOutputBlockSize(vfoName));
//audioResamp.setInput(&cpx2stereo.output);
audioBw = std::min<float>(bandwidth, outputSampleRate / 2.0f);
audioResamp.setInputSampleRate(10000, API->getVFOOutputBlockSize(vfoName), audioBw, audioBw);
cpx2stereo.start();
}
else {
spdlog::error("UNIMPLEMENTED DEMODULATOR IN SigPath::setDemodulator (start): {0}", demId);
}
@ -207,6 +221,9 @@ void SigPath::setBandwidth(float bandWidth) {
ssbDemod.setBandwidth(bandwidth);
ssbDemod.start();
}
else if (_demod == DEMOD_RAW) {
// Notbing to change
}
else {
spdlog::error("UNIMPLEMENTED DEMODULATOR IN SigPath::setBandwidth");
}

Wyświetl plik

@ -30,6 +30,7 @@ public:
DEMOD_USB,
DEMOD_LSB,
DEMOD_DSB,
DEMOD_RAW,
_DEMOD_COUNT
};
@ -52,9 +53,11 @@ private:
dsp::FMDemodulator demod;
dsp::AMDemodulator amDemod;
dsp::SSBDemod ssbDemod;
dsp::ComplexToStereo cpx2stereo;
// Audio output
dsp::FloatFIRResampler audioResamp;
dsp::MonoToStereo m2s;
dsp::FIRResampler<float> audioResamp;
std::string vfoName;

Wyświetl plik

@ -3,25 +3,25 @@
"Radio": {
"device": "Speakers (Realtek High Definiti",
"sampleRate": 48000.0,
"volume": 0.32258063554763794
"volume": 0.4354838728904724
}
},
"bandPlan": "General",
"bandPlanEnabled": true,
"fftHeight": 300,
"frequency": 99000000,
"frequency": 91000000,
"max": 0.0,
"maximized": false,
"menuWidth": 300,
"min": -52.20588302612305,
"min": -70.0,
"showWaterfall": true,
"source": "HackRF One #0 901868dc282c8f8b",
"sourceSettings": {
"HackRF One #0 901868dc282c8f8b": {
"gains": {
"AMP": 0.0,
"LNA": 24.503000259399414,
"VGA": 16.229999542236328
"LNA": 0.0,
"VGA": 0.0
},
"sampleRate": 8000000
}

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -3,13 +3,13 @@
"Radio": {
"device": "Speakers (Realtek High Definiti",
"sampleRate": 48000.0,
"volume": 0.2956989109516144
"volume": 0.4032258093357086
}
},
"bandPlan": "General",
"bandPlanEnabled": true,
"fftHeight": 300,
"frequency": 103184112,
"frequency": 100100000,
"max": 0.0,
"maximized": false,
"menuWidth": 300,
@ -27,7 +27,7 @@
}
},
"windowSize": {
"h": 720,
"h": 725,
"w": 1280
}
}

Wyświetl plik

@ -1,4 +1,4 @@
{
"Radio": "./modules/radio.dll",
"Recorder": "./modules/recorder.dll"
"Radio": "../build/modules/radio/Release/radio.dll",
"Recorder": "../build/modules/recorder/Release/recorder.dll"
}

121
src/dsp/block.h 100644
Wyświetl plik

@ -0,0 +1,121 @@
#pragma once
#include <vector>
#include <dsp/stream.h>
namespace dsp {
template <class D, class I, class O, int IC, int OC>
class Block {
public:
Block(std::vector<int> inBs, std::vector<int> outBs, D* inst, void (*workerFunc)(D* _this)) {
derived = inst;
worker = workerFunc;
inputBlockSize = inBs;
outputBlockSize = outBs;
in.reserve(IC);
out.reserve(OC);
for (int i = 0; i < IC; i++) {
in.push_back(NULL);
}
for (int i = 0; i < OC; i++) {
out.push_back(new stream<I>(outBs[i] * 2));
}
}
void start() {
if (running) {
return;
}
running = true;
startHandler();
workerThread = std::thread(worker, derived);
}
void stop() {
if (!running) {
return;
}
stopHandler();
for (auto is : in) {
is->stopReader();
}
for (auto os : out) {
os->stopWriter();
}
workerThread.join();
for (auto is : in) {
is->clearReadStop();
}
for (auto os : out) {
os->clearWriteStop();
}
running = false;
}
virtual void setBlockSize(int blockSize) {
if (running) {
return;
}
for (int i = 0; i < IC; i++) {
in[i]->setMaxLatency(blockSize * 2);
inputBlockSize[i] = blockSize;
}
for (int i = 0; i < OC; i++) {
out[i]->setMaxLatency(blockSize * 2);
outputBlockSize[i] = blockSize;
}
}
std::vector<stream<I>*> out;
protected:
virtual void startHandler() {}
virtual void stopHandler() {}
std::vector<stream<I>*> in;
std::vector<int> inputBlockSize;
std::vector<int> outputBlockSize;
bool running = false;
private:
void (*worker)(D* _this);
std::thread workerThread;
D* derived;
};
class DemoMultiplier : public Block<DemoMultiplier, complex_t, complex_t, 2, 1> {
public:
DemoMultiplier() : Block({2}, {1}, this, worker) {}
void init(stream<complex_t>* a, stream<complex_t>* b, int blockSize) {
in[0] = a;
in[1] = b;
inputBlockSize[0] = blockSize;
inputBlockSize[1] = blockSize;
out[0]->setMaxLatency(blockSize * 2);
outputBlockSize[0] = blockSize;
}
private:
static void worker(DemoMultiplier* _this) {
int blockSize = _this->inputBlockSize[0];
stream<complex_t>* inA = _this->in[0];
stream<complex_t>* inB = _this->in[1];
stream<complex_t>* out = _this->out[0];
complex_t* aBuf = (complex_t*)volk_malloc(sizeof(complex_t) * blockSize, volk_get_alignment());
complex_t* bBuf = (complex_t*)volk_malloc(sizeof(complex_t) * blockSize, volk_get_alignment());
complex_t* outBuf = (complex_t*)volk_malloc(sizeof(complex_t) * blockSize, volk_get_alignment());
while (true) {
if (inA->read(aBuf, blockSize) < 0) { break; };
if (inB->read(bBuf, blockSize) < 0) { break; };
volk_32fc_x2_multiply_32fc((lv_32fc_t*)outBuf, (lv_32fc_t*)aBuf, (lv_32fc_t*)bBuf, blockSize);
if (out->write(outBuf, blockSize) < 0) { break; };
}
volk_free(aBuf);
volk_free(bBuf);
volk_free(outBuf);
}
};
};

Wyświetl plik

@ -86,4 +86,73 @@ namespace dsp {
std::thread _workerThread;
bool running = false;
};
class ComplexToStereo {
public:
ComplexToStereo() {
}
ComplexToStereo(stream<complex_t>* input, int bufferSize) : output(bufferSize * 2) {
_in = input;
_bufferSize = bufferSize;
}
void init(stream<complex_t>* input, int bufferSize) {
output.init(bufferSize * 2);
_in = input;
_bufferSize = bufferSize;
}
void start() {
if (running) {
return;
}
_workerThread = std::thread(_worker, this);
running = true;
}
void stop() {
if (!running) {
return;
}
_in->stopReader();
output.stopWriter();
_workerThread.join();
_in->clearReadStop();
output.clearWriteStop();
running = false;
}
void setBlockSize(int blockSize) {
if (running) {
return;
}
_bufferSize = blockSize;
output.setMaxLatency(blockSize * 2);
}
stream<StereoFloat_t> output;
private:
static void _worker(ComplexToStereo* _this) {
complex_t* inBuf = new complex_t[_this->_bufferSize];
StereoFloat_t* outBuf = new StereoFloat_t[_this->_bufferSize];
while (true) {
if (_this->_in->read(inBuf, _this->_bufferSize) < 0) { break; };
for (int i = 0; i < _this->_bufferSize; i++) {
outBuf[i].l = inBuf[i].i;
outBuf[i].r = inBuf[i].q;
}
if (_this->output.write(outBuf, _this->_bufferSize) < 0) { break; };
}
delete[] inBuf;
delete[] outBuf;
}
stream<complex_t>* _in;
int _bufferSize;
std::thread _workerThread;
bool running = false;
};
};

Plik diff jest za duży Load Diff

Wyświetl plik

@ -4,10 +4,52 @@ namespace dsp {
struct complex_t {
float q;
float i;
complex_t operator+(complex_t& c) {
complex_t res;
res.i = c.i + i;
res.q = c.q + q;
return res;
}
complex_t operator-(complex_t& c) {
complex_t res;
res.i = i - c.i;
res.q = q - c.q;
return res;
}
complex_t operator*(float& f) {
complex_t res;
res.i = i * f;
res.q = q * f;
return res;
}
};
struct StereoFloat_t {
float l;
float r;
StereoFloat_t operator+(StereoFloat_t& s) {
StereoFloat_t res;
res.l = s.l + l;
res.r = s.r + r;
return res;
}
StereoFloat_t operator-(StereoFloat_t& s) {
StereoFloat_t res;
res.l = l - s.l;
res.r = r - s.r;
return res;
}
StereoFloat_t operator*(float& f) {
StereoFloat_t res;
res.l = l * f;
res.r = r * f;
return res;
}
};
};

Wyświetl plik

@ -4,6 +4,7 @@
#include <dsp/resampling.h>
#include <dsp/filter.h>
#include <spdlog/spdlog.h>
#include <dsp/block.h>
namespace dsp {
class VFO {
@ -22,7 +23,8 @@ namespace dsp {
lo.init(offset, inputSampleRate, blockSize);
mixer.init(in, &lo.output, blockSize);
resamp.init(&mixer.output, inputSampleRate, outputSampleRate, blockSize, _bandWidth * 0.8f, _bandWidth);
//resamp.init(&mixer.output, inputSampleRate, outputSampleRate, blockSize, _bandWidth * 0.8f, _bandWidth);
resamp.init(mixer.out[0], inputSampleRate, outputSampleRate, blockSize, _bandWidth * 0.8f, _bandWidth);
}
void start() {
@ -87,8 +89,10 @@ namespace dsp {
private:
SineSource lo;
Multiplier mixer;
FIRResampler resamp;
//Multiplier mixer;
DemoMultiplier mixer;
FIRResampler<complex_t> resamp;
DecimatingFIRFilter filter;
stream<complex_t>* _input;
float _outputSampleRate;

Wyświetl plik

@ -12,7 +12,7 @@ namespace io {
SoapyWrapper() {
SoapySDR::registerLogHandler(_logHandler);
SoapySDR::Device::make("");
output.init(64000);
currentGains = new float[1];
refresh();

Wyświetl plik

@ -14,6 +14,8 @@
#include <stb_image.h>
#include <config.h>
#include <dsp/block.h>
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include <stb_image_resize.h>
@ -22,7 +24,7 @@
#endif
// Comment to build a normal release
// #define DEV_BUILD
#define DEV_BUILD
bool maximized = false;
bool fullScreen = false;
@ -40,6 +42,7 @@ static void maximized_callback(GLFWwindow* window, int n) {
}
}
// main
int main() {
#ifdef _WIN32
//FreeConsole();
@ -48,7 +51,7 @@ int main() {
spdlog::info("SDR++ v" VERSION_STR);
#ifdef DEV_BUILD
config::setRootDirectory("../root");
config::setRootDirectory("../root_dev");
#elif _WIN32
config::setRootDirectory(".");
#else
@ -134,6 +137,27 @@ int main() {
style::setDarkStyle();
// ====================================================
// glfwPollEvents();
// ImGui_ImplOpenGL3_NewFrame();
// ImGui_ImplGlfw_NewFrame();
// ImGui::NewFrame();
// ImGui::ShowDemoWindow();
// ImGui::Render();
// int display_w, display_h;
// glfwGetFramebufferSize(window, &display_w, &display_h);
// glViewport(0, 0, display_w, display_h);
// glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
// //glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT);
// ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
// glfwSwapBuffers(window);
// ====================================================
spdlog::info("Loading icons");
icons::load();

Wyświetl plik

@ -216,8 +216,8 @@ void windowInit() {
// Bandwidth ajustment
// CW and RAW modes;
// Bring VFO to a visible place when changing sample rate if it's smaller
// Have a proper root directory
// Add save config for modules
// 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

Wyświetl plik

@ -33,6 +33,7 @@ namespace ImGui {
float lowerOffset;
float upperOffset;
float bandwidth;
float snapInterval;
int reference = REF_CENTER;
ImVec2 rectMin;