mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-27 21:07:50 +02:00
new stuff
This commit is contained in:
121
src/dsp/block.h
Normal file
121
src/dsp/block.h
Normal file
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
@ -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;
|
||||
};
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
}
|
||||
};
|
||||
};
|
@ -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;
|
||||
|
@ -12,7 +12,7 @@ namespace io {
|
||||
SoapyWrapper() {
|
||||
SoapySDR::registerLogHandler(_logHandler);
|
||||
SoapySDR::Device::make("");
|
||||
|
||||
|
||||
output.init(64000);
|
||||
currentGains = new float[1];
|
||||
refresh();
|
||||
|
28
src/main.cpp
28
src/main.cpp
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -33,6 +33,7 @@ namespace ImGui {
|
||||
float lowerOffset;
|
||||
float upperOffset;
|
||||
float bandwidth;
|
||||
float snapInterval;
|
||||
int reference = REF_CENTER;
|
||||
|
||||
ImVec2 rectMin;
|
||||
|
Reference in New Issue
Block a user