diff --git a/examples/arduino-rx/arduino-rx.ino b/examples/arduino-rx/arduino-rx.ino index b9e4bdf..2f850e8 100644 --- a/examples/arduino-rx/arduino-rx.ino +++ b/examples/arduino-rx/arduino-rx.ino @@ -53,7 +53,7 @@ void loop() { p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16; p.samplesPerFrame = 128; p.payloadLength = 16; - p.operatingMode = GGWAVE_OPERATING_MODE_RX; + p.operatingMode = (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_RX | GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES); GGWave ggwave(p); ggwave.setRxProtocols({ @@ -105,6 +105,25 @@ void loop() { Serial.println(tEnd - tStart); Serial.println(nr); Serial.println((char *)result.data()); + + if (strcmp((char *)result.data(), "test") == 0) { + ggwave.init("hello", ggwave.getTxProtocol(GGWAVE_TX_PROTOCOL_MT_FASTEST)); + ggwave.encode(nullptr); + + const auto & waveformTones = ggwave.getWaveformTones(); + for (int i = 0; i < (int) waveformTones.size(); ++i) { + Serial.print(" - frame "); + Serial.print(i); + Serial.print(", "); + Serial.print(waveformTones[i].size()); + Serial.print(": "); + for (int j = 0; j < (int) waveformTones[i].size(); ++j) { + Serial.print((int)(waveformTones[i][j].freq_hz)); + Serial.print(" "); + } + Serial.println(); + } + } } } if (err > 0) { diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index 429f3c9..fc6afa6 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -364,8 +364,8 @@ public: } struct ToneData { - double freq_hz; - double duration_ms; + float freq_hz; + float duration_ms; }; using Tones = std::vector; diff --git a/src/ggwave.cpp b/src/ggwave.cpp index 8843893..afb281b 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -543,10 +543,12 @@ GGWave::GGWave(const Parameters & parameters) : if (m_isTxEnabled) { m_tx = std::unique_ptr(new Tx()); - { - const int maxDataBits = 2*16*maxBytesPerTx(); + const int maxDataBits = 2*16*maxBytesPerTx(); - m_tx->dataBits.resize(maxDataBits); + m_tx->txData.resize(kMaxDataSize); + m_tx->dataBits.resize(maxDataBits); + + if (m_txOnlyTones == false) { m_tx->phaseOffsets.resize(maxDataBits); m_tx->bit0Amplitude.resize(maxDataBits); for (auto & a : m_tx->bit0Amplitude) { @@ -556,13 +558,12 @@ GGWave::GGWave(const Parameters & parameters) : for (auto & a : m_tx->bit1Amplitude) { a.resize(m_samplesPerFrame); } - } - m_tx->txData.resize(kMaxDataSize); - m_tx->outputBlock.resize(m_samplesPerFrame), - m_tx->outputBlockResampled.resize(2*m_samplesPerFrame), - m_tx->outputBlockTmp.resize(kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut), - m_tx->outputBlockI16.resize(kMaxRecordedFrames*m_samplesPerFrame); + m_tx->outputBlock.resize(m_samplesPerFrame); + m_tx->outputBlockResampled.resize(2*m_samplesPerFrame); + m_tx->outputBlockTmp.resize(kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut); + m_tx->outputBlockI16.resize(kMaxRecordedFrames*m_samplesPerFrame); + } // TODO // m_tx->waveformTones; @@ -797,6 +798,7 @@ bool GGWave::encode(const CBWaveformOut & cbWaveformOut) { } if (m_txOnlyTones) { + m_tx->hasNewTxData = false; return true; } }