added rx888

This commit is contained in:
Ryzerth
2020-11-12 00:53:38 +01:00
parent 0a5fd5c271
commit 02ae50905d
37 changed files with 6038 additions and 85 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <dsp/block.h>
#include <volk/volk.h>
#include <spdlog/spdlog.h>
@ -138,6 +139,14 @@ namespace dsp {
volk_32fc_magnitude_32f(out.data, (lv_32fc_t*)_in->data, count);
_in->flush();
volk_32f_accumulator_s32f(&avg, out.data, count);
avg /= (float)count;
for (int i = 0; i < count; i++) {
out.data[i] -= avg;
}
out.write(count);
return count;
}
@ -145,6 +154,7 @@ namespace dsp {
stream<float> out;
private:
float avg;
int count;
stream<complex_t>* _in;

View File

@ -1,8 +1,7 @@
#pragma once
#include <dsp/block.h>
#include <dsp/window.h>
#include <spdlog/spdlog.h>
#include <string.h>
namespace dsp {

View File

@ -1,7 +1,7 @@
#pragma once
#include <dsp/block.h>
#include <spdlog/spdlog.h>
#include <fftw3.h>
#include <string.h>
namespace dsp {
class FrequencyXlator : public generic_block<FrequencyXlator> {
@ -75,4 +75,56 @@ namespace dsp {
stream<complex_t>* _in;
};
class AGC : public generic_block<AGC> {
public:
AGC() {}
AGC(stream<float>* in, float ratio) { init(in, ratio); }
~AGC() { generic_block<AGC>::stop(); }
void init(stream<float>* in, float ratio) {
_in = in;
_ratio = ratio;
generic_block<AGC>::registerInput(_in);
generic_block<AGC>::registerOutput(&out);
}
void setInputSize(stream<float>* in) {
std::lock_guard<std::mutex> lck(generic_block<AGC>::ctrlMtx);
generic_block<AGC>::tempStop();
generic_block<AGC>::unregisterInput(_in);
_in = in;
generic_block<AGC>::registerInput(_in);
generic_block<AGC>::tempStart();
}
int run() {
count = _in->read();
if (count < 0) { return -1; }
if (out.aquire() < 0) { return -1; }
for (int i = 0; i < count; i++) {
level = (fabsf(_in->data[i]) * _ratio) + (level * (1.0f - _ratio));
out.data[i] = _in->data[i] / level;
}
_in->flush();
out.write(count);
return count;
}
stream<float> out;
private:
int count;
float level = 1.0f;
float _ratio;
stream<float>* _in;
};
}

View File

@ -2,6 +2,7 @@
#include <dsp/block.h>
#include <dsp/window.h>
#include <numeric>
#include <string.h>
namespace dsp {
template <class T>

View File

@ -1,7 +1,7 @@
#pragma once
#include <dsp/block.h>
#include <dsp/buffer.h>
#include <cstring>
#include <string.h>
#include <numeric>
#include <spdlog/spdlog.h>

View File

@ -27,7 +27,7 @@ namespace dsp {
void setCutoff(float cutoff) {
_cutoff = cutoff;
}
void setTransWidth(float transWidth) {
_transWidth = transWidth;
}

42
core/src/event.h Normal file
View File

@ -0,0 +1,42 @@
#pragma once
#include <vector>
#include <spdlog/spdlog.h>
template <class T>
class Event {
public:
Event() {}
~Event() {}
struct EventHandler {
EventHandler(void (*handler)(T, void*), void* ctx) {
this->handler = handler;
this->ctx = ctx;
}
void (*handler)(T, void*);
void* ctx;
};
void emit(T value) {
for (auto const& handler : handlers) {
handler.handler(value, handler.ctx);
}
}
void bindHandler(const EventHandler& handler) {
handlers.push_back(handler);
}
void unbindHandler(const EventHandler& handler) {
if (handlers.find(handler) == handlers.end()) {
spdlog::error("Tried to remove a non-existant event handler");
return;
}
handlers.erase(std::remove(handlers.begin(), handlers.end(), handler), handlers.end());
}
private:
std::vector<EventHandler> handlers;
};

View File

@ -7,13 +7,8 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <imgui_plot.h>
#include <dsp/resampling.h>
#include <dsp/demodulator.h>
#include <dsp/filter.h>
#include <thread>
#include <complex>
#include <dsp/source.h>
#include <dsp/math.h>
#include <gui/waterfall.h>
#include <gui/frequency_select.h>
#include <fftw3.h>

View File

@ -1,13 +1,8 @@
#pragma once
#include <dsp/filter.h>
#include <dsp/resampling.h>
#include <dsp/source.h>
#include <dsp/math.h>
#include <dsp/demodulator.h>
#include <dsp/routing.h>
#include <dsp/sink.h>
#include <dsp/vfo.h>
#include <map>
#include <dsp/sink.h>
#include <module.h>
class SignalPath {

View File

@ -4,4 +4,5 @@ namespace sigpath {
SignalPath signalPath;
VFOManager vfoManager;
SourceManager sourceManager;
SinkManager sinkManager;
};

View File

@ -2,10 +2,12 @@
#include <signal_path/dsp.h>
#include <signal_path/vfo_manager.h>
#include <signal_path/source.h>
#include <signal_path/sink.h>
#include <module.h>
namespace sigpath {
SDRPP_EXPORT SignalPath signalPath;
SDRPP_EXPORT VFOManager vfoManager;
SDRPP_EXPORT SourceManager sourceManager;
SDRPP_EXPORT SinkManager sinkManager;
};

View File

@ -0,0 +1,98 @@
#include <signal_path/sink.h>
#include <spdlog/spdlog.h>
#include <core.h>
SinkManager::SinkManager() {
}
SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
_in = in;
srChange.bindHandler(srChangeHandler);
_sampleRate = sampleRate;
splitter.init(_in);
}
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
std::lock_guard<std::mutex> lck(ctrlMtx);
_in = in;
splitter.setInput(_in);
}
dsp::stream<dsp::stereo_t>* SinkManager::Stream::bindStream() {
dsp::stream<dsp::stereo_t>* stream = new dsp::stream<dsp::stereo_t>;
splitter.bindStream(stream);
return stream;
}
void SinkManager::Stream::unbindStream(dsp::stream<dsp::stereo_t>* stream) {
splitter.unbindStream(stream);
delete stream;
}
void SinkManager::Stream::setSampleRate(float sampleRate) {
std::lock_guard<std::mutex> lck(ctrlMtx);
_sampleRate = sampleRate;
srChange.emit(sampleRate);
}
void SinkManager::registerSinkProvider(std::string name, SinkProvider provider) {
if (providers.find(name) != providers.end()) {
spdlog::error("Cannot create sink provider '{0}', this name is already taken", name);
return;
}
providers[name] = provider;
}
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
if (streams.find(name) != streams.end()) {
spdlog::error("Cannot register stream '{0}', this name is already taken", name);
return;
}
core::configManager.aquire();
std::string providerName = core::configManager.conf["defaultSink"];
core::configManager.release();
SinkManager::SinkProvider provider;
if (providers.find(providerName) == providers.end()) {
// TODO: get default
}
else {
provider = providers[providerName];
}
stream->sink = provider.create(stream, provider.ctx);
}
void SinkManager::unregisterStream(std::string name) {
if (streams.find(name) == streams.end()) {
spdlog::error("Cannot unregister stream '{0}', this stream doesn't exist", name);
return;
}
SinkManager::Stream* stream = streams[name];
delete stream->sink;
delete stream;
}
dsp::stream<dsp::stereo_t>* SinkManager::bindStream(std::string name) {
if (streams.find(name) == streams.end()) {
spdlog::error("Cannot bind to stream '{0}'. Stream doesn't exist", name);
return NULL;
}
return streams[name]->bindStream();
}
void SinkManager::unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream) {
if (streams.find(name) == streams.end()) {
spdlog::error("Cannot unbind from stream '{0}'. Stream doesn't exist", name);
return;
}
streams[name]->unbindStream(stream);
}
void SinkManager::showMenu() {
for (auto const& [name, stream] : streams) {
}
}

View File

@ -0,0 +1,65 @@
#pragma once
#include <map>
#include <string>
#include <dsp/stream.h>
#include <dsp/types.h>
#include <dsp/routing.h>
#include <mutex>
#include <event.h>
class SinkManager {
public:
SinkManager();
class Sink {
public:
virtual void menuHandler() = 0;
};
class Stream {
public:
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
void setInput(dsp::stream<dsp::stereo_t>* in);
dsp::stream<dsp::stereo_t>* bindStream();
void unbindStream(dsp::stream<dsp::stereo_t>* stream);
friend SinkManager;
friend SinkManager::Sink;
Event<float> srChange;
private:
void setSampleRate(float sampleRate);
dsp::stream<dsp::stereo_t>* _in;
dsp::Splitter<dsp::stereo_t> splitter;
SinkManager::Sink* sink;
std::mutex ctrlMtx;
float _sampleRate;
};
struct SinkProvider {
SinkManager::Sink* (*create)(SinkManager::Stream* stream, void* ctx);
void* ctx;
};
void registerSinkProvider(std::string name, SinkProvider provider);
void registerStream(std::string name, Stream* stream);
void unregisterStream(std::string name);
dsp::stream<dsp::stereo_t>* bindStream(std::string name);
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
void showMenu();
private:
// TODO: Replace with std::unordered_map
std::map<std::string, SinkProvider> providers;
std::map<std::string, Stream*> streams;
};