diff --git a/plugins/channeltx/modm17/CMakeLists.txt b/plugins/channeltx/modm17/CMakeLists.txt
index 82d0a789a..97e2ad3ff 100644
--- a/plugins/channeltx/modm17/CMakeLists.txt
+++ b/plugins/channeltx/modm17/CMakeLists.txt
@@ -5,6 +5,7 @@ set(modm17_SOURCES
m17modbaseband.cpp
m17modsource.cpp
m17modprocessor.cpp
+ m17modfifo.cpp
m17modplugin.cpp
m17modsettings.cpp
m17modwebapiadapter.cpp
@@ -15,6 +16,7 @@ set(modm17_HEADERS
m17modbaseband.h
m17modsource.h
m17modprocessor.h
+ m17modfifo.h
m17modplugin.h
m17modsettings.h
m17modwebapiadapter.h
diff --git a/plugins/channeltx/modm17/m17modfifo.cpp b/plugins/channeltx/modm17/m17modfifo.cpp
new file mode 100644
index 000000000..128baadbe
--- /dev/null
+++ b/plugins/channeltx/modm17/m17modfifo.cpp
@@ -0,0 +1,114 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2022 Edouard Griffiths, F4EXB //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation as version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License V3 for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#include "m17modfifo.h"
+
+M17ModFIFO::M17ModFIFO() :
+ m_fifo(nullptr)
+{
+ m_size = 0;
+ m_writeIndex = 0;
+ m_readIndex = 0;
+}
+
+M17ModFIFO::M17ModFIFO(uint32_t numSamples) :
+ m_fifo(nullptr)
+{
+ QMutexLocker mutexLocker(&m_mutex);
+ create(numSamples);
+}
+
+M17ModFIFO::~M17ModFIFO()
+{
+ QMutexLocker mutexLocker(&m_mutex);
+
+ if (m_fifo)
+ {
+ delete[] m_fifo;
+ m_fifo = nullptr;
+ }
+
+ m_size = 0;
+}
+
+void M17ModFIFO::setSize(uint32_t numSamples)
+{
+ QMutexLocker mutexLocker(&m_mutex);
+ create(numSamples);
+}
+
+void M17ModFIFO::create(uint32_t numSamples)
+{
+ if (m_fifo)
+ {
+ delete[] m_fifo;
+ m_fifo = nullptr;
+ }
+
+ m_writeIndex = 0;
+ m_readIndex = 0;
+
+ m_fifo = new int16_t[numSamples];
+ m_size = numSamples;
+}
+
+uint32_t M17ModFIFO::write(const int16_t* data, uint32_t numSamples)
+{
+ QMutexLocker mutexLocker(&m_mutex);
+
+ if (m_readIndex > m_writeIndex)
+ {
+ int rem = m_readIndex - m_writeIndex;
+ int written = std::min(rem, (int) numSamples);
+ std::copy(data, data + written, &m_fifo[m_writeIndex]);
+ m_writeIndex += written;
+ return written;
+ }
+
+ int remSize = m_size - m_writeIndex;
+ int written = std::min(remSize, (int) numSamples);
+ std::copy(data, data + written, &m_fifo[m_writeIndex]);
+ m_writeIndex += written;
+ m_writeIndex = m_writeIndex == (int) m_size ? 0 : m_writeIndex;
+
+ if (written == (int) numSamples) {
+ return written;
+ }
+
+ // wrap
+ int remWrite = (int) numSamples - written;
+ int remWritten = std::min(remWrite, m_readIndex);
+ std::copy(data + written, data + written + remWritten, m_fifo);
+ m_writeIndex = remWritten;
+ return written + remWritten;
+}
+
+uint32_t M17ModFIFO::readOne(int16_t* data)
+{
+ QMutexLocker mutexLocker(&m_mutex);
+
+ if (m_readIndex == m_writeIndex)
+ {
+ *data = 0;
+ return 0;
+ }
+
+ *data = m_fifo[m_readIndex++];
+ m_readIndex = m_readIndex == (int) m_size ? 0 : m_readIndex;
+ return 1;
+}
+
diff --git a/plugins/channeltx/modm17/m17modfifo.h b/plugins/channeltx/modm17/m17modfifo.h
new file mode 100644
index 000000000..84e95fe21
--- /dev/null
+++ b/plugins/channeltx/modm17/m17modfifo.h
@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2022 Edouard Griffiths, F4EXB //
+// //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation as version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License V3 for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef PLUGINS_CHANNELTX_MODM17_M17MODFIFO_H_
+#define PLUGINS_CHANNELTX_MODM17_M17MODFIFO_H_
+
+#include
+#include
+
+class M17ModFIFO: public QObject
+{
+ Q_OBJECT
+public:
+ M17ModFIFO();
+ M17ModFIFO(uint32_t numSamples);
+ ~M17ModFIFO();
+
+ void setSize(uint32_t numSamples);
+ uint32_t write(const int16_t* data, uint32_t numSamples);
+ uint32_t readOne(int16_t* data);
+
+private:
+ QMutex m_mutex;
+ int16_t* m_fifo;
+ uint32_t m_size;
+ int m_writeIndex;
+ int m_readIndex;
+
+ void create(uint32_t numSamples);
+};
+
+
+#endif // PLUGINS_CHANNELTX_MODM17_M17MODFIFO_H_
diff --git a/plugins/channeltx/modm17/m17modprocessor.cpp b/plugins/channeltx/modm17/m17modprocessor.cpp
index 2ef296589..070ce03e7 100644
--- a/plugins/channeltx/modm17/m17modprocessor.cpp
+++ b/plugins/channeltx/modm17/m17modprocessor.cpp
@@ -24,7 +24,7 @@ MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgSendSMS, Message)
M17ModProcessor::M17ModProcessor() :
m_m17Modulator("MYCALL", "")
{
- m_basebandFifo.setSampleSize(sizeof(int16_t), 96000);
+ m_basebandFifo.setSize(96000);
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
}
@@ -114,7 +114,7 @@ void M17ModProcessor::send_preamble()
preamble_bytes.fill(0x77);
std::array preamble_symbols = mobilinkd::M17Modulator::bytes_to_symbols(preamble_bytes);
std::array preamble_baseband = m_m17Modulator.symbols_to_baseband(preamble_symbols);
- m_basebandFifo.write((const quint8*) preamble_baseband.data(), 1920);
+ m_basebandFifo.write(preamble_baseband.data(), 1920);
}
void M17ModProcessor::send_eot()
@@ -128,7 +128,7 @@ void M17ModProcessor::send_eot()
std::array eot_symbols = mobilinkd::M17Modulator::bytes_to_symbols(eot_bytes);
std::array eot_baseband = m_m17Modulator.symbols_to_baseband(eot_symbols);
- m_basebandFifo.write((const quint8*) eot_baseband.data(), 1920);
+ m_basebandFifo.write(eot_baseband.data(), 1920);
}
void M17ModProcessor::output_baseband(std::array sync_word, const std::array& frame)
@@ -140,5 +140,5 @@ void M17ModProcessor::output_baseband(std::array sync_word, const st
auto fit = std::copy(sw.begin(), sw.end(), temp.begin()); // start with sync word dibits
std::copy(symbols.begin(), symbols.end(), fit); // then the frame dibits
std::array baseband = m_m17Modulator.symbols_to_baseband(temp); // 1920 48 kS/s int16_t samples
- m_basebandFifo.write((const quint8*) baseband.data(), 1920);
+ m_basebandFifo.write(baseband.data(), 1920);
}
diff --git a/plugins/channeltx/modm17/m17modprocessor.h b/plugins/channeltx/modm17/m17modprocessor.h
index 5492b3e28..72331a13f 100644
--- a/plugins/channeltx/modm17/m17modprocessor.h
+++ b/plugins/channeltx/modm17/m17modprocessor.h
@@ -24,7 +24,7 @@
#include "m17/M17Modulator.h"
#include "util/message.h"
#include "util/messagequeue.h"
-#include "audio/audiofifo.h"
+#include "m17modfifo.h"
class M17ModProcessor : public QObject
{
@@ -59,11 +59,11 @@ public:
~M17ModProcessor();
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
- AudioFifo *getBasebandFifo() { return &m_basebandFifo; }
+ M17ModFIFO *getBasebandFifo() { return &m_basebandFifo; }
private:
MessageQueue m_inputMessageQueue;
- AudioFifo m_basebandFifo; //!< Samples are 16 bit integer baseband 48 kS/s samples
+ M17ModFIFO m_basebandFifo; //!< Samples are 16 bit integer baseband 48 kS/s samples
mobilinkd::M17Modulator m_m17Modulator;
bool handleMessage(const Message& cmd);
diff --git a/plugins/channeltx/modm17/m17modsource.cpp b/plugins/channeltx/modm17/m17modsource.cpp
index 2235d4ee6..d87e6ed5a 100644
--- a/plugins/channeltx/modm17/m17modsource.cpp
+++ b/plugins/channeltx/modm17/m17modsource.cpp
@@ -272,9 +272,8 @@ void M17ModSource::pullAF(Real& sample, bool& carrier)
void M17ModSource::pullM17(Real& sample, bool& carrier)
{
- quint8 bbSampleBytes[2];
- carrier = m_processor->getBasebandFifo()->readOne(bbSampleBytes);
- int16_t basbandSample = bbSampleBytes[0] | (bbSampleBytes[1]<<8);
+ int16_t basbandSample;
+ carrier = m_processor->getBasebandFifo()->readOne(&basbandSample) != 0;
if (carrier)
{