Skip to content

Commit

Permalink
ggmorse : get threshold level + build fix (#13)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
f4exb and srcejon authored May 31, 2024
1 parent 90cdc62 commit 8fb433d
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 9 deletions.
4 changes: 4 additions & 0 deletions examples/ggmorse-gui/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <thread>
#include <vector>

#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
Expand Down
6 changes: 4 additions & 2 deletions include/ggmorse/ggmorse.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extern "C" {
#include <vector>
#include <functional>

class GGMorse {
class GGMORSE_API GGMorse {
public:
static constexpr auto kBaseSampleRate = 4000.0f;
static constexpr auto kDefaultSamplesPerFrame = 128;
Expand All @@ -101,6 +101,7 @@ class GGMorse {
using TxRx = std::vector<std::uint8_t>;
using Spectrogram = std::vector<std::vector<float>>;
using SignalF = std::vector<float>;
using ThresholdF = std::vector<float>;

using CBWaveformOut = std::function<void(const void * data, uint32_t nBytes)>;
using CBWaveformInp = std::function<uint32_t(void * data, uint32_t nMaxBytes)>;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <cmath>

#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;
Expand Down
6 changes: 5 additions & 1 deletion src/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <cmath>

#if defined(_WIN32) && !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif

#ifndef pi
#define pi 3.1415926535897932384626433832795
#endif
Expand Down Expand Up @@ -132,7 +136,7 @@ struct Filter {
float a2;
float b1;
float b2;

float xnz1;
float xnz2;
float ynz1;
Expand Down
26 changes: 20 additions & 6 deletions src/ggmorse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ struct GGMorse::Impl {
TxRx rxData = {};
TxRx txData = {};
SignalF signalF = {};
ThresholdF thresholdF = {};
WaveformI16 txWaveformI16 = {};

TxRx outputBlockTmp = {};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/goertzel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <vector>
#include <cmath>

#if defined(_WIN32) && !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif

struct GoertzelRunningFIR {
void init(
float sampleRate,
Expand Down
4 changes: 4 additions & 0 deletions src/resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <cmath>
#include <cstdio>

#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));
Expand Down
4 changes: 4 additions & 0 deletions src/stfft.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <vector>
#include <cmath>

#if defined(_WIN32) && !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif

struct STFFT {
void init(
int sampleRate,
Expand Down

0 comments on commit 8fb433d

Please sign in to comment.