From 915dd8be169651d517eef83eb07e94b894a278ff Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sat, 11 Jun 2022 20:23:13 +0300 Subject: [PATCH] ggwave : add DSS test + remove OperatingMode enum --- examples/arduino-rx-web/arduino-rx-web.cpp | 4 ++-- examples/ggwave-common-sdl2.cpp | 4 ++-- examples/ggwave-to-file/main.cpp | 4 ++-- examples/r2t2/main.cpp | 4 ++-- examples/r2t2/r2t2-rx.cpp | 4 ++-- examples/waver/common.cpp | 6 +++--- include/ggwave/ggwave.h | 24 +++++++++++----------- src/ggwave.cpp | 2 +- tests/test-ggwave.cpp | 2 ++ 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/examples/arduino-rx-web/arduino-rx-web.cpp b/examples/arduino-rx-web/arduino-rx-web.cpp index 954a793..aeb0637 100644 --- a/examples/arduino-rx-web/arduino-rx-web.cpp +++ b/examples/arduino-rx-web/arduino-rx-web.cpp @@ -225,8 +225,8 @@ bool GGWave_init( if (reinit) { if (g_ggWave) delete g_ggWave; - ggwave_OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; - if (useDSS) mode = ggwave_OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; + if (useDSS) mode |= GGWAVE_OPERATING_MODE_USE_DSS; g_ggWave = new GGWave({ payloadLength, diff --git a/examples/ggwave-common-sdl2.cpp b/examples/ggwave-common-sdl2.cpp index fc1002d..4f09acc 100644 --- a/examples/ggwave-common-sdl2.cpp +++ b/examples/ggwave-common-sdl2.cpp @@ -212,8 +212,8 @@ bool GGWave_init( } if (reinit) { - ggwave_OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; - if (useDSS) mode = ggwave_OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; + if (useDSS) mode |= GGWAVE_OPERATING_MODE_USE_DSS; g_ggWave = std::make_shared(GGWave::Parameters { payloadLength, diff --git a/examples/ggwave-to-file/main.cpp b/examples/ggwave-to-file/main.cpp index 3f8dc1d..bb6b621 100644 --- a/examples/ggwave-to-file/main.cpp +++ b/examples/ggwave-to-file/main.cpp @@ -79,8 +79,8 @@ int main(int argc, char** argv) { fprintf(stderr, "Generating waveform for message '%s' ...\n", message.c_str()); - ggwave_OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; - if (useDSS) mode = ggwave_OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; + if (useDSS) mode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave ggWave({ payloadLength, diff --git a/examples/r2t2/main.cpp b/examples/r2t2/main.cpp index b5f387d..3c10a37 100644 --- a/examples/r2t2/main.cpp +++ b/examples/r2t2/main.cpp @@ -71,8 +71,8 @@ int main(int argc, char** argv) { const int txProtocolId = argm.count("t") == 0 ? 0 : std::stoi(argm.at("t")); const int payloadLength = argm.count("l") == 0 ? 16 : std::stoi(argm.at("l")); - ggwave_OperatingMode mode = ggwave_OperatingMode(GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES); - if (useDSS) mode = ggwave_OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES; + if (useDSS) mode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave ggWave({ payloadLength, diff --git a/examples/r2t2/r2t2-rx.cpp b/examples/r2t2/r2t2-rx.cpp index cc4ceb0..8730258 100644 --- a/examples/r2t2/r2t2-rx.cpp +++ b/examples/r2t2/r2t2-rx.cpp @@ -224,8 +224,8 @@ bool GGWave_init( if (reinit) { if (g_ggWave) delete g_ggWave; - ggwave_OperatingMode mode = GGWAVE_OPERATING_MODE_RX; - if (useDSS) mode = ggwave_OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_RX; + if (useDSS) mode |= GGWAVE_OPERATING_MODE_USE_DSS; g_ggWave = new GGWave({ payloadLength, diff --git a/examples/waver/common.cpp b/examples/waver/common.cpp index 98db451..1c94534 100644 --- a/examples/waver/common.cpp +++ b/examples/waver/common.cpp @@ -623,12 +623,12 @@ void updateCore() { if (inputCurrent.flags.needReinit) { static auto sampleRateInpOld = ggWave->sampleRateInp(); static auto sampleRateOutOld = ggWave->sampleRateOut(); - GGWave::SampleFormat sampleFormatInpOld = ggWave->sampleFormatInp(); - GGWave::SampleFormat sampleFormatOutOld = ggWave->sampleFormatOut(); + auto sampleFormatInpOld = ggWave->sampleFormatInp(); + auto sampleFormatOutOld = ggWave->sampleFormatOut(); auto rxProtocolsOld = ggWave->rxProtocols(); GGWave::OperatingMode mode = GGWAVE_OPERATING_MODE_RX_AND_TX; - if (inputCurrent.directSequenceSpread) mode = GGWave::OperatingMode(mode | GGWAVE_OPERATING_MODE_USE_DSS); + if (inputCurrent.directSequenceSpread) mode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave::Parameters parameters { inputCurrent.payloadLength, diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index 15238d3..852f7b5 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -87,14 +87,14 @@ extern "C" { // GGWAVE_OPERATING_MODE_USE_DSS: // Enable the built-in Direct Sequence Spread (DSS) algorithm // - typedef enum { + enum { GGWAVE_OPERATING_MODE_RX = 1 << 1, GGWAVE_OPERATING_MODE_TX = 1 << 2, GGWAVE_OPERATING_MODE_RX_AND_TX = (GGWAVE_OPERATING_MODE_RX | GGWAVE_OPERATING_MODE_TX), GGWAVE_OPERATING_MODE_TX_ONLY_TONES = 1 << 3, GGWAVE_OPERATING_MODE_USE_DSS = 1 << 4, - } ggwave_OperatingMode; + }; // GGWave instance parameters // @@ -123,15 +123,15 @@ extern "C" { // not be allocated. // typedef struct { - int payloadLength; // payload length - float sampleRateInp; // capture sample rate - float sampleRateOut; // playback sample rate - float sampleRate; // the operating sample rate - int samplesPerFrame; // number of samples per audio frame - float soundMarkerThreshold; // sound marker detection threshold - ggwave_SampleFormat sampleFormatInp; // format of the captured audio samples - ggwave_SampleFormat sampleFormatOut; // format of the playback audio samples - ggwave_OperatingMode operatingMode; // operating mode + int payloadLength; // payload length + float sampleRateInp; // capture sample rate + float sampleRateOut; // playback sample rate + float sampleRate; // the operating sample rate + int samplesPerFrame; // number of samples per audio frame + float soundMarkerThreshold; // sound marker detection threshold + ggwave_SampleFormat sampleFormatInp; // format of the captured audio samples + ggwave_SampleFormat sampleFormatOut; // format of the playback audio samples + int operatingMode; // operating mode } ggwave_Parameters; // GGWave instances are identified with an integer and are stored @@ -415,7 +415,7 @@ public: using ProtocolId = ggwave_ProtocolId; using TxProtocolId = ggwave_ProtocolId; using RxProtocolId = ggwave_ProtocolId; - using OperatingMode = ggwave_OperatingMode; + using OperatingMode = int; // ggwave_OperatingMode; struct Protocol { const char * name; // string identifier of the protocol diff --git a/src/ggwave.cpp b/src/ggwave.cpp index 46be4fd..da2601c 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -644,7 +644,7 @@ const GGWave::Parameters & GGWave::getDefaultParameters() { kDefaultSoundMarkerThreshold, GGWAVE_SAMPLE_FORMAT_F32, GGWAVE_SAMPLE_FORMAT_F32, - (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_RX | GGWAVE_OPERATING_MODE_TX), + GGWAVE_OPERATING_MODE_RX | GGWAVE_OPERATING_MODE_TX, }; return result; diff --git a/tests/test-ggwave.cpp b/tests/test-ggwave.cpp index 2e1223a..bf8fae3 100644 --- a/tests/test-ggwave.cpp +++ b/tests/test-ggwave.cpp @@ -265,6 +265,7 @@ int main(int argc, char ** argv) { auto parameters = GGWave::getDefaultParameters(); parameters.sampleFormatInp = formatInp; parameters.sampleFormatOut = formatOut; + if (rand() % 2 == 0) parameters.operatingMode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave instance(parameters); instance.rxProtocols().only(GGWave::ProtocolId(protocolId)); @@ -292,6 +293,7 @@ int main(int argc, char ** argv) { parameters.payloadLength = length; parameters.sampleFormatInp = formatInp; parameters.sampleFormatOut = formatOut; + if (rand() % 2 == 0) parameters.operatingMode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave instance(parameters); instance.rxProtocols().only(GGWave::ProtocolId(protocolId));