From bade0ecb4345028d4c8b81a6515a54c1cb8fd2a5 Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 8 Apr 2024 23:14:37 +1000 Subject: [PATCH] Port for SDR++ v1.0.4 --- .github/workflows/arm-macos.yml | 2 +- .github/workflows/x86-macos.yml | 2 +- .github/workflows/x86-ubuntu.yml | 2 +- .github/workflows/x86-windows.yml | 2 +- CMakeLists.txt | 4 +- README.md | 8 +- cmake/Findsdrpp_core.cmake | 113 ++++++++++++++++++++++++++ src/CMakeLists.txt | 2 +- src/dab_module.cpp | 22 ++--- src/dab_module.h | 7 +- src/main.cpp | 3 +- src/render_formatters.cpp | 2 +- src/render_radio_block.cpp | 2 +- toolchains/macos/Brewfile | 1 + toolchains/ubuntu/install_packages.sh | 2 +- vcpkg.json | 4 + vendor/sdrplusplus | 2 +- 17 files changed, 149 insertions(+), 31 deletions(-) create mode 100644 cmake/Findsdrpp_core.cmake diff --git a/.github/workflows/arm-macos.yml b/.github/workflows/arm-macos.yml index 021526f..64f8a3f 100644 --- a/.github/workflows/arm-macos.yml +++ b/.github/workflows/arm-macos.yml @@ -3,7 +3,7 @@ name: arm-macos on: workflow_dispatch: push: - branches: [ "master", "dev" ] + branches: [ "master", "dev", "sdr-1.0.4" ] env: BUILD_TYPE: Release diff --git a/.github/workflows/x86-macos.yml b/.github/workflows/x86-macos.yml index b919b15..2dcf5ba 100644 --- a/.github/workflows/x86-macos.yml +++ b/.github/workflows/x86-macos.yml @@ -3,7 +3,7 @@ name: x86-macos on: workflow_dispatch: push: - branches: [ "master", "dev" ] + branches: [ "master", "dev", "sdr-1.0.4" ] env: BUILD_TYPE: Release diff --git a/.github/workflows/x86-ubuntu.yml b/.github/workflows/x86-ubuntu.yml index 43d7acd..097c5fc 100644 --- a/.github/workflows/x86-ubuntu.yml +++ b/.github/workflows/x86-ubuntu.yml @@ -3,7 +3,7 @@ name: x86-ubuntu on: workflow_dispatch: push: - branches: [ "master", "dev" ] + branches: [ "master", "dev", "sdr-1.0.4" ] env: BUILD_TYPE: Release diff --git a/.github/workflows/x86-windows.yml b/.github/workflows/x86-windows.yml index 25a6bec..65919e8 100644 --- a/.github/workflows/x86-windows.yml +++ b/.github/workflows/x86-windows.yml @@ -3,7 +3,7 @@ name: x86-windows on: workflow_dispatch: push: - branches: [ "master", "dev" ] + branches: [ "master", "dev", "sdr-1.0.4" ] env: BUILD_TYPE: Release diff --git a/CMakeLists.txt b/CMakeLists.txt index cf1ca48..a3e2787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,9 +39,7 @@ else() # however pkg-config cant find libcorrect because it is not a package in the repository endif() set(OPT_BACKEND_GLFW ON CACHE BOOL "Enable glfw backend") -add_subdirectory(${CMAKE_SOURCE_DIR}/vendor/sdrplusplus/core) -set_target_properties(sdrpp_core PROPERTIES CXX_STANDARD 17) - +find_package(sdrpp_core REQUIRED) # build dab modules # copied from ./vendor/DAB-Radio/CMakeLists.txt diff --git a/README.md b/README.md index 38a83f2..d514e22 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## Introduction -[![x86-windows](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-windows.yml/badge.svg)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-windows.yml) -[![x86-ubuntu](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-ubuntu.yml/badge.svg)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-ubuntu.yml) -[![x86-macos](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-macos.yml/badge.svg)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-macos.yml) -[![arm-macos](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/arm-macos.yml/badge.svg)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/arm-macos.yml) +[![x86-windows](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-windows.yml/badge.svg?branch=sdr-1.0.4)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-windows.yml) +[![x86-ubuntu](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-ubuntu.yml/badge.svg?branch=sdr-1.0.4)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-ubuntu.yml) +[![x86-macos](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-macos.yml/badge.svg?branch=sdr-1.0.4)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/x86-macos.yml) +[![arm-macos](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/arm-macos.yml/badge.svg?branch=sdr-1.0.4)](https://github.com/williamyang98/SDRPlusPlus-DAB-Radio-Plugin/actions/workflows/arm-macos.yml) SDR++ DAB radio plugin. diff --git a/cmake/Findsdrpp_core.cmake b/cmake/Findsdrpp_core.cmake new file mode 100644 index 0000000..ef9bd29 --- /dev/null +++ b/cmake/Findsdrpp_core.cmake @@ -0,0 +1,113 @@ +# Copied from vendor/sdrplusplus/core/CMakeLists.txt +cmake_minimum_required(VERSION 3.13) +project(sdrpp_core) + +set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../vendor/sdrplusplus/core) + +# Main code +file(GLOB_RECURSE SRC "${SRC_DIR}/src/*.cpp" "${SRC_DIR}/src/*.c") + +if (MSVC) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif () + +# Add code to dyn lib +add_library(sdrpp_core SHARED ${SRC}) +# configure SDRPP_EXPORT dllimport/dllexport/extern properly for core/src/module.h +target_compile_definitions(sdrpp_core PRIVATE SDRPP_IS_CORE) + +# Set compiler options +if (MSVC) + target_compile_options(sdrpp_core PRIVATE /O2 /Ob2 /std:c++17 /EHsc) +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(sdrpp_core PRIVATE -O3 -std=c++17) +else () + target_compile_options(sdrpp_core PRIVATE -O3 -std=c++17) +endif () + + +# Set the install prefix +target_compile_definitions(sdrpp_core PUBLIC INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") + +# Include core headers +target_include_directories(sdrpp_core PUBLIC "${SRC_DIR}/src/") +target_include_directories(sdrpp_core PUBLIC "${SRC_DIR}/src/imgui") + +# Link to linkcorrect +if (USE_INTERNAL_LIBCORRECT) +add_subdirectory("${SRC_DIR}/libcorrect/") +target_include_directories(sdrpp_core PUBLIC "${SRC_DIR}/libcorrect/include") +target_link_libraries(sdrpp_core PUBLIC correct_static) +endif (USE_INTERNAL_LIBCORRECT) + +if (OPT_OVERRIDE_STD_FILESYSTEM) +target_include_directories(sdrpp_core PUBLIC "${SRC_DIR}/std_replacement") +endif (OPT_OVERRIDE_STD_FILESYSTEM) + +if (MSVC) + # Lib path + target_link_directories(sdrpp_core PUBLIC "C:/Program Files/PothosSDR/lib/") + + # Misc headers + target_include_directories(sdrpp_core PUBLIC "C:/Program Files/PothosSDR/include/") + + # Volk + target_link_libraries(sdrpp_core PUBLIC volk) + + # Glew + find_package(GLEW REQUIRED) + target_link_libraries(sdrpp_core PUBLIC GLEW::GLEW) + + # GLFW3 + find_package(glfw3 CONFIG REQUIRED) + target_link_libraries(sdrpp_core PUBLIC glfw) + + # FFTW3 + find_package(FFTW3f CONFIG REQUIRED) + target_link_libraries(sdrpp_core PUBLIC FFTW3::fftw3f) + + # WinSock2 + target_link_libraries(sdrpp_core PUBLIC wsock32 ws2_32) + +else() + find_package(PkgConfig) + find_package(OpenGL REQUIRED) + + pkg_check_modules(GLEW REQUIRED glew) + pkg_check_modules(FFTW3 REQUIRED fftw3f) + pkg_check_modules(VOLK REQUIRED volk) + pkg_check_modules(GLFW3 REQUIRED glfw3) + + target_include_directories(sdrpp_core PUBLIC + ${GLEW_INCLUDE_DIRS} + ${FFTW3_INCLUDE_DIRS} + ${GLFW3_INCLUDE_DIRS} + ${VOLK_INCLUDE_DIRS} + ) + + target_link_directories(sdrpp_core PUBLIC + ${GLEW_LIBRARY_DIRS} + ${FFTW3_LIBRARY_DIRS} + ${GLFW3_LIBRARY_DIRS} + ${VOLK_LIBRARY_DIRS} + ) + + target_link_libraries(sdrpp_core PUBLIC + ${OPENGL_LIBRARIES} + ${GLEW_LIBRARIES} + ${FFTW3_LIBRARIES} + ${GLFW3_LIBRARIES} + ${VOLK_LIBRARIES} + ) + + if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + target_link_libraries(sdrpp_core PUBLIC stdc++fs) + endif () + + if (NOT USE_INTERNAL_LIBCORRECT) + pkg_check_modules(CORRECT REQUIRED libcorrect) + target_include_directories(sdrpp_core PUBLIC ${CORRECT_INCLUDE_DIRS}) + target_link_directories(sdrpp_core PUBLIC ${CORRECT_LIBRARY_DIRS}) + target_link_libraries(sdrpp_core PUBLIC ${CORRECT_LIBRARIES}) + endif (NOT USE_INTERNAL_LIBCORRECT) +endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d46a93a..d421f54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,4 +23,4 @@ target_include_directories(dab_plugin PRIVATE ${SRC_DIR} ${ROOT_DIR} ${AUDIO_DIR target_link_libraries(dab_plugin PRIVATE sdrpp_core ofdm_core dab_core basic_radio audio_mixer - fmt) \ No newline at end of file +) \ No newline at end of file diff --git a/src/dab_module.cpp b/src/dab_module.cpp index 1952f6c..05ed3c6 100644 --- a/src/dab_module.cpp +++ b/src/dab_module.cpp @@ -13,15 +13,18 @@ #include "utility/span.h" ConfigManager config; // extern - -int OFDM_Demodulator_Sink::run() { - int count = base_type::_in->read(); - if (count < 0) return -1; - auto* buf = base_type::_in->readBuf; - auto block = tcb::span(reinterpret_cast*>(buf), size_t(count)); - m_ofdm_demod->Process(block); - base_type::_in->flush(); - return count; + // +OFDM_Demodulator_Sink::OFDM_Demodulator_Sink(std::shared_ptr ofdm_demod) +: m_ofdm_demod(ofdm_demod) +{ + setHandler( + [](dsp::complex_t* buf, int count, void* ctx) { + auto ofdm_demod = reinterpret_cast(ctx); + auto block = tcb::span(reinterpret_cast*>(buf), size_t(count)); + ofdm_demod->Process(block); + }, + reinterpret_cast(m_ofdm_demod.get()) + ); } Audio_Player_Stream::Audio_Player_Stream(float sample_rate, float block_size_seconds) @@ -74,7 +77,6 @@ DABModule::DABModule(std::string _name) // setup radio radio_block = std::make_unique(1,1); ofdm_demodulator_sink = std::make_unique(radio_block->get_ofdm_demodulator()); - ofdm_demodulator_sink->init(nullptr); radio_view_controller = std::make_unique(); // setup audio const float DEFAULT_AUDIO_SAMPLE_RATE = 48000.0f; diff --git a/src/dab_module.h b/src/dab_module.h index f920e55..bc99b46 100644 --- a/src/dab_module.h +++ b/src/dab_module.h @@ -19,18 +19,17 @@ class OFDM_Demod; class Radio_View_Controller; class Radio_Block; -class OFDM_Demodulator_Sink: public dsp::Sink +class OFDM_Demodulator_Sink: public dsp::HandlerSink { private: - using base_type = dsp::Sink; + using base_type = dsp::HandlerSink; std::shared_ptr m_ofdm_demod; public: - OFDM_Demodulator_Sink(std::shared_ptr ofdm_demod): m_ofdm_demod(ofdm_demod) {} + OFDM_Demodulator_Sink(std::shared_ptr ofdm_demod); ~OFDM_Demodulator_Sink() override { if (!base_type::_block_init) return; base_type::stop(); } - int run(); }; class Audio_Player_Stream: public AudioPipelineSink diff --git a/src/main.cpp b/src/main.cpp index 92f5f7a..5304975 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "./dab_module.h" @@ -14,7 +15,7 @@ SDRPP_MOD_INFO{ MOD_EXPORT void _INIT_() { json def = json({}); - config.setPath(core::args["root"].s() + "/dab_plugin_config.json"); + config.setPath(options::opts.root + "/dab_plugin_config.json"); config.load(def); config.enableAutoSave(); } diff --git a/src/render_formatters.cpp b/src/render_formatters.cpp index 36b05ce..c87dad2 100644 --- a/src/render_formatters.cpp +++ b/src/render_formatters.cpp @@ -1,5 +1,5 @@ #include "./render_formatters.h" -#include +#include #include "dab/constants/subchannel_protection_tables.h" #include "dab/constants/country_table.h" diff --git a/src/render_radio_block.cpp b/src/render_radio_block.cpp index 9fb6ee5..a231c8e 100644 --- a/src/render_radio_block.cpp +++ b/src/render_radio_block.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/toolchains/macos/Brewfile b/toolchains/macos/Brewfile index d1a024a..42fe5fe 100644 --- a/toolchains/macos/Brewfile +++ b/toolchains/macos/Brewfile @@ -1,5 +1,6 @@ brew 'pkg-config' brew 'fftw' +brew 'glew' brew 'glfw' brew 'zstd' brew 'cmake' diff --git a/toolchains/ubuntu/install_packages.sh b/toolchains/ubuntu/install_packages.sh index a94cb41..bda5faa 100755 --- a/toolchains/ubuntu/install_packages.sh +++ b/toolchains/ubuntu/install_packages.sh @@ -1,7 +1,7 @@ #!/bin/sh sudo apt-get --yes install build-essential ninja-build -sudo apt-get --yes install libglfw3-dev libopengl-dev libfftw3-dev libfftw3-single3 libvolk2-dev libzstd-dev libcpu-features-dev +sudo apt-get --yes install libglew-dev libglfw3-dev libopengl-dev libfftw3-dev libfftw3-single3 libvolk2-dev libzstd-dev libcpu-features-dev # install mako for volk build python3 -m pip install mako --quiet diff --git a/vcpkg.json b/vcpkg.json index a6cf656..feedf27 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,6 +3,10 @@ "version-string": "latest", "builtin-baseline": "c9140a3b500812ad3206317885860d9553b93f13", "dependencies": [ + { + "name": "glew", + "version>=": "2.2.0#3" + }, { "name": "glfw3", "version>=": "3.3.6" diff --git a/vendor/sdrplusplus b/vendor/sdrplusplus index fdfb1db..f539cfa 160000 --- a/vendor/sdrplusplus +++ b/vendor/sdrplusplus @@ -1 +1 @@ -Subproject commit fdfb1dbf5e0abe8191f9393b19f34b0427c98ed3 +Subproject commit f539cfad329859ffd0d99e1ae03dd06da35aadf7