From a29fb485e11090ded753f8efd3b97e075d17802e Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 12 Jul 2022 23:52:33 +0300 Subject: [PATCH] ggwave : update tests --- .github/workflows/build.yml | 1 + examples/spectrogram/main.cpp | 6 +++--- src/ggwave.cpp | 2 ++ tests/test-ggwave.cpp | 6 +++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b150ef9..57a4710 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,7 @@ jobs: run: | make ctest --output-on-failure + ./bin/test-ggwave-cpp --full ubuntu-18_04-python: runs-on: ubuntu-18.04 diff --git a/examples/spectrogram/main.cpp b/examples/spectrogram/main.cpp index c03753d..7b55073 100644 --- a/examples/spectrogram/main.cpp +++ b/examples/spectrogram/main.cpp @@ -214,15 +214,15 @@ bool GGWave_mainLoop() { if (n <= 0) break; if (g_filter2) { - GGWave::filter(GGWAVE_FILTER_FIRST_ORDER_HIGH_PASS, data, g_nSamplesPerFrame, 750.0f, GGWave::kDefaultSampleRate, workF2); + GGWave::filter(GGWAVE_FILTER_FIRST_ORDER_HIGH_PASS, data, g_nSamplesPerFrame, 250.0f, GGWave::kDefaultSampleRate, workF2); } if (g_filter0) { - GGWave::filter(GGWAVE_FILTER_HANN, data, g_nSamplesPerFrame, 750.0f, GGWave::kDefaultSampleRate, workF0); + GGWave::filter(GGWAVE_FILTER_HANN, data, g_nSamplesPerFrame, 250.0f, GGWave::kDefaultSampleRate, workF0); } if (g_filter1) { - GGWave::filter(GGWAVE_FILTER_HAMMING, data, g_nSamplesPerFrame, 750.0f, GGWave::kDefaultSampleRate, workF1); + GGWave::filter(GGWAVE_FILTER_HAMMING, data, g_nSamplesPerFrame, 250.0f, GGWave::kDefaultSampleRate, workF1); } if (GGWave::computeFFTR(data, out, g_nSamplesPerFrame, workI, workF) == false) { diff --git a/src/ggwave.cpp b/src/ggwave.cpp index 3ca8eb1..2030926 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -1672,11 +1672,13 @@ void GGWave::decode_variable() { if ((rsLength.Decode(m_dataEncoded.data(), m_rx.data.data()) == 0) && (m_rx.data[0] > 0 && m_rx.data[0] <= 140)) { knownLength = true; decodedLength = m_rx.data[0]; + //printf("decoded length = %d, recvDuration_frames = %d\n", decodedLength, m_rx.recvDuration_frames); const int nTotalBytesExpected = m_encodedDataOffset + decodedLength + ::getECCBytesForLength(decodedLength); const int nTotalFramesExpected = 2*m_nMarkerFrames + ((nTotalBytesExpected + protocol.bytesPerTx - 1)/protocol.bytesPerTx)*protocol.framesPerTx; if (m_rx.recvDuration_frames > nTotalFramesExpected || m_rx.recvDuration_frames < nTotalFramesExpected - 2*m_nMarkerFrames) { + //printf(" - invalid number of frames: %d (expected %d)\n", m_rx.recvDuration_frames, nTotalFramesExpected); knownLength = false; break; } diff --git a/tests/test-ggwave.cpp b/tests/test-ggwave.cpp index bf8fae3..ead5b6b 100644 --- a/tests/test-ggwave.cpp +++ b/tests/test-ggwave.cpp @@ -265,7 +265,9 @@ 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; + // it seems DSS is not suitable for "variable-length" transmission + // sometimes, the decoder incorrectly detects an early "end" marker when DSS is enabled + //if (rand() % 2 == 0) parameters.operatingMode |= GGWAVE_OPERATING_MODE_USE_DSS; GGWave instance(parameters); instance.rxProtocols().only(GGWave::ProtocolId(protocolId)); @@ -275,6 +277,7 @@ int main(int argc, char ** argv) { printf("Expected = %d, actual = %d\n", expectedSize, nBytes); CHECK(expectedSize == nBytes); { auto p = (const uint8_t *)(instance.txWaveform()); buffer.resize(nBytes); memcpy(buffer.data(), p, nBytes); } + addNoiseHelper(0.02, parameters.sampleFormatOut); // add some artificial noise convertHelper(formatOut, formatInp); instance.decode(buffer.data(), buffer.size()); @@ -303,6 +306,7 @@ int main(int argc, char ** argv) { printf("Expected = %d, actual = %d\n", expectedSize, nBytes); CHECK(expectedSize == nBytes); { auto p = (const uint8_t *)(instance.txWaveform()); buffer.resize(nBytes); memcpy(buffer.data(), p, nBytes); } + addNoiseHelper(0.10, parameters.sampleFormatOut); // add some artificial noise convertHelper(formatOut, formatInp); instance.decode(buffer.data(), buffer.size());