mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-05 15:34:57 -04:00
IQ swap: initial implementation in plugins
This commit is contained in:
@@ -52,7 +52,7 @@ MESSAGE_CLASS_DEFINITION(XTRXInput::MsgStartStop, Message)
|
||||
XTRXInput::XTRXInput(DeviceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_XTRXInputThread(0),
|
||||
m_XTRXInputThread(nullptr),
|
||||
m_deviceDescription("XTRXInput"),
|
||||
m_running(false)
|
||||
{
|
||||
@@ -201,9 +201,9 @@ void XTRXInput::init()
|
||||
|
||||
XTRXInputThread *XTRXInput::findThread()
|
||||
{
|
||||
if (m_XTRXInputThread == 0) // this does not own the thread
|
||||
if (!m_XTRXInputThread) // this does not own the thread
|
||||
{
|
||||
XTRXInputThread *xtrxInputThread = 0;
|
||||
XTRXInputThread *xtrxInputThread = nullptr;
|
||||
|
||||
// find a buddy that has allocated the thread
|
||||
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
||||
@@ -243,7 +243,7 @@ void XTRXInput::moveThreadToBuddy()
|
||||
if (buddySource)
|
||||
{
|
||||
buddySource->setThread(m_XTRXInputThread);
|
||||
m_XTRXInputThread = 0; // zero for others
|
||||
m_XTRXInputThread = nullptr; // zero for others
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,8 +308,9 @@ bool XTRXInput::start()
|
||||
xtrxInputThread->stopWork();
|
||||
delete xtrxInputThread;
|
||||
xtrxInputThread = new XTRXInputThread(m_deviceShared.m_dev->getDevice(), 2); // MI mode (2 channels)
|
||||
m_XTRXInputThread = xtrxInputThread; // take ownership
|
||||
xtrxInputThread->setIQOrder(m_settings.m_iqOrder);
|
||||
m_deviceShared.m_thread = xtrxInputThread;
|
||||
m_XTRXInputThread = xtrxInputThread; // take ownership
|
||||
|
||||
for (int i = 0; i < 2; i++) // restore original FIFO references
|
||||
{
|
||||
@@ -394,8 +395,8 @@ void XTRXInput::stop()
|
||||
qDebug("XTRXInput::stop: SI mode. Just stop and delete the thread");
|
||||
xtrxInputThread->stopWork();
|
||||
delete xtrxInputThread;
|
||||
m_XTRXInputThread = 0;
|
||||
m_deviceShared.m_thread = 0;
|
||||
m_XTRXInputThread = nullptr;
|
||||
m_deviceShared.m_thread = nullptr;
|
||||
|
||||
// remove old thread address from buddies (reset in all buddies)
|
||||
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
||||
@@ -410,6 +411,7 @@ void XTRXInput::stop()
|
||||
m_XTRXInputThread = xtrxInputThread; // take ownership
|
||||
m_deviceShared.m_thread = xtrxInputThread;
|
||||
|
||||
xtrxInputThread->setIQOrder(m_settings.m_iqOrder);
|
||||
xtrxInputThread->setFifo(requestedChannel, &m_sampleFifo);
|
||||
xtrxInputThread->setLog2Decimation(requestedChannel, m_settings.m_log2SoftDecim);
|
||||
|
||||
@@ -1040,6 +1042,17 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_iqOrder != settings.m_iqOrder) || force)
|
||||
{
|
||||
reverseAPIKeys.append("iqOrder");
|
||||
|
||||
if (inputThread)
|
||||
{
|
||||
inputThread->setIQOrder(settings.m_iqOrder);
|
||||
qDebug() << "XTRXInput::applySettings: set IQ order to " << (settings.m_iqOrder ? "IQ" : "QI");
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_antennaPath != settings.m_antennaPath) || force)
|
||||
{
|
||||
reverseAPIKeys.append("antennaPath");
|
||||
|
||||
@@ -43,6 +43,7 @@ void XTRXInputSettings::resetToDefaults()
|
||||
m_extClock = false;
|
||||
m_extClockFreq = 0; // Auto
|
||||
m_pwrmode = 1;
|
||||
m_iqOrder = true;
|
||||
m_fileRecordName = "";
|
||||
m_useReverseAPI = false;
|
||||
m_reverseAPIAddress = "127.0.0.1";
|
||||
@@ -76,6 +77,7 @@ QByteArray XTRXInputSettings::serialize() const
|
||||
s.writeString(23, m_reverseAPIAddress);
|
||||
s.writeU32(24, m_reverseAPIPort);
|
||||
s.writeU32(25, m_reverseAPIDeviceIndex);
|
||||
s.writeBool(26, m_iqOrder);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
@@ -127,6 +129,7 @@ bool XTRXInputSettings::deserialize(const QByteArray& data)
|
||||
|
||||
d.readU32(25, &uintval, 0);
|
||||
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
|
||||
d.readBool(26, &m_iqOrder, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ struct XTRXInputSettings
|
||||
bool m_extClock; //!< True if external clock source
|
||||
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
|
||||
uint32_t m_pwrmode;
|
||||
bool m_iqOrder;
|
||||
QString m_fileRecordName;
|
||||
bool m_useReverseAPI;
|
||||
QString m_reverseAPIAddress;
|
||||
|
||||
@@ -29,7 +29,8 @@ XTRXInputThread::XTRXInputThread(struct xtrx_dev *dev, unsigned int nbChannels,
|
||||
m_running(false),
|
||||
m_dev(dev),
|
||||
m_nbChannels(nbChannels),
|
||||
m_uniqueChannelIndex(uniqueChannelIndex)
|
||||
m_uniqueChannelIndex(uniqueChannelIndex),
|
||||
m_iqOrder(true)
|
||||
{
|
||||
qDebug("XTRXInputThread::XTRXInputThread: nbChannels: %u uniqueChannelIndex: %u", nbChannels, uniqueChannelIndex);
|
||||
m_channels = new Channel[2];
|
||||
@@ -150,10 +151,17 @@ void XTRXInputThread::run()
|
||||
qDebug("XTRXInputThread::run: overflow");
|
||||
}
|
||||
|
||||
if (m_nbChannels > 1) {
|
||||
if (m_nbChannels > 1)
|
||||
{
|
||||
callbackMI((const qint16*) buffs[0], (const qint16*) buffs[1], 2 * nfo.out_samples);
|
||||
} else {
|
||||
callbackSI((const qint16*) buffs[0], 2 * nfo.out_samples);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_iqOrder) {
|
||||
callbackSIIQ((const qint16*) buffs[0], 2 * nfo.out_samples);
|
||||
} else {
|
||||
callbackSIQI((const qint16*) buffs[0], 2 * nfo.out_samples);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,35 +231,73 @@ SampleSinkFifo *XTRXInputThread::getFifo(unsigned int channel)
|
||||
}
|
||||
}
|
||||
|
||||
void XTRXInputThread::callbackSI(const qint16* buf, qint32 len)
|
||||
void XTRXInputThread::callbackSIIQ(const qint16* buf, qint32 len)
|
||||
{
|
||||
SampleVector::iterator it = m_channels[m_uniqueChannelIndex].m_convertBuffer.begin();
|
||||
|
||||
if (m_channels[m_uniqueChannelIndex].m_log2Decim == 0)
|
||||
{
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate1(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate1(&it, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_channels[m_uniqueChannelIndex].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate2_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate2_cen(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate4_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate4_cen(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate8_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate8_cen(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate16_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate16_cen(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate32_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate32_cen(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[m_uniqueChannelIndex].m_decimators.decimate64_cen(&it, buf, len);
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsIQ.decimate64_cen(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_channels[m_uniqueChannelIndex].m_sampleFifo->write(m_channels[m_uniqueChannelIndex].m_convertBuffer.begin(), it);
|
||||
}
|
||||
|
||||
void XTRXInputThread::callbackSIQI(const qint16* buf, qint32 len)
|
||||
{
|
||||
SampleVector::iterator it = m_channels[m_uniqueChannelIndex].m_convertBuffer.begin();
|
||||
|
||||
if (m_channels[m_uniqueChannelIndex].m_log2Decim == 0)
|
||||
{
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate1(&it, buf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_channels[m_uniqueChannelIndex].m_log2Decim)
|
||||
{
|
||||
case 1:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate2_cen(&it, buf, len);
|
||||
break;
|
||||
case 2:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate4_cen(&it, buf, len);
|
||||
break;
|
||||
case 3:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate8_cen(&it, buf, len);
|
||||
break;
|
||||
case 4:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate16_cen(&it, buf, len);
|
||||
break;
|
||||
case 5:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate32_cen(&it, buf, len);
|
||||
break;
|
||||
case 6:
|
||||
m_channels[m_uniqueChannelIndex].m_decimatorsQI.decimate64_cen(&it, buf, len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -267,10 +313,21 @@ void XTRXInputThread::callbackMI(const qint16* buf0, const qint16* buf1, qint32
|
||||
|
||||
// channel 0
|
||||
m_uniqueChannelIndex = 0;
|
||||
callbackSI(buf0, len);
|
||||
|
||||
if (m_iqOrder) {
|
||||
callbackSIIQ(buf0, len);
|
||||
} else {
|
||||
callbackSIQI(buf0, len);
|
||||
}
|
||||
|
||||
// channel 1
|
||||
m_uniqueChannelIndex = 1;
|
||||
callbackSI(buf1, len);
|
||||
|
||||
if (m_iqOrder) {
|
||||
callbackSIIQ(buf1, len);
|
||||
} else {
|
||||
callbackSIQI(buf1, len);
|
||||
}
|
||||
|
||||
m_uniqueChannelIndex = uniqueChannelIndex;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
unsigned int getLog2Decimation(unsigned int channel) const;
|
||||
void setFifo(unsigned int channel, SampleSinkFifo *sampleFifo);
|
||||
SampleSinkFifo *getFifo(unsigned int channel);
|
||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||
|
||||
private:
|
||||
struct Channel
|
||||
@@ -54,7 +55,8 @@ private:
|
||||
SampleVector m_convertBuffer;
|
||||
SampleSinkFifo* m_sampleFifo;
|
||||
unsigned int m_log2Decim;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, true> m_decimatorsIQ;
|
||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, false> m_decimatorsQI;
|
||||
|
||||
Channel() :
|
||||
m_sampleFifo(0),
|
||||
@@ -73,10 +75,12 @@ private:
|
||||
Channel *m_channels; //!< Array of channels dynamically allocated for the given number of Rx channels
|
||||
unsigned int m_nbChannels;
|
||||
unsigned int m_uniqueChannelIndex;
|
||||
bool m_iqOrder;
|
||||
|
||||
void run();
|
||||
unsigned int getNbFifos();
|
||||
void callbackSI(const qint16* buf, qint32 len);
|
||||
void callbackSIQI(const qint16* buf, qint32 len);
|
||||
void callbackSIIQ(const qint16* buf, qint32 len);
|
||||
void callbackMI(const qint16* buf0, const qint16* buf1, qint32 len);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user