mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-07-08 18:15:21 +02:00
modules
This commit is contained in:
55
modules/radio/CMakeLists.txt
Normal file
55
modules/radio/CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
project(radio)
|
||||
|
||||
if (MSVC)
|
||||
set(CMAKE_CXX_FLAGS "-O2 /std:c++17")
|
||||
link_directories(radio "C:/Program Files/PothosSDR/lib/")
|
||||
include_directories(radio "C:/Program Files/PothosSDR/include/volk/")
|
||||
include_directories(radio "C:/Program Files/PothosSDR/include/")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fsanitize=address -g")
|
||||
include_directories(radio "/usr/include/volk")
|
||||
link_libraries(pthread)
|
||||
link_libraries(GL)
|
||||
link_libraries(GLEW)
|
||||
link_libraries(glfw)
|
||||
link_libraries(fftw3)
|
||||
link_libraries(fftw3f)
|
||||
link_libraries(portaudio)
|
||||
link_libraries(X11)
|
||||
link_libraries(Xxf86vm)
|
||||
endif (MSVC)
|
||||
|
||||
link_libraries(volk)
|
||||
link_libraries(SoapySDR)
|
||||
|
||||
# Main code
|
||||
include_directories(radio "src/")
|
||||
include_directories(radio "../../src/")
|
||||
include_directories(radio "../../src/imgui")
|
||||
file(GLOB SRC "src/*.cpp")
|
||||
file(GLOB IMGUI "../../src/imgui/*.cpp")
|
||||
add_library(radio SHARED ${SRC} ${IMGUI})
|
||||
set_target_properties(radio PROPERTIES OUTPUT_NAME radio)
|
||||
|
||||
if (MSVC)
|
||||
# Glew
|
||||
find_package(GLEW REQUIRED)
|
||||
target_link_libraries(radio PRIVATE GLEW::GLEW)
|
||||
|
||||
# GLFW3
|
||||
find_package(glfw3 CONFIG REQUIRED)
|
||||
target_link_libraries(radio PRIVATE glfw)
|
||||
|
||||
# FFTW3
|
||||
find_package(FFTW3 CONFIG REQUIRED)
|
||||
target_link_libraries(radio PRIVATE FFTW3::fftw3)
|
||||
find_package(FFTW3f CONFIG REQUIRED)
|
||||
target_link_libraries(radio PRIVATE FFTW3::fftw3f)
|
||||
|
||||
# PortAudio
|
||||
find_package(portaudio CONFIG REQUIRED)
|
||||
target_link_libraries(radio PRIVATE portaudio portaudio_static)
|
||||
endif (MSVC)
|
||||
|
||||
# cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/Users/Alex/vcpkg/scripts/buildsystems/vcpkg.cmake" -G "Visual Studio 15 2017 Win64"
|
79
modules/radio/src/main.cpp
Normal file
79
modules/radio/src/main.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include <imgui.h>
|
||||
#include <module.h>
|
||||
#include <path.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
|
||||
mod::API_t* API;
|
||||
|
||||
struct RadioContext_t {
|
||||
std::string name;
|
||||
int demod = 1;
|
||||
SigPath sigPath;
|
||||
};
|
||||
|
||||
MOD_EXPORT void* _INIT_(mod::API_t* _API, ImGuiContext* imctx, std::string _name) {
|
||||
API = _API;
|
||||
RadioContext_t* ctx = new RadioContext_t;
|
||||
ctx->name = _name;
|
||||
ctx->sigPath.init(_name, 200000, 1000, API->registerVFO(_name, mod::API_t::REF_CENTER, 0, 200000, 200000, 1000));
|
||||
ctx->sigPath.start();
|
||||
ImGui::SetCurrentContext(imctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
MOD_EXPORT void _DRAW_MENU_(RadioContext_t* ctx) {
|
||||
ImGui::BeginGroup();
|
||||
|
||||
ImGui::Columns(4, CONCAT("RadioModeColumns##_", ctx->name), false);
|
||||
if (ImGui::RadioButton(CONCAT("NFM##_", ctx->name), ctx->demod == 0) && ctx->demod != 0) {
|
||||
ctx->sigPath.setDemodulator(SigPath::DEMOD_NFM);
|
||||
ctx->demod = 0;
|
||||
API->setVFOBandwidth(ctx->name, 12500);
|
||||
// vfo->setReference(ImGui::WaterFall::REF_CENTER);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("WFM##_", ctx->name), ctx->demod == 1) && ctx->demod != 1) {
|
||||
ctx->sigPath.setDemodulator(SigPath::DEMOD_FM);
|
||||
ctx->demod = 1;
|
||||
API->setVFOBandwidth(ctx->name, 200000);
|
||||
// vfo->setReference(ImGui::WaterFall::REF_CENTER);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("AM##_", ctx->name), ctx->demod == 2) && ctx->demod != 2) {
|
||||
ctx->sigPath.setDemodulator(SigPath::DEMOD_AM);
|
||||
ctx->demod = 2;
|
||||
API->setVFOBandwidth(ctx->name, 12500);
|
||||
// vfo->setReference(ImGui::WaterFall::REF_CENTER);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("DSB##_", ctx->name), ctx->demod == 3) && ctx->demod != 3) { ctx->demod = 3; };
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("USB##_", ctx->name), ctx->demod == 4) && ctx->demod != 4) {
|
||||
ctx->sigPath.setDemodulator(SigPath::DEMOD_USB);
|
||||
ctx->demod = 4;
|
||||
API->setVFOBandwidth(ctx->name, 3000);
|
||||
// vfo->setReference(ImGui::WaterFall::REF_LOWER);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("CW##_", ctx->name), ctx->demod == 5) && ctx->demod != 5) { ctx->demod = 5; };
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("LSB##_", ctx->name), ctx->demod == 6) && ctx->demod != 6) {
|
||||
ctx->sigPath.setDemodulator(SigPath::DEMOD_LSB);
|
||||
ctx->demod = 6;
|
||||
API->setVFOBandwidth(ctx->name, 3000);
|
||||
// vfo->setReference(ImGui::WaterFall::REF_UPPER);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("RAW##_", ctx->name), ctx->demod == 7) && ctx->demod != 7) { ctx->demod = 7; };
|
||||
ImGui::Columns(1, CONCAT("EndRadioModeColumns##_", ctx->name), false);
|
||||
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
|
||||
MOD_EXPORT void _HANDLE_EVENT_(RadioContext_t* ctx, int eventId) {
|
||||
if (eventId == mod::EVENT_STREAM_PARAM_CHANGED) {
|
||||
ctx->sigPath.updateBlockSize();
|
||||
}
|
||||
}
|
||||
|
||||
MOD_EXPORT void _STOP_(RadioContext_t* ctx) {
|
||||
API->removeVFO(ctx->name);
|
||||
delete ctx;
|
||||
}
|
114
modules/radio/src/path.cpp
Normal file
114
modules/radio/src/path.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
#include <path.h>
|
||||
|
||||
SigPath::SigPath() {
|
||||
|
||||
}
|
||||
|
||||
void SigPath::init(std::string vfoName, uint64_t sampleRate, int blockSize, dsp::stream<dsp::complex_t>* input) {
|
||||
this->sampleRate = sampleRate;
|
||||
this->blockSize = blockSize;
|
||||
this->vfoName = vfoName;
|
||||
|
||||
_demod = DEMOD_FM;
|
||||
|
||||
// TODO: Set default VFO options
|
||||
|
||||
demod.init(input, 100000, 200000, 800);
|
||||
amDemod.init(input, 50);
|
||||
ssbDemod.init(input, 6000, 3000, 22);
|
||||
|
||||
audioResamp.init(&demod.output, 200000, 48000, 800);
|
||||
audio.init(&audioResamp.output, 64);
|
||||
}
|
||||
|
||||
void SigPath::setSampleRate(float sampleRate) {
|
||||
this->sampleRate = sampleRate;
|
||||
|
||||
// Reset the demodulator and audio systems
|
||||
setDemodulator(_demod);
|
||||
}
|
||||
|
||||
void SigPath::setVolume(float volume) {
|
||||
audio.setVolume(volume);
|
||||
}
|
||||
|
||||
void SigPath::setDemodulator(int demId) {
|
||||
if (demId < 0 || demId >= _DEMOD_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
audioResamp.stop();
|
||||
|
||||
// Stop current demodulator
|
||||
if (_demod == DEMOD_FM) {
|
||||
demod.stop();
|
||||
}
|
||||
else if (_demod == DEMOD_NFM) {
|
||||
demod.stop();
|
||||
}
|
||||
else if (_demod == DEMOD_AM) {
|
||||
amDemod.stop();
|
||||
}
|
||||
else if (_demod == DEMOD_USB) {
|
||||
ssbDemod.stop();
|
||||
}
|
||||
else if (_demod == DEMOD_LSB) {
|
||||
ssbDemod.stop();
|
||||
}
|
||||
_demod = demId;
|
||||
|
||||
// Set input of the audio resampler
|
||||
if (demId == DEMOD_FM) {
|
||||
API->setVFOSampleRate(vfoName, 200000, 200000);
|
||||
demod.setBlockSize(API->getVFOOutputBlockSize(vfoName));
|
||||
demod.setSampleRate(200000);
|
||||
demod.setDeviation(100000);
|
||||
audioResamp.setInput(&demod.output);
|
||||
audioResamp.setInputSampleRate(200000, API->getVFOOutputBlockSize(vfoName));
|
||||
demod.start();
|
||||
}
|
||||
if (demId == DEMOD_NFM) {
|
||||
API->setVFOSampleRate(vfoName, 12500, 12500);
|
||||
demod.setBlockSize(API->getVFOOutputBlockSize(vfoName));
|
||||
demod.setSampleRate(12500);
|
||||
demod.setDeviation(6250);
|
||||
audioResamp.setInput(&demod.output);
|
||||
audioResamp.setInputSampleRate(12500, API->getVFOOutputBlockSize(vfoName));
|
||||
demod.start();
|
||||
}
|
||||
else if (demId == DEMOD_AM) {
|
||||
API->setVFOSampleRate(vfoName, 12500, 12500);
|
||||
amDemod.setBlockSize(API->getVFOOutputBlockSize(vfoName));
|
||||
audioResamp.setInput(&amDemod.output);
|
||||
audioResamp.setInputSampleRate(12500, API->getVFOOutputBlockSize(vfoName));
|
||||
amDemod.start();
|
||||
}
|
||||
else if (demId == DEMOD_USB) {
|
||||
API->setVFOSampleRate(vfoName, 6000, 3000);
|
||||
ssbDemod.setBlockSize(API->getVFOOutputBlockSize(vfoName));
|
||||
ssbDemod.setMode(dsp::SSBDemod::MODE_USB);
|
||||
audioResamp.setInput(&ssbDemod.output);
|
||||
audioResamp.setInputSampleRate(6000, API->getVFOOutputBlockSize(vfoName));
|
||||
ssbDemod.start();
|
||||
}
|
||||
else if (demId == DEMOD_LSB) {
|
||||
API->setVFOSampleRate(vfoName, 6000, 3000);
|
||||
ssbDemod.setBlockSize(API->getVFOOutputBlockSize(vfoName));
|
||||
ssbDemod.setMode(dsp::SSBDemod::MODE_LSB);
|
||||
audioResamp.setInput(&ssbDemod.output);
|
||||
audioResamp.setInputSampleRate(6000, API->getVFOOutputBlockSize(vfoName));
|
||||
ssbDemod.start();
|
||||
}
|
||||
|
||||
audioResamp.start();
|
||||
}
|
||||
|
||||
void SigPath::updateBlockSize() {
|
||||
setDemodulator(_demod);
|
||||
}
|
||||
|
||||
void SigPath::start() {
|
||||
demod.start();
|
||||
audioResamp.start();
|
||||
audio.start();
|
||||
}
|
54
modules/radio/src/path.h
Normal file
54
modules/radio/src/path.h
Normal file
@ -0,0 +1,54 @@
|
||||
#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/correction.h>
|
||||
#include <dsp/vfo.h>
|
||||
#include <io/audio.h>
|
||||
#include <module.h>
|
||||
|
||||
class SigPath {
|
||||
public:
|
||||
SigPath();
|
||||
void init(std::string vfoName, uint64_t sampleRate, int blockSize, dsp::stream<dsp::complex_t>* input);
|
||||
void start();
|
||||
void setSampleRate(float sampleRate);
|
||||
|
||||
void setVFOFrequency(long frequency);
|
||||
void setVolume(float volume);
|
||||
|
||||
void updateBlockSize();
|
||||
|
||||
void setDemodulator(int demod);
|
||||
|
||||
enum {
|
||||
DEMOD_FM,
|
||||
DEMOD_NFM,
|
||||
DEMOD_AM,
|
||||
DEMOD_USB,
|
||||
DEMOD_LSB,
|
||||
_DEMOD_COUNT
|
||||
};
|
||||
|
||||
private:
|
||||
dsp::stream<dsp::complex_t> input;
|
||||
|
||||
// Demodulators
|
||||
dsp::FMDemodulator demod;
|
||||
dsp::AMDemodulator amDemod;
|
||||
dsp::SSBDemod ssbDemod;
|
||||
|
||||
// Audio output
|
||||
dsp::FloatFIRResampler audioResamp;
|
||||
io::AudioSink audio;
|
||||
|
||||
std::string vfoName;
|
||||
|
||||
float sampleRate;
|
||||
int blockSize;
|
||||
int _demod;
|
||||
};
|
Reference in New Issue
Block a user