M17 mod: corrected LSF stream type for audio and implemented CAN

pull/1344/head
f4exb 2022-06-30 00:17:31 +02:00
rodzic 6015fce33d
commit 15e3d843f3
6 zmienionych plików z 40 dodań i 93 usunięć

Wyświetl plik

@ -111,7 +111,7 @@ public:
return baseband;
}
static std::array<int8_t, 368> make_lsf(lsf_t& lsf, const std::string& src, const std::string& dest, int8_t can = 10, bool streamElsePacket = false)
static std::array<int8_t, 368> make_lsf(lsf_t& lsf, const std::string& src, const std::string& dest, uint8_t can = 10, bool streamElsePacket = false)
{
lsf.fill(0);
@ -380,6 +380,7 @@ public:
M17Modulator(const std::string& source, const std::string& dest = "") :
source_(encode_callsign(source)),
dest_(encode_callsign(dest)),
can_(10),
rrc(makeFirFilter(rrc_taps))
{ }
@ -398,9 +399,17 @@ public:
dest_ = encode_callsign(callsign);
}
/**
* Set the Channel Access Number (0..15)
*/
void can(uint8_t can) {
can_ = can & 0xF;
}
private:
LinkSetupFrame::encoded_call_t source_;
LinkSetupFrame::encoded_call_t dest_;
uint8_t can_;
BaseFirFilter<150> rrc;
static const std::array<float, 150> rrc_taps;
CRC16<0x5935, 0xFFFF> crc_;

Wyświetl plik

@ -767,6 +767,7 @@ void M17ModGUI::makeUIConnections()
QObject::connect(ui->smsText, &CustomTextEdit::editingFinished, this, &M17ModGUI::on_smsText_editingFinished);
QObject::connect(ui->source, &QLineEdit::editingFinished, this, &M17ModGUI::on_source_editingFinished);
QObject::connect(ui->destination, &QLineEdit::editingFinished, this, &M17ModGUI::on_destination_editingFinished);
QObject::connect(ui->can, QOverload<int>::of(&QSpinBox::valueChanged), this, &M17ModGUI::on_can_valueChanged);
}
void M17ModGUI::updateAbsoluteCenterFrequency()

Wyświetl plik

@ -1314,7 +1314,7 @@
</rect>
</property>
<property name="maximum">
<number>255</number>
<number>15</number>
</property>
<property name="value">
<number>10</number>

Wyświetl plik

