Morse Decoder: adeed scope and set bytes block size appropriately plus minor changes

This commit is contained in:
f4exb 2024-05-19 18:56:18 +02:00
parent 31274b1227
commit 1edaa0d98a
5 changed files with 87 additions and 60 deletions

View File

@ -128,9 +128,13 @@ void MorseDecoder::start()
m_state = StRunning;
m_thread->start();
MorseDecoderWorker::MsgConfigureMorseDecoderWorker *msg
MorseDecoderWorker::MsgConfigureMorseDecoderWorker *msgConfigure
= MorseDecoderWorker::MsgConfigureMorseDecoderWorker::create(m_settings, QList<QString>(), true);
m_worker->getInputMessageQueue()->push(msg);
m_worker->getInputMessageQueue()->push(msgConfigure);
MorseDecoderWorker::MsgConfigureSampleRate *msgSampleRate
= MorseDecoderWorker::MsgConfigureSampleRate::create(m_sampleRate);
m_worker->getInputMessageQueue()->push(msgSampleRate);
if (m_dataPipe)
{
@ -217,6 +221,7 @@ bool MorseDecoder::handleMessage(const Message& cmd)
if (report.getChannelAPI() == m_selectedChannel)
{
m_sampleRate = report.getSampleRate();
qDebug("MorseDecoder::handleMessage: MainCore::MsgChannelDemodReport: %d S/s", m_sampleRate);
if (m_running) {
m_worker->applySampleRate(m_sampleRate);

View File

@ -196,7 +196,7 @@ MorseDecoderGUI::MorseDecoderGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISe
m_scopeVis = m_morseDecoder->getScopeVis();
m_scopeVis->setGLScope(ui->glScope);
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
m_scopeVis->setLiveRate(1484/4.7488);
m_scopeVis->setLiveRate(4800); // 1 second
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));

View File

@ -270,16 +270,26 @@ QString MorseDecoderSettings::formatText(const QString& text)
{
// Format text
QString showText = text.simplified();
QString spaceFirst;
QString spaceLast;
if (text.size() > 3)
if (text.size() >= 2)
{
if (text.right(1)[0].isSpace()) {
showText.append(text.right(1));
spaceLast = text.right(1);
}
if (text.left(1)[0].isSpace()) {
showText = text.left(1) + showText;
spaceFirst = text.left(1);
}
}
if (spaceFirst.size() != 0) {
showText = spaceFirst + showText;
}
if (spaceLast.size() != 0) {
showText.append(spaceLast);
}
return showText;
}

View File

@ -25,6 +25,7 @@
#include "morsedecoderworker.h"
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConfigureMorseDecoderWorker, Message)
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConfigureSampleRate, Message)
MESSAGE_CLASS_DEFINITION(MorseDecoderWorker::MsgConnectFifo, Message)
MorseDecoderWorker::MorseDecoderWorker() :
@ -92,54 +93,28 @@ void MorseDecoderWorker::feedPart(
DataFifo::DataType dataType
)
{
if (dataType != DataFifo::DataTypeI16) {
return;
}
int countBytes = end - begin;
int bytesLeft = m_bytesBufferSize - m_bytesBufferCount;
if (dataType == DataFifo::DataTypeCI16) // (re, im) -> one sample conversion
if (countBytes > m_bytesBufferSize) {
return;
}
if (countBytes >= bytesLeft)
{
countBytes /= 2;
if (countBytes != m_convBuffer.size()) {
m_convBuffer.resize(countBytes);
}
int16_t *s = (int16_t*) begin;
int16_t *b = (int16_t*) m_convBuffer.begin();
for (int is = 0; is < countBytes; is++)
{
int32_t re = s[2*is];
int32_t im = s[2*is+1];
b[is] = (int16_t) ((re+im) / 2);
}
if (countBytes >= bytesLeft)
{
std::copy(m_convBuffer.begin(), m_convBuffer.begin() + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
int unprocessedBytes = processBuffer(m_convBuffer, countBytes);
std::copy(m_convBuffer.begin() + bytesLeft - unprocessedBytes, m_convBuffer.end(), m_bytesBuffer.begin());
m_bytesBufferCount = bytesLeft + unprocessedBytes;
}
else
{
std::copy(m_convBuffer.begin(), m_convBuffer.end(), m_bytesBuffer.begin() + m_bytesBufferCount);
m_bytesBufferCount += countBytes;
}
std::copy(begin, begin + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
int unprocessedBytes = processBuffer(m_bytesBuffer, countBytes);
std::copy(begin + bytesLeft - unprocessedBytes, end, m_bytesBuffer.begin());
m_bytesBufferCount = bytesLeft + unprocessedBytes;
}
else
{
if (countBytes >= bytesLeft)
{
std::copy(begin, begin + bytesLeft, m_bytesBuffer.begin() + m_bytesBufferCount); // fill buffer
int unprocessedBytes = processBuffer(m_bytesBuffer, countBytes);
std::copy(begin + bytesLeft - unprocessedBytes, end, m_bytesBuffer.begin());
m_bytesBufferCount = bytesLeft + unprocessedBytes;
}
else
{
std::copy(begin, end, m_bytesBuffer.begin() + m_bytesBufferCount);
m_bytesBufferCount += countBytes;
}
std::copy(begin, end, m_bytesBuffer.begin() + m_bytesBufferCount);
m_bytesBufferCount += countBytes;
}
}
@ -203,27 +178,31 @@ int MorseDecoderWorker::processBuffer(QByteArray& bytesBuffer, int countBytes)
int traceSize = m_ggMorse->takeSignalF(trace);
std::vector<float> thresholds;
int thrSize = m_ggMorse->takeThresholdF(thresholds);
qDebug("MorseDecoderWorker::processBuffer: traceSize: %d thrSize: %d", traceSize, thrSize);
// qDebug("MorseDecoderWorker::processBuffer: traceSize: %d thrSize: %d", traceSize, thrSize);
int i = 0;
int d = (traceSize / thrSize) + 1;
float ftrace = traceSize / 4800.0f; // interpolation to scope basic trace size
float fthres = thrSize / 4800.0f;
if (traceSize != 0)
{
SampleVector strace;
strace.resize(traceSize);
std::transform(
trace.begin(),
trace.end(),
strace.resize(4800, 0);
std::for_each(
strace.begin(),
[&](float& t) {
float im = thresholds[i/d];
strace.end(),
[&](Sample& s)
{
int itrace = ftrace * i;
int ithres = fthres * i;
float re = trace[itrace];
float im = thresholds[ithres];
i++;
return Sample(t*SDR_RX_SCALEF, im*SDR_RX_SCALEF);
s = Sample(re*SDR_RX_SCALEF, im*SDR_RX_SCALEF);
}
);
std::vector<SampleVector::const_iterator> vbegin;
vbegin.push_back(strace.begin());
m_scopeVis->feed(vbegin, traceSize);
m_scopeVis->feed(vbegin, 4800);
}
}
}
@ -255,6 +234,15 @@ bool MorseDecoderWorker::handleMessage(const Message& cmd)
return true;
}
else if (MsgConfigureSampleRate::match(cmd))
{
QMutexLocker mutexLocker(&m_mutex);
MsgConfigureSampleRate& cfg = (MsgConfigureSampleRate&) cmd;
qDebug("MorseDecoderWorker::handleMessage: MsgConfigureSampleRate");
applySampleRate(cfg.getSampleRate());
return true;
}
else if (MsgConnectFifo::match(cmd))
{
QMutexLocker mutexLocker(&m_mutex);
@ -323,14 +311,18 @@ void MorseDecoderWorker::applySettings(const MorseDecoderSettings& settings, con
void MorseDecoderWorker::applySampleRate(int sampleRate)
{
QMutexLocker mutexLocker(&m_mutex);
m_sinkSampleRate = sampleRate;
m_ggMorseParameters->sampleRateInp = sampleRate;
int ggMorseBlockSize = (sampleRate / GGMorse::kBaseSampleRate)*GGMorse::kDefaultSamplesPerFrame;
// m_bytesBufferSize = (GGMorse::kBaseSampleRate/GGMorse::kDefaultSamplesPerFrame)*ggMorseBlockSize*10; // ~5s
m_bytesBufferSize = sampleRate*9.4976; // + ggMorseBlockSize;
m_bytesBufferSize = 64*ggMorseBlockSize*2;
m_bytesBuffer.resize(m_bytesBufferSize);
m_bytesBufferCount = 0;
float seconds = m_bytesBufferSize/(sampleRate*2.0f);
if (m_scopeVis) {
m_scopeVis->setLiveRate(4800/seconds);
}
qDebug("MorseDecoderWorker::applySampleRate: m_sinkSampleRate: %d ggMorseBlockSize: %d m_bytesBufferSize: %d",
m_sinkSampleRate, ggMorseBlockSize, m_bytesBufferSize);
}

View File

@ -65,6 +65,26 @@ public:
{ }
};
class MsgConfigureSampleRate : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
static MsgConfigureSampleRate* create(int sampleRate)
{
return new MsgConfigureSampleRate(sampleRate);
}
private:
int m_sampleRate;
MsgConfigureSampleRate(int sampleRate) :
Message(),
m_sampleRate(sampleRate)
{ }
};
class MsgConnectFifo : public Message {
MESSAGE_CLASS_DECLARATION