From 8fb433d6cd6a71940f51b5724663ec0c75bf0b62 Mon Sep 17 00:00:00 2001 From: Edouard Griffiths Date: Fri, 31 May 2024 15:34:33 +0200 Subject: [PATCH] ggmorse : get threshold level + build fix (#13) * Install include * Fix for some compilers * Core: store thresholds in vector for display or debugging * Fix for MSVC * Use CMAKE_INSTALL_LIBDIR in installation * Corrected export of symbols for MSVC * Use GGMORSE_SHARED which is defined in src/CMakeLists.txt * Define GGMORSE_BUILD for MSVC so __declspec(dllexport) is used * Remove GGMORSE_BUILD which doesn't do anything * Removed vscode files from tracking * Corrected break placement * Try to resolve conflicts --------- Co-authored-by: Jon Beniston --- examples/ggmorse-gui/common.cpp | 4 ++++ include/ggmorse/ggmorse.h | 6 ++++-- src/CMakeLists.txt | 5 +++++ src/fft.h | 4 ++++ src/filter.h | 6 +++++- src/ggmorse.cpp | 26 ++++++++++++++++++++------ src/goertzel.h | 4 ++++ src/resampler.cpp | 4 ++++ src/stfft.h | 4 ++++ 9 files changed, 54 insertions(+), 9 deletions(-) diff --git a/examples/ggmorse-gui/common.cpp b/examples/ggmorse-gui/common.cpp index 36b855c..425d089 100644 --- a/examples/ggmorse-gui/common.cpp +++ b/examples/ggmorse-gui/common.cpp @@ -28,6 +28,10 @@ #include #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + #if defined(IOS) || defined(ANDROID) #include "imgui-wrapper/icons_font_awesome.h" #endif diff --git a/include/ggmorse/ggmorse.h b/include/ggmorse/ggmorse.h index a98b016..0e6b0bf 100644 --- a/include/ggmorse/ggmorse.h +++ b/include/ggmorse/ggmorse.h @@ -81,7 +81,7 @@ extern "C" { #include #include -class GGMorse { +class GGMORSE_API GGMorse { public: static constexpr auto kBaseSampleRate = 4000.0f; static constexpr auto kDefaultSamplesPerFrame = 128; @@ -101,6 +101,7 @@ class GGMorse { using TxRx = std::vector; using Spectrogram = std::vector>; using SignalF = std::vector; + using ThresholdF = std::vector; using CBWaveformOut = std::function; using CBWaveformInp = std::function; @@ -140,6 +141,7 @@ class GGMorse { int takeRxData(TxRx & dst); int takeSignalF(SignalF & dst); + int takeThresholdF(ThresholdF & dst); int takeTxWaveformI16(WaveformI16 & dst); const Statistics & getStatistics() const; @@ -152,7 +154,7 @@ class GGMorse { // // For example: setCharacter("01101", 'A') will set the character 'A' to the Morse Code sequence "01101" // - bool setCharacter(const std::string & s01, char c); + bool setCharacter(const char * s01, char c); private: void decode_float(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e50dbc8..d79ea07 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,11 @@ if (BUILD_SHARED_LIBS) target_compile_definitions(${TARGET} PUBLIC GGMORSE_SHARED ) + if (MSVC) + target_compile_definitions(${TARGET} PUBLIC + GGMORSE_BUILD + ) + endif() endif() if (MINGW) diff --git a/src/fft.h b/src/fft.h index b744d54..2b1e01b 100644 --- a/src/fft.h +++ b/src/fft.h @@ -2,6 +2,10 @@ #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + // FFT routines taken from https://stackoverflow.com/a/37729648/4039976 constexpr auto kMaxSamplesPerFrame = 1024; diff --git a/src/filter.h b/src/filter.h index ab1329a..9b7721e 100644 --- a/src/filter.h +++ b/src/filter.h @@ -2,6 +2,10 @@ #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + #ifndef pi #define pi 3.1415926535897932384626433832795 #endif @@ -132,7 +136,7 @@ struct Filter { float a2; float b1; float b2; - + float xnz1; float xnz2; float ynz1; diff --git a/src/ggmorse.cpp b/src/ggmorse.cpp index 9f15b02..763678c 100644 --- a/src/ggmorse.cpp +++ b/src/ggmorse.cpp @@ -155,6 +155,7 @@ struct GGMorse::Impl { TxRx rxData = {}; TxRx txData = {}; SignalF signalF = {}; + ThresholdF thresholdF = {}; WaveformI16 txWaveformI16 = {}; TxRx outputBlockTmp = {}; @@ -756,6 +757,8 @@ void GGMorse::decode_float() { nModes = 1; } + m_impl->thresholdF.push_back(m_impl->statistics.signalThreshold); + for (int mode = 0; mode < nModes; ++mode) { if (mode == 1) { s0 = std::min(std::max(0.0f, std::round(m_impl->statistics.estimatedSpeed_wpm - 5.0f - 2.0f)), 50.0f); @@ -972,8 +975,10 @@ void GGMorse::decode_float() { } else { if (intervals[j].type == 0 || intervals[j].type == 2 || - intervals[j].type == 3) { - if (auto let = m_impl->alphabet.find(m_impl->curLetter); let != m_impl->alphabet.end()) { + intervals[j].type == 3) + { + auto let = m_impl->alphabet.find(m_impl->curLetter); + if (let != m_impl->alphabet.end()) { m_impl->rxData.push_back(let->second); printf("%c", let->second); } else { @@ -1035,6 +1040,14 @@ int GGMorse::takeSignalF(SignalF & dst) { return (int) dst.size(); } +int GGMorse::takeThresholdF(ThresholdF & dst) { + if (m_impl->thresholdF.size() == 0) return 0; + + dst = std::move(m_impl->thresholdF); + + return (int) dst.size(); +} + int GGMorse::takeTxWaveformI16(WaveformI16 & dst) { if (m_impl->txWaveformI16.size() == 0) return false; @@ -1046,11 +1059,12 @@ int GGMorse::takeTxWaveformI16(WaveformI16 & dst) { const GGMorse::Statistics & GGMorse::getStatistics() const { return m_impl->statistics; } const GGMorse::Spectrogram GGMorse::getSpectrogram() const { return m_impl->stfft.spectrogram(); } -bool GGMorse::setCharacter(const std::string & s01, char c) { +bool GGMorse::setCharacter(const char * s01, char c) { // remove old character - for (auto it : m_impl->alphabet) { - if (it.second == c) { - m_impl->alphabet.erase(it.first); + for (TAlphabet::iterator it = m_impl->alphabet.begin(); it != m_impl->alphabet.end(); ++it) + { + if (it->second == c) { + m_impl->alphabet.erase(it->first); break; } } diff --git a/src/goertzel.h b/src/goertzel.h index 05df90e..6a4947b 100644 --- a/src/goertzel.h +++ b/src/goertzel.h @@ -3,6 +3,10 @@ #include #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + struct GoertzelRunningFIR { void init( float sampleRate, diff --git a/src/resampler.cpp b/src/resampler.cpp index 4b68eb5..e835039 100644 --- a/src/resampler.cpp +++ b/src/resampler.cpp @@ -4,6 +4,10 @@ #include #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + namespace { double linear_interp(double first_number, double second_number, double fraction) { return (first_number + ((second_number - first_number)*fraction)); diff --git a/src/stfft.h b/src/stfft.h index 7f1ef08..08cd975 100644 --- a/src/stfft.h +++ b/src/stfft.h @@ -5,6 +5,10 @@ #include #include +#if defined(_WIN32) && !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif + struct STFFT { void init( int sampleRate,