1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-04-10 21:50:10 -04:00

M17 mod: fixed FIFO

This commit is contained in:
f4exb 2022-06-18 06:15:54 +02:00
parent 6b863287d8
commit 9738e986c2
6 changed files with 172 additions and 10 deletions

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
}

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_CHANNELTX_MODM17_M17MODFIFO_H_
#define PLUGINS_CHANNELTX_MODM17_M17MODFIFO_H_
#include <QObject>
#include <QMutex>
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_

View File

@ -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<int8_t, 192> preamble_symbols = mobilinkd::M17Modulator::bytes_to_symbols(preamble_bytes);
std::array<int16_t, 1920> 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<int8_t, 192> eot_symbols = mobilinkd::M17Modulator::bytes_to_symbols(eot_bytes);
std::array<int16_t, 1920> 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<uint8_t, 2> sync_word, const std::array<int8_t, 368>& frame)
@ -140,5 +140,5 @@ void M17ModProcessor::output_baseband(std::array<uint8_t, 2> 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<int16_t, 1920> 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);
}

View File

@ -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);

View File

@ -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)
{