@ -22,7 +22,6 @@
#include "m17modprocessor.h"
MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgSendSMS, Message)
MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgSendAudio, Message)
MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgSendAudioFrame, Message)
MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgStartAudio, Message)
MESSAGE_CLASS_DEFINITION(M17ModProcessor::MsgStopAudio, Message)
@ -54,17 +53,10 @@ bool M17ModProcessor::handleMessage(const Message& cmd)
QByteArray packetBytes = notif.getSMSText().toUtf8();
packetBytes.prepend(0x05); // SMS standard type
packetBytes.truncate(798); // Maximum packet size is 798 payload + 2 bytes CRC = 800 bytes (32*25)
processPacket(notif.getSourceCall(), notif.getDestCall(), packetBytes);
processPacket(notif.getSourceCall(), notif.getDestCall(), notif.getCAN(), packetBytes);
// test(notif.getSourceCall(), notif.getDestCall());
return true;
}
else if (MsgSendAudio::match(cmd))
{
MsgSendAudio& notif = (MsgSendAudio&) cmd;
// qDebug("M17ModProcessor::handleMessage: MsgSendAudio: %lu samples", notif.getAudioBuffer().size());
processAudio(notif.getAudioBuffer());
return true;
}
else if (MsgSendAudioFrame::match(cmd))
{
MsgSendAudioFrame& notif = (MsgSendAudioFrame&) cmd;
@ -77,7 +69,7 @@ bool M17ModProcessor::handleMessage(const Message& cmd)
MsgStartAudio& notif = (MsgStartAudio&) cmd;
qDebug("M17ModProcessor::handleMessage: MsgStartAudio: %s to %s",
qPrintable(notif.getSourceCall()), qPrintable(notif.getDestCall()));
audioStart(notif.getSourceCall(), notif.getDestCall());
audioStart(notif.getSourceCall(), notif.getDestCall(), notif.getCAN());
return true;
}
else if (MsgStopAudio::match(cmd))
@ -113,7 +105,7 @@ void M17ModProcessor::test(const QString& sourceCall, const QString& destCall)
}
}
void M17ModProcessor::processPacket(const QString& sourceCall, const QString& destCall, const QByteArray& packetBytes)
void M17ModProcessor::processPacket(const QString& sourceCall, const QString& destCall, uint8_t can, const QByteArray& packetBytes)
{
qDebug("M17ModProcessor::processPacket: %s to %s: %s", qPrintable(sourceCall), qPrintable(destCall), qPrintable(packetBytes));
m_m17Modulator.source(sourceCall.toStdString());
@ -123,7 +115,7 @@ void M17ModProcessor::processPacket(const QString& sourceCall, const QString& de
// LSF
std::array<uint8_t, 30> lsf;
std::array<int8_t, 368> lsf_frame = mobilinkd::M17Modulator::make_lsf(lsf, sourceCall.toStdString(), destCall.toStdString());
std::array<int8_t, 368> lsf_frame = mobilinkd::M17Modulator::make_lsf(lsf, sourceCall.toStdString(), destCall.toStdString(), can);
output_baseband(mobilinkd::M17Modulator::LSF_SYNC_WORD, lsf_frame);
// Packets
@ -150,18 +142,19 @@ void M17ModProcessor::processPacket(const QString& sourceCall, const QString& de
send_eot(); // EOT
}
void M17ModProcessor::audioStart(const QString& sourceCall, const QString& destCall)
void M17ModProcessor::audioStart(const QString& sourceCall, const QString& destCall, uint8_t can)
{
qDebug("M17ModProcessor::audioStart");
m_m17Modulator.source(sourceCall.toStdString());
m_m17Modulator.dest(destCall.toStdString());
m_m17Modulator.can(can);
m_audioFrameNumber = 0;
send_preamble(); // preamble
// LSF
std::array<uint8_t, 30> lsf;
std::array<int8_t, 368> lsf_frame = mobilinkd::M17Modulator::make_lsf(lsf, sourceCall.toStdString(), destCall.toStdString());
std::array<int8_t, 368> lsf_frame = mobilinkd::M17Modulator::make_lsf(lsf, sourceCall.toStdString(), destCall.toStdString(), can, true);
output_baseband(mobilinkd::M17Modulator::LSF_SYNC_WORD, lsf_frame);
// Prepare LICH
@ -197,46 +190,6 @@ void M17ModProcessor::send_preamble()
m_basebandFifo.write(preamble_baseband.data(), 1920);
}
void M17ModProcessor::processAudio(const std::vector<int16_t>& audioBuffer)
{
int audioBufferRemainder = audioBuffer.size();
std::vector<int16_t>::const_iterator audioBufferIt = audioBuffer.begin();
int audioFrameRemainder = m_audioFrame.size() - m_audioFrameIndex;
if (audioBufferRemainder < audioFrameRemainder) {
qDebug("M17ModProcessor::processAudio: too few samples: %d/%d", audioBufferRemainder, audioFrameRemainder);
}
while (audioBufferRemainder >= (int) m_audioFrame.size())
{
m_audioFrame.fill(0);
std::copy(
audioBufferIt,
audioBufferIt + audioFrameRemainder,
m_audioFrame.begin() + m_audioFrameIndex);
if (m_basebandFifo.getFill() < m_basebandFifoHigh) {
processAudioFrame();
}
if (m_basebandFifo.getFill() < m_basebandFifoLow)
{
qDebug("M17ModProcessor::processAudio: repeat frame: %d", m_basebandFifo.getFill());
// m_audioFrame.fill(0);
processAudioFrame();
}
audioBufferRemainder -= audioFrameRemainder;
audioBufferIt += audioFrameRemainder;
m_audioFrameIndex = 0;
audioFrameRemainder = m_audioFrame.size();
}
std::copy(audioBufferIt, audioBuffer.end(), m_audioFrame.begin());
m_audioFrameIndex = audioBufferRemainder;
}
void M17ModProcessor::processAudioFrame()
{
std::array<uint8_t, 16> audioPayload = encodeAudio(m_audioFrame);
@ -265,7 +218,6 @@ std::array<uint8_t, 16> M17ModProcessor::encodeAudio(std::array<int16_t, 320*6>&
std::array<int16_t, 320> audioFrame8k;
m_decimator.decimate(audioFrame.data(), audioFrame8k.data(), 320);
std::array<uint8_t, 16> result;
// result.fill(0); // test
codec2_encode(m_codec2, &result[0], const_cast<int16_t*>(&audioFrame8k[0]));
codec2_encode(m_codec2, &result[8], const_cast<int16_t*>(&audioFrame8k[160]));
return result;

Wyświetl plik

@ -38,49 +38,28 @@ public:
public:
const QString& getSourceCall() const { return m_sourceCall; }
const QString& getDestCall() const { return m_destCall; }
uint8_t getCAN() const { return m_can; }
const QString& getSMSText() const { return m_smsText; }
static MsgSendSMS* create(const QString& sourceCall, const QString& destCall, const QString& smsText) {
return new MsgSendSMS(sourceCall, destCall, smsText);
static MsgSendSMS* create(const QString& sourceCall, const QString& destCall, uint8_t can, const QString& smsText) {
return new MsgSendSMS(sourceCall, destCall, can, smsText);
}
private:
QString m_sourceCall;
QString m_destCall;
uint8_t m_can;
QString m_smsText;
MsgSendSMS(const QString& sourceCall, const QString& destCall, const QString& smsText) :
MsgSendSMS(const QString& sourceCall, const QString& destCall, uint8_t can, const QString& smsText) :
Message(),
m_sourceCall(sourceCall),
m_destCall(destCall),
m_can(can),
m_smsText(smsText)
{ }
};
class MsgSendAudio : public Message {
MESSAGE_CLASS_DECLARATION
public:
const QString& getSourceCall() const { return m_sourceCall; }
const QString& getDestCall() const { return m_destCall; }
std::vector<int16_t>& getAudioBuffer() { return m_audioBuffer; }
static MsgSendAudio* create(const QString& sourceCall, const QString& destCall) {
return new MsgSendAudio(sourceCall, destCall);
}
private:
QString m_sourceCall;
QString m_destCall;
std::vector<int16_t> m_audioBuffer;
MsgSendAudio(const QString& sourceCall, const QString& destCall) :
Message(),
m_sourceCall(sourceCall),
m_destCall(destCall)
{ }
};
class MsgSendAudioFrame : public Message {
MESSAGE_CLASS_DECLARATION
@ -111,19 +90,22 @@ public:
public:
const QString& getSourceCall() const { return m_sourceCall; }
const QString& getDestCall() const { return m_destCall; }
uint8_t getCAN() const { return m_can; }
static MsgStartAudio* create(const QString& sourceCall, const QString& destCall) {
return new MsgStartAudio(sourceCall, destCall);
static MsgStartAudio* create(const QString& sourceCall, const QString& destCall, uint8_t can) {
return new MsgStartAudio(sourceCall, destCall, can);
}
private:
QString m_sourceCall;
QString m_destCall;
uint8_t m_can;
MsgStartAudio(const QString& sourceCall, const QString& destCall) :
MsgStartAudio(const QString& sourceCall, const QString& destCall, uint8_t can) :
Message(),
m_sourceCall(sourceCall),
m_destCall(destCall)
m_destCall(destCall),
m_can(can)
{ }
};
@ -163,10 +145,9 @@ private:
struct CODEC2 *m_codec2;
bool handleMessage(const Message& cmd);
void processPacket(const QString& sourceCall, const QString& destCall, const QByteArray& packetBytes);
void audioStart(const QString& sourceCall, const QString& destCall);
void processPacket(const QString& sourceCall, const QString& destCall, uint8_t can, const QByteArray& packetBytes);
void audioStart(const QString& sourceCall, const QString& destCall, uint8_t can);
void audioStop();
void processAudio(const std::vector<int16_t>& audioBuffer);
void processAudioFrame();
std::array<uint8_t, 16> encodeAudio(std::array<int16_t, 320*6>& audioFrame);
void test(const QString& sourceCall, const QString& destCall);

Wyświetl plik

@ -231,7 +231,7 @@ void M17ModSource::pullAF(Real& sample, bool& carrier)
{
if (m_settings.m_audioType == M17ModSettings::AudioFile)
{
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
// sox f4exb_call.wav --encoding float --endian little --rate 48k f4exb_call.raw
// ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw
if (m_ifstream && m_ifstream->is_open())
{
@ -287,7 +287,10 @@ void M17ModSource::pullM17(Real& sample, bool& carrier)
{
if (!m_m17PullAudio)
{
M17ModProcessor::MsgStartAudio *msg = M17ModProcessor::MsgStartAudio::create(m_settings.m_sourceCall, m_settings.m_destCall);
M17ModProcessor::MsgStartAudio *msg = M17ModProcessor::MsgStartAudio::create(
m_settings.m_sourceCall,
m_settings.m_destCall,
m_settings.m_can);
m_processor->getInputMessageQueue()->push(msg);
m_m17PullAudio = true;
}
@ -569,6 +572,7 @@ void M17ModSource::sendPacket()
M17ModProcessor::MsgSendSMS *msg = M17ModProcessor::MsgSendSMS::create(
m_settings.m_sourceCall,
m_settings.m_destCall,
m_settings.m_can,
m_settings.m_smsText
);
m_processor->getInputMessageQueue()->push(msg